Wuppy’s Minecraft Forge Modding Tutorials for 1.6.2: Basic Item Part 1

In this tutorial I will show you how to add a basic Item to Minecraft. In the first tutorial I will explain all the code you need in the mod file. The second tutorial will be about the Item file.
This is the mod file I will start with.


package tutorial;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = Tutorial.modid, name = “Mod Name”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial
{
       public static final String modid = “YourName_ModName”;
      
       public static Block tutorialBlock;
      
       @EventHandler
       public void load(FMLInitializationEvent event)
       {
             tutorialBlock = new BlockTutorialBlock(500, Material.rock).setUnlocalizedName(“tutorialBlock”);
            
             GameRegistry.registerBlock(tutorialBlockmodid + tutorialBlock.getUnlocalizedName2());
            
             LanguageRegistry.addName(tutorialBlock“Tutorial Block”);
       }
}

The first line of code you will have to add to your mod file looks like this.


public static Item tutorialItem;


This line has to be added below the CommonProxy line and above the @Init line. When you add it you will get an error under Item. To fix that Press Ctrl, Shift, O and select the net.minecraft.item.Item import, or you can add this line of code to the file yourself above the @Mod line.


import net.minecraft.item.Item;


Now inside of the load method you have to add a line like this one.


tutorialItem = new ItemTutorial(5000).setUnlocalizedName(“tutorial”);


The first thing you put in this line is the item variable name you created earlier. What you set it equal to is the file where you will put a lot of information for the item. Inside of the brackets behind ItemTutorial is the Id for the item. I suggest keeping this somewhere above 4096.
.setUnlocalizedName(“tutorial”) simply sets a name for the item. It isn’t really used in the code, but you have to get a different one for every item or you will get strange errors. I suggest keeping it the same as the variable name.

There is one last line of code that you have to add to the mod file. It should be similar to the one below.


LanguageRegistry.addName(tutorialItem“Tutorial Item”);


This line of code will simply make sure that your tutorialItem will get the name Tutorial Item inside of the game. The first parameter is always the item and the second one the name in game.
You will also have to import LanguageRegistry just like you did earlier.
The whole file should now look something like this.


package tutorial;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = Tutorial.modid, name = “Mod Name”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial
{
       public static final String modid = “YourName_ModName”;
      
       public static Block tutorialBlock;
      
       public static Item tutorialItem;
      
       @EventHandler
       public void load(FMLInitializationEvent event)
       {
             tutorialBlock = new BlockTutorialBlock(500, Material.rock).setUnlocalizedName(“tutorialBlock”);
            
             GameRegistry.registerBlock(tutorialBlockmodid + tutorialBlock.getUnlocalizedName2());
            
             LanguageRegistry.addName(tutorialBlock“Tutorial Block”);
            
             tutorialItem = new ItemTutorial(5000).setUnlocalizedName(“tutorial”);
            
             LanguageRegistry.addName(tutorialItem“Tutorial Item”);
       }
}

Right now you will have an error under ItemTutorial. We will fix that in the next tutorial.
The tutorial source code will be available at the last part of the basic item tutorials.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">