Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LevelableItemsLoader extends SimpleJsonResourceReloadListener {
- private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
- public LevelableItemsLoader() {
- super(GSON, "levelable_items");
- }
- private Map<ResourceLocation, Item> itemmap = ImmutableMap.of();
- @Override
- protected void apply(Map<ResourceLocation, JsonElement> jsonMap, ResourceManager pResourceManager, ProfilerFiller pProfiler) {
- ImmutableMap.Builder<ResourceLocation, Item> builder = ImmutableMap.builder();
- jsonMap.forEach((resourceLocation, jsonElement) -> {
- try {
- JsonObject jsonObject = jsonElement.getAsJsonObject();
- String keyString = resourceLocation.getPath();
- WeaponLeveling.LOGGER.info("This is the path: " + keyString);
- if(ForgeRegistries.ITEMS.containsKey(resourceLocation)) {
- Item item = ForgeRegistries.ITEMS.getValue(resourceLocation);
- builder.put(resourceLocation, item);
- } else WeaponLeveling.LOGGER.error("{} is not a valid Item", resourceLocation);
- }catch (IllegalArgumentException | JsonParseException jsonparseexception) {
- WeaponLeveling.LOGGER.error("Parsing error loading Item Levels {}: {}", resourceLocation, jsonparseexception.getMessage());
- }});
- Map<ResourceLocation, Item> map = builder.build();
- this.itemmap = map;
- }
- public Item get(ResourceLocation resourceLocation) {
- return this.itemmap.get(resourceLocation);
- }
- public boolean contains(Item item) {
- return get(item.getRegistryName()) != null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement