Modding: Your first item part 1

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.ModLoader;
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;

@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”);
}
}


If you don’t know what everything above here means you should follow this tutorial.

Adding an item to your game is partially the same. You will have to add this to your file:


public static Item youritem;


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

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


You might also have to add this if your Eclipse wont do that itself.


import net.minecraft.src.Item;


The whole file should now look like this.


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”);
}
}


Now I will explain what all those new things mean.


public static Item youritem;


youritem is the name of the new item.
public static Item is the same as public static Block, but for an item.


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


.setIconIndex(1) is the texture of the item. In this case it will be a chain helmet.
.setItemName(“youritem”) is the same as with block.
new ItemTutorial(550) is the new item class you are going to create. Right now it should be red underlined. 550 is the id of the item.


LanguageRegistry.addName(youritem, “Your Item”)


This gives the name of the item.

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