Basic Block Introductory
Blocks are the cubes in minecraft. Blocks are composed of two class files. The first obviously being a @Mod file and the other being the Block Class. For this tutorial it is expected that you know about @Mod files. If you do not we have documentation here.
The first part of making a block is to set up a declaration. For a block it will look a little like this.
public static Block YourBlock;
The next thing we will need to do is make some properties for our block. This code will go into the FMLInitializationEvent. Some things to note about the code is that the first part is the same as what you declared above. the BlockYourBlock is a class file to hold many properties of your block. The number 230 is the block ID and the 0 points to the space on the sprite sheet. The steposound is obvious and the BlockName gets overridden but is needed.
YourBlock = new BlockYourBlock(230, 0).setStepSound(Block.soundStoneFootstep).setBlockName("YourBlock");
It is now time for us to register the block into the game. This is done with a single line of code that goes in the FMLInitializationEvent just like the code above. Note that the YourBlock is referring back to the declaration.
GameRegistry.registerBlock(YourBlock);
Now we will add a name for our block. This goes in the FMLInitializationEvent aswell. The YourBlock is another relation back to the declaration you made while the second bit in blue is the next that will appear over the item when moused over.
LanguageRegistry.addName(YourBlock, "The Name Of Your Block");
That is all you will need to do in your @Mod file however you are not done yet. Remember the BlockYourBlock class that we made previously? We have an error with that which we will need to fix. Simply hover over the error and it will give you the option to "Create Class 'BlockYourBlock' " it would be good to choose this one.
Eclipse will now have made you a class file for you to code your block in. I will not be going over all of the code individually however i will be adding comments to all the code for ease of viewing.
package your.package.here;
public class BlockYourBlock extends Block
{
//This is the constructor. the first bit is the material,The material gives the
//Block several properties such as sounds. The next line is for the addition
//of the block the the creative menu. The hardness and the resistance is
//self explanatory. Hardness is how long it takes to break the block and
//resistance is how resistant it is to explosions.
public BlockYourBlock(int par1)
{
super(par1, Material.rock);
this.setCreativeTab(CreativeTabs.tabBlock);
this.setHardness(1.0F);
this.setResistance(1.0F);
}
//This is were you can add other methods to the blocks.
}
The first part of making a block is to set up a declaration. For a block it will look a little like this.
public static Block YourBlock;
The next thing we will need to do is make some properties for our block. This code will go into the FMLInitializationEvent. Some things to note about the code is that the first part is the same as what you declared above. the BlockYourBlock is a class file to hold many properties of your block. The number 230 is the block ID and the 0 points to the space on the sprite sheet. The steposound is obvious and the BlockName gets overridden but is needed.
YourBlock = new BlockYourBlock(230, 0).setStepSound(Block.soundStoneFootstep).setBlockName("YourBlock");
It is now time for us to register the block into the game. This is done with a single line of code that goes in the FMLInitializationEvent just like the code above. Note that the YourBlock is referring back to the declaration.
GameRegistry.registerBlock(YourBlock);
Now we will add a name for our block. This goes in the FMLInitializationEvent aswell. The YourBlock is another relation back to the declaration you made while the second bit in blue is the next that will appear over the item when moused over.
LanguageRegistry.addName(YourBlock, "The Name Of Your Block");
That is all you will need to do in your @Mod file however you are not done yet. Remember the BlockYourBlock class that we made previously? We have an error with that which we will need to fix. Simply hover over the error and it will give you the option to "Create Class 'BlockYourBlock' " it would be good to choose this one.
Eclipse will now have made you a class file for you to code your block in. I will not be going over all of the code individually however i will be adding comments to all the code for ease of viewing.
package your.package.here;
public class BlockYourBlock extends Block
{
//This is the constructor. the first bit is the material,The material gives the
//Block several properties such as sounds. The next line is for the addition
//of the block the the creative menu. The hardness and the resistance is
//self explanatory. Hardness is how long it takes to break the block and
//resistance is how resistant it is to explosions.
public BlockYourBlock(int par1)
{
super(par1, Material.rock);
this.setCreativeTab(CreativeTabs.tabBlock);
this.setHardness(1.0F);
this.setResistance(1.0F);
}
//This is were you can add other methods to the blocks.
}