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

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
    ItemStackcItem
    AllowNewStacksboolean
    PrioritySlotnumber
    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 PrioritySlot is set to a non-negative value, then the corresponding slot will be used first (if empty or compatible with added items). If PrioritySlot is set to -1 (default), regular order applies. Returns the number of items that fit.
    AddItems
    ItemStackListcItems
    AllowNewStacksboolean
    PrioritySlotnumber
    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 PrioritySlot is set to a non-negative value, then the corresponding slot will be used first (if empty or compatible with added items). If PrioritySlot is set to -1 (default), regular order applies. Returns the total number of items that fit.
    ChangeSlotCount
    SlotNumnumber
    AddToCountnumber
    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
    Xnumber
    Ynumber
    AddToCountnumber
    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
    cItemscItems
    Copies all non-empty slots into the cItems object provided; original cItems contents are preserved as well.
    DamageItem
    SlotNumnumber
    DamageAmountnumber
    HasReachedMaxDamageboolean
    Adds the specified damage (1 by default) to the specified item, returns true if the item reached its max damage and should be destroyed (but doesn't destroy the item).
    DamageItem
    Xnumber
    Ynumber
    DamageAmountnumber
    HasReachedMaxDamageboolean
    Adds the specified damage (1 by default) to the specified item, returns true if the item reached its max damage and should be destroyed (but doesn't destroy the item).
    EmptySlot
    SlotNumnumber
    Destroys the item in the specified slot
    EmptySlot
    Xnumber
    Ynumber
    Destroys the item in the specified slot
    FindItem
    RecipeItemcItem
    cItem
    Finds an item within the grid matching `ItemType` and `ItemDamage`. The actual item is returned, if none is found `nullptr`.
    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
    StartFromnumber
    number
    Returns the SlotNumber of the first empty slot following StartFrom, -1 if all the following slots are full
    GetNextUsedSlot
    StartFromnumber
    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
    SlotNumbernumber
    cItem
    Returns the item in the specified slot. Note that the item is read-only
    GetSlot
    Xnumber
    Ynumber
    cItem
    Returns the item in the specified slot. Note that the item is read-only
    GetSlotCoords
    SlotNumnumber
    number
    number
    Returns the X and Y coords for the specified SlotNumber. Returns "-1, -1" on invalid SlotNumber
    GetSlotNum
    Xnumber
    Ynumber
    number
    Returns the SlotNumber for the specified slot coords. Returns -1 on invalid coords
    GetWidth
    number
    Returns the X dimension of the grid
    HasItems
    ItemStackcItem
    boolean
    Returns true if there are at least as many items of the specified type as in the parameter
    HowManyCanFit
    ItemStackcItem
    AllowNewStacksboolean
    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
    ItemcItem
    number
    Returns the number of the specified item that are currently stored
    IsSlotEmpty
    SlotNumnumber
    boolean
    Returns true if the specified slot is empty, or an invalid slot is specified
    IsSlotEmpty
    Xnumber
    Ynumber
    boolean
    Returns true if the specified slot is empty, or an invalid slot is specified
    RemoveItem
    ItemStackcItem
    number
    Removes the specified item from the grid, as many as possible, up to ItemStack's m_ItemCount. Returns the number of items that were removed.
    RemoveOneItem
    SlotNumnumber
    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
    Xnumber
    Ynumber
    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
    Xnumber
    Ynumber
    cItemcItem
    Sets the specified slot to the specified item
    SetSlot
    SlotNumnumber
    ItemTypenumber
    ItemCountnumber
    ItemDamagenumber
    Sets the specified slot to the specified item
    SetSlot
    Xnumber
    Ynumber
    ItemTypenumber
    ItemCountnumber
    ItemDamagenumber
    Sets the specified slot to the specified item
    SetSlot
    SlotNumnumber
    cItemcItem
    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 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 item

    The 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
    
    Generated by APIDump on 2022-10-28 17:00:47, Build ID Unknown, Commit approx: 21ec3ebe26bff24b5fc6d96f86a441c9c9628247