Tutorial - Creation of a block
In this part we're going to create a simple block.
Open the mod.js file.
The mod.js file is the most important file of your mod. It contains everything that adds, edits or removes things. Don't worry, there is a way to outsource the contents into multiple files
if you don't like huge files.
In order to add a block, you have to do four things:
At first, you have to copy the textures for your block to assets/tutorial/textures/blocks. If you want to use vanilla minecraft textures or textures from other mods, you can skip this.
For this block, use the platinumOre.png file.
Secondly, you have to create a file in the blocks directory. This file contains all attributes that describe the block, such as the name, material or step sound.
Name the file platinumOre.js and add the following lines to it:
material = "rock";
stepSound = "stone";
creativeTab = "buildingBlocks";
addToCreative[0] = true;
hardness[0] = 3.0;
toolClass[0] = "pickaxe";
harvestLevel[0] = 2;
drop[0] = "Tutorial:platinumOre 1";
textureFileXP[0] = "platinumOre.png";
textureFileXN[0] = "platinumOre.png";
textureFileYP[0] = "platinumOre.png";
textureFileYN[0] = "platinumOre.png";
textureFileZP[0] = "platinumOre.png";
textureFileZN[0] = "platinumOre.png";
Attributes that end with [0] can have different values for different metadata versions of the block. Blocks can have a maximum of 16 metdata versions (0 to 15). It can have less, depending on the block type.
An example of metadata versions of blocks is wool. All wool blocks share the same block name but they have different textures.
- The 'name' attribute defines the name of the block and should be unique in your mod. This is not the name that is displayed in the game but is used when you have to reference the block in a recipe for example.
- The 'material' attribute defines the block's materials. Different materials have different abilities, for example, rock makes the block not harvestable with bare hands.
- The 'stepSound' attribute defines the step and harvest sound of the block.
- The 'toolClass' attribute defines what tools can harvest the block.
- The 'harvestLevel' attribute defines what level the tool has to have to harvest the block. For example iron ore has harvest level 1 (needs at least a stone pickaxe) and obsidian has harvest level 3 (needs at least a diamond pickaxe). We use 2, so our block can only be harvested by at least an iron pickaxe.
- The 'drop' attribute defines what the block drops when harvested with a proper tool. 'Tutorial' is the mod's id and 'platinumOre' the name of the block. The '1' defines the amount dropped. You can also remove this line as the default value is set up so the block drops itself with an amount of 1.
- The texture file attributes define the textures for different sides. YP means y-positive and is the top side, YN means y-negative and is the bottom side, and so on. If you want to use a minecraft texture, you can use "/minecraft:dirt.png" or just "/dirt.png". If you want to use a texture from another mod, you can use "/anothermod:some_texture.png".
Next, you have to set the name that is displayed ingame. Open the en_US.lang located in assets/tutorial/lang and add the following line to it:
platinumOre is the name you've used in your block file. The 0 (zero) is the metadata. For example, if your block uses two metadata versions, you would also add 'tile.platinumOre1.name=...'.
If you want to add names for multiple languages, create the language file for a language (de_DE.lang for German for example) and add the same line as in en_US.lang but with a different text after the equation sign.
The last thing to do is to add our block in the mod.js file. Add the following line to it:
The first argument is the name of the block's file inside the blocks directory.
The second argument is the block's type. In our case a normal block.
That's it. Run Minecraft and you'll find the block in the building blocks creative tab.
Continue with: Adding the block to the world generation