Fabric API

Fabric API

108M Downloads

Checking if a mod is loaded before calling Registry method causes game crash

JackHTerrell opened this issue ยท 2 comments

commented

The issue:
This only occurs if the mod being checked for is not loaded

If I create an if statement like so:

if(FabricLoader.getInstance().isModLoaded("copperequipment")) {
     Registry.register(Registry.ITEM, new Identifier(WooledBoots.MOD_ID, "redy1aye_copper_wooled_boots"), redy1aye_copper_wooled_boots);
     Registry.register(Registry.ITEM, new Identifier(WooledBoots.MOD_ID, "redy1aye_waxed_copper_wooled_boots"), redy1aye_waxed_copper_wooled_boots);
}

The game will run successfully in the development environment, but crash on startup outside the development environment.
This code crashes with the error Some intrusive holders were not added to registry: [Reference{null=air}, Reference{null=air}]
Click to view Pastebin of full log

Conversely, if I do not check for a mod being loaded, the game will start up successfully on both ends. This works fine:

Registry.register(Registry.ITEM, new Identifier(WooledBoots.MOD_ID, "redy1aye_copper_wooled_boots"), redy1aye_copper_wooled_boots);
Registry.register(Registry.ITEM, new Identifier(WooledBoots.MOD_ID, "redy1aye_waxed_copper_wooled_boots"), redy1aye_waxed_copper_wooled_boots);
commented

All registry object needs to be registered now. Create the instance of your items inside the if check.

commented

All registry object needs to be registered now. Create the instance of your items inside the if check.

That did the trick, thank you.