Interface Inventory
- All Superinterfaces:
- ValueContainer
- All Known Subinterfaces:
- BlockEntityInventory<T>,- CarriedInventory<C>,- Container,- CraftingGridInventory,- CraftingInventory,- CraftingOutput,- EmptyInventory,- EquipmentInventory,- EquipmentSlot,- FilteringSlot,- FuelSlot,- GridInventory,- Hotbar,- InputSlot,- Inventory2D,- InventoryColumn,- InventoryRow,- OutputSlot,- PersistentInventory,- PlayerInventory,- PotionSlot,- PrimaryPlayerInventory,- SidedSlot,- Slot,- UserInventory,- ViewableInventory,- ViewableInventory.Custom
- 
Nested Class SummaryNested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA builder for free-form Inventories.
- 
Method SummaryModifier and TypeMethodDescriptionReturns this inventory as a viewable inventory if possible.static Inventory.Builderbuilder()Creates a newInventory.Builderto build a basicInventory.booleanReturns true if the entire stack can fit in this inventory.intcapacity()The number of slots in this inventory.children()Returns a list of all direct child inventories.voidclear()Clears this inventory if it is clearable.booleanChecks whether the stacks quantity or more of given stack is contained in this Inventory.booleanChecks whether the given ItemType is contained in this InventorybooleancontainsAny(ItemStack stack) Checks whether the given stack is contained in this Inventory.booleancontainsChild(Inventory child) Returns true if the given inventory is a direct child of this one.booleancontainsInventory(Inventory inventory) Returns true if the given inventory is a descendant of this one.intThe number of empty slots in this inventory.<V> Optional<V> Gets a key defined directly on this Inventory if one is defined.<V> Optional<V> Gets the key defined in this inventory for the specified (immediate) sub-inventory.booleanReturns true if this Inventory contains children.Intersects the slots of both inventories.Adds an ItemStack to the slot at given index.Adds one or more ItemStacks to this inventory.parent()peek()Returns a copy of the first non empty stack from this Inventory.peekAt(int index) Returns a copy of the stack at given slot index.poll()Gets and removes the first non empty stack from this Inventory.poll(int limit) Gets and removes up tolimititems of the type in the first non empty stack in this Inventory from all stacks in this Inventory.pollFrom(int index) Gets and removes the stack at the supplied index in this Inventory.pollFrom(int index, int limit) Gets and removes the stack at the supplied index in this Inventory.Query this inventory for a single inventory matching the supplied inventory type.default <P> Inventoryquery(Supplier<QueryType.OneParam<P>> queryType, Supplier<P> param) Query this inventory with givenQueryType.OneParamand one parameter.default <P> Inventoryquery(Supplier<QueryType.OneParam<P>> queryType, P param) Query this inventory with givenQueryType.OneParamand one parameter.default <P1,P2> Inventory query(Supplier<QueryType.TwoParam<P1, P2>> queryType, P1 param1, P2 param2) Query this inventory with givenQueryType.TwoParamand two parameters.default Inventoryquery(KeyValueMatcher<?> matcher) Query this inventory for inventories matching the suppliedKeyValueMatcher.Query this inventory with givenQueryroot()Adds the ItemStack to the slot at given index overwriting the existing item.slot(int index) Gets theSlotat the given index.slots()Returns a list of allSlots (leaf nodes) in this Inventory.intReturns the total quantity of items in this inventory.Constructs a union of the slots in both inventories.
- 
Method Details- 
builderCreates a newInventory.Builderto build a basicInventory.Inventories created by this builder cannot be opened. If you want to show the inventory to a PlayeruseViewableInventory.builder()- Returns:
- The builder
 
- 
parentInventory parent()- Returns:
- the parent inventory, returns this inventory if there is no parent (this is a top-level inventory)
 
- 
rootInventory root()Gets the rootInventoryof thisInventory. This is equivalent to callingparent()until it returns itself.- Returns:
- the root inventory, returns this inventory if there is no parent (this is a top-level inventory)
 
- 
slotsReturns a list of allSlots (leaf nodes) in this Inventory.- Returns:
- a list of all Slots (leaf nodes) in this inventory
 
- 
childrenReturns a list of all direct child inventories.- Returns:
- a list of all direct child inventories.
 
