====== cItem Class ======
cItem is what defines an item or stack of items in the game, it contains the item ID, damage, quantity and enchantments. Each slot in a [[cInventory]] or a [[cItemGrid]] is a cItem and each [[cPickup]] contains a cItem. The enchantments are contained in a [[API:cEnchantments|cEnchantments]] class

===== Functions =====
^ Function ^ Parameters ^ Return type ^ Notes ^
| () | | cItem | Creates a new empty cItem object
| () | ItemType, Count, Damage, EnchantmentString | cItem | Creates a new cItem object of the specified type, count (1 by default), damage (0 by default) and enchantments (non-enchanted by default) |
| () | cItem | cItem | Creates an exact copy of the cItem object in the parameter |
| Clear | | | Resets the instance to an empty item |
| CopyOne | | cItem | Creates a copy of this object, with its count set to 1 |
| DamageItem | [Amount] | bool | Adds the specified damage. Returns true when damage reaches max value and the item should be destroyed (but doesn't destroy the item) |
| Empty | | | Resets the instance to an empty item |
| GetMaxDamage | | number | Returns the maximum value for damage that this item can get before breaking; zero if damage is not accounted for for this item type |
| IsDamageable | | bool | Returns true if this item does account for its damage |
| IsEmpty | bool |
| IsEnchantable | ItemType | bool | (static) Returns true if the specified ItemType is an enchantable item, as defined by the 1.2.5 network protocol (deprecated) |
| IsEqual | cItem | bool | Returns true if the item in the parameter is the same as the one stored in the object (type, damage and enchantments) |
| IsSameType | cItem | bool | Returns true if the item in the parameter is of the same ItemType as the one stored in the object |
| IsStackableWith | cItem | bool | Returns true if the item in the parameter is stackable with the one stored in the object |

===== Variables =====
cItem's member variables can be accessed directly by Lua plugins, using the dot operator (e. g. "Item.m_ItemType")
^ Value type ^ Variable name ^
| number | m_ItemType |
| number | m_ItemCount |
| number | m_ItemDamage|
| [[API:cEnchantments|cEnchantments]] | m_Enchantments |

===== Usage Notes =====
Note that the object contained in a cItem class is quite complex and quite often new Minecraft versions add more stuff. Therefore it is recommended to copy cItem objects using the copy-constructor ("local copy = cItem(original);"), this is the only way that guarantees that the object will be copied at full, even with future versions of MCServer.

===== Example code =====
The following code shows how to create items in several different ways (adapted from the Debuggers plugin):
<code lua>
local Item1 = cItem();  -- empty item
local Item2 = cItem(E_ITEM_DIAMOND_SWORD, 1, 0, "1=1");  -- enchanted sword, enchantment given as numeric string
local Item3 = cItem(E_ITEM_DIAMOND_SHOVEL);  -- 1 undamaged shovel, no enchantment
Item3.m_Enchantments:SetLevel(cEnchantments.enchUnbreaking, 4);  -- Add the Unbreaking enchantment. Note that Vanilla's levelcap isn't enforced
local Item4 = cItem(E_ITEM_DIAMOND_PICKAXE);  -- 1 undamaged pickaxe, no enchantment
Item4.m_Enchantments:SetLevel(cEnchantments.enchUnbreaking, 5);
Item4.m_Enchantments:SetLevel(cEnchantments.enchEfficiency, 3);  -- Add multiple enchantments
local Item5 = cItem(E_ITEM_DIAMOND_CHESTPLATE, 1, 0, "thorns=1;unbreaking=3");  -- enchanted chestplate, enchantment given as textual stringdesc
</code>