🇬🇧 English
🇬🇧 English
Appearance
🇬🇧 English
🇬🇧 English
Appearance
This page is written for:
1.21
This page is written for:
1.21
Tools are essential for survival and progression, allowing players to gather resources, construct buildings, and defend themselves.
INFO
If you're creating multiple tool materials, consider using an Enum
to store them. Vanilla does this in the ToolMaterials
class, which stores all the tool materials that are used in the game.
This class can also be used to determine your tool material's properties in relation to vanilla tool materials.
You can create a tool material by creating a new class that inherits it - in this example, I'll be creating "Guidite" tools:
public class GuiditeMaterial implements ToolMaterial {
// Your IDE should override the interface's methods for you, or at least shout at you to do so.
}
The tool material tells the game the following information:
getDurability()
How many times the tool can be used before breaking.
Example
@Override
public int getDurability() {
return 455;
}
getMiningSpeedMultiplier()
If the tool is used to break blocks, how fast should it break the blocks?
For reference purposes, the diamond tool material has a mining speed of 8.0F
whilst the stone tool material has a mining speed of 4.0F
.
Example
@Override
public float getMiningSpeedMultiplier() {
return 5.0F;
}
getAttackDamage()
How many points of damage should the tool do when used as a weapon against another entity?
Example
@Override
public float getAttackDamage() {
return 1.5F;
}
getMiningLevel()
The inverse tag shows what the tool cannot mine. For instance, using the BlockTags.INCORRECT_FOR_WOODEN_TOOL
tag stops the tool from mining certain blocks:
{
"values": [
"#minecraft:needs_diamond_tool",
"#minecraft:needs_iron_tool",
"#minecraft:needs_stone_tool"
]
}
This means the tool can't mine blocks that need a diamond, iron, or stone tool.
Example
We'll use the iron tool tag. This stops Guidite tools from mining blocks that require a stronger tool than iron.
@Override
public TagKey<Block> getInverseTag() {
return BlockTags.INCORRECT_FOR_IRON_TOOL;
}
You can use TagKey.of(...)
to create a custom tag key if you want to use a custom tag.
getEnchantability()
How easy is it to get better and higher level enchantments with this item? For reference, Gold has an enchantability of 22 whilst Netherite has an enchantability of 15.
Example
@Override
public int getEnchantability() {
return 22;
}
getRepairIngredient()
What item or items are used to repair the tool?
Example
@Override
public Ingredient getRepairIngredient() {
return Ingredient.ofItems(ModItems.SUSPICIOUS_SUBSTANCE, Items.POTATO);
}
Once you have created your tool material and tweaked it to your likings, you can create an instance of it to be used in the tool item constructors.
public static final GuiditeMaterial INSTANCE = new GuiditeMaterial();
Using the same utility function as in the Creating Your First Item guide, you can create your tool items:
public static final Item GUIDITE_SWORD = register(new SwordItem(GuiditeMaterial.INSTANCE, new Item.Settings()), "guidite_sword");
Remember to add them to an item group if you want to access them from the creative inventory!
ItemGroupEvents.modifyEntriesEvent(ItemGroups.TOOLS)
.register((itemGroup) -> itemGroup.add(ModItems.GUIDITE_SWORD));
You will also have to add a texture, item translation and item model. However, for the item model, you'll want to use the item/handheld
model as your parent.
For this example, I will be using the following model and texture for the "Guidite Sword" item:
{
"parent": "item/handheld",
"textures": {
"layer0": "fabric-docs-reference:item/guidite_sword"
}
}
That's pretty much it! If you go in-game you should see your tool item(s) in the tools tab of the creative inventory menu.