tutorial:tools
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:tools [2020/07/30 11:03] – Fixed an incorrect method name boogiemonster1o1 | 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:// | ||
| - | ==== Introduction | + | ===== Creating a Tool Material ===== |
| - | Creating a tool is very similar to making armor. It's a bit more complicated than making an item, but it's easy to make multiple of them | + | |
| - | ==== Creating | + | Tools require |
| + | * durability | ||
| + | * mining speed | ||
| + | * attack damage | ||
| + | * mining level | ||
| + | * enchantability | ||
| + | * repair ingredient | ||
| - | The first step to creating a tool is to implement | + | In other words, Tool Materials defines the //base// functionality for tools of that type, and tools can choose |
| - | It's best to make the class as an enum, as it doesnt require you to create | + | Vanilla Tool Materials can be found in ''< |
| - | + | <yarncode | |
| - | <code java [enable_line_numbers=true]> | + | public |
| - | public | + | |
| - | | + | |
| - | + | ||
| - | } | + | |
| } | } | ||
| - | </code> | + | </yarncode> |
| - | What each argument does:- | + | '' |
| - | 1. `miningLevel` refers to the strength of the tool necessary to mine any material. Wood is 1, Stone is 2, Iron is 3, Diamond is 4. | + | |
| - | 2. `itemDurability` refers to the initial durability of a tool. Gold is 32, Iron is 250, Netherite is 2031. | + | |
| - | 3. `miningSpeedMultiplier ` refers to how fast your tools can break blocks. Gold is 12.0f, Diamond is 8.0f, Iron is 6.0f. | + | |
| - | 4. `attackDamage` refers to the melee damage that your tools perform. Wood is 0.0f, Stone is 1.0f, Diamond is 3.0f | + | |
| - | 5. `enchantability` refers to the chance of getting high-level enchantments on your tools. Wood is 15, Stone is 5, Gold is 22, Iron is 14. | + | |
| - | 6. `repairIngredient` refers to the item that can repair your tools in an anvil. This will not be stored in an `Ingredient`, | + | |
| - | + | ||
| - | To make these values accessible from outside the constructor, | + | |
| - | <code java [enable_line_numbers=true]> | + | |
| - | public enum CustomToolMaterial implements ToolMaterial {; | + | |
| - | private final int miningLevel; | + | |
| - | private final int itemDurability; | + | |
| - | private final float miningSpeedMultiplier; | + | |
| - | private final float attackDamage; | + | |
| - | private final int enchantability; | + | |
| - | private final Lazy< | + | |
| - | + | ||
| - | CustomToolMaterial(int miningLevel, | + | |
| - | this.miningLevel = miningLevel; | + | |
| - | this.itemDurability = itemDurability; | + | |
| - | this. miningSpeedMultiplier = miningSpeedMultiplier; | + | |
| - | this.attackDamage = attackDamage; | + | |
| - | this.enchantability = enchantability; | + | |
| - | this.repairIngredient = new Lazy<> | + | |
| - | } | + | |
| - | } | + | |
| - | </ | + | |
| - | + | ||
| - | Now its time to implement | + | |
| - | You should have something like this. Change the return value of each implemented method to the corresponding field. | + | |
| - | <code java [enable_line_numbers=true]> | + | |
| - | public enum CustomToolMaterial implements ToolMaterial {; | + | |
| - | private final int miningLevel; | + | |
| - | private final int itemDurability; | + | |
| - | private final float miningSpeedMultiplier; | + | |
| - | private final float attackDamage; | + | |
| - | private final int enchantability; | + | |
| - | private final Lazy< | + | |
| - | + | ||
| - | CustomToolMaterial(int miningLevel, | + | |
| - | this.miningLevel = miningLevel; | + | |
| - | this.itemDurability = itemDurability; | + | |
| - | this.miningSpeedMultiplier = miningSpeedMultiplier; | + | |
| - | this.attackDamage = attackDamage; | + | |
| - | this.enchantability = enchantability; | + | |
| - | this.repairIngredient = new Lazy<> | + | |
| - | } | + | |
| + | === Durability === | ||
| + | ''< | ||
| + | < | ||
| @Override | @Override | ||
| - | public int getDurability() { | + | public int method_8025() { |
| - | return | + | return |
| } | } | ||
| + | </ | ||
| + | === Mining Speed === | ||
| + | ''< | ||
| + | < | ||
| @Override | @Override | ||
| - | public float getMiningSpeedMultiplier() { | + | public float method_8027() { |
| - | return | + | return |
| } | } | ||
| + | </ | ||
| + | === Attack Damage === | ||
| + | ''< | ||
| + | < | ||
| @Override | @Override | ||
| - | public float getAttackDamage() { | + | public float method_8028() { |
| - | return | + | return |
| } | } | ||
| + | </ | ||
| + | === Mining Level === | ||
| + | ''< | ||
| + | < | ||
| @Override | @Override | ||
| - | public int getMiningLevel() { | + | public int method_8024() { |
| - | return | + | return |
| } | } | ||
| + | </ | ||
| + | === Enchantability === | ||
| + | ''< | ||
| + | < | ||
| @Override | @Override | ||
| - | public int getEnchantability() { | + | public int method_8026() { |
| - | return | + | return |
| } | } | ||
| + | </ | ||
| + | === Repair Ingredient === | ||
| + | ''< | ||
| + | < | ||
| @Override | @Override | ||
| - | public | + | public |
| - | return | + | return |
| } | } | ||
| - | } | + | </yarncode> |
| - | </code> | + | |
| - | + | ||
| - | Next, create an enum constant. You can create multiple enum constants if you need multiple tool materials. | + | |
| - | This enum constant is for potato tools. | + | |
| - | <code java [enable_line_numbers=true]> | + | '' |
| - | public | + | < |
| - | | + | public |
| - | return Ingredient.ofItems(Items.POTATO); | + | |
| - | }); | + | |
| | | ||
| [...] | [...] | ||
| } | } | ||
| - | </code> | + | </yarncode> |
| + | '' | ||
| - | ==== Creating | + | ===== Creating |
| - | Swords, shovels, pickaxes | + | **In newer versions, all base tool class constructors are public |
| - | <code java [enable_line_numbers=true]> | + | <yarncode |
| - | public static | + | public final class TutorialItems { |
| - | public static | + | |
| - | </ | + | public static |
| - | Unfortunately, | + | public |
| - | <code java [enable_line_numbers=true]> | + | |
| - | public class PickaxeSubclass extends PickaxeItem { | + | |
| - | public | + | |
| - | super(material, attackDamage, | + | |
| - | } | + | |
| } | } | ||
| - | </code> | + | </yarncode> |
| - | To make a pickaxe, hoe and axe, create objects of the subclasses. | + | |
| - | <code java> | + | |
| - | public static ToolItem POTATO_PICKAXE = new PickaxeSubclass(CustomToolMaterial.POTATO, | + | |
| - | public static ToolItem POTATO_AXE = new AxeSubclass(CustomToolMaterial.POTATO, | + | |
| - | public static ToolItem POTATO_HOE = new HoeSubclass(CustomToolMaterial.POTATO, | + | |
| - | </code> | + | |
| - | If you want to add any special attributes or behavior to your tool, create a class that extends one of the tool items, and override any required methods. | + | ===== Creating Tool Subclasses ===== |
| - | ==== Registering Tools ==== | + | **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. |
| - | Registering tools is done the same way you would register | + | In older versions, all base tool classes (''< |
| - | <code java [enable_line_numbers=true]> | + | '' |
| - | | + | < |
| - | + | public class CustomPickaxeItem extends class_1810 { | |
| - | @Override | + | public |
| - | public | + | |
| - | Registry.register(Registry.ITEM,new Identifier(" | + | |
| - | Registry.register(Registry.ITEM, | + | |
| - | Registry.register(Registry.ITEM, | + | |
| - | Registry.register(Registry.ITEM, | + | |
| - | | + | |
| } | } | ||
| - | </code> | + | } |
| + | </yarncode> | ||
| + | |||
| + | Using the public classes: | ||
| + | < | ||
| + | public static class_1831 POTATO_PICKAXE = new CustomPickaxeItem(PotatoToolMaterial.INSTANCE, | ||
| + | public static class_1831 POTATO_AXE = new CustomAxeItem(PotatoToolMaterial.INSTANCE, | ||
| + | public static class_1831 POTATO_HOE = new CustomHoeItem(PotatoToolMaterial.INSTANCE, | ||
| + | </ | ||
| - | ==== 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.1596107039.txt.gz · Last modified: 2020/07/30 11:03 by boogiemonster1o1