Skip to Content
⚠ Under Construction
ReferenceC++ APIInventory

endstone::Inventory

Interface to the various inventories.

Functions:

NameDescription
addItemStores the given ItemStacks in the inventory.
addItemStores the given ItemStacks in the inventory.
allFinds all slots in the inventory containing any ItemStacks with the given ItemType .
allFinds all slots in the inventory containing any ItemStacks with the given ItemStack .
clearClears out a particular slot in the index.
clearClears out the whole Inventory .
containsChecks if the inventory contains any ItemStacks with the given ItemType .
containsChecks if the inventory contains any ItemStacks with the given ItemStack .
containsChecks if the inventory contains at least the minimum amount specified of exactly matching ItemStacks.
containsAtLeastChecks if the inventory contains any ItemStacks with the given ItemType , adding to at least the minimum amount specified.
containsAtLeastChecks if the inventory contains ItemStacks matching the given ItemStack whose amounts sum to at least the minimum amount specified.
firstFinds the first slot in the inventory containing an ItemStack with the given ItemType .
firstReturns the first slot in the inventory containing an ItemStack with the given stack.
firstEmptyReturns the first empty Slot.
getContentsReturns all ItemStacks from the inventory.
getItemReturns the ItemStack found in the slot at the given index.
getMaxStackSizeReturns the maximum stack size for an ItemStack in this inventory.
getSizeReturns the size of the inventory.
isEmptyCheck whether this inventory is empty. An inventory is considered to be empty if there are no ItemStacks in any slot of this inventory.
removeRemoves all stacks in the inventory matching the given ItemType .
removeRemoves all stacks in the inventory matching the given stack.
removeItemRemoves the given ItemStacks from the inventory.
removeItemRemoves the given ItemStacks from the inventory.
setContentsCompletely replaces the inventory’s contents. Removes all existing contents and replaces it with the ItemStacks given in the array.
setItemStores the ItemStack at the given index of the inventory.

addItem

std::unordered_map<int, ItemStack *> addItem(std::vector<ItemStack *> items)

Stores the given ItemStacks in the inventory.

Note:

This will try to fill existing stacks and empty slots as well as it can.

Note:

The returned map contains what it couldn’t store, where the key is the index, and the value is the ItemStack. If all items are stored, it will return an empty map.

Parameters:

  • items The ItemStacks to add

Returns:

A map containing items that couldn’t be added.

template <typename... Args, typename> std::unordered_map<int, ItemStack *> addItem(Args &&...items)

Stores the given ItemStacks in the inventory.

Note:

This will try to fill existing stacks and empty slots as well as it can.

Note:

The returned map contains what it couldn’t store, where the key is the index, and the value is the ItemStack. If all items are stored, it will return an empty map.

Parameters:

  • items The ItemStacks to add

Returns:

A map containing items that couldn’t be added.

all

std::unordered_map<int, std::unique_ptr<ItemStack>> all(const std::string &type) const

Finds all slots in the inventory containing any ItemStacks with the given ItemType .

The returned map contains entries where, the key is the slot index, and the value is the ItemStack in that slot. If no matching ItemStack is found, an empty map is returned.

Parameters:

Returns:

A map from slot indexes to item at index

std::unordered_map<int, std::unique_ptr<ItemStack>> all(const ItemStack &item) const

Finds all slots in the inventory containing any ItemStacks with the given ItemStack .

Note:

This will only match slots if both the type and the amount of the stack match

The returned map contains entries where, the key is the slot index, and the value is the ItemStack in that slot. If no matching ItemStack is found, an empty map is returned.

Parameters:

Returns:

A map from slot indexes to item at index

clear

void clear(int index)

Clears out a particular slot in the index.

Parameters:

  • index The index to empty.
void clear()

Clears out the whole Inventory .

contains

bool contains(const std::string &type) const

Checks if the inventory contains any ItemStacks with the given ItemType .

Parameters:

  • type The item type to check for

Returns:

true if an ItemStack is found with the given ItemType

bool contains(const ItemStack &item) const

Checks if the inventory contains any ItemStacks with the given ItemStack .

Note:

This will only return true if both the type and the amount of the stack match.

Parameters:

Returns:

