Class GhostStackHandler

java.lang.Object
top.girlkisser.lazuli.api.inventory.GhostStackHandler
All Implemented Interfaces:
net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>, net.neoforged.neoforge.items.IItemHandler, net.neoforged.neoforge.items.IItemHandlerModifiable

@ParametersAreNonnullByDefault public class GhostStackHandler extends Object implements net.neoforged.neoforge.items.IItemHandler, net.neoforged.neoforge.items.IItemHandlerModifiable, net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
A "fake item stack handler." Extracted items are cleared instead of given and inserted items are copied and not consumed.
This is useful for filter-style blocks and items where you want to specify item filters without needing to consume an item or use a weird UI.
TODO: EMI/JEI/REI/other recipe viewers drag-n-drop support
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.Codec<net.minecraft.core.NonNullList<GhostItemStack>>
    A codec for a net.minecraft.core.NonNullList<GhostItemStack>.
    protected net.minecraft.core.NonNullList<GhostItemStack>
    The contained ghost stacks.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a ghost stack handler with a single slot.
    GhostStackHandler(int slots)
    A "fake item stack handler." Extracted items are cleared instead of given and inserted items are copied and not consumed.
    Create a ghost stack handler with the given stacks.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    deserializeNBT(net.minecraft.core.HolderLookup.Provider registries, net.minecraft.nbt.CompoundTag tag)
     
    net.minecraft.world.item.ItemStack
    extractItem(int i, int maxCount, boolean simulate)
    Use instead.
    get(int i)
    Get an item from the slot.
    int
    getSlotLimit(int i)
     
    int
     
    net.minecraft.world.item.ItemStack
     
    net.minecraft.world.item.ItemStack
    insertItem(int i, net.minecraft.world.item.ItemStack stack, boolean simulate)
    Use instead.
    boolean
    isItemValid(int i, net.minecraft.world.item.ItemStack arg)
     
    void
    Invoked any time the contents of the ghost stack handler change.
    net.minecraft.nbt.CompoundTag
    serializeNBT(net.minecraft.core.HolderLookup.Provider registries)
     
    void
    setStackInSlot(int i, net.minecraft.world.item.ItemStack stack)
     

    Methods inherited from class java.lang.Object

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

    • LIST_CODEC

      public static final com.mojang.serialization.Codec<net.minecraft.core.NonNullList<GhostItemStack>> LIST_CODEC
      A codec for a net.minecraft.core.NonNullList<GhostItemStack>.
    • stacks

      protected net.minecraft.core.NonNullList<GhostItemStack> stacks
      The contained ghost stacks.
  • Constructor Details

    • GhostStackHandler

      public GhostStackHandler()
      Create a ghost stack handler with a single slot.
    • GhostStackHandler

      public GhostStackHandler(int slots)
      A "fake item stack handler." Extracted items are cleared instead of given and inserted items are copied and not consumed.
      This is useful for filter-style blocks and items where you want to specify item filters without needing to consume an item or use a weird UI.
      Parameters:
      slots - The amount of slots for the inventory.
    • GhostStackHandler

      public GhostStackHandler(Collection<GhostItemStack> stacks)
      Create a ghost stack handler with the given stacks.
      Parameters:
      stacks - The stacks.
  • Method Details

    • onContentsChanged

      public void onContentsChanged(int slot)
      Invoked any time the contents of the ghost stack handler change.
      Parameters:
      slot - The slot that changed.
    • get

      public GhostItemStack get(int i)
      Get an item from the slot.
      Parameters:
      i - The index to get an item from.
      Returns:
      The ghost item stack.
    • setStackInSlot

      public void setStackInSlot(int i, net.minecraft.world.item.ItemStack stack)
      Specified by:
      setStackInSlot in interface net.neoforged.neoforge.items.IItemHandlerModifiable
    • getSlots

      public int getSlots()
      Specified by:
      getSlots in interface net.neoforged.neoforge.items.IItemHandler
    • getStackInSlot

      public net.minecraft.world.item.ItemStack getStackInSlot(int i)
      Specified by:
      getStackInSlot in interface net.neoforged.neoforge.items.IItemHandler
    • insertItem

      @Obsolete public net.minecraft.world.item.ItemStack insertItem(int i, net.minecraft.world.item.ItemStack stack, boolean simulate)
      Use instead.
      Specified by:
      insertItem in interface net.neoforged.neoforge.items.IItemHandler
    • extractItem

      @Obsolete public net.minecraft.world.item.ItemStack extractItem(int i, int maxCount, boolean simulate)
      Use instead.
      Specified by:
      extractItem in interface net.neoforged.neoforge.items.IItemHandler
    • getSlotLimit

      public int getSlotLimit(int i)
      Specified by:
      getSlotLimit in interface net.neoforged.neoforge.items.IItemHandler
    • isItemValid

      public boolean isItemValid(int i, net.minecraft.world.item.ItemStack arg)
      Specified by:
      isItemValid in interface net.neoforged.neoforge.items.IItemHandler
    • serializeNBT

      public net.minecraft.nbt.CompoundTag serializeNBT(net.minecraft.core.HolderLookup.Provider registries)
      Specified by:
      serializeNBT in interface net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
    • deserializeNBT

      public void deserializeNBT(net.minecraft.core.HolderLookup.Provider registries, net.minecraft.nbt.CompoundTag tag)
      Specified by:
      deserializeNBT in interface net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>