cInventory


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


cInventory class

This object is used to store the items that a cPlayer has. It also keeps track of what item the player has currently selected in their hotbar. Internally, the class uses three cItemGrid objects to store the contents:

  • Armor
  • Inventory
  • Hotbar
  • These ItemGrids are available in the API and can be manipulated by the plugins, too.

    When using the raw slot access functions, such as GetSlot() and SetSlot(), the slots are numbered consecutively, each ItemGrid has its offset and count. To future-proff your plugins, use the named constants instead of hard-coded numbers.


    Constants

    Rather than hardcoding numbers, use the following constants for slot indices and counts:

    NameValueNotes
    invArmorCount 4 Number of slots in the Armor part
    invArmorOffset 0 Starting slot number of the Armor part
    invHotbarCount 9 Number of slots in the Hotbar part
    invHotbarOffset 31 Starting slot number of the Hotbar part
    invInventoryCount 27 Number of slots in the main inventory part
    invInventoryOffset 4 Starting slot number of the main inventory part
    invNumSlots 41 Total number of slots in a cInventory
    invShieldCount 1 Number of slots in the Shield part
    invShieldOffset 40 Starting slot number of the Shield part



    Functions

    NameParametersReturn valueNotes
    AddItem
    cItemcItem
    AllowNewStacksboolean
    number
    Adds an item to the storage; if AllowNewStacks is true (default), will also create new stacks in empty slots. Fills existing stacks first and fills the hotbar before the main inventory. Returns the number of items added
    AddItems
    cItemscItems
    AllowNewStacksboolean
    number
    Same as AddItem, but for several items at once
    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
    Clear Empties all slots
    CopyToItems
    cItemscItems
    Copies all non-empty slots into the cItems object provided; original cItems contents are preserved
    DamageEquippedItem
    DamageAmountnumber
    HasDestroyedboolean
    Adds the specified damage (1 by default) to the currently equipped item. Removes the item and returns true if the item reached its max damage and was destroyed.
    DamageItem
    SlotNumnumber
    DamageAmountnumber
    HasDestroyedboolean
    Adds the specified damage (1 by default) to the specified item. Removes the item and returns true if the item reached its max damage and was destroyed.
    FindItem
    RecipeItemcItem
    cItem
    Finds an item in the shield, hotbar and inventory slots matching `ItemType` and `ItemDamage`. The actual item is returned, if none is found `nullptr`. This can be used to validate that the player has a specific type of item.
    GetArmorGrid
    cItemGrid
    Returns the ItemGrid representing the armor grid (1 x 4 slots)
    GetArmorSlot
    ArmorSlotNumnumber
    cItem
    Returns the specified armor slot contents. Note that the returned item is read-only
    GetEquippedBoots
    cItem
    Returns the item in the "boots" slot of the armor grid. Note that the returned item is read-only
    GetEquippedChestplate
    cItem
    Returns the item in the "chestplate" slot of the armor grid. Note that the returned item is read-only
    GetEquippedHelmet
    cItem
    Returns the item in the "helmet" slot of the armor grid. Note that the returned item is read-only
    GetEquippedItem
    cItem
    Returns the currently selected item from the hotbar. Note that the returned item is read-only. Also note that the returned item is bound to the actual inventory slot - if a player moves another item into the slot, this object will update to the new item. Use a cItem constructor to make a copy if you need to store the contents of the slot.
    GetEquippedLeggings
    cItem
    Returns the item in the "leggings" slot of the armor grid. Note that the returned item is read-only
    GetEquippedSlotNum
    number
    Returns the hotbar slot number for the currently selected item
    GetHotbarGrid
    cItemGrid
    Returns the ItemGrid representing the hotbar grid (9 x 1 slots)
    GetHotbarSlot
    HotBarSlotNumnumber
    cItem
    Returns the specified hotbar slot contents. Note that the returned item is read-only
    GetInventoryGrid
    cItemGrid
    Returns the ItemGrid representing the main inventory (9 x 3 slots)
    GetInventorySlot
    InventorySlotNumnumber
    cItem
    Returns the specified main inventory slot contents. Note that the returned item is read-only
    GetOwner
    cPlayer
    Returns the player whose inventory this object represents
    GetShieldSlot
    cItem
    Returns current item in shield slot.
    GetSlot
    SlotNumnumber
    cItem
    Returns the contents of the specified slot. Note that the returned item is read-only
    HasItems
    cItemcItem
    boolean
    Returns true if there are at least as many items of the specified type as in the parameter
    HowManyCanFit
    ItemStackcItem
    AllowNewStacksboolean
    number
    Returns number of items out of a_ItemStack that can fit in the storage. If AllowNewStacks is false, only considers slots already containing the specified item. AllowNewStacks defaults to true if not given.
    HowManyCanFit
    ItemStackcItem
    BeginSlotNumnumber
    EndSlotNumnumber
    AllowNewStacksboolean
    number
    Returns how many items of the specified type would fit into the slot range specified. If AllowNewStacks is false, only considers slots already containing the specified item. AllowNewStacks defaults to true if not given.
    HowManyItems
    cItemcItem
    number
    Returns the number of the specified items that are currently stored
    RemoveItem
    cItemcItem
    number
    Removes the specified item from the inventory, as many as possible, up to the item's m_ItemCount. Returns the number of items that were removed.
    RemoveOneEquippedItem
    boolean
    Removes one item from the hotbar's currently selected slot. Returns true on success.
    ReplaceOneEquippedItem
    ItemcItem
    TryOtherSlotsboolean
    number
    Removes one item from the the current equipped item stack, and attempts to add the specified item stack back to the same slot. If it is not possible to place the item in the same slot, optionally (default true) tries to place the specified item elsewhere in the inventory. Returns the number of items successfully added. If the currently equipped slot is empty, its contents are simply set to the given Item.
    SendEquippedSlot Sends the equipped item slot to the client
    SetArmorSlot
    ArmorSlotNumnumber
    cItemcItem
    Sets the specified armor slot contents
    SetEquippedItem
    ItemcItem
    Sets current item in the equipped hotbar slot
    SetEquippedSlotNum
    EquippedSlotNumnumber
    Sets the currently selected hotbar slot number
    SetHotbarSlot
    HotbarSlotNumnumber
    cItemcItem
    Sets the specified hotbar slot contents
    SetInventorySlot
    InventorySlotNumnumber
    cItemcItem
    Sets the specified main inventory slot contents
    SetShieldSlot
    ItemcItem
    Sets the shield slot content
    SetSlot
    SlotNumnumber
    cItemcItem
    Sets the specified slot contents
    Generated by APIDump on 2024-12-18 00:46:06, Build ID 101, Commit b92dc1cda3576ffc4c85347b0e8449d5adb87ef6