O'Reilly logo

Minecraft Modding with Forge by Arun Gupta, Aditya Gupta

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

Chapter 8. New Item

Now that you have made a new block, it is time to move on to a new item.

Items can do many things. Most items are used for crafting, smelting, and brewing. Some items light fire (e.g., flint and steel, or fire charges), while others can be eaten (e.g., cookies and potatoes). Some items, such as bows or snowballs, do something when you right-click with them. A lot of items don’t do much, such as magma cream or iron ingots.

The item created in this chapter will be an ingot. At first, the item will not do anything, but the later parts of the chapter will offer some variations of this item. The first one will make it spawn an enderman on right-click. The second one will make it a food item. The last one will make it drop when you break an Enderium Block.

Creating the Item Class

A new item does not require as much code as a new block, but there are more ways to customize it. First of all, you will need a new class for the item, just as with the block. Call it EnderIngot.

Just as with the new block, replace the generated code with the code in Example 8-1.

Example 8-1. New item final code
package org.devoxx4kids.forge.mods;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

public class EnderIngot extends Item {

	public EnderIngot() {
		super(); 1
		this.setUnlocalizedName("ingotEnder"); 
		this.setCreativeTab(CreativeTabs.tabMaterials); 
	}

}

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