Tutorial - Creation of tools
In this part we're going to create a set of tools.
Since tools are damageable, you have to create one file per tool. Also copy the following textures to the assets/tutorial/textures/items directory:
Let's start with the axe. Create a file in the items directory and name it platinumAxe.js. Add the following lines to it:
name = "platinumAxe";
creativeTab = "tools";
full3d = true;
toolClass = "axe";
harvestLevel = 3;
maxDamage = 200;
addToCreative[0] = true;
damage = 2;
efficiency[0] = 6.0;
onHitEntity[0] = "itemstack.damageItem(2);";
onBlockDestroyed[0] = "itemstack.damageItem(1);";
textureFile[0] = "platinumAxe.png";
creativeTab = "tools";
full3d = true;
toolClass = "axe";
harvestLevel = 3;
maxDamage = 200;
addToCreative[0] = true;
damage = 2;
efficiency[0] = 6.0;
onHitEntity[0] = "itemstack.damageItem(2);";
onBlockDestroyed[0] = "itemstack.damageItem(1);";
textureFile[0] = "platinumAxe.png";
New attributes here are full3d, maxDamage, damage, efficiency, onHitEntity and onBlockDestroyed.
- The 'full3d' attribute is set to true, so the item is rendered as a tool in the player's hand.
- The 'maxDamage' attribute defines the maximum damage the item can have, so it is its durability. Since the damage starts with 0, the tool has actually 201 uses.
- The 'damage' attribute defines the damage against mobs. The value is given in half hearts.
- The 'efficiency' attribute defines how fast the tool can harvest blocks. This only applied to blocks that it can actually break. For example, it is not applied to stone.
- The 'onHitEntity' and 'onBlockDestroyed' attributes are triggers that contain a script. This script is executed when the player hits an entity or destroys a block with the tool.
Add the following line to the en_US.lang file:
item.platinumAxe0.name=Platinum Axe
To be continued...