Interface Container

All Superinterfaces:
Inventory, ValueContainer

public interface Container extends Inventory
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).
  • Method Details

    • isViewedSlot

      boolean isViewedSlot(Slot slot)
      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

      List<Inventory> 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

      boolean setCursor(ItemStack item)
      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

      Optional<ItemStack> 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 viewing player.
      Returns:
      The viewing player
    • isOpen

      boolean isOpen()
      Returns whether this Container is open.
      Returns:
      Whether this Container is open.
    • type

      Returns the ContainerType of this container.
      Returns:
      the ContainerType of this container.
    • currentMenu

      Optional<InventoryMenu> currentMenu()
      Returns the InventoryMenu if this container has been opened by one.
      Returns:
      the current InventoryMenu if present