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
tutorial:tools [2023/09/07 05:26] – Add suggestion to make an enum for multiple tool materials drakonkinsttutorial:tools [2023/09/07 05:32] (current) – [Creating Tools] drakonkinst
Line 92: Line 92:
 ==== Creating Tools ==== ==== Creating Tools ====
  
-All base tool classes (''<yarn class_1810>'', ''<yarn class_1821>'', ''<yarn class_1794>'', ''<yarn class_1743>'', ''<yarn class_1829>'') require a ''<yarn class_1832>'', an attack speed (float), an additional attack damage amount (float for <yarn class_1743>; int for the rest), and an ''<yarn class_1792.class_1793>'' instance.+**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.
  
-<yarncode java [enable_line_numbers=true]+<yarncode java> 
-public static class_1831 POTATO_SHOVEL = new class_1821(PotatoToolMaterial.INSTANCE, 1.5F, -3.0F, new class_1792.class_1793()); +public static class_1831 POTATO_PICKAXE = new PickaxeItem(PotatoToolMaterial.INSTANCE, 1, -2.8F, new FabricItemSettings()); 
-public static class_1831 POTATO_SWORD = new class_1829(PotatoToolMaterial.INSTANCE, 3, -2.4F, new class_1792.class_1793());+public static class_1831 POTATO_AXE = new AxeItem(PotatoToolMaterial.INSTANCE, 7.0F, -3.2F, new FabricItemSettings()); 
 +public static class_1831 POTATO_HOE = new HoeItem(PotatoToolMaterial.INSTANCE, 7, -3.2F, new FabricItemSettings());
 </yarncode> </yarncode>
 +
 +=== Creating Tool Subclasses ===
 +
 +**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 (''<yarn class_1810>'', ''<yarn class_1821>'', ''<yarn class_1794>'', ''<yarn class_1743>'', ''<yarn class_1829>'') require a ''<yarn class_1832>'', an attack speed (float), an additional attack damage amount (float for <yarn class_1743>; int for the rest), and an ''<yarn class_1792.class_1793>'' instance.
  
 ''<yarn class_1810>'' , ''<yarn class_1794>'' and ''<yarn class_1743>'' have protected constructors, which means you will need to create your own classes with public constructors:  ''<yarn class_1810>'' , ''<yarn class_1794>'' and ''<yarn class_1743>'' have protected constructors, which means you will need to create your own classes with public constructors: 
Line 114: Line 121:
 public static class_1831 POTATO_HOE = new CustomHoeItem(PotatoToolMaterial.INSTANCE, 7, -3.2F, new class_1792.class_1793()); public static class_1831 POTATO_HOE = new CustomHoeItem(PotatoToolMaterial.INSTANCE, 7, -3.2F, new class_1792.class_1793());
 </yarncode> </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