Creating a new block
1. You need to make a new file called BlockExample.java in the src directory.
2. The basic structure of this file is this:
package net.minecraft.src; import java.util.Random; public class BlockExample extends Block { public BlockExample(int i, int j) { super(i, j, Material.rock); } public int idDropped(int i, Random random) { return 0; } }
3. You now need to add this block to minecraft so that it knows about it. To do this open up Block.java
4. You should see a whole bunch of variable declarations towards the bottom of the file, add a new one:
public static final Block example;
5. Below the declarations you should see initialisation of these instance variables, initialise your block.
example = (new BlockExample(92, 1)).setHardness(1.5F).setResistance(10F).setStepSound(soundStoneFootstep);
Like mentioned before this example block is creating a new 'stone' block.
new BlockExample(92, 1) creates the new block, the first number is the block id - THIS HAS TO BE UNIQUE, the second number is the graphic of the block, in this case the same as stone.
setHardness(1.5F) is the same as stone, this is how long it takes to destroy a block.
setResistance(10F) is the same as stone, this is how strong the block is against explosions.
setStepSound(soundStoneFootstep) is the same as stone, this is the sound it makes when you walk on it.
You have now successfully created a new block class. To use this block you need to generate it, this can be done using the Single Player Commands mod using this command: "/give 92".
Continue on reading if you want to add a recipe to the crafting table to make this block.
Creating a new recipe
1. Open up CraftingManager.java
2. You should immediately see the constructor for the class and within it recipes being added using the addRecipe function.
3. Scroll to the bottom of this list of recipes and add in a new one:
addRecipe(new ItemStack(Block.example, 1), new Object[] {"##", "##", Character.valueOf('#'), Block.dirt});
This will add a recipe in which when you craft four dirt is a square share will give you your new block.
new ItemStack(Block.example, 1) - this specifies what item is going to be generated and the quantity.
new Object[] {"##", "##", Character.valueOf('#'), Block.dirt} - this specifies how it is created.
This should allow you to now craft a very basic new block using four dirt like so:
:tongue.gif:



39