Jump to content

Recommended Posts

Posted (edited)

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 by CamHex
Solved
Posted
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?

Posted
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();
            }
        );
    }
}

 

  • CamHex changed the title to [Solved]​[1.18.2] How to register LootItemFunction and others
Posted
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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.