Tutorial - Creation of tools

In this part we're going to create a set of tools.

Firstly, we create the configuration properties for our tools. Add the following lines to the mod.js file:

config.addItemIdProperty("platinumAxe", 7001);
config.addItemIdProperty("platinumHoe", 7002);
config.addItemIdProperty("platinumPickaxe", 7003);
config.addItemIdProperty("platinumShovel", 7004);
config.addItemIdProperty("platinumSword", 7005);

Since tools are damageable, you have to create one file per tool. Also copy the following textures to the assets/CSTutorial/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:

id = config.getItemId("platinumAxe");
name = "platinumAxe";
creativeTab = "tools";
full3d = true;
toolClass = "axe";
harvestLevel = 3;
maxDamage = 200;
displayName[0] = "Platinum Axe";
addToCreative[0] = true;
damage[0] = 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, onHitEnitty 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.
To be continued...