User Tools

Site Tools


tutorial:tools

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:tools [2020/06/09 03:30] – Increase heading size boogiemonster1o1tutorial: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 ArmorMaterial {;+public enum CustomToolMaterial implements ToolMaterial {;
     CustomToolMaterial(int miningLevel, int itemDurability, float miningSpeed, float attackDamage, int enchantability, Supplier<Ingredient> repairIngredient) {     CustomToolMaterial(int miningLevel, int itemDurability, float miningSpeed, float attackDamage, int enchantability, Supplier<Ingredient> repairIngredient) {
    
Line 28: Line 28:
  
 To make these values accessible from outside the constructor, create a final field for each of them and assign their values in the constructor. To make these values accessible from outside the constructor, create a final field for each of them and assign their values in the constructor.
-<code java> +<code java [enable_line_numbers=true]
-public enum CustomToolMaterial implements ArmorMaterial {;+public enum CustomToolMaterial implements ToolMaterial {;
     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 the tools ====+==== Creating the tool objects ====
  
 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, 1.5F, -3.0F, new Item.Settings().group(ItemGroup.TOOLS)); public static ToolItem POTATO_SHOVEL = new ShovelItem(CustomToolMaterial.POTATO, 1.5F, -3.0F, new Item.Settings().group(ItemGroup.TOOLS));
 public static ToolItem POTATO_SWORD = new SwordItem(CustomToolMaterial.POTATO, 3, -2.4F, new Item.Settings().group(ItemGroup.COMBAT)); public static ToolItem POTATO_SWORD = new SwordItem(CustomToolMaterial.POTATO, 3, -2.4F, new Item.Settings().group(ItemGroup.COMBAT));
Line 122: Line 122:
 </code> </code>
 Unfortunately, `PickaxeItem` and `AxeItem` only have a protected constructor, so you'll have to make classes that extends each of them. Creating a subclass makes making multiple pickaxes or axes easier. Unfortunately, `PickaxeItem` and `AxeItem` only have a protected constructor, so you'll have to make classes that extends each of them. Creating a subclass makes making multiple pickaxes or axes easier.
-<code java>+<code java [enable_line_numbers=true]>
 public class PickaxeSubclass extends PickaxeItem { public class PickaxeSubclass extends PickaxeItem {
     public PickaxeSubclass(ToolMaterial material, int attackDamage, float attackSpeed, Settings settings) {     public PickaxeSubclass(ToolMaterial material, int attackDamage, float attackSpeed, Settings settings) {
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 and texturing a tool is done the exact same way as an item.  +==== Registering Tools ==== 
-After creating an object for each tool, register them in your mod initializer class just like how you would with a regular item+ 
 +Registering tools is done the same way you would register a normal item. 
 + 
 +<code java [enable_line_numbers=true]> 
 +    [...] 
 +     
 +    @Override 
 +    public void onInitialize() { 
 +        Registry.register(Registry.ITEM,new Identifier("tutorial","potato_pickaxe"), POTATO_PICKAXE); 
 + Registry.register(Registry.ITEM,new Identifier("tutorial","potato_axe"), POTATO_AXE); 
 + Registry.register(Registry.ITEM,new Identifier("tutorial","potato_sword"), POTATO_SWORD); 
 + Registry.register(Registry.ITEM,new Identifier("tutorial","potato_hoe"), POTATO_HOE); 
 +        Registry.register(Registry.ITEM,new Identifier("tutorial","potato_shovel"), POTATO_SHOVEL); 
 +    } 
 +</code> 
tutorial/tools.txt · Last modified: 2023/09/07 05:32 by drakonkinst