O'Reilly logo

Minecraft™ Mod Development in 24 Hours, Sams Teach Yourself by Jimmy Koene

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Food Item

Now that you know how food works in Minecraft, it is time to create your own food item. To do this, you add a new item to the mod file.

The Mod File Code

First, add the basic item code to the file, which is as follows in the mod file:

public static Item berry;

Then, add the following to the preInit method:

berry = new ItemBerry();GameRegistry.registerItem(berry, "Berry");

With this code, you have an error under ItemBerry. That is because you haven’t yet created that class.

Creating the ItemBerry Class

To create the ItemBerry class, hover your mouse over the error and click Create Class. You will get a file that looks like Listing 6.1.

LISTING 6.1 Empty ItemBerry File

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required