cItemGrid


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


cItemGrid class

This 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:

  • Chest contents
  • (TODO) Chest minecart contents
  • Dispenser contents
  • Dropper contents
  • Furnace contents (?)
  • Hopper contents
  • (TODO) Hopper minecart contents
  • Player Inventory areas
  • (TODO) Trapped chest contents
  • 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

    NameParametersReturn valueNotes
    AddItem ItemStack, [AllowNewStacks], [PrioritarySlot] number Adds as many items out of ItemStack as can fit. If AllowNewStacks is set to false, only existing stacks can be topped up. If AllowNewStacks is set to true (default), empty slots can be used for the rest. If PrioritarySlot is set to a non-negative value, then the corresponding slot will be used first (if empty or compatible with added items). If PrioritarySlot is set to -1 (default), regular order applies. Returns the number of items that fit.
    AddItems ItemStackList, [AllowNewStacks], [PrioritarySlot] number Same as AddItem, but works on an entire list of item stacks. The a_ItemStackList is modified to reflect the leftover items. If a_AllowNewStacks is set to false, only existing stacks can be topped up. If AllowNewStacks is set to true, empty slots can be used for the rest. If PrioritarySlot is set to a non-negative value, then the corresponding slot will be used first (if empty or compatible with added items). If PrioritarySlot is set to -1 (default), regular order applies. Returns the total number of items that fit.
    ChangeSlotCount SlotNum, AddToCount number Adds AddToCount to the count of items in the specified slot. If the slot was empty, ignores the call. Returns the new count in the slot, or -1 if invalid SlotNum
    ChangeSlotCount X, Y, AddToCount number Adds AddToCount to the count of items in the specified slot. If the slot was empty, ignores the call. Returns the new count in the slot, or -1 if invalid slot coords
    Clear Empties all slots
    CopyToItems cItems Copies all non-empty slots into the cItems object provided; original cItems contents are preserved as well.
    DamageItem SlotNum, [DamageAmount] bool Adds the specified damage (1 by default) to the specified item, returns true if the item reached its max damage and should be destroyed
    DamageItem X, Y, [DamageAmount] bool Adds the specified damage (1 by default) to the specified item, returns true if the item reached its max damage and should be destroyed
    EmptySlot SlotNum Destroys the item in the specified slot
    EmptySlot X, Y Destroys the item in the specified slot
    GetFirstEmptySlot number Returns the SlotNumber of the first empty slot, -1 if all slots are full
    GetFirstUsedSlot number Returns the SlotNumber of the first non-empty slot, -1 if all slots are empty
    GetHeight number Returns the Y dimension of the grid
    GetLastEmptySlot number Returns the SlotNumber of the last empty slot, -1 if all slots are full
    GetLastUsedSlot number Returns the SlotNumber of the last non-empty slot, -1 if all slots are empty
    GetNextEmptySlot StartFrom number Returns the SlotNumber of the first empty slot following StartFrom, -1 if all the following slots are full
    GetNextUsedSlot StartFrom number Returns the SlotNumber of the first non-empty slot following StartFrom, -1 if all the following slots are full
    GetNumSlots number Returns the total number of slots in the grid (Width * Height)
    GetSlot SlotNumber cItem Returns the item in the specified slot. Note that the item is read-only
    GetSlot X, Y cItem Returns the item in the specified slot. Note that the item is read-only
    GetSlotCoords SlotNum number, number Returns the X and Y coords for the specified SlotNumber. Returns "-1, -1" on invalid SlotNumber
    GetSlotNum X, Y number Returns the SlotNumber for the specified slot coords. Returns -1 on invalid coords
    GetWidth number Returns the X dimension of the grid
    HasItems cItem bool Returns true if there are at least as many items of the specified type as in the parameter
    HowManyCanFit cItem, [AllowNewStacks] number Returns the number of the specified items that can fit in the storage. If AllowNewStacks is true (default), includes empty slots in the returned count.
    HowManyItems cItem number Returns the number of the specified items that are currently stored
    IsSlotEmpty SlotNum bool Returns true if the specified slot is empty, or an invalid slot is specified
    IsSlotEmpty X, Y bool Returns true if the specified slot is empty, or an invalid slot is specified
    RemoveItem cItem number Removes the specified item from the grid, as many as possible, up to the item's m_ItemCount. Returns the number of items that were removed.
    RemoveOneItem SlotNum cItem Removes one item from the stack in the specified slot and returns it as a single cItem. Empty slots are skipped and an empty item is returned
    RemoveOneItem X, Y cItem Removes one item from the stack in the specified slot and returns it as a single cItem. Empty slots are skipped and an empty item is returned
    SetSlot SlotNum, ItemType, ItemCount, ItemDamage Sets the specified slot to the specified item
    SetSlot SlotNum, cItem Sets the specified slot to the specified item
    SetSlot X, Y, ItemType, ItemCount, ItemDamage Sets the specified slot to the specified item
    SetSlot X, Y, cItem Sets the specified slot to the specified item

    Code example: Add items to player inventory

    The following code tries to add 32 sticks to a player's main inventory:
    local Items = cItem(E_ITEM_STICK, 32);
    local PlayerMainInventory = Player:GetInventorySlots();  -- 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 item

    The following code damages the helmet in the player's armor and destroys it if it reaches max damage:
    local PlayerArmor = Player:GetArmorSlots();  -- 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
    
    Generated on 2016-08-22 23:53:06, Build ID Unknown, Commit approx: 2ed4af74edd14ae17e1c6c64d44caa7b7fc30d5a