Class StackCopySlot

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

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

For an implementation for use with an IItemHandler see ItemHandlerCopySlot.

Vanilla MC code modifies the stack returned by `getStack()` 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)
      Overrides:
      set in class Slot
    • setChanged

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

      public final ItemStack remove(int amount)
      Overrides:
      remove in class Slot