Difference between revisions of "Making Items"

From Forge Community Wiki
(Inital Import dokuwiki)
 
(Update to 1.18)
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
{{Under construction}}
 +
 
Along with blocks, items are a key component of most mods. While blocks make up the world around you, items are what let you change it.
 
Along with blocks, items are a key component of most mods. While blocks make up the world around you, items are what let you change it.
  
 
== Creating an Item ==
 
== Creating an Item ==
 
=== Basic Items ===
 
=== Basic Items ===
Basic items that need no special functionality (think sticks or sugar) don’t need custom classes. You can create an item by instantiate the <code><nowiki>Item</nowiki></code> class with an <code><nowiki>Item$Properties</nowiki></code> object. This <code><nowiki>Item$Properties</nowiki></code> object can be made calling the constructor and it can be customised by calling its methods. For instance:
+
Basic items that need no special functionality (think sticks or sugar) don’t need custom classes. You can create an item by instantiating the <code><nowiki>Item</nowiki></code> class with an <code><nowiki>Item$Properties</nowiki></code> object. This <code><nowiki>Item$Properties</nowiki></code> object can be made by calling the constructor and can be customised by calling its methods. For instance:
 
{| class="wikitable sortable" border=1
 
{| class="wikitable sortable" border=1
 
!Method                  !!Description   
 
!Method                  !!Description   
 
|-
 
|-
|  <code><nowiki>group</nowiki></code>          ||  Sets which <code><nowiki>ItemGroup</nowiki></code> (previously called creative tab) this item is under. Must be called if this item is meant to be shown on the creative menu. Vanilla groups can be found in the class <code><nowiki>ItemGroup</nowiki></code>.  
+
|  <code><nowiki>tab</nowiki></code>          ||  Sets which <code><nowiki>CreativeModeTab</nowiki></code> (previously called creative tab) this item is under. Must be called if this item is meant to be shown on the creative menu. Vanilla tabs can be found in the class <code><nowiki>CreativeModeTab</nowiki></code>.  
 
|-
 
|-
|  <code><nowiki>maxDamage</nowiki></code>      ||  Sets the maximum damage value for this item. If it is greater than ''0'', the properties ''damaged'' and ''damage'' are added to keep track of the current ''ItemStack'' damage.  
+
|  <code><nowiki>durability</nowiki></code>      ||  Sets the maximum damage value for this item. If it is greater than ''0'', the properties ''damaged'' and ''damage'' are added to keep track of the current ''ItemStack'' damage.  
 
|-
 
|-
|  <code><nowiki>maxStackSize</nowiki></code>    ||  Sets the maximum stack size. You cannot have an item that is both damagable and stackable.  
+
|  <code><nowiki>stacksTo</nowiki></code>    ||  Sets the maximum stack size. You cannot have an item that is both damagable and stackable.  
 
|-
 
|-
 
|  <code><nowiki>setNoRepair</nowiki></code>    ||  Makes this item impossible to repair, even if it is damageable.  
 
|  <code><nowiki>setNoRepair</nowiki></code>    ||  Makes this item impossible to repair, even if it is damageable.  
 
|-
 
|-
|  <code><nowiki>containerItem</nowiki></code>  ||  Sets this item’s container item. For example, milk buckets give you back an empty bucket when they are crafted.
+
|  <code><nowiki>craftRemainder</nowiki></code>  ||  Sets this item’s container item. For example, milk buckets give you back an empty bucket when they are crafted.  
|-
 
|  <code><nowiki>addToolType</nowiki></code>    ||  Gives the item the ability of a <code><nowiki>ToolType</nowiki></code> (<code><nowiki>SHOVEL</nowiki></code>, <code><nowiki>AXE</nowiki></code>) at the specified harvest level (''0'' for Wood/Gold, ''1'' for Stone, ''2'' for Iron, ''3'' for Gold).  
 
 
|-
 
|-
 
|}
 
|}
  
  
The above methods are chainable meaning they <code><nowiki>return this</nowiki></code> to facilitate calling them in series.
+
The above methods are chainable, meaning they <code><nowiki>return this</nowiki></code> to facilitate calling them in series.
  
 
=== Advanced Items ===
 
=== Advanced Items ===
Line 29: Line 29:
 
== Registering an Item ==
 
== Registering an Item ==
 
Items must be [[Registration|registered]] to function.
 
Items must be [[Registration|registered]] to function.
 +
 +
 +
[[Category:Items]]

Latest revision as of 13:57, 12 January 2022

This page is under construction.

This page is incomplete, and needs more work. Feel free to edit and improve this page!

Along with blocks, items are a key component of most mods. While blocks make up the world around you, items are what let you change it.

Creating an Item

Basic Items

Basic items that need no special functionality (think sticks or sugar) don’t need custom classes. You can create an item by instantiating the Item class with an Item$Properties object. This Item$Properties object can be made by calling the constructor and can be customised by calling its methods. For instance:

Method Description
tab Sets which CreativeModeTab (previously called creative tab) this item is under. Must be called if this item is meant to be shown on the creative menu. Vanilla tabs can be found in the class CreativeModeTab.
durability Sets the maximum damage value for this item. If it is greater than 0, the properties damaged and damage are added to keep track of the current ItemStack damage.
stacksTo Sets the maximum stack size. You cannot have an item that is both damagable and stackable.
setNoRepair Makes this item impossible to repair, even if it is damageable.
craftRemainder Sets this item’s container item. For example, milk buckets give you back an empty bucket when they are crafted.


The above methods are chainable, meaning they return this to facilitate calling them in series.

Advanced Items

Setting the properties of an item as above only works for simple items. If you want more complicated items, you should subclass Item and override its methods.

Registering an Item

Items must be registered to function.