Class SimpleContainer

java.lang.Object
fr.fidorial.inventory.SimpleContainer
All Implemented Interfaces:
Container
Direct Known Subclasses:
EnderChestInventory, PlayerInventory

public abstract class SimpleContainer extends Object implements Container
A Container backed by an array, the base of the built-in inventories.

Instances are not thread-safe; touch them from the region thread owning their holder.

Since:
0.1.0
  • Constructor Details

    • SimpleContainer

      protected SimpleContainer(int size)
      Creates an empty container.
      Parameters:
      size - the number of slots
      Throws:
      IllegalArgumentException - if size is negative
      Since:
      0.1.0
  • Method Details

    • size

      public final int size()
      Description copied from interface: Container
      Returns the number of slots exposed by this container.
      Specified by:
      size in interface Container
      Returns:
      the number of slots exposed by this container
    • get

      public ItemStack get(int slot)
      Description copied from interface: Container
      Gets the contents of a slot.
      Specified by:
      get in interface Container
      Parameters:
      slot - the slot index, from 0 to size() - 1
      Returns:
      the stack in the slot, ItemStack.EMPTY when it is empty
    • set

      public void set(int slot, @Nullable ItemStack stack)
      Description copied from interface: Container
      Replaces the contents of a slot.
      Specified by:
      set in interface Container
      Parameters:
      slot - the slot index, from 0 to size() - 1
      stack - the new stack; null is normalized to ItemStack.EMPTY
    • clear

      public void clear()
      Description copied from interface: Container
      Empties every slot.
      Specified by:
      clear in interface Container
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Container
      Returns true if every slot is empty.
      Specified by:
      isEmpty in interface Container
      Returns:
      true if every slot is empty
    • contents

      public ItemStack[] contents()
      Description copied from interface: Container
      Returns a copy of every slot, in index order.
      Specified by:
      contents in interface Container
      Returns:
      a copy of every slot, in index order