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 | ContentscItem classcItem 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
Functions
Usage notesNote 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 codeThe 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"); |