cItem


Index:
Articles
Classes
Hooks

Quick navigation:
cArrowEntity
cBeaconEntity
cBlockArea
cBlockEntity
cBlockEntityWithItems
cBlockInfo
cBoundingBox
cBrewingstandEntity
cChatColor
cChestEntity
cChunkDesc
cClientHandle
cCommandBlockEntity
cCompositeChat
cCraftingGrid
cCraftingRecipe
cCryptoHash
cCuboid
cDispenserEntity
cDropperEntity
cDropSpenserEntity
cEnchantments
cEntity
cEntityEffect
cExpBottleEntity
cFile
cFireChargeEntity
cFireworkEntity
cFloater
cFlowerPotEntity
cFurnaceEntity
cGhastFireballEntity
cHangingEntity
cHopperEntity
cIniFile
cInventory
cItem
cItemFrame
cItemGrid
cItems
cJson
cJukeboxEntity
cLineBlockTracer
cLuaWindow
cMap
cMapManager
cMobHeadEntity
cMobSpawnerEntity
cMojangAPI
cMonster
cNetwork
cNoteEntity
cObjective
cPainting
cPawn
cPickup
cPlayer
cPlugin
cPluginLua
cPluginManager
cProjectileEntity
cRankManager
cRoot
cScoreboard
cServer
cServerHandle
cSignEntity
cSplashPotionEntity
cStatManager
cStringCompression
cTCPLink
cTeam
cThrownEggEntity
cThrownEnderPearlEntity
cThrownSnowballEntity
cTNTEntity
cTracer
cUDPEndpoint
cUrlClient
cUrlParser
cWebAdmin
cWindow
cWitherSkullEntity
cWorld
HTTPFormData
HTTPRequest
HTTPTemplateRequest
ItemCategory
lxp
sqlite3
TakeDamageInfo
tolua
Vector3d
Vector3f
Vector3i
Globals

Contents


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 class or a cItemGrid class is a cItem and each cPickup contains a cItem. The enchantments are contained in a separate cEnchantments class and are accessible through the m_Enchantments variable.

To test if a cItem object represents an empty item, do not compare the item type nor the item count, but rather use the IsEmpty() function.

To translate from a cItem to its string representation, use the global function ItemToString(), ItemTypeToString() or ItemToFullString(). To translate from a string to a cItem, use the StringToItem() global function.


Member variables

NameTypeNotes
m_CustomName string The custom name for an item.
m_Enchantments cEnchantments} The enchantments of the item.
m_FireworkItem (undocumented)
m_ItemColor (undocumented)
m_ItemCount number Number of items in this stack
m_ItemDamage number The damage of the item. Zero means no damage. Maximum damage can be queried with GetMaxDamage()
m_ItemType number The item type. One of E_ITEM_ or E_BLOCK_ constants
m_Lore string The lore for an item. Line breaks are represented by the ` character.
m_RepairCost number The repair cost of the item. The anvil need this value

Functions

NameParametersReturn valueNotes
() (constructor) cItem Creates a new empty cItem object
() (constructor) ItemType, [Count], [Damage], [EnchantmentString], [CustomName], [Lore] cItem Creates a new cItem object of the specified type, count (1 by default), damage (0 by default), enchantments (non-enchanted by default), CustomName (empty by default) and Lore (string, empty by default)
() (constructor) cItem cItem Creates an exact copy of the cItem object in the parameter
AddCount AmountToAdd cItem Adds the specified amount to the item count. Returns self (useful for chaining).
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
EnchantByXPLevels NumXPLevels bool Enchants the item using the specified number of XP levels. Returns true if item enchanted, false if not.
GetEnchantability number Returns the enchantability of the item. When the item hasn't a enchantability, it will returns 0
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
GetMaxStackSize number Returns the maximum stack size for this item.
IsBothNameAndLoreEmpty bool Returns if both the custom name and lore are not set.
IsCustomNameEmpty bool Returns if the custom name of the cItem is empty.
IsDamageable bool Returns true if this item does account for its damage
IsEmpty bool Returns true if this object represents an empty item (zero count or invalid ID)
IsEnchantable ItemType, WithBook bool (STATIC) Returns true if the specified item type is enchantable. If WithBook is true, the function is used in the anvil inventory with book enchantments. So it checks the "only book enchantments" too. Example: You can only enchant a hoe with a book.
IsEqual cItem bool Returns true if the item in the parameter is the same as the one stored in the object (type, damage, lore, name and enchantments)
IsFullStack bool Returns true if the item is stacked up to its maximum stacking
IsLoreEmpty Returns if the lore of the cItem is empty.
IsSameType cItem bool Returns true if the item in the parameter is of the same ItemType as the one stored in the object. This is true even if the two items have different 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 Cuberite.

Example code

The following code shows how to create items in several different ways (adapted from the Debuggers plugin):
-- empty item:
local Item1 = cItem();

-- enchanted sword, enchantment given as numeric string (bad style; see Item5):
local Item2 = cItem(E_ITEM_DIAMOND_SWORD, 1, 0, "1=1");

-- 1 undamaged shovel, no enchantment:
local Item3 = cItem(E_ITEM_DIAMOND_SHOVEL);

-- Add the Unbreaking enchantment. Note that Vanilla's levelcap isn't enforced:
Item3.m_Enchantments:SetLevel(cEnchantments.enchUnbreaking, 4);

-- 1 undamaged pickaxe, no enchantment:
local Item4 = cItem(E_ITEM_DIAMOND_PICKAXE);

-- Add multiple enchantments:
Item4.m_Enchantments:SetLevel(cEnchantments.enchUnbreaking, 5);
Item4.m_Enchantments:SetLevel(cEnchantments.enchEfficiency, 3);

-- enchanted chestplate, enchantment given as textual stringdesc (good style)
local Item5 = cItem(E_ITEM_DIAMOND_CHESTPLATE, 1, 0, "thorns=1;unbreaking=3");
Generated on 2016-08-22 23:53:06, Build ID Unknown, Commit approx: 2ed4af74edd14ae17e1c6c64d44caa7b7fc30d5a