tutorial:tools
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:tools [2021/10/31 09:43] – Updated to fix sentence that said attackDamage was int, while it's float for AxeItem metaltxus | tutorial:tools [2024/08/23 13:25] (current) – [Adding Tools] solidblock | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Adding Tools ====== | ====== Adding Tools ====== | ||
| + | :!: This tutorial may be **outdated** as since 1.20.5, item components are used. For latest tutorial see [[https:// | ||
| - | ==== Creating a Tool Material ==== | + | ===== Creating a Tool Material |
| - | Tools require a '' | + | Tools require a '' |
| * durability | * durability | ||
| * mining speed | * mining speed | ||
| Line 13: | Line 14: | ||
| In other words, Tool Materials defines the //base// functionality for tools of that type, and tools can choose to use the values provided by the material, or roll with their own. | In other words, Tool Materials defines the //base// functionality for tools of that type, and tools can choose to use the values provided by the material, or roll with their own. | ||
| - | Vanilla Tool Materials can be found in '' | + | Vanilla Tool Materials can be found in '' |
| - | <code java [enable_line_numbers=true]> | + | <yarncode |
| - | public class PotatoToolMaterial implements | + | public class PotatoToolMaterial implements |
| - | | + | |
| [...] | [...] | ||
| } | } | ||
| - | </code> | + | </yarncode> |
| - | '' | + | '' |
| === Durability === | === Durability === | ||
| - | '' | + | '' |
| - | <code java [enable_line_numbers=true]> | + | <yarncode |
| - | @Override | + | @Override |
| - | public int getDurability() { | + | public int method_8025() { |
| - | return 500; | + | return 500; |
| - | } | + | } |
| - | </code> | + | </yarncode> |
| === Mining Speed === | === Mining Speed === | ||
| - | '' | + | '' |
| - | <code java [enable_line_numbers=true]> | + | <yarncode |
| - | @Override | + | @Override |
| - | public float getMiningSpeedMultiplier() { | + | public float method_8027() { |
| - | return 5.0F; | + | return 5.0F; |
| - | } | + | } |
| - | </code> | + | </yarncode> |
| === Attack Damage === | === Attack Damage === | ||
| - | '' | + | '' |
| - | <code java [enable_line_numbers=true]> | + | <yarncode |
| - | @Override | + | @Override |
| - | public float getAttackDamage() { | + | public float method_8028() { |
| - | return 3.0F; | + | return 3.0F; |
| - | } | + | } |
| - | </code> | + | </yarncode> |
| === Mining Level === | === Mining Level === | ||
| - | '' | + | '' |
| - | <code java [enable_line_numbers=true]> | + | <yarncode |
| - | @Override | + | @Override |
| - | public int getMiningLevel() { | + | public int method_8024() { |
| - | return 2; | + | return 2; |
| - | } | + | } |
| - | </code> | + | </yarncode> |
| === Enchantability === | === Enchantability === | ||
| - | '' | + | '' |
| - | <code java [enable_line_numbers=true]> | + | <yarncode |
| - | @Override | + | @Override |
| - | public int getEnchantability() { | + | public int method_8026() { |
| - | return 15; | + | return 15; |
| - | } | + | } |
| - | </code> | + | </yarncode> |
| === Repair Ingredient === | === Repair Ingredient === | ||
| - | '' | + | '' |
| - | <code java [enable_line_numbers=true]> | + | <yarncode |
| - | @Override | + | @Override |
| - | public | + | public |
| - | return | + | return |
| - | } | + | } |
| - | </code> | + | </yarncode> |
| - | + | ||
| - | '' | + | |
| - | <code java [enable_line_numbers=true]> | + | |
| - | public class PotatoToolMaterial implements ToolMaterial { | + | |
| + | ''< | ||
| + | < | ||
| + | public class PotatoToolMaterial implements class_1832 { | ||
| public static final PotatoToolMaterial INSTANCE = new PotatoToolMaterial(); | public static final PotatoToolMaterial INSTANCE = new PotatoToolMaterial(); | ||
| | | ||
| [...] | [...] | ||
| } | } | ||
| - | </code> | + | </yarncode> |
| - | '' | + | '' |
| - | ==== Creating Tools ==== | + | ===== Creating Tools Items ===== |
| - | All base tool classes ('' | + | **In newer versions, all base tool class constructors are public and can be used directly to register the item.** This constructor lets you specify attack damage and attack speed of the tool. Remember they should be registered |
| - | <code java [enable_line_numbers=true]> | + | <yarncode |
| - | public static | + | public final class TutorialItems { |
| - | public static | + | |
| - | </code> | + | public static class_1831 POTATO_AXE = new AxeItem(PotatoToolMaterial.INSTANCE, 7.0F, -3.2F, new FabricItemSettings()); |
| + | public static | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Creating Tool Subclasses ===== | ||
| + | |||
| + | **This section is not necessary in the current version of Fabric.** This is a good way to implement special attributes or behaviors for your tool, however. | ||
| + | |||
| + | In older versions, all base tool classes (''< | ||
| - | `PickaxeItem` | + | ''< |
| - | <code java [enable_line_numbers=true]> | + | <yarncode |
| - | public class CustomPickaxeItem extends | + | public class CustomPickaxeItem extends |
| - | public CustomPickaxeItem(ToolMaterial | + | public CustomPickaxeItem(class_1832 |
| super(material, | super(material, | ||
| } | } | ||
| } | } | ||
| - | </code> | + | </yarncode> |
| Using the public classes: | Using the public classes: | ||
| - | <code java> | + | <yarncode |
| - | public static | + | public static |
| - | public static | + | public static |
| - | public static | + | public static |
| - | </code> | + | </yarncode> |
| - | + | ||
| - | If you want to add any special attributes or behaviors to your tool, create a subclass that extends one of the base tool classes, and override any required methods. | + | |
| - | + | ||
| - | ==== Registering Tools ==== | + | |
| - | + | ||
| - | For a recap on registering items, read through the item tutorial [[tutorial: | + | |
| - | ==== Making your tool work with non-vanilla blocks ==== | + | ===== Making your tool work with non-vanilla blocks |
| - | Visit the last section of https:// | + | See [[mining_levels]]. |
tutorial/tools.1635673439.txt.gz · Last modified: 2021/10/31 09:43 by metaltxus