endstone::Inventory
Interface to the various inventories.
Functions:
Name | Description |
---|---|
addItem | Stores the given ItemStacks in the inventory. |
addItem | Stores the given ItemStacks in the inventory. |
all | Finds all slots in the inventory containing any ItemStacks with the given ItemType . |
all | Finds all slots in the inventory containing any ItemStacks with the given ItemStack . |
clear | Clears out a particular slot in the index. |
clear | Clears out the whole Inventory . |
contains | Checks if the inventory contains any ItemStacks with the given ItemType . |
contains | Checks if the inventory contains any ItemStacks with the given ItemStack . |
contains | Checks if the inventory contains at least the minimum amount specified of exactly matching ItemStacks. |
containsAtLeast | Checks if the inventory contains any ItemStacks with the given ItemType , adding to at least the minimum amount specified. |
containsAtLeast | Checks if the inventory contains ItemStacks matching the given ItemStack whose amounts sum to at least the minimum amount specified. |
first | Finds the first slot in the inventory containing an ItemStack with the given ItemType . |
first | Returns the first slot in the inventory containing an ItemStack with the given stack. |
firstEmpty | Returns the first empty Slot. |
getContents | Returns all ItemStacks from the inventory. |
getItem | Returns the ItemStack found in the slot at the given index. |
getMaxStackSize | Returns the maximum stack size for an ItemStack in this inventory. |
getSize | Returns the size of the inventory. |
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. |
remove | Removes all stacks in the inventory matching the given ItemType . |
remove | Removes all stacks in the inventory matching the given stack. |
removeItem | Removes the given ItemStacks from the inventory. |
removeItem | Removes the given ItemStacks from the inventory. |
setContents | Completely replaces the inventory’s contents. Removes all existing contents and replaces it with the ItemStacks given in the array. |
setItem | Stores 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:
type
The ItemType to match against
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:
item
The ItemStack to match against
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:
item
The ItemStack to match against
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 againstamount
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 foramount
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 againstamount
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:
type
The ItemType to look for
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:
item
The ItemStack to match against
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:
type
The ItemType to remove
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:
item
The ItemStack to match against
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: