izofar Posted December 6, 2021 Posted December 6, 2021 (edited) In 1.16, LootModifierManager#deserializeModifier read: private IGlobalLootModifier deserializeModifier(ResourceLocation location, JsonElement element) { if (!element.isJsonObject()) return null; JsonObject object = element.getAsJsonObject(); ILootCondition[] lootConditions = GSON_INSTANCE.fromJson(object.get("conditions"), ILootCondition[].class); // For backward compatibility with the initial implementation, fall back to using the location as the type. // TODO: Remove fallback in 1.16 ResourceLocation serializer = location; if (object.has("type")) { serializer = new ResourceLocation(JSONUtils.getAsString(object, "type")); } return ForgeRegistries.LOOT_MODIFIER_SERIALIZERS.getValue(serializer).read(location, object, lootConditions); } Note the if(object.has(type")){} block, which is lacking from the 1.18 version of the class: private IGlobalLootModifier deserializeModifier(ResourceLocation location, JsonElement element) { if (!element.isJsonObject()) return null; JsonObject object = element.getAsJsonObject(); LootItemCondition[] lootConditions = GSON_INSTANCE.fromJson(object.get("conditions"), LootItemCondition[].class); ResourceLocation serializer = new ResourceLocation(GsonHelper.getAsString(object, "type")); return ForgeRegistries.LOOT_MODIFIER_SERIALIZERS.getValue(serializer).read(location, object, lootConditions); } So, the "value" tag is required now for loot modifiers... fine. I added this to my loot modifer json files when I kept getting NullPointerExceptions. But when I use a valid "value" tag I get: [15:27:02] [Render thread/ERROR]: Couldn't parse loot modifier examplemod:add_structure_loot java.lang.NullPointerException: Cannot invoke "net.minecraftforge.common.loot.GlobalLootModifierSerializer.read(net.minecraft.resources.ResourceLocation, com.google.gson.JsonObject, net.minecraft.world.level.storage.loot.predicates.LootItemCondition[])" because the return value of "net.minecraftforge.registries.IForgeRegistry.getValue(net.minecraft.resources.ResourceLocation)" is null at net.minecraftforge.common.loot.LootModifierManager.deserializeModifier(LootModifierManager.java:133) ~[forge-1.18-38.0.14_mapped_official_1.18-recomp.jar%2376%2382!:?] at net.minecraftforge.common.loot.LootModifierManager.lambda$apply$0(LootModifierManager.java:115) ~[forge-1.18-38.0.14_mapped_official_1.18-recomp.jar%2376%2382!:?] at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?] at net.minecraftforge.common.loot.LootModifierManager.apply(LootModifierManager.java:113) ~[forge-1.18-38.0.14_mapped_official_1.18-recomp.jar%2376%2382!:?] at net.minecraftforge.common.loot.LootModifierManager.apply(LootModifierManager.java:54) ~[forge-1.18-38.0.14_mapped_official_1.18-recomp.jar%2376%2382!:?] My json file is: { "type": "chest", "conditions": [ { "condition": "forge:loot_table_id", "loot_table_id": "examplemod:chests/modstructure" } ] } I tried printing the contents of ForgeRegistries.LOOT_MODIFIER_SERIALIZERS to know which keys I can use, but got: [15:26:13] [modloading-worker-0/INFO]: Printing LOOT_MODIFER_SERIALIZERS [15:26:13] [modloading-worker-0/INFO]: Printed LOOT_MODIFER_SERIALIZERS Is this a bug, given 1.18 is new, or am I not using these classes right? Edited December 6, 2021 by izofar Quote
izofar Posted December 6, 2021 Author Posted December 6, 2021 1 minute ago, diesieben07 said: "minecraft:chest" is not a valid loot modifier registry name. I got this from the link above, which says: Quote Optional type of the loot table. Must be one of empty if the loot table does not generate any loot, entity for loot an entity drops, block for loot a block drops, chest for a treasure chest, fishing for a fishing loot table, gift for a cat or villager gift, advancement_reward if it's used as a reward for an advancement, barter for loot from bartering with piglins, command for /execute, selector for predicate= in selectors, advancement_entity for entity predicates in advancements or generic if none of the above apply. If these are not the valid names, then what are? Quote
izofar Posted December 6, 2021 Author Posted December 6, 2021 2 minutes ago, diesieben07 said: That is for loot tables. You are making a loot modifier. You registered your GlobalLootModifierSerializer to the registry with a registry name. The "type" field tells the game which serializer to use. Just noticed the first part. As for the second, thanks lad! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.