Interface Container
- All Superinterfaces:
Inventory
,ValueContainer
A Container is effectively a ViewModel for a particular set of
Inventory
objects used to allow players to interact
with the Inventories, usually via a GUI (the View).-
Nested Class Summary
Nested classes/interfaces inherited from interface org.spongepowered.api.item.inventory.Inventory
Inventory.Builder
-
Method Summary
Modifier and TypeMethodDescriptionReturns theInventoryMenu
if this container has been opened by one.cursor()
Gets the viewing players cursor item.boolean
isOpen()
Returns whether this Container is open.boolean
isViewedSlot
(Slot slot) Returns whether given slot is part of the viewed inventories but not part of the viewers own inventory.boolean
setCursor
(ItemStackLike item) Sets the viewing players cursor item.type()
Returns theContainerType
of this container.viewed()
Returns the list of viewed inventories.viewer()
Gets the viewingplayer
.Methods inherited from interface org.spongepowered.api.item.inventory.Inventory
asViewable, canFit, capacity, children, clear, contains, contains, containsAny, containsChild, containsInventory, freeCapacity, get, get, hasChildren, intersect, offer, offer, parent, peek, peekAt, poll, poll, pollFrom, pollFrom, query, query, query, query, query, query, root, set, slot, slots, totalQuantity, union
-
Method Details
-
isViewedSlot
Returns whether given slot is part of the viewed inventories but not part of the viewers own inventory.Examples for viewed inventory slots:
All the slots of the opened chest and not the player grid below.
The slots of the crafting grid in the opened player inventory.
- Parameters:
slot
- The slot to check.- Returns:
true
when the slot is part of the viewed inventories.
-
viewed
Returns the list of viewed inventories.This is usually at least the inventory a player opened and the players inventory.
It is not necessary, that all slots of the viewed inventories are visible or interactable with.
- Returns:
- the list of viewed inventories.
-
setCursor
Sets the viewing players cursor item.Returns false when the container is no longer open.
- Parameters:
item
- The item to set.- Returns:
- true if the cursor was set.
-
cursor
Gets the viewing players cursor item.Returns
Optional.empty()
when the container was closed.- Returns:
- The players cursor item.
-
viewer
ServerPlayer viewer()Gets the viewingplayer
.- Returns:
- The viewing player
-
isOpen
boolean isOpen()Returns whether this Container is open.- Returns:
- Whether this Container is open.
-
type
Optional<ContainerType> type()Returns theContainerType
of this container.Notably the players own inventory does not have a ContainerType
- Returns:
- the ContainerType of this container.
-
currentMenu
Optional<InventoryMenu> currentMenu()Returns theInventoryMenu
if this container has been opened by one.- Returns:
- the current InventoryMenu if present
-