Class SlotContainer

java.lang.Object
net.ixdarklord.coolcatcore.api.container.SlotContainer
All Implemented Interfaces:
Trackable, net.minecraft.world.Clearable, net.minecraft.world.Container

public class SlotContainer extends Object implements net.minecraft.world.Container, Trackable
An inventory following a ContainerLayout. It's a vanilla Container, so menus, hoppers and Containers work with it as they are; use createSlot(int, int, int) for menu slots that respect the layout's filters, limits and roles.

Stored as a

invalid reference
Attachment
, its changes save and sync on their own. ItemContainers binds one to an item stack.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
  • Field Summary

    Fields inherited from interface net.minecraft.world.Container

    DEFAULT_DISTANCE_BUFFER
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Calls listener after a slot changes (slot -1: several at once).
    boolean
    canExtractFrom(int slot, @Nullable net.minecraft.core.Direction side)
    Whether automation may take from the slot through a face (null: any face).
    boolean
    canInsertFrom(int slot, net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.Direction side)
    Whether automation may put the item in through a face (null: any face).
    boolean
    canPlaceItem(int slot, net.minecraft.world.item.ItemStack stack)
    Whether automation without a face (a hopper under a plain container) may put the item in.
    boolean
    canPlayerPlace(int slot, net.minecraft.world.item.ItemStack stack)
    Whether a player may put the item in through a menu.
    boolean
    canTakeItem(net.minecraft.world.Container into, int slot, net.minecraft.world.item.ItemStack stack)
     
    void
     
    int
    The comparator signal the contents give (0 to 15).
    List<net.minecraft.world.item.ItemStack>
    Copies of the stacks, in order.
    int
    count(Predicate<net.minecraft.world.item.ItemStack> filter)
     
    net.minecraft.world.inventory.Slot
    createSlot(int slot, int x, int y)
    A menu slot that respects the layout's filters, limits and roles.
    void
    dropContents(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
    Spills the contents at a position and empties the container.
    net.minecraft.world.item.ItemStack
    extract(int slot, int amount, boolean simulate)
    Takes up to amount from one slot, for the holder's own code.
    net.minecraft.world.item.ItemStack
    extract(Predicate<net.minecraft.world.item.ItemStack> filter, int amount, boolean simulate)
    Takes up to amount of the first item matching filter, gathered from every slot holding it.
    void
    fromContents(net.minecraft.world.item.component.ItemContainerContents contents)
     
    int
     
    net.minecraft.world.item.ItemStack
    getItem(int slot)
     
    List<net.minecraft.world.item.ItemStack>
    The slots, in order.
    int
     
    int
    getSlotLimit(int slot, net.minecraft.world.item.ItemStack stack)
    How many of the item the slot holds.
    net.minecraft.world.item.ItemStack
    insert(int slot, net.minecraft.world.item.ItemStack stack, boolean simulate)
    Puts as much of stack as fits into one slot, for the holder's own code: filters and limits apply, roles don't.
    net.minecraft.world.item.ItemStack
    insert(net.minecraft.world.item.ItemStack stack, boolean simulate)
    Puts as much of stack as fits anywhere, topping up matching stacks before filling empty slots.
    boolean
     
    boolean
    isItemValid(int slot, net.minecraft.world.item.ItemStack stack)
    Whether the slot's filter takes the item, whoever puts it in.
     
    protected void
    onChanged(int slot)
    Called after a slot changes (slot -1: several at once).
    net.minecraft.world.item.ItemStack
    removeItem(int slot, int count)
     
    net.minecraft.world.item.ItemStack
     
    void
     
    void
     
    void
    setChangeListener(@Nullable Runnable listener)
    Called by the holder storing this value; call listener after every change.
    void
    setItem(int slot, net.minecraft.world.item.ItemStack stack)
     
    void
    setItems(List<net.minecraft.world.item.ItemStack> stacks)
    Replaces the contents; slots past stacks' end are emptied.
    setValidator(Predicate<net.minecraft.world.entity.player.Player> validator)
    Who may keep a menu on this container open; everyone by default.
    boolean
    stillValid(net.minecraft.world.entity.player.Player player)
     
    net.minecraft.world.item.component.ItemContainerContents
    The contents as an item component (the first 256 slots).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface net.minecraft.world.Container

    countItem, getMaxStackSize, hasAnyMatching, hasAnyOf, startOpen, stopOpen
  • Constructor Details

  • Method Details

    • layout

      public ContainerLayout layout()
    • getContainerSize

      public int getContainerSize()
      Specified by:
      getContainerSize in interface net.minecraft.world.Container
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface net.minecraft.world.Container
    • getItem

      public net.minecraft.world.item.ItemStack getItem(int slot)
      Specified by:
      getItem in interface net.minecraft.world.Container
    • removeItem

      public net.minecraft.world.item.ItemStack removeItem(int slot, int count)
      Specified by:
      removeItem in interface net.minecraft.world.Container
    • removeItemNoUpdate

      public net.minecraft.world.item.ItemStack removeItemNoUpdate(int slot)
      Specified by:
      removeItemNoUpdate in interface net.minecraft.world.Container
    • setItem

      public void setItem(int slot, net.minecraft.world.item.ItemStack stack)
      Specified by:
      setItem in interface net.minecraft.world.Container
    • getMaxStackSize

      public int getMaxStackSize()
      Specified by:
      getMaxStackSize in interface net.minecraft.world.Container
    • setChanged

      public void setChanged()
      Specified by:
      setChanged in interface net.minecraft.world.Container
    • stillValid

      public boolean stillValid(net.minecraft.world.entity.player.Player player)
      Specified by:
      stillValid in interface net.minecraft.world.Container
    • canPlaceItem

      public boolean canPlaceItem(int slot, net.minecraft.world.item.ItemStack stack)
      Whether automation without a face (a hopper under a plain container) may put the item in.
      Specified by:
      canPlaceItem in interface net.minecraft.world.Container
    • canTakeItem

      public boolean canTakeItem(net.minecraft.world.Container into, int slot, net.minecraft.world.item.ItemStack stack)
      Specified by:
      canTakeItem in interface net.minecraft.world.Container
    • clearContent

      public void clearContent()
      Specified by:
      clearContent in interface net.minecraft.world.Clearable
    • isItemValid

      public boolean isItemValid(int slot, net.minecraft.world.item.ItemStack stack)
      Whether the slot's filter takes the item, whoever puts it in.
    • canPlayerPlace

      public boolean canPlayerPlace(int slot, net.minecraft.world.item.ItemStack stack)
      Whether a player may put the item in through a menu.
    • canInsertFrom

      public boolean canInsertFrom(int slot, net.minecraft.world.item.ItemStack stack, @Nullable @Nullable net.minecraft.core.Direction side)
      Whether automation may put the item in through a face (null: any face).
    • canExtractFrom

      public boolean canExtractFrom(int slot, @Nullable @Nullable net.minecraft.core.Direction side)
      Whether automation may take from the slot through a face (null: any face).
    • getSlotLimit

      public int getSlotLimit(int slot, net.minecraft.world.item.ItemStack stack)
      How many of the item the slot holds.
    • insert

      public net.minecraft.world.item.ItemStack insert(int slot, net.minecraft.world.item.ItemStack stack, boolean simulate)
      Puts as much of stack as fits into one slot, for the holder's own code: filters and limits apply, roles don't. stack isn't changed.
      Returns:
      what didn't fit
    • insert

      public net.minecraft.world.item.ItemStack insert(net.minecraft.world.item.ItemStack stack, boolean simulate)
      Puts as much of stack as fits anywhere, topping up matching stacks before filling empty slots.
    • extract

      public net.minecraft.world.item.ItemStack extract(int slot, int amount, boolean simulate)
      Takes up to amount from one slot, for the holder's own code.
    • extract

      public net.minecraft.world.item.ItemStack extract(Predicate<net.minecraft.world.item.ItemStack> filter, int amount, boolean simulate)
      Takes up to amount of the first item matching filter, gathered from every slot holding it.
    • count

      public int count(Predicate<net.minecraft.world.item.ItemStack> filter)
    • getItems

      public List<net.minecraft.world.item.ItemStack> getItems()
      The slots, in order. Read-only; don't change the stacks in it either.
    • copyItems

      public List<net.minecraft.world.item.ItemStack> copyItems()
      Copies of the stacks, in order.
    • setItems

      public void setItems(List<net.minecraft.world.item.ItemStack> stacks)
      Replaces the contents; slots past stacks' end are emptied.
    • toContents

      public net.minecraft.world.item.component.ItemContainerContents toContents()
      The contents as an item component (the first 256 slots).
    • fromContents

      public void fromContents(net.minecraft.world.item.component.ItemContainerContents contents)
    • dropContents

      public void dropContents(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
      Spills the contents at a position and empties the container.
    • comparatorSignal

      public int comparatorSignal()
      The comparator signal the contents give (0 to 15).
    • createSlot

      public net.minecraft.world.inventory.Slot createSlot(int slot, int x, int y)
      A menu slot that respects the layout's filters, limits and roles.
    • addListener

      public SlotContainer addListener(SlotContainer.Listener listener)
      Calls listener after a slot changes (slot -1: several at once).
    • removeListener

      public void removeListener(SlotContainer.Listener listener)
    • setValidator

      public SlotContainer setValidator(Predicate<net.minecraft.world.entity.player.Player> validator)
      Who may keep a menu on this container open; everyone by default.
    • setChangeListener

      public void setChangeListener(@Nullable @Nullable Runnable listener)
      Description copied from interface: Trackable
      Called by the holder storing this value; call listener after every change. null unbinds.
      Specified by:
      setChangeListener in interface Trackable
    • onChanged

      protected void onChanged(int slot)
      Called after a slot changes (slot -1: several at once).