- 
hasChildrenboolean hasChildren()Returns true if this Inventory contains children.- Returns:
- true if this inventory contains child inventories
 
- 
pollGets and removes the first non empty stack from this Inventory.- Returns:
- A SUCCESS transaction-result if an item was removed. FAILURE when nothing was removed.
 
- 
pollGets and removes up tolimititems of the type in the first non empty stack in this Inventory from all stacks in this Inventory.Note that this method attempts to consume items up to limit, which may consume items from an arbitrary number of slots.For example, assume an inventory containing 4 slots contains stacks as follows: [Stone x10] [Dirt x3] [Arrows x9] [Stone x32] Calling poll(16)on this inventory will consume Stone from the Inventory (because the first stack contains stone), and will then consume the remaining 6 items from the 4th slot.It is intended that this method is used in conjunction with a query which returns a set of slots containing a specific item type: ItemStack q = inv.query(ItemTypes.DIRT).poll(1);- Parameters:
- limit- Maximum quantity of items to consume from the inventory
- Returns:
- A SUCCESS transaction-result only if all limititems were removed else FAILURE.
 
- 
peekItemStack peek()Returns a copy of the first non empty stack from this Inventory.- Returns:
- First non empty ItemStack, or ItemStack.empty()if unavailable
 
- 
offerAdds one or more ItemStacks to this inventory.- Parameters:
- stacks- The stacks to add to this inventory.
- Returns:
- A SUCCESS transaction-result if all stacks were added and FAILURE when at least one stack was not or only partially added to the inventory.
 
- 
canFitReturns true if the entire stack can fit in this inventory.If this returns trueoffer(ItemStack...)should always succeed.- Parameters:
- stack- The stack of items to check if it can fit in this inventory.
- Returns:
- true if the entire stack can fit in this inventory.
 
- 
pollFromGets and removes the stack at the supplied index in this Inventory.- Parameters:
- index- The slot index
- Returns:
- SUCCESS transaction-result if an item was removed. FAILURE when nothing was removed.
- See Also:
 
- 
pollFromGets and removes the stack at the supplied index in this Inventory.- Parameters:
- index- The slot index
- limit- The item limit
- Returns:
- A SUCCESS transaction-result only if all limititems were removed else FAILURE.
- See Also:
 
- 
peekAtReturns a copy of the stack at given slot index.Returns Optional.empty()when there is no Slot at given index- Parameters:
- index- The slot index
- Returns:
- a copy of the stack at given slot index. Optional.empty()if there is no matching slot.
 
- 
offerAdds an ItemStack to the slot at given index. Returns aInventoryTransactionResult.Type.SUCCESSonly if the entireItemStackfits the slot.- Parameters:
- index- The slot index
- stack- The stack to add to this inventory.
- Returns:
- A SUCCESS transaction-result if the entire stack was added and FAILURE when the stack was not or only partially added to the inventory.
 
- 
setAdds the ItemStack to the slot at given index overwriting the existing item.Always returns a InventoryTransactionResult.Type.FAILUREwhen there is no Slot at given indexStacks bigger than the max stack size will be partially rejected. - Parameters:
- index- The slot index
- stack- The stack to add to the slot.
- Returns:
- A SUCCESS transaction-result if the entire stack was added and FAILURE when the stack was not or only partially added to the inventory.
 
- 
slotGets theSlotat the given index.- Parameters:
- index- The slot index
- Returns:
- slot at the specified position, or Optional.empty()if no matching slot
 
- 
clearvoid clear()Clears this inventory if it is clearable.
- 
freeCapacityint freeCapacity()The number of empty slots in this inventory. Either 1 or 0 forSlots and always 0 forEmptyInventorys.- Returns:
- the number of empty slots in this inventory
 
- 
totalQuantityint totalQuantity()Returns the total quantity of items in this inventory.This equivalent to summing ItemStack.quantity()for all slots.- Returns:
- the total quantity of items in this inventory
 
- 
capacityint capacity()The number of slots in this inventory. Always 1 forSlots and always 0 forEmptyInventorys.- Returns:
- the number of slots in this inventory
 