true if any exactly matching ItemStacks were found, false otherwise

bool contains(const ItemStack &item, int amount) const

Checks if the inventory contains at least the minimum amount specified of exactly matching ItemStacks.

Note:

An ItemStack only counts if both the type and the amount of the stack match.

Parameters:

  • item the ItemStack to match against
  • amount how many identical stacks to check for

Returns:

true if amount less than 1 or if amount of exactly matching ItemStacks were found, false otherwise

containsAtLeast

bool containsAtLeast(const std::string &type, int amount) const

Checks if the inventory contains any ItemStacks with the given ItemType , adding to at least the minimum amount specified.

Parameters:

  • type The ItemType to check for
  • amount The minimum amount

Returns:

true if amount is less than 1, true if enough ItemStacks were found to add to the given amount

bool containsAtLeast(const ItemStack &item, int amount) const

Checks if the inventory contains ItemStacks matching the given ItemStack whose amounts sum to at least the minimum amount specified.

Parameters:

  • item the ItemStack to match against
  • amount the minimum amount

Returns:

true if amount less than 1 or enough ItemStacks were found to add to the given amount, false otherwise

first

int first(const std::string &type) const

Finds the first slot in the inventory containing an ItemStack with the given ItemType .

Parameters:

Returns:

The slot index of the given ItemType or -1 if not found

int first(const ItemStack &item) const

Returns the first slot in the inventory containing an ItemStack with the given stack.

Parameters:

Returns:

The slot index of the given ItemStack or -1 if not found

firstEmpty

int firstEmpty() const

Returns the first empty Slot.

Returns:

The first empty Slot found, or -1 if no empty slots.

getContents

std::vector<std::unique_ptr<ItemStack>> getContents() const

Returns all ItemStacks from the inventory.

Returns:

An array of ItemStacks from the inventory. Individual items may be null.

getItem

std::unique_ptr<ItemStack> getItem(int index) const

Returns the ItemStack found in the slot at the given index.

Parameters:

  • index The index of the Slot’s ItemStack to return

Returns:

The ItemStack in the slot

getMaxStackSize

int getMaxStackSize() const

Returns the maximum stack size for an ItemStack in this inventory.

Returns:

The maximum size for an ItemStack in this inventory.

getSize

int getSize() const

Returns the size of the inventory.

Returns:

The size of the inventory

isEmpty

bool isEmpty() const

Check whether this inventory is empty. An inventory is considered to be empty if there are no ItemStacks in any slot of this inventory.

Returns:

true if empty, false otherwise

remove

void remove(const std::string &type)

Removes all stacks in the inventory matching the given ItemType .

Parameters:

void remove(const ItemStack &item)

Removes all stacks in the inventory matching the given stack.

Note:

This will only match a slot if both the type and the amount of the stack match

Parameters:

removeItem

std::unordered_map<int, ItemStack *> removeItem(std::vector<ItemStack *> items)

Removes the given ItemStacks from the inventory.

Note:

It will try to remove ‘as much as possible’ from the types and amounts you give as arguments.

Note:

The returned HashMap contains what it couldn’t remove, where the key is the index, and the value is the ItemStack. If all the given ItemStacks are removed, it will return an empty map.

Parameters:

  • items The ItemStacks to remove

Returns:

A map containing items that couldn’t be removed.

template <typename... Args, typename> std::unordered_map<int, ItemStack *> removeItem(Args &&...items)

Removes the given ItemStacks from the inventory.

Note:

It will try to remove ‘as much as possible’ from the types and amounts you give as arguments.

Note:

The returned HashMap contains what it couldn’t remove, where the key is the index, and the value is the ItemStack. If all the given ItemStacks are removed, it will return an empty map.

Parameters:

  • items The ItemStacks to remove

Returns:

A map containing items that couldn’t be removed.

setContents

Result<void> setContents(std::vector<const ItemStack *> items)

Completely replaces the inventory’s contents. Removes all existing contents and replaces it with the ItemStacks given in the array.

Parameters:

  • items A complete replacement for the contents; the length must be less than or equal to getSize().

setItem

void setItem(int index, const ItemStack *item)

Stores the ItemStack at the given index of the inventory.

Parameters:

Last updated on