Skip to content

Class endstone::Inventory

ClassList > endstone > Inventory

Interface to the various inventories.

  • #include <endstone/inventory/inventory.h>

Inherited by the following classes: endstone::PlayerInventory

Public Functions

Type Name
virtual std::unordered_map< int, ItemStack * > addItem (std::vector< ItemStack * > items) = 0
Stores the given ItemStacks in the inventory.
std::unordered_map< int, ItemStack * > addItem (Args &&... items)
Stores the given ItemStacks in the inventory.
virtual Result< std::unordered_map< int, std::unique_ptr< ItemStack > > > all (const std::string & type) const = 0
Finds all slots in the inventory containing any ItemStacks with the given ItemType .
virtual std::unordered_map< int, std::unique_ptr< ItemStack > > all (const ItemStack & item) const = 0
Finds all slots in the inventory containing any ItemStacks with the given ItemStack .
virtual void clear (int index) = 0
Clears out a particular slot in the index.
virtual void clear () = 0
Clears out the whole Inventory .
virtual Result< bool > contains (const std::string & type) const = 0
Checks if the inventory contains any ItemStacks with the given ItemType .
virtual bool contains (const ItemStack & item) const = 0
Checks if the inventory contains any ItemStacks with the given ItemStack .
virtual bool contains (const ItemStack & item, int amount) const = 0
Checks if the inventory contains at least the minimum amount specified of exactly matching ItemStacks.
virtual Result< bool > containsAtLeast (const std::string & type, int amount) const = 0
Checks if the inventory contains any ItemStacks with the given ItemType , adding to at least the minimum amount specified.
virtual bool containsAtLeast (const ItemStack & item, int amount) const = 0
Checks if the inventory contains ItemStacks matching the given ItemStack whose amounts sum to at least the minimum amount specified.
virtual Result< int > first (const std::string & type) const = 0
Finds the first slot in the inventory containing an ItemStack with the givenItemType .
virtual int first (const ItemStack & item) const = 0
Returns the first slot in the inventory containing an ItemStack with the given stack.
virtual int firstEmpty () const = 0
Returns the first empty Slot.
virtual std::vector< std::unique_ptr< ItemStack > > getContents () const = 0
Returns all ItemStacks from the inventory.
virtual std::unique_ptr< ItemStack > getItem (int index) const = 0
Returns the ItemStack found in the slot at the given index.
virtual int getMaxStackSize () const = 0
Returns the maximum stack size for an ItemStack in this inventory.
virtual int getSize () const = 0
Returns the size of the inventory.
virtual bool isEmpty () const = 0
Check whether this inventory is empty. An inventory is considered to be empty if there are no ItemStacks in any slot of this inventory.
virtual Result< void > remove (const std::string & type) = 0
Removes all stacks in the inventory matching the given ItemType .
virtual void remove (const ItemStack & item) = 0
Removes all stacks in the inventory matching the given stack.
virtual std::unordered_map< int, ItemStack * > removeItem (std::vector< ItemStack * > items) = 0
Removes the given ItemStacks from the inventory.
std::unordered_map< int, ItemStack * > removeItem (Args &&... items)
Removes the given ItemStacks from the inventory.
virtual Result< void > setContents (std::vector< const ItemStack * > items) = 0
Completely replaces the inventory's contents. Removes all existing contents and replaces it with the ItemStacks given in the array.
virtual void setItem (int index, const ItemStack * item) = 0
Stores the ItemStack at the given index of the inventory.
virtual ~Inventory () = default

Public Functions Documentation

function addItem [½]

Stores the given ItemStacks in the inventory.

virtual std::unordered_map< int, ItemStack * > endstone::Inventory::addItem (
    std::vector< ItemStack * > items
) = 0

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.


function addItem [2/2]

Stores the given ItemStacks in the inventory.

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

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.


function all [½]

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

virtual Result< std::unordered_map< int, std::unique_ptr< ItemStack > > > endstone::Inventory::all (
    const std::string & type
) const = 0

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


function all [2/2]

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

virtual std::unordered_map< int, std::unique_ptr< ItemStack > > endstone::Inventory::all (
    const ItemStack & item
) const = 0

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


function clear [½]

Clears out a particular slot in the index.

virtual void endstone::Inventory::clear (
    int index
) = 0

Parameters:

  • index The index to empty.

function clear [2/2]

Clears out the whole Inventory .

virtual void endstone::Inventory::clear () = 0


function contains [⅓]

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

virtual Result< bool > endstone::Inventory::contains (
    const std::string & type
) const = 0

Parameters:

  • type The item type to check for

Returns:

true if an ItemStack is found with the given ItemType


function contains [⅔]

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

virtual bool endstone::Inventory::contains (
    const ItemStack & item
) const = 0

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


function contains [3/3]

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

virtual bool endstone::Inventory::contains (
    const ItemStack & item,
    int amount
) const = 0

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


function containsAtLeast [½]

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

virtual Result< bool > endstone::Inventory::containsAtLeast (
    const std::string & type,
    int amount
) const = 0

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


function containsAtLeast [2/2]

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

virtual bool endstone::Inventory::containsAtLeast (
    const ItemStack & item,
    int amount
) const = 0

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


function first [½]

Finds the first slot in the inventory containing an ItemStack with the givenItemType .

virtual Result< int > endstone::Inventory::first (
    const std::string & type
) const = 0

Parameters:

Returns:

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


function first [2/2]

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

virtual int endstone::Inventory::first (
    const ItemStack & item
) const = 0

Parameters:

Returns:

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


function firstEmpty

Returns the first empty Slot.

virtual int endstone::Inventory::firstEmpty () const = 0

Returns:

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


function getContents

Returns all ItemStacks from the inventory.

virtual std::vector< std::unique_ptr< ItemStack > > endstone::Inventory::getContents () const = 0

Returns:

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


function getItem

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

virtual std::unique_ptr< ItemStack > endstone::Inventory::getItem (
    int index
) const = 0

Parameters:

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

Returns:

The ItemStack in the slot


function getMaxStackSize

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

virtual int endstone::Inventory::getMaxStackSize () const = 0

Returns:

The maximum size for an ItemStack in this inventory.


function getSize

Returns the size of the inventory.

virtual int endstone::Inventory::getSize () const = 0

Returns:

The size of the inventory


function isEmpty

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

virtual bool endstone::Inventory::isEmpty () const = 0

Returns:

true if empty, false otherwise


function remove [½]

Removes all stacks in the inventory matching the given ItemType .

virtual Result< void > endstone::Inventory::remove (
    const std::string & type
) = 0

Parameters:


function remove [2/2]

Removes all stacks in the inventory matching the given stack.

virtual void endstone::Inventory::remove (
    const ItemStack & item
) = 0

Note:

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

Parameters:


function removeItem [½]

Removes the given ItemStacks from the inventory.

virtual std::unordered_map< int, ItemStack * > endstone::Inventory::removeItem (
    std::vector< ItemStack * > items
) = 0

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.


function removeItem [2/2]

Removes the given ItemStacks from the inventory.

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

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.


function setContents

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

virtual Result< void > endstone::Inventory::setContents (
    std::vector< const ItemStack * > items
) = 0

Parameters:

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

function setItem

Stores the ItemStack at the given index of the inventory.

virtual void endstone::Inventory::setItem (
    int index,
    const ItemStack * item
) = 0

Parameters:


function ~Inventory

virtual endstone::Inventory::~Inventory () = default


The documentation for this class was generated from the following file include/endstone/inventory/inventory.h