🇬🇧 English
🇬🇧 English
Appearance
🇬🇧 English
🇬🇧 English
Appearance
This page is written for version:
1.20.4
This page is written for version:
1.20.4
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()
What blocks can be broken by this tool? Can it mine diamonds?
A mining level of 3+ is needed to require obsidian whilst a level of 2 is required to mine diamonds.
Example
@Override
public int getMiningLevel() {
return 3;
}
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 way you registered your first item, you should register each tool similarly:
public static final Item GUIDITE_SWORD = register(new SwordItem(GuiditeMaterial.INSTANCE, 2, 0.5F, new FabricItemSettings()), "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.