tutorial:tools
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:tools [2020/06/09 03:30] – Increase heading size boogiemonster1o1 | tutorial:tools [2020/06/09 06:13] – Interface fix boogiemonster1o1 | ||
---|---|---|---|
Line 11: | Line 11: | ||
- | <code java> | + | <code java [enable_line_numbers=true]> |
- | public enum CustomToolMaterial implements | + | public enum CustomToolMaterial implements |
CustomToolMaterial(int miningLevel, | CustomToolMaterial(int miningLevel, | ||
Line 28: | Line 28: | ||
To make these values accessible from outside the constructor, | To make these values accessible from outside the constructor, | ||
- | <code java> | + | <code java [enable_line_numbers=true]> |
- | public enum CustomToolMaterial implements | + | public enum CustomToolMaterial implements |
private final int miningLevel; | private final int miningLevel; | ||
private final int itemDurability; | private final int itemDurability; | ||
Line 50: | Line 50: | ||
Now its time to implement the methods from the `ToolMaterial` interface. | Now its time to implement the methods from the `ToolMaterial` interface. | ||
You should have something like this. Change the return value of each implemented method to the corresponding field. | You should have something like this. Change the return value of each implemented method to the corresponding field. | ||
- | <code java> | + | <code java [enable_line_numbers=true]> |
public enum CustomToolMaterial implements ToolMaterial {; | public enum CustomToolMaterial implements ToolMaterial {; | ||
private final int miningLevel; | private final int miningLevel; | ||
Line 103: | Line 103: | ||
This enum constant is for potato tools. | This enum constant is for potato tools. | ||
- | <code java> | + | <code java [enable_line_numbers=true]> |
public enum CustomToolMaterial implements ToolMaterial { | public enum CustomToolMaterial implements ToolMaterial { | ||
POTATO(1, 167, 4.8F, 1.1F, 11, () -> Ingredient.ofItems(Items.POTATO)); | POTATO(1, 167, 4.8F, 1.1F, 11, () -> Ingredient.ofItems(Items.POTATO)); | ||
Line 112: | Line 112: | ||
- | ==== Registering | + | ==== Creating |
Swords, shovels, pickaxes and axes take in four arguments : The Tool Material, The Attack Damage, The Attack Speed and Item Settings | Swords, shovels, pickaxes and axes take in four arguments : The Tool Material, The Attack Damage, The Attack Speed and Item Settings | ||
- | <code java> | + | <code java [enable_line_numbers=true]> |
public static ToolItem POTATO_SHOVEL = new ShovelItem(CustomToolMaterial.POTATO, | public static ToolItem POTATO_SHOVEL = new ShovelItem(CustomToolMaterial.POTATO, | ||
public static ToolItem POTATO_SWORD = new SwordItem(CustomToolMaterial.POTATO, | public static ToolItem POTATO_SWORD = new SwordItem(CustomToolMaterial.POTATO, | ||
Line 122: | Line 122: | ||
</ | </ | ||
Unfortunately, | Unfortunately, | ||
- | <code java> | + | <code java [enable_line_numbers=true]> |
public class PickaxeSubclass extends PickaxeItem { | public class PickaxeSubclass extends PickaxeItem { | ||
public PickaxeSubclass(ToolMaterial material, int attackDamage, | public PickaxeSubclass(ToolMaterial material, int attackDamage, | ||
Line 137: | Line 137: | ||
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. | 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. | ||
- | Registering | + | ==== Registering |
- | After creating an object for each tool, register | + | |
+ | Registering tools is done the same way you would register a normal | ||
+ | |||
+ | <code java [enable_line_numbers=true]> | ||
+ | [...] | ||
+ | |||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | Registry.register(Registry.ITEM,new Identifier(" | ||
+ | Registry.register(Registry.ITEM,new Identifier(" | ||
+ | Registry.register(Registry.ITEM, | ||
+ | Registry.register(Registry.ITEM, | ||
+ | Registry.register(Registry.ITEM, | ||
+ | } | ||
+ | </ |
tutorial/tools.txt · Last modified: 2023/09/07 05:32 by drakonkinst