Posted March 5, 20223 yr Hello, I want to register additional LootItemFunction(LootItemFunctionType), LootItemConditions(LootItemConditionType) and etc, At 1.18.1, I was using the following code, it works fine: @Mod("testmod") public final class TestMod { public TestMod() { TestLootItemFunctions.init(); } } public final class TestLootItemFunctions { public static void init() {} public static final LootItemFunctionType TEST_FUNCTION = register(new ResourceLocation("testmod:test"), new TestFunction.Serializer()); private static LootItemFunctionType register(ResourceLocation id, Serializer<? extends LootItemFunction> serializer) { // net.minecraft.core.Registry return Registry.register(Registry.LOOT_FUNCTION_TYPE, id, new LootItemFunctionType(serializer)); } } But it is no longer works (Minecraft 1.18.2, official mappings, Forge 40.0.3): Caused by: java.lang.IllegalStateException: Registry is already frozen (trying to add key ResourceKey[minecraft:loot_function_type / testmod:test]) at net.minecraft.core.MappedRegistry.validateWrite(MappedRegistry.java:78) ~[forge-1.18.2-40.0.3_mapped_official_1.18.2-recomp.jar%2376!/:?] at net.minecraft.core.MappedRegistry.registerMapping(MappedRegistry.java:87) ~[forge-1.18.2-40.0.3_mapped_official_1.18.2-recomp.jar%2376!/:?] at net.minecraft.core.MappedRegistry.registerMapping(MappedRegistry.java:83) ~[forge-1.18.2-40.0.3_mapped_official_1.18.2-recomp.jar%2376!/:?] at net.minecraft.core.MappedRegistry.register(MappedRegistry.java:128) ~[forge-1.18.2-40.0.3_mapped_official_1.18.2-recomp.jar%2376!/:?] at net.minecraft.core.Registry.register(Registry.java:564) ~[forge-1.18.2-40.0.3_mapped_official_1.18.2-recomp.jar%2376!/:?] at net.minecraft.core.Registry.register(Registry.java:560) ~[forge-1.18.2-40.0.3_mapped_official_1.18.2-recomp.jar%2376!/:?] at com.testmod.server.loot.TestLootItemConditions.register(TestLootItemConditions.java:17) ~[%2380!/:?] at com.testmod.server.loot.TestLootItemConditions.<clinit>(TestLootItemConditions.java:14) ~[%2380!/:?] at com.testmod.TestMod.<init>(TestMod.java:23) ~[%2380!/:?] ... 14 more Edited March 6, 20223 yr by CamHex Solved
March 6, 20223 yr Author 19 hours ago, diesieben07 said: From what it looks like you currently cannot. Thanks. So is there any plan to support register additional registry entry (such as LootItemFunctionType) in the future?
March 6, 20223 yr Author 2 hours ago, diesieben07 said: I have since learned that it should work if you do it from within any RegistryEvent.Register. Thanks! It works fine: @Mod("testmod") public final class TestMod { public TestMod() { FMLJavaModLoadingContext.get().getModEventBus().addGenericListener( GlobalLootModifierSerializer.class, (RegistryEvent.Register event) -> { TestLootItemFunctions.init(); } ); } }
March 6, 20223 yr Author 26 minutes ago, diesieben07 said: I hope you adjusted your code to now create and register the function in the init method, not in a static initializer. Yes, of course, those codes are just for testing.
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.