Modding: Your first item part 2

In this tutorial you will learn how to create your own item in Minecraft.
This is the file you can start with.


package Tutorial.common;

import net.minecraft.src.Block;
import net.minecraft.src.Item;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
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 = “YourName_ModName”, name = “ModName”, version = “Version number”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
public static Block oreblock;

public static Item youritem;

@Init
public void load(FMLInitializationEvent event) 
{
oreblock = new BlockOres(230, 0).setStepSound(Block.soundStoneFootstep).setHardness(3F).setResistance(1.0F).setBlockName(“oreblock”);

GameRegistry.registerBlock(oreblock);

LanguageRegistry.addName(oreblock, “Your Ore”);

youritem = new ItemTutorial(550).setIconIndex(1).setItemName(“youritem”);

LanguageRegistry.addName(youritem, “Your Item”);
}
}


The ItemTutorial is still underlined. To fix that you have to create a new class called ItemTutorial.

You will get a file that looks like this.

package Tutorial.common;

public class ItemTutorial 
{

}


To get a good item you need to make the file like this.


package Tutorial.common;

import net.minecraft.src.CreativeTabs;
import net.minecraft.src.Item;

public class ItemTutorial extends Item
{
    public ItemTutorial(int i)
    {
        super(i);
        maxStackSize = 64;
        this.setCreativeTab(CreativeTabs.tabMaterials);
    }
}


Now I will explain what this means.


public class ItemTutorial extends Item


extends Item means that this class is a type of item. You need to have this for the item to work. It also gives you acces to a lot of methods.


public ItemTutorial(int i)
    {
        
    }


This is the constructer of this class. In here you will have to give some settings to the item.
int i is the id you gave it in the Tutorial class


 super(i);
 maxStackSize = 64;
 this.setCreativeTab(CreativeTabs.tabMaterials);


super(i) passes the id into the Item class so that Minecraft knows the Id.
maxStackSize = 64; simply is the maximum stack size of the item.
this.setTabToDisplayOn(CreativeTabs.tabMaterials); is used in minecraft to get the tab of the creative inventory where it should be shown. If you want to change the location you need to remove the tabMaterials and find another tab in CreativeTabs.This will give you a simple item with the texture of a chain helmet. You can’t do anything with it just yet, but that is for a later tutorial.

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="">