-
Notifications
You must be signed in to change notification settings - Fork 0
Custom Tools
Just like Custom Blocks, Custom Tools are based on a CustomToolType. A CustomToolType controls the behaviour and looks of its Tools. This page will only cover the basics and some concepts. For more information on a specific topic or method, please refer to the Javadocs.
CustomToolTypes require at minimum a display name, a base material for the itemstack, a mining level (otherwise acts like the players hand), a mining speed (defaults to the base material one, if present and not set) and, if the base material is not damageable, a maximum durability. If the base material is damageable, its maximum durability will be used if none is set.
Configurable options of a CustomToolType are:
- Display Name
- Lore
- Mining Speed (not vanilla-bound)
- Mining Level (not vanilla-bound)
- Maximum Durability (not vanilla-bound)
- Including Vanilla Mineables (currently only applies to pickaxes, further information on the Minecraft Wiki)
- Overwrite Vanilla Mineables (currently only applies to pickaxes, prevents overwriting vanilla defaults, if set, with the tools default speed)
- Affected by Wrong Tool
- Affected by Underwater
- Affected by Floating
As previously mentioned, a CustomToolType has many configurations. For this example we will create a Wooden Pickaxe which behaves like a Diamond Pickaxe.
CustomToolType WOOD_DIA_PICKAXE = CustomToolType.builder()
.name(Component.text("Wooden Diamond Pickaxe"))
.material(Material.WOODEN_PICKAXE)
.speed(CustomToolType.MiningSpeed.DIAMOND) // Like with Custom Blocks, this can also just be a decimal value
.miningLevel(CustomToolType.MiningLevel.DIAMOND) // This can also be any positive full number
.includeVanillaMineables(true) // Makes sure blocks breakable by all pickaxes and not specified further are actually breakable
.build();Warning
Registration of any kind must always happen during STARTUP. Attempting to register entries later could lead to data loss and unexpected behaviour!
Just like with CustomBlockTypes, CustomToolTypes also need to be registered. We will create a CustomTools class including a similar register helper method.
Very important! We will need to call the static init() method in our onEnable(), as due to how Java behaves and loads classes, our CustomToolTypes would not get registered until accessed which will throw upon using a tool as MoonBreak is not aware of our types yet.
public class CustomTools {
public static void init() {}
private static CustomToolType register(Key key, CustomToolType.Builder builder) {
CustomToolType type = builder.build();
BuiltinRegistries.TOOL_TYPE.register(key, type);
return type;
}
}Now we can easily register our CustomToolType.
public static final CustomToolType WOOD_DIA_PICKAXE = register(
Key.key("test:wood_dia_pickaxe"),
CustomToolType.builder()
.name(Component.text("Wooden Diamond Pickaxe"))
.material(Material.WOODEN_PICKAXE)
.speed(CustomToolType.MiningSpeed.DIAMOND)
.miningLevel(CustomToolType.MiningLevel.DIAMOND)
.includeVanillaMineables(true)
);Now that we have successfully created and registered our CustomToolType, we can obtain its representing itemstack. Itemstacks are cached to prevent unneeded recreation.
CustomTool tool = CustomTool.of(CustomTools.WOOD_DIA_PICKAXE);
ItemStack item = tool.itemStack(); // We could also passthrough ItemMeta to be used as a base using CustomTool#itemStack(ItemMeta)We can now give the itemstack to ourselves and test our CustomTool.
insert GIF