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/06/09 03:30] – Increase heading size boogiemonster1o1 | tutorial:tools [2023/09/07 05:32] (current) – [Creating Tools] drakonkinst | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Adding Tools ====== | ====== Adding Tools ====== | ||
- | ==== 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> | + | 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. `miningSpeed` 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 | + | |
- | 6. `repairIngredient` refers | + | |
- | To make these values accessible from outside | + | === Durability === |
- | <code java> | + | ''< |
- | public | + | <yarncode |
- | | + | @Override |
- | | + | public |
- | | + | |
- | private final float attackDamage; | + | } |
- | private final int enchantability; | + | </yarncode> |
- | private final Lazy<Ingredient> repairIngredient; | + | |
- | CustomToolMaterial(int miningLevel, | + | === Mining Speed === |
- | this.miningLevel = miningLevel; | + | '' |
- | this.itemDurability = itemDurability; | + | < |
- | this.miningSpeed = miningSpeed; | + | @Override |
- | this.attackDamage = attackDamage; | + | public float method_8027() { |
- | | + | |
- | | + | |
- | | + | |
} | } | ||
- | </code> | + | </yarncode> |
- | Now its time to implement | + | === Attack Damage === |
- | You should have something like this. Change the return | + | ''< |
- | <code java> | + | <yarncode |
- | public | + | @Override |
- | | + | public |
- | | + | |
- | | + | } |
- | private final float attackDamage; | + | </yarncode> |
- | private final int enchantability; | + | |
- | private final Lazy<Ingredient> repairIngredient; | + | |
- | CustomToolMaterial(int miningLevel, | + | === Mining Level === |
- | this.miningLevel | + | ''< |
- | this.itemDurability | + | < |
- | this.miningSpeed | + | @Override |
- | this.attackDamage | + | public int method_8024() { |
- | this.enchantability = enchantability; | + | return 2; |
- | | + | } |
- | } | + | </ |
- | | + | === Enchantability === |
- | public int getDurability() { | + | ''< |
- | return | + | < |
- | } | + | @Override |
+ | public int method_8026() { | ||
+ | return | ||
+ | } | ||
+ | </ | ||
- | @Override | + | === Repair Ingredient === |
- | | + | ''< |
- | return this.miningSpeed; | + | < |
- | } | + | @Override |
- | + | public | |
- | | + | return |
- | public | + | |
- | return this.attackDamage; | + | |
- | | + | |
- | + | ||
- | @Override | + | |
- | public int getMiningLevel() { | + | |
- | | + | |
- | } | + | |
- | + | ||
- | @Override | + | |
- | public int getEnchantability() { | + | |
- | return this.enchantability; | + | |
- | } | + | |
- | + | ||
- | @Override | + | |
- | public Ingredient getRepairIngredient() { | + | |
- | return this.repairIngredient.get(); | + | |
- | } | + | |
} | } | ||
- | </code> | + | </yarncode> |
- | Next, create an enum constant. You can create multiple enum constants if you need multiple tool materials. | + | ''< |
- | This enum constant is for potato tools. | + | < |
+ | public class PotatoToolMaterial implements class_1832 { | ||
- | <code java> | + | |
- | public | + | |
- | POTATO(1, 167, 4.8F, 1.1F, 11, () -> Ingredient.ofItems(Items.POTATO)); | + | |
| | ||
[...] | [...] | ||
} | } | ||
- | </code> | + | </yarncode> |
+ | '' | ||
- | ==== Registering the tools ==== | + | ==== Creating Tools ==== |
- | Swords, shovels, pickaxes | + | **In newer versions, all base tool class constructors are public |
- | <code java> | + | <yarncode |
- | public static | + | public static |
- | public static | + | public static |
- | public static | + | public static |
- | </code> | + | </ |
- | Unfortunately, `PickaxeItem` | + | |
- | <code java> | + | === Creating Tool Subclasses === |
- | public class PickaxeSubclass | + | |
- | public | + | **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 (''< | ||
+ | |||
+ | ''< | ||
+ | <yarncode | ||
+ | public class CustomPickaxeItem | ||
+ | public | ||
super(material, | super(material, | ||
} | } | ||
} | } | ||
- | </code> | + | </yarncode> |
- | To make a pickaxe and axe, create objects of the subclasses. | + | |
- | <code java> | + | Using the public classes: |
- | public static | + | <yarncode |
- | public static | + | public static |
- | </code> | + | public static |
+ | public static class_1831 POTATO_HOE = new CustomHoeItem(PotatoToolMaterial.INSTANCE, | ||
+ | </yarncode> | ||
+ | |||
+ | ==== Registering Tools ==== | ||
+ | |||
+ | For a recap on registering items, read through the item tutorial [[tutorial: | ||
- | 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. | + | ==== Making |
- | Registering and texturing a tool is done the exact same way as an item. | + | Visit the last section of https:// |
- | After creating an object for each tool, register them in your mod initializer class just like how you would with a regular item. | + |
tutorial/tools.1591673430.txt.gz · Last modified: 2020/06/09 03:30 by boogiemonster1o1