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:
Axe
Let's start with the axe. Create a file in the items directory and name it platinumAxe.js. Add the following lines to it:
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:
Hoe
Create a file in the items directory and name it platinumHoe.js. Add the following lines to it:
addToCreative[0] = true;
creativeTab = "tools";
full3d = true;
maxDamage = 200;
onUse[0] = "if (world.getBlockName(position) == 'minecraft:dirt' || world.getBlockName(position) == 'minecraft:grass') { world.setBlock(position, 'minecraft:farmland'); itemstack.damageItem(1); }";
textureFile[0] = "platinumHoe.png";
Add the following line to the en_US.lang file:
Pickaxe
Create a file in the items directory and name it platinumPickaxe.js. Add the following lines to it:
addToCreative[0] = true;
creativeTab = "tools";
damage = 2;
full3d = true;
toolClass = "pickaxe";
harvestLevel = 3;
efficiency[0] = 6.0;
maxDamage = 200;
onHitEntity[0] = "itemstack.damageItem(2);";
onBlockDestroyed[0] = "itemstack.damageItem(1);";
textureFile[0] = "platinumPickaxe.png";
Add the following line to the en_US.lang file:
Shovel
Create a file in the items directory and name it platinumShovel.js. Add the following lines to it:
addToCreative[0] = true;
creativeTab = "tools";
damage = 2;
full3d = true;
toolClass = "shovel";
efficiency[0] = 6.0;
maxDamage = 200;
onHitEntity[0] = "itemstack.damageItem(2);";
onBlockDestroyed[0] = "itemstack.damageItem(1);";
textureFile[0] = "platinumShovel.png";
Add the following line to the en_US.lang file:
Sword
Create a file in the items directory and name it platinumSword.js. Add the following lines to it:
addToCreative[0] = true;
creativeTab = "combat";
damage = 10;
full3d = true;
effectiveBlocks = "minecraft:web";
harvestBlocks = "minecraft:web";
efficiency[0] = 6.0;
maxDamage = 200;
maxUsingDuration[0] = 72000;
usingAction[0] = "block";
onHitEntity[0] = "itemstack.damageItem(1);";
onRightClick[0] = "player.setItemInUse();";
onBlockDestroyed[0] = "itemstack.damageItem(2);";
textureFile[0] = "platinumSword.png";
Add the following line to the en_US.lang file:
Finally add the tools to your mod by adding the following lines to your mod.js file:
mod.addItem("platinumHoe.js", "normal");
mod.addItem("platinumPickaxe.js", "normal");
mod.addItem("platinumShovel.js", "normal");
mod.addItem("platinumSword.js", "normal");
To be continued...