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

  • Constructor Details

    • StackCopySlot

      public StackCopySlot(int slot, int x, int y)
      Parameters:
      slot - The slot in the underlying container, whatever it may be; zero if not applicable.
  • 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 ItemStack remove(int amount)
      Overrides:
      remove in class Slot