Class SlotReference<T>

java.lang.Object
net.ixdarklord.coolcatcore.api.utils.SlotReference<T>
Type Parameters:
T - The type of the inventory owner (e.g., Player or Container).
Direct Known Subclasses:
SlotReference.Container, SlotReference.Player

public abstract class SlotReference<T> extends Object
Represents a reference to a specific slot within an inventory or container.

A SlotReference provides direct access to an ItemStack stored in a slot, allowing retrieval, modification, and clearing operations.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A SlotReference implementation for generic containers (e.g., chests, furnaces).
    static class 
    A SlotReference implementation for player inventories.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final SlotReference<?>
    A static empty slot reference used as a placeholder for invalid or unavailable slots.
    protected final int
     
    protected final T
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    SlotReference(T owner, int index)
    Creates a new SlotReference instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Clears the slot by setting its contents to ItemStack.EMPTY.
    abstract @NotNull net.minecraft.world.item.ItemStack
    get()
    Retrieves the ItemStack currently stored in this slot.
    int
    Returns the slot index within the container or inventory.
    Returns the inventory owner associated with this slot.
    abstract boolean
    set(net.minecraft.world.item.ItemStack stack)
    Replaces the item in this slot.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EMPTY

      public static final SlotReference<?> EMPTY
      A static empty slot reference used as a placeholder for invalid or unavailable slots.

      Always returns ItemStack.EMPTY and does not permit modifications.

    • owner

      protected final T owner
    • index

      protected final int index
  • Constructor Details

    • SlotReference

      public SlotReference(@Nullable T owner, int index)
      Creates a new SlotReference instance.
      Parameters:
      owner - the inventory owner managing this slot, or null if invalid
      index - the index of the slot within the inventory
  • Method Details

    • getOwner

      @Nullable public T getOwner()
      Returns the inventory owner associated with this slot.
      Returns:
      the owner, or null if this reference is invalid
    • getIndex

      public int getIndex()
      Returns the slot index within the container or inventory.
      Returns:
      the slot index
    • get

      @NotNull public abstract @NotNull net.minecraft.world.item.ItemStack get()
      Retrieves the ItemStack currently stored in this slot.
      Returns:
      the stored item, or ItemStack.EMPTY if the slot is empty
      Throws:
      IllegalStateException - if the owner is null
    • set

      public abstract boolean set(net.minecraft.world.item.ItemStack stack)
      Replaces the item in this slot.
      Parameters:
      stack - the new ItemStack to place
      Returns:
      true if the item was successfully set, false if unchanged
      Throws:
      IllegalStateException - if the owner is null
    • clear

      public boolean clear()
      Clears the slot by setting its contents to ItemStack.EMPTY.
      Returns:
      true if an item was removed, false if already empty
      Throws:
      IllegalStateException - if the owner is null