One thing that’s been bugging me about modding for Minecraft is how much code you need to define data. I decided to see if it’s possible to data drive item creation with Forge. Doing this will allow more flexibility when modding, and will allow users to further modify any mods you release.
Note that this article is a proof of concept only. The code is nowhere near complete. I will be expanding on it in the future to allow for the creation of many different item types, including food, durable items, block items and so on. Later I plan to data drive blocks in the same way for further flexibility.
As always, the latest code that I am working on can be found on my github page.
Defining the Items
Before we do anything we need to define the JSON document we will use to describe our items. I’m going to start with very basic items that don’t do anything except act as ingredients for other items.
A basic item JSON document will look like this:
{
"type": "item",
"itemGroup": "food",
"name": "common_flour"
}
You can see a list of other items I’ve defined in the github project.
This creates a basic item called “common_flour” that will appear under the Food Group in the creative menu. For now the type is always item but I plan to expand this so we can create different kinds of items (such as edible food).
The item files will go under the data/<modid>/items folder. We use data because this is information that both the client and the server will need. Remember data is for game rule information used by both a client and a server, while assets is information only needed for rendering, which only a client needs to know.