Data Driving Minecraft

Registering the Items

Now that we have all the data we need to actually register it. This is pretty simple, we just need to update the method subscribed to an item register event:

@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event)
{
    //  TODO: This should be moved to a more centralised location.
    ModResourceManager modResourceManager = new ModResourceManager(ResourcePackType.SERVER_DATA, WheatMod.MOD_ID);
    ModItemManager itemManager = new ModItemManager();
    itemManager.loadItems(modResourceManager);

    event.getRegistry().registerAll(itemManager.getItems());

    <snip>
}

We use SERVER_DATA since we need to load the items from the data folder (and because the server needs to know this information). After that we just use our ModItemManager to load the items and register the results.

This code still works with ObjectHolders. So if we have a variable with the same name as our item’s registry name it will still be set to the correct value by Forge.

And that’s pretty much it. For now…