cItem


Index:
Articles
Classes
Hooks

Quick navigation:
BannerPattern
BossBarColor
BossBarDivisionType
cArrowEntity
cBeaconEntity
cBedEntity
cBlockArea
cBlockEntity
cBlockEntityWithItems
cBlockInfo
cBoat
cBoundingBox
cBrewingstandEntity
cChatColor
cChestEntity
cChunkDesc
cClientHandle
cColor
cCommandBlockEntity
cCompositeChat
cCraftingGrid
cCraftingRecipe
cCryptoHash
cCuboid
cDispenserEntity
cDropperEntity
cDropSpenserEntity
cEnchantments
cEnderCrystal
cEntity
cEntityEffect
cExpBottleEntity
cExpOrb
cFallingBlock
cFile
cFireChargeEntity
cFireworkEntity
cFloater
cFlowerPotEntity
cFurnaceEntity
cGhastFireballEntity
cHangingEntity
cHopperEntity
cIniFile
cInventory
cItem
cItemFrame
cItemGrid
cItems
cJson
cJukeboxEntity
cLeashKnot
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
cStringCompression
cTCPLink
cTeam
cThrownEggEntity
cThrownEnderPearlEntity
cThrownSnowballEntity
cTNTEntity
cUDPEndpoint
cUrlClient
cUrlParser
CustomStatistic
cUUID
cWebAdmin
cWindow
cWitherSkullEntity
cWorld
EffectID
HTTPFormData
HTTPRequest
HTTPTemplateRequest
ItemCategory
lxp
SmokeDirection
sqlite3
StatisticsManager
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 (undocumented)
m_LoreTable table The lore for an item. Represented as an array table of lines.
m_RepairCost number The repair cost of the item. The anvil need this value

Functions

NameParametersReturn valueNotes
() (constructor)
cItemcItem
cItem
Creates an exact copy of the cItem object in the parameter
() (constructor)
cItem
Creates a new empty cItem object
() (constructor)
ItemTypenumber
Countnumber
Damagenumber
EnchantmentStringstring
CustomNamestring
Loretable
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)
AddCount
AmountToAddnumber
cItem
Adds the specified amount to the item count. Returns self (useful for chaining).
AddEnchantment
Enchantment IDnumber
Levelnumber
FromBookboolean
number
Adds the given enchantment at the given level to this item, following anvil enchantment combining rules. Returns the XP level cost of the addition. FromBook specifies whether to use the XP multiplier for books or the multiplier used for other items, if true it uses the multiplier for books.
AddEnchantmentsFromItem
AdditivecItem
LevelCostnumber
Adds the enchantments from the specified item to this item, returning the cost as if this were an anvil.
Clear Resets the instance to an empty item
CopyOne
cItem
Creates a copy of this object, with its count set to 1
DamageItem
Amountnumber
HasReachedMaxDamageboolean
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
NumXPLevelsnumber
HasEnchantedboolean
Randomly enchants the item using the specified number of XP levels. Returns true if the item was enchanted, false if not (not enchantable / too many enchantments already).
GetEnchantability
number
Returns the enchantability of the item. Returns zero if the item doesn't have enchantability.
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
boolean
Returns if both the custom name and lore are not set.
IsCustomNameEmpty
boolean
Returns if the custom name is empty.
IsDamageable
boolean
Returns true if this item does account for its damage
IsEmpty
boolean
Returns true if this object represents an empty item (zero count or invalid ItemType)
IsEnchantable
ItemTypenumber
FromBookboolean
boolean
(STATIC) Returns true if the specified item type is enchantable. If FromBook 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
OtherItemcItem
boolean
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
boolean
Returns true if the item is stacked up to its maximum stacking
IsLoreEmpty
boolean
Returns if the lore of the cItem is empty.
IsSameType
OtherItemcItem
boolean
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 by APIDump on 2022-10-28 17:00:47, Build ID Unknown, Commit approx: 21ec3ebe26bff24b5fc6d96f86a441c9c9628247