Advertisement
GeradesoLukas

Untitled

Oct 20th, 2022
1,169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1.  
  2. public class LevelableItemsLoader extends SimpleJsonResourceReloadListener {
  3.  
  4.     private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
  5.  
  6.     public LevelableItemsLoader() {
  7.         super(GSON, "levelable_items");
  8.     }
  9.  
  10.     private Map<ResourceLocation, Item> itemmap = ImmutableMap.of();
  11.  
  12.     @Override
  13.     protected void apply(Map<ResourceLocation, JsonElement> jsonMap, ResourceManager pResourceManager, ProfilerFiller pProfiler) {
  14.  
  15.         ImmutableMap.Builder<ResourceLocation, Item> builder = ImmutableMap.builder();
  16.         jsonMap.forEach((resourceLocation, jsonElement) -> {
  17.             try {
  18.                 JsonObject jsonObject = jsonElement.getAsJsonObject();
  19.                 String keyString = resourceLocation.getPath();
  20.  
  21.                 WeaponLeveling.LOGGER.info("This is the path: " + keyString);
  22.  
  23.                 if(ForgeRegistries.ITEMS.containsKey(resourceLocation)) {
  24.                     Item item = ForgeRegistries.ITEMS.getValue(resourceLocation);
  25.                     builder.put(resourceLocation, item);
  26.                  
  27.                 } else WeaponLeveling.LOGGER.error("{} is not a valid Item", resourceLocation);
  28.  
  29.             }catch (IllegalArgumentException | JsonParseException jsonparseexception) {
  30.                 WeaponLeveling.LOGGER.error("Parsing error loading Item Levels {}: {}", resourceLocation,           jsonparseexception.getMessage());
  31.             }});
  32.             Map<ResourceLocation, Item> map = builder.build();
  33.  
  34.             this.itemmap = map;
  35.     }
  36.  
  37.  
  38.     public Item get(ResourceLocation resourceLocation) {
  39.         return this.itemmap.get(resourceLocation);
  40.     }
  41.  
  42.     public boolean contains(Item item) {
  43.         return get(item.getRegistryName()) != null;
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement