This is the Item.class that we made. and is where we set the creative tab for our item and the texture for it.
package mods.obsidian;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
public class obsidianIngot extends Item{
public obsidianIngot(int par1) {
super(par1);
// TODO Auto-generated constructor stub
this.setCreativeTab(CreativeTabs.tabMaterials);}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister) {
this.itemIcon = iconRegister.registerIcon("tutorial.obsidian.mod:obsidianIngot");
}
}
This is telling forge where to get the item's texture from.
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister) {
this.itemIcon = iconRegister.registerIcon("tutorial.obsidian.mod:obsidianIngot");
3.Creating Blocks
[media][media][/media[/media]]
Telling Forge we are creating this block.
//Blocks
public static Block obsidianBrick;
Defining the block.
obsidianBrick = new obsidianBrick(1000, Material.rock).setHardness(1.5F).setResistance(2000.0F).setStepSound(Block.soundStoneFootstep).setUnlocalizedName("obsidianBrick");
Finally we need to change the ID's of the items and blocks we added to the integers so that when we change the ID's in the configuration file it will change the ID of the block/item.
//Declaring Init
@Init
public void load(FMLInitializationEvent event){
this.InitConfiguration(event);
// define items/blocks
//Item
obsidianIngot = new obsidianIngot(this.obsidianIngotID).setUnlocalizedName("obsidianIngot");
//Block
obsidianBrick = new obsidianBrick(this.obsidianBrickID, Material.rock).setHardness(1.5F).setResistance(2000.0F).setStepSound(Block.soundStoneFootstep).setUnlocalizedName("obsidianBrick");
5. Creating a metadata Block
[media][media][/media[/media]]
First we need to create the block file.
package mods.obsidian;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
public class obsidianBrick extends Block
{
public static final String[] STONE_BRICK_TYPES = new String[] {"default", "carved"};
public static final String[] field_94407_b = new String[] {null, "carved"};
@SideOnly(Side.CLIENT)
private Icon[] field_94408_c;
public obsidianBrick(int par1)
{
super(par1, Material.rock);
this.setCreativeTab(CreativeTabs.tabBlocks);
}
@SideOnly(Side.CLIENT)
/**
* From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
*/
public Icon getIcon(int par1, int par2)
{
if (par2 < 0 || par2 >= field_94407_b.length)
{
par2 = 0;
}
return this.field_94408_c[par2];
}
/**
* Determines the damage on the item the block drops. Used in cloth and wood.
*/
public int damageDropped(int par1)
{
return par1;
}
@SideOnly(Side.CLIENT)
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int j = 0; j < 2; ++j)
{
par3List.add(new ItemStack(par1, 1, j));
}
}
@SideOnly(Side.CLIENT)
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister par1IconRegister)
{
this.field_94408_c = new Icon[field_94407_b.length];
for (int i = 0; i < this.field_94408_c.length; ++i)
{
String s = this.func_111023_E();
if (field_94407_b[i] != null)
{
s = s + "_" + field_94407_b[i];
}
this.field_94408_c[i] = par1IconRegister.registerIcon(s);
}
}
}
This tells forge the different blocks that are using this ID.
public static final String[] STONE_BRICK_TYPES = new String[] {"default", "carved"};
This tells forge what the texture file's name is.
public static final String[] field_94407_b = new String[] {null, "carved"};
This tells forge how many metadata blocks we are creating.
@SideOnly(Side.CLIENT)
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int j = 0; j < 2; ++j)
{
par3List.add(new ItemStack(par1, 1, j));
}
}
This tells forge where to grab the block texture(ie: tutorial.obsidian.mod/textures/blocks/obsidianbrick_carved.png).
@SideOnly(Side.CLIENT)
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister par1IconRegister)
{
this.field_94408_c = new Icon[field_94407_b.length];
for (int i = 0; i < this.field_94408_c.length; ++i)
{
String s = this.func_111023_E();
if (field_94407_b[i] != null)
{
s = s + "_" + field_94407_b[i];
}
this.field_94408_c[i] = par1IconRegister.registerIcon(s);
}
}
}
Next we need to go into our main mod file and tell forge that we are using metadata and what the different block names are
Add this under where you define your blocks and before where you add the names to your items. This is saying that this block is a multitextured block, basically a block using metadata.
@cpw.mods.fml.common.Mod.PostInit
public void PostInit(FMLPostInitializationEvent event)
{
Item.itemsList[obsidianBrick.blockID] = (new ItemMultiTextureTile(obsidianBrick.blockID - 256, obsidianBrick, BlockObsidianBrick.STONE_BRICK_TYPES)).setUnlocalizedName("obsidianbricks");
This is telling forge the names of the metadata blocks, because at the moment forge named our blocks tile.Obsidian:obsidianbricks.default.name and tile.Obsidian:obsidianbricks.carved.name.
After that we need to add this bit of line to the same place we added the line that defined about obsidian brick being a metadata block. Except this line is defining that we are able to "stack" the halfslabs, thus making them a double slab.
@cpw.mods.fml.common.Mod.PostInit
public void PostInit(FMLPostInitializationEvent event)
{
Item.itemsList[obsidianBrick.blockID] = (new ItemMultiTextureTile(obsidianBrick.blockID - 256, obsidianBrick, BlockObsidianBrick.STONE_BRICK_TYPES)).setUnlocalizedName("obsidianbricks");
Item.itemsList[obsidianBrickSingle.blockID] = (new ItemSlab(obsidianBrickSingle.blockID - 256, (BlockHalfSlab)obsidianBrickSingle, (BlockHalfSlab)obsidianBrickDouble, false));
And now we need to add a name to our new half slab so the name shows up in our inventory and creative tab.
can you please tell me what to use instead of this in Minecraft 1.7.2?
in 1.7.2 everything that had to do with block id's changed to just block. for instance, if you were to call a block using mod.block.blockId, you'd change it to mod.block for 1.7.2, so basically anything that has to do with id's needs to be getting the block itself instead.
From my research the constructor for block has changed from block(int, material) to just block(material)
So where one does new block(id, material) you instead do new block(material)
The change comes from the fact that blocks no longer have IDs in 1.7 and later.
so new myblock(1347, material.dirt) becomes just new myblock(material.dirt)
If you want to know how to modify your block class look at block.java in net.minecraft
Also nice job on the tutorials but it seems more a reference format then a tutorial.
I been looking in the Block class, BlockSlab class, BlockStoneSlab class and about 100 other mods but all of them is doing it to do about a million(exaggeration here) different types of half slabs I am just trying to keep it simple and have 1 class to make a obsidian slab and have it stack on top of each other and when middle clicked it returns a obsidian slab and when mined it returns 2 slabs instead of the doubleslab block.
I am setting up my own website for this tutorial. what do you guys think? it will be hopefully be ready soon. ill show how to code for 1.6, 1.7, and 1.8. what do you guys think?
1. Setting up MCP and Eclipse
[media][media][/media[/media]]
Forge Download
This is used to tell forge that we are creating a mod. It tells forge the name of our mod and the version.
2. Creating Items
[media][media][/media[/media]]
This is telling forge that we are creating this item
This is defining the item that we created, telling forge the item ID and whether or not it is a food.
This is making it so the name of our item shows up when its in our inventory. basically its adding the name for it.
This is the Item.class that we made. and is where we set the creative tab for our item and the texture for it.
This is telling forge where to get the item's texture from.
3.Creating Blocks
[media][media][/media[/media]]
Telling Forge we are creating this block.
Defining the block.
Registering the block to the game.
Adding a name to the block.
This is going to be our block.class.
This tells forge where to get the texture for our block from.
4. Creating a Config File
[media][media][/media[/media]]
First we need to tell forge that we are making new integers.
Next we need to define the integers for the configuration file and tell forge where to create the configuration file.
Finally we need to change the ID's of the items and blocks we added to the integers so that when we change the ID's in the configuration file it will change the ID of the block/item.
5. Creating a metadata Block
[media][media][/media[/media]]
First we need to create the block file.
This tells forge the different blocks that are using this ID.
This tells forge what the texture file's name is.
This tells forge how many metadata blocks we are creating.
This tells forge where to grab the block texture(ie: tutorial.obsidian.mod/textures/blocks/obsidianbrick_carved.png).
Next we need to go into our main mod file and tell forge that we are using metadata and what the different block names are
Add this under where you define your blocks and before where you add the names to your items. This is saying that this block is a multitextured block, basically a block using metadata.
This is telling forge the names of the metadata blocks, because at the moment forge named our blocks tile.Obsidian:obsidianbricks.default.name and tile.Obsidian:obsidianbricks.carved.name.
You also need to add this little bit of code at the end of where you defined your block.
And that is all that is need to create a metadata block.
6. Creating half slabs
First what we need to do is tell forge that we are making two blocks, a single and double slab.
Next we need to have the new blocks register in the config file so when people use our mod they will be able to change both block ID's.
Next we have to define both halfslabs(this is just like creating your normal block, with a couple changes).
After that we need to add this bit of line to the same place we added the line that defined about obsidian brick being a metadata block. Except this line is defining that we are able to "stack" the halfslabs, thus making them a double slab.
And now we need to add a name to our new half slab so the name shows up in our inventory and creative tab.
And now we need to create the block file for the half slabs.
in 1.7.2 everything that had to do with block id's changed to just block. for instance, if you were to call a block using mod.block.blockId, you'd change it to mod.block for 1.7.2, so basically anything that has to do with id's needs to be getting the block itself instead.
Sorry, i wish i could. im currently updating my own mod to 1.7.2 as well. when i do and if it works ill tell you how to fix this.
Have you figured out how to do this in 1.7 yet?
I been looking in the Block class, BlockSlab class, BlockStoneSlab class and about 100 other mods but all of them is doing it to do about a million(exaggeration here) different types of half slabs I am just trying to keep it simple and have 1 class to make a obsidian slab and have it stack on top of each other and when middle clicked it returns a obsidian slab and when mined it returns 2 slabs instead of the doubleslab block.
I am setting up my own website for this tutorial. what do you guys think? it will be hopefully be ready soon. ill show how to code for 1.6, 1.7, and 1.8. what do you guys think?