[Beginner] Creating a new Item [22/4/11] [1.4_01] [2.11]
Page 1 of 1
[Beginner] Creating a new Item [22/4/11] [1.4_01] [2.11]
Creating a new item with ModLoader is very simple. For this tutorial, I will assume that you have completed the "Creating a new Block" tutorial, and that you still have the two java files you created. First of all, open your mod_Emeralds.java file. It should read like this:
If it doesn't have this general look, go back and do the Creating a Block tutorial again. If your mod_Emeralds is good, then continue on.
Take a look at this code snippet:
This tells us that there is a new Item called emeraldItem with an ID of 2000. This code is needed to show the game that the emeraldItem exists. This piece of code should fit in right below the block declerations, like so:
Next, you need to create an Override (if you wish) to create your own picture for it. So, to that end, we create the following:
Note that it says iconIndex instead of blockIndexInTexture. This should be obvious, because obviously emeraldItem is not a block. Also note that it overrides /gui/items.png, instead of /terrain.png. This should go below the other overrides but above the AddNames.
Next, you want to add a name for your emeralds. There is no change from the way we add names for blocks - just put this code below the other AddNames:
After all of that, this is what our code should look like:
Save your mod_Emeralds.java file and create a new file called ItemEmerald.java. In this file, we will create a maximum stack size for the emerald item. It's very basic, it looks like this:
All you would need to change for that would be the maxStackSize = (your number here);
Remember to remove the brackets and make sure not to make it more than 64, or else it won't work. Save this file, add ItemEmerald to your client_obfuscation file, and recompile. There should be no errors except maybe Java syntax errors. Congrats on making your first item!
Previous Next- COMING SOON
- Code:
package net.minecraft.src;
public class mod_Emeralds extends BaseMod
{
public static final Block emeraldOre = new BlockEmeraldOre(97, 0).setHardness(2.0F).setResistance(5.0F).setBlockName("emeraldOre");
public mod_Emeralds()
{
ModLoader.RegisterBlock(emeraldOre);
emeraldOre.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/tutorials/emeraldore.png");
ModLoader.AddName(emeraldOre, "Emerald Ore");
public String Version()
{
return "1.4_01";
}
}
If it doesn't have this general look, go back and do the Creating a Block tutorial again. If your mod_Emeralds is good, then continue on.
Take a look at this code snippet:
- Code:
public static final Item emeraldItem = new Item(2000).setItemName("emeraldItem");
This tells us that there is a new Item called emeraldItem with an ID of 2000. This code is needed to show the game that the emeraldItem exists. This piece of code should fit in right below the block declerations, like so:
- Code:
public class mod_Emeralds extends BaseMod
{
public static final Block emeraldOre = new BlockEmeraldOre(97, 0).setHardness(2.0F).setResistance(5.0F).setBlockName("emeraldOre");
public static final Block emeraldBlock = new BlockEmerald(98, 0).setHardness(1.5F).setResistance(5.0F).setBlockName("emeraldBlock");
public static final Item emeraldItem = new Item(2000).setItemName("emeraldItem");
Next, you need to create an Override (if you wish) to create your own picture for it. So, to that end, we create the following:
- Code:
emeraldItem.iconIndex = ModLoader.addOverride("/gui/items.png", "/tutorial/emeralditem.png");
Note that it says iconIndex instead of blockIndexInTexture. This should be obvious, because obviously emeraldItem is not a block. Also note that it overrides /gui/items.png, instead of /terrain.png. This should go below the other overrides but above the AddNames.
Next, you want to add a name for your emeralds. There is no change from the way we add names for blocks - just put this code below the other AddNames:
- Code:
ModLoader.AddName(emeraldItem, "Emerald");
After all of that, this is what our code should look like:
- Code:
package net.minecraft.src;
public class mod_Emeralds extends BaseMod
{
public static final Block emeraldOre = new BlockEmeraldOre(97, 0).setHardness(2.0F).setResistance(5.0F).setBlockName("emeraldOre");
public static final Block emeraldBlock = new BlockEmerald(98, 0).setHardness(1.5F).setResistance(5.0F).setBlockName("emeraldBlock");
public static final Item emeraldItem = new Item(2000).setItemName("emeraldItem");
public mod_Emeralds()
{
ModLoader.RegisterBlock(emeraldOre);
ModLoader.RegisterBlock(emeraldBlock);
emeraldOre.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/moreores/emeraldore.png");
emeraldBlock.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/moreores/emeraldblock.png");
emeraldItem.iconIndex = ModLoader.addOverride("/gui/items.png", "/moreores/emeralditem.png");
ModLoader.AddName(emeraldOre, "Emerald Ore");
ModLoader.AddName(emeraldBlock, "Emerald Block");
ModLoader.AddName(emeraldItem, "Emerald");
public String Version()
{
return "1.4_01";
}
}
Save your mod_Emeralds.java file and create a new file called ItemEmerald.java. In this file, we will create a maximum stack size for the emerald item. It's very basic, it looks like this:
- Code:
package net.minecraft.src;
public class ItemEmerald extends Item {
public ItemEmerald (int i)
{
super(i);
maxStackSize = (your number here);
}
}
All you would need to change for that would be the maxStackSize = (your number here);
Remember to remove the brackets and make sure not to make it more than 64, or else it won't work. Save this file, add ItemEmerald to your client_obfuscation file, and recompile. There should be no errors except maybe Java syntax errors. Congrats on making your first item!
Previous Next- COMING SOON
Similar topics
» Official ModLoader Tutorials: Creating a new Block and Item
» [Beginner] Creating a new Tool Set [22/4/11] [1.4_01] [2.11]
» [Beginner] Creating a new Recipe [22/4/11] [1.4_01] [2.11]
» [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
» How Do You Make Item Smeltable?
» [Beginner] Creating a new Tool Set [22/4/11] [1.4_01] [2.11]
» [Beginner] Creating a new Recipe [22/4/11] [1.4_01] [2.11]
» [Beginner] Creating a new Block [22/4/11] [1.4_01] [2.11]
» How Do You Make Item Smeltable?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|