cItemGrid
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 | ContentscItemGrid classThis class represents a 2D array of items. It is used as the underlying storage and API for all cases that use a grid of items: The items contained in this object are accessed either by a pair of XY coords, or a slot number (x + Width * y). There are functions available for converting between the two formats. Functions
Code example: Add items to player inventoryThe following code tries to add 32 sticks to a player's main inventory:local Items = cItem(E_ITEM_STICK, 32); local PlayerInventory = Player:GetInventory(); local PlayerMainInventory = PlayerInventory:GetInventoryGrid(); -- PlayerMainInventory is of type cItemGrid local NumAdded = PlayerMainInventory:AddItem(Items); if (NumAdded == Items.m_ItemCount) then -- All the sticks did fit LOG("Added 32 sticks"); else -- Some (or all) of the sticks didn't fit LOG("Tried to add 32 sticks, but only " .. NumAdded .. " could fit"); end Code example: Damage an itemThe following code damages the helmet in the player's armor and destroys it if it reaches max damage:local PlayerInventory = Player:GetInventory(); local PlayerArmor = PlayerInventory:GetArmorGrid(); -- PlayerArmor is of type cItemGrid if (PlayerArmor:DamageItem(0)) then -- Helmet is at SlotNum 0 -- The helmet has reached max damage, destroy it: PlayerArmor:EmptySlot(0); end |