Posted June 27, 20223 yr Specifically, I'm trying to add my custom enchantment to a loot table with the setup below. public class AncientCityLootModifier extends LootModifier { private final Item addition; protected AncientCityLootModifier(LootItemCondition[] conditionsIn, Item addition) { super(conditionsIn); this.addition = addition; } @Nonnull @Override protected @NotNull ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context) { int x = 0; int y = 0; while(x < 4){ if(context.getRandom().nextFloat() < 0.08F){ generatedLoot.add(new ItemStack(ModItems.SCULK_SOUL.get(), 1)); } x += 1; } if(context.getRandom().nextFloat() < 0.06F){ generatedLoot.add(new ItemStack(ModItems.SCULK_INGOT.get(), 1)); } while(y < 3){ if(context.getRandom().nextFloat() < 0.03F){ generatedLoot.add(new ItemStack(addition, 1)); } y += 1; } return generatedLoot; } public static class Serializer extends GlobalLootModifierSerializer<AncientCityLootModifier> { @Override public AncientCityLootModifier read(ResourceLocation name, JsonObject object, LootItemCondition[] conditionsIn) { Item addition = ForgeRegistries.ITEMS.getValue( new ResourceLocation(GsonHelper.getAsString(object, "addition"))); return new AncientCityLootModifier(conditionsIn, addition); } @Override public JsonObject write(AncientCityLootModifier instance) { JsonObject json = makeConditions(instance.conditions); json.addProperty("addition", ForgeRegistries.ITEMS.getKey(instance.addition).toString()); return json; } } }
June 27, 20223 yr Author 31 minutes ago, diesieben07 said: Deserialize it from JSON and then call its apply method. Is there an example of how I would do that? I'm not sure how json serialization works, I've just been following this tutorial Edited June 27, 20223 yr by nu11une
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.