Class StackCopySlot

java.lang.Object
net.minecraft.world.inventory.Slot
net.neoforged.neoforge.world.inventory.StackCopySlot
Direct Known Subclasses:
ItemHandlerCopySlot, ResourceHandlerSlot

public abstract class StackCopySlot extends Slot
Slot to handle immutable itemstack storages (Ex: ItemAccessItemHandler).

For an implementation for use with a ResourceHandler see ResourceHandlerSlot.

Vanilla MC code modifies the stack returned by getItem() directly, but it calls setChanged() when that happens, so we just cache the returned stack, and set it when setChanged() is called.

  • Field Details

    • emptyInventory

      private static final Container emptyInventory
    • cachedReturnedStack

      @Nullable private @Nullable ItemStack cachedReturnedStack
  • Constructor Details

    • StackCopySlot

      public StackCopySlot(int x, int y)
  • Method Details

    • getStackCopy

      protected abstract ItemStack getStackCopy()
      Gets the itemstack from the storage.
      Returns:
      the stack in this slot
    • setStackCopy

      protected abstract void setStackCopy(ItemStack stack)
      Sets the itemstack from the storage.
      Parameters:
      stack - the stack to put into this slot
    • getItem

      public final ItemStack getItem()
      Overrides:
      getItem in class Slot
    • set

      public final void set(ItemStack stack)
      Description copied from class: Slot
      Helper method to put a stack in the slot.
      Overrides:
      set in class Slot
    • setChanged

      public final void setChanged()
      Overrides:
      setChanged in class Slot
    • remove

      public final ItemStack remove(int amount)
      Description copied from class: Slot
      Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new stack.
      Overrides:
      remove in class Slot