Tutorial - Creating a block
We're going to add a new ore to the game: the platinum ore.
First of all create a new file in the mod's blocks directory and name it platinumOre.js. Open that file
and add the following contents to it:
id = config.getBlockId("platinumOre");
creativeTab = "buildingBlocks";
addToCreative[0] = true;
displayName[0] = "Platinum Ore";
material = "rock";
stepSound = "stone";
hardness[0] = 3.0;
toolClass[0] = "pickaxe";
harvestLevel[0] = 2;
textureFileXP[0] = "platinumOre.png";
textureFileXN[0] = "platinumOre.png";
textureFileYP[0] = "platinumOre.png";
textureFileYN[0] = "platinumOre.png";
textureFileZP[0] = "platinumOre.png";
textureFileZN[0] = "platinumOre.png";
name: This attribute gives the block an unique name.
id: The block receives its id from the mod's configuration file.
displayName[0]: The [0] means metadata 0. Every attribute that can be different for each metadata must
have this postfix or it won't work.
toolClass[0]: Only pickaxes can harvest the block.
harvestLevel[0]: Only pickaxes with harvest level 2 or higher can harvest the block. The iron and diamond
pickaxes are the only vanilla ones that have harvest level 2 or higher.
textureFileXX: XP means x-positive, XN means x-negative, YP y-positive and so on.
Now copy the platinumOre.png file into the textures/blocks directory.
The last thing you have to is to add the block to your mod.js file. To do so open the mod.js file and add
the following contents to it:
mod.addBlock("platinumOre.js", "normal");
The first line adds a blockId property to the mod's configuration file. We already used that property in the block file.
The second line adds the block to the game. The first argument is the name of the block's file. The second is the type of the block.
That's it. You'll find the block in the building blocks creative tab.
Continue with: Adding the block to the world generation