- 
containsChecks whether the stacks quantity or more of given stack is contained in this Inventory. To check if an inventory contains any amount usecontainsAny(ItemStack).- Parameters:
- stack- The stack to check for
- Returns:
- True if there are at least the given stack's amount of items present in this inventory.
 
- 
containsChecks whether the given ItemType is contained in this Inventory- Parameters:
- type- The type to search for
- Returns:
- True if at least one stack in this list has the given type
 
- 
containsAnyChecks whether the given stack is contained in this Inventory. The stack size is ignored.Note this will return true if any amount of the supplied stack is found. To check if an inventory contains at least a given quantity use contains(ItemStack).- Parameters:
- stack- The stack to check for
- Returns:
- True if the stack is present in this inventory
 
- 
getGets the key defined in this inventory for the specified (immediate) sub-inventory.- Type Parameters:
- V- The key value type
- Parameters:
- child- The child inventory to inspect
- key- The key to retrieve the value for
- Returns:
- The key value, if available
 
- 
getGets a key defined directly on this Inventory if one is defined. For sub-inventories this is effectively the same asinv.getParent().getProperty(inv, property);but for top-level inventories may include properties defined on the inventory directly.- Specified by:
- getin interface- ValueContainer
- Type Parameters:
- V- The key value type
- Parameters:
- key- The key to retrieve the value for
- Returns:
- The key value, if available
 
- 
queryQuery this inventory with givenQuery- Parameters:
- query- The query
- Returns:
- The queried inventory
 
- 
queryQuery this inventory with givenQueryType.OneParamand one parameter.- Type Parameters:
- P- The parameter type
- Parameters:
- queryType- The queryType
- param- The parameter
- Returns:
- The queried inventory
 
- 
queryQuery this inventory with givenQueryType.OneParamand one parameter.- Type Parameters:
- P- The parameter type
- Parameters:
- queryType- The queryType
- param- The parameter
- Returns:
- The queried inventory
 
- 
querydefault <P1,P2> Inventory query(Supplier<QueryType.TwoParam<P1, P2>> queryType, P1 param1, P2 param2) Query this inventory with givenQueryType.TwoParamand two parameters.- Type Parameters:
- P1- The first parameter type
- P2- The second parameter type
- Parameters:
- queryType- The queryType
- param1- The first parameter
- param2- The second parameter
- Returns:
- The queried inventory
 
- 
queryQuery this inventory for inventories matching the suppliedKeyValueMatcher.- Parameters:
- matcher- The key value matcher
- Returns:
- The query result
 
- 
queryQuery this inventory for a single inventory matching the supplied inventory type. This query will returnOptional.empty()when the query does not return a single inventory matching the supplied inventory type.- Type Parameters:
- T- The Type of inventory
- Parameters:
- inventoryType- The inventory type to query for
- Returns:
- the query result
 
- 
intersectIntersects the slots of both inventories. The resulting inventory will only contain slots that are present in both inventories.- Parameters:
- inventory- the other inventory
- Returns:
- an inventory wrapping all slots that are present in both inventories
 
- 
unionConstructs a union of the slots in both inventories.The resulting inventory will contain all slots from both inventories. The slots of this inventory are ordered before the slots of the given inventory. If the same slot is contained in both inventories the duplicate in the second one is removed. - Parameters:
- inventory- the other inventory
- Returns:
- an inventory wrapping all slots of both inventories.
 
- 
containsInventoryReturns true if the given inventory is a descendant of this one. This method will check for deeply nested inventories but will only return true if the entire inventory structure is contained. This means that e.g. for a query result of multiple slots the inventory will not return true even if all slots are contained. If you want to check if all slots of an inventory are contained in another one useintersect(Inventory)instead.You can use this if you want to check if a single Slot is contained in an inventory or an entire row is contained in a Grid. - Parameters:
- inventory- the other inventory
- Returns:
- whether the given inventory is contained in this one.
 
- 
containsChildReturns true if the given inventory is a direct child of this one.- Parameters:
- child- the child inventory to check for.
- Returns:
- whether the given inventory is a direct child of this one.
 
- 
asViewableOptional<ViewableInventory> asViewable()Returns this inventory as a viewable inventory if possible.Not all inventories are viewable (e.g. a custom inventory of size 5x5) - Returns:
- This inventory as an viewable inventory if possible.
 
 
-