Interface Container

All Known Implementing Classes:
EnderChestInventory, PlayerInventory, SimpleContainer

public interface Container
A fixed number of item slots, indexed from 0.

Empty slots hold ItemStack.EMPTY, never null.

Since:
0.1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Empties every slot.
    default ItemStack[]
    Returns a copy of every slot, in index order.
    default int
    Returns the index of the first empty slot, or -1 when the container is full.
    get(int slot)
    Gets the contents of a slot.
    boolean
    Returns true if every slot is empty.
    void
    set(int slot, @Nullable ItemStack stack)
    Replaces the contents of a slot.
    default void
    Replaces every slot at once.
    int
    Returns the number of slots exposed by this container.
  • Method Details

    • size

      int size()
      Returns the number of slots exposed by this container.
      Returns:
      the number of slots exposed by this container
      Since:
      0.1.0
    • get

      ItemStack get(int slot)
      Gets the contents of a slot.
      Parameters:
      slot - the slot index, from 0 to size() - 1
      Returns:
      the stack in the slot, ItemStack.EMPTY when it is empty
      Throws:
      IndexOutOfBoundsException - if the slot is out of bounds
      Since:
      0.1.0
    • set

      void set(int slot, @Nullable ItemStack stack)
      Replaces the contents of a slot.
      Parameters:
      slot - the slot index, from 0 to size() - 1
      stack - the new stack; null is normalized to ItemStack.EMPTY
      Throws:
      IndexOutOfBoundsException - if the slot is out of bounds
      Since:
      0.1.0
    • clear

      void clear()
      Empties every slot.
      Since:
      0.1.0
    • isEmpty

      boolean isEmpty()
      Returns true if every slot is empty.
      Returns:
      true if every slot is empty
      Since:
      0.1.0
    • firstEmpty

      default int firstEmpty()
      Returns the index of the first empty slot, or -1 when the container is full.
      Returns:
      the index of the first empty slot, or -1 when the container is full
      Since:
      0.1.0
    • contents

      default ItemStack[] contents()
      Returns a copy of every slot, in index order.
      Returns:
      a copy of every slot, in index order
      Since:
      0.1.0
    • setContents

      default void setContents(@Nullable ItemStack[] contents)
      Replaces every slot at once.

      The container is cleared first; stacks beyond size() are ignored and null entries leave their slot empty.

      Parameters:
      contents - the new contents, in index order
      Since:
      0.1.0