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 [2023/09/07 05:32] (current) – [Creating Tools] drakonkinst | ||
---|---|---|---|
Line 3: | Line 3: | ||
==== Creating a Tool Material ==== | ==== Creating a Tool Material ==== | ||
- | Tools require a '' | + | Tools require a '' |
* durability | * durability | ||
* mining speed | * mining speed | ||
Line 13: | Line 13: | ||
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]> | + | <yarncode |
- | public class PotatoToolMaterial implements | + | public class PotatoToolMaterial implements |
public static final PotatoToolMaterial INSTANCE = new PotatoToolMaterial(); | public static final PotatoToolMaterial INSTANCE = new PotatoToolMaterial(); | ||
Line 86: | Line 86: | ||
[...] | [...] | ||
} | } | ||
- | </code> | + | </yarncode> |
- | '' | + | '' |
==== Creating Tools ==== | ==== Creating Tools ==== | ||
- | 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. |
- | <code java [enable_line_numbers=true]> | + | <yarncode |
- | public static | + | public static |
- | public static | + | public static |
- | </code> | + | public static class_1831 POTATO_HOE = new HoeItem(PotatoToolMaterial.INSTANCE, 7, -3.2F, new FabricItemSettings()); |
+ | </yarncode> | ||
- | `PickaxeItem` | + | === Creating Tool Subclasses === |
- | <code java [enable_line_numbers=true]> | + | |
- | public class CustomPickaxeItem extends | + | **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. |
- | public CustomPickaxeItem(ToolMaterial | + | |
+ | In older versions, all base tool classes (''< | ||
+ | |||
+ | ''< | ||
+ | <yarncode | ||
+ | public class CustomPickaxeItem extends | ||
+ | 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 ==== | ==== Registering Tools ==== |
tutorial/tools.txt · Last modified: 2023/09/07 05:32 by drakonkinst