Difference between revisions of "Making Tools"

From Forge Community Wiki
(Categorize with Category:Items by SizableShrimp#0755)
(Update to 1.17)
Line 2: Line 2:
 
Tools are simply an extension of the <code>Item</code> class. All of the logic is handled directly through one class with the others just being helpers to specify an exact tool type. Their implementations rely mainly on extending a specific class, it's properties, and the use of a tier system.
 
Tools are simply an extension of the <code>Item</code> class. All of the logic is handled directly through one class with the others just being helpers to specify an exact tool type. Their implementations rely mainly on extending a specific class, it's properties, and the use of a tier system.
  
== <tt>IItemTier</tt> ==
+
== <tt>Tier</tt> ==
  
To create any tool that does not derive from vanilla tiers, you will need your own implementation of <code>IItemTier</code>. This is the basis of which all tool levels are created. If you would like to use a vanilla tier, then you should specify one of the enums within <code>ItemTier</code>.
+
To create any tool that does not derive from vanilla tiers, you will need your own implementation of <code>Tier</code>. This is the basis of which all tool levels are created. If you would like to use a vanilla tier, then you should specify one of the enums within <code>Tiers</code>.
  
 
Here are what each methods defines:
 
Here are what each methods defines:
Line 10: Line 10:
 
!Method !!Return Type !!Description  
 
!Method !!Return Type !!Description  
 
|-
 
|-
|  <code>getMaxUses</code>  ||  <code>Integer</code>  ||  The durability of all items in this tier.  
+
|  <code>getUses</code>  ||  <code>Integer</code>  ||  The durability of all items in this tier.  
 
|-
 
|-
|  <code>getEfficiency</code>  ||  <code>Float</code>  ||  The efficiency multiplier of all items in this tier.  
+
|  <code>getSpeed</code>  ||  <code>Float</code>  ||  The efficiency multiplier of all items in this tier.  
 
|-
 
|-
|  <code>getAttackDamage</code>  ||  <code>Float</code>  ||  The base attack damage of all items in this tier.  
+
|  <code>getAttackDamageBonus</code>  ||  <code>Float</code>  ||  The base attack damage of all items in this tier.  
 
|-
 
|-
|  <code>getHarvestLevel</code>  ||  <code>Integer</code>  ||  The harvest level of this tier. Vanilla uses values 0-4.   
+
|  <code>getLevel</code>  ||  <code>Integer</code>  ||  The harvest level of this tier. Vanilla uses values 0-4.   
 
|-
 
|-
|  <code>getEnchantability</code>  ||  <code>Integer</code>  ||  How enchantable an item of this tier is.  
+
|  <code>getEnchantmentValue</code>  ||  <code>Integer</code>  ||  How enchantable an item of this tier is.  
 
|-
 
|-
|  <code>getRepairMaterial</code>  ||  <code>Ingredient</code>  ||  What ingredient can be used to repair this item.  
+
|  <code>getRepairIngredient</code>  ||  <code>Ingredient</code>  ||  What ingredient can be used to repair this item.  
 
|-
 
|-
 
|}
 
|}
Line 26: Line 26:
 
{{Tip/Important|An ingredient should be wrapped in a supplier to avoid calling the object directly. Tiers are loaded before registries are populated, so the call to the item needs to be deferred.}}
 
{{Tip/Important|An ingredient should be wrapped in a supplier to avoid calling the object directly. Tiers are loaded before registries are populated, so the call to the item needs to be deferred.}}
  
== <tt>ToolItem</tt> ==
+
== <tt>DiggerItem</tt> ==
  
<code>ToolItem</code> is the base of which all tool items extend. You do not necessarily have to use this or any of its supertypes/subtypes. However, it is convenient if you are looking for standard behavior. The subtypes normally referenced are <code>AxeItem</code>, <code>HoeItem</code>, <code>PickaxeItem</code>, <code>ShovelItem</code>.
+
<code>DiggerItem</code> is the base of which all tool items extend. You do not necessarily have to use this or any of its supertypes/subtypes. However, it is convenient if you are looking for standard behavior. The subtypes normally referenced are <code>AxeItem</code>, <code>HoeItem</code>, <code>PickaxeItem</code>, <code>ShovelItem</code>.
  
Each tool has four parameters: tier, attack damage, attack speed, and properties. Tiers and properties have already been explained in this and within the [[Making Items|item]] docs. Attack damage specifies how much damage to do above the current base set for that specific tier. Attack speed specifies the speed modifier to apply to your current attack speed (defaults to <code>4.0D</code>).  
+
Each tool has four parameters: tier, attack damage, attack speed, and properties. Tiers and properties have already been explained in this and within the [[Making Items|item]] docs. Attack damage specifies how much damage to do above the current base set for that specific tier. Attack speed specifies the speed modifier to apply to your current attack speed (the base attack speed for a player is <code>4.0D</code>).  
  
{{Tip|content=If you decide to extend <code>ToolItem</code>, there will be a fifth parameter which defines which blocks this tool is effective on. This parameter can just be an empty set as that is now specified on each block itself.}}
+
{{Tip|content=If you decide to extend <code>DiggerItem</code>, there will be a fifth parameter which defines a tag of which blocks this item is effective on.}}
  
 
== Registering ==
 
== Registering ==
  
A tool must be [[Registration|registered]] the same as an item. If using one of the subtypes of <code>ToolItem</code>, that is all that is required. If not, you will need to chain <code>addToolType</code> onto your properties. This will take in a <code>ToolType</code> and a harvest level. The type is held within <code>ToolType</code> itself. The harvest level will be the value from your tier using <code>IItemTier#getHarvestLevel</code>.
+
A tool must be [[Registration|registered]] the same as an item. If using one of the subtypes of <code>DiggerItem</code>, that is all that is required. If not, you will need to chain <code>addToolType</code> onto your properties. This will take in a <code>ToolType</code> and a harvest level. The type is held within <code>ToolType</code> itself. The harvest level will be the value from your tier using <code>Tier#getLevel</code>.
  
{{Tip|content=If you would like to use a custom tool type, you can call <code>ToolType::get</code>. All strings passed in should have their modid appended to them to remove any conflict issues (e.g. <code>examplemod::custom_tool_type</code>). If a standard implementation across mods is used for compatibility, no namespace is needed.}}
+
{{Tip|content=If you would like to use a custom tool type, you can call <code>ToolType::get</code>. All strings passed in should have their modid appended to them to remove any conflict issues (e.g. <code>examplemod_custom_tool_type</code>). If a standard implementation across mods is used for compatibility, no namespace is needed.}}
  
  
 
[[Category:Items]]
 
[[Category:Items]]

Revision as of 22:57, 30 July 2021

Tools are simply an extension of the Item class. All of the logic is handled directly through one class with the others just being helpers to specify an exact tool type. Their implementations rely mainly on extending a specific class, it's properties, and the use of a tier system.

Tier

To create any tool that does not derive from vanilla tiers, you will need your own implementation of Tier. This is the basis of which all tool levels are created. If you would like to use a vanilla tier, then you should specify one of the enums within Tiers.

Here are what each methods defines:

Method Return Type Description
getUses Integer The durability of all items in this tier.
getSpeed Float The efficiency multiplier of all items in this tier.
getAttackDamageBonus Float The base attack damage of all items in this tier.
getLevel Integer The harvest level of this tier. Vanilla uses values 0-4.
getEnchantmentValue Integer How enchantable an item of this tier is.
getRepairIngredient Ingredient What ingredient can be used to repair this item.

Important

An ingredient should be wrapped in a supplier to avoid calling the object directly. Tiers are loaded before registries are populated, so the call to the item needs to be deferred.

DiggerItem

DiggerItem is the base of which all tool items extend. You do not necessarily have to use this or any of its supertypes/subtypes. However, it is convenient if you are looking for standard behavior. The subtypes normally referenced are AxeItem, HoeItem, PickaxeItem, ShovelItem.

Each tool has four parameters: tier, attack damage, attack speed, and properties. Tiers and properties have already been explained in this and within the item docs. Attack damage specifies how much damage to do above the current base set for that specific tier. Attack speed specifies the speed modifier to apply to your current attack speed (the base attack speed for a player is 4.0D).

If you decide to extend DiggerItem, there will be a fifth parameter which defines a tag of which blocks this item is effective on.

Registering

A tool must be registered the same as an item. If using one of the subtypes of DiggerItem, that is all that is required. If not, you will need to chain addToolType onto your properties. This will take in a ToolType and a harvest level. The type is held within ToolType itself. The harvest level will be the value from your tier using Tier#getLevel.

If you would like to use a custom tool type, you can call ToolType::get. All strings passed in should have their modid appended to them to remove any conflict issues (e.g. examplemod_custom_tool_type). If a standard implementation across mods is used for compatibility, no namespace is needed.