Class ComparatorItemStackHandler

java.lang.Object
net.minecraftforge.items.ItemStackHandler
me.desht.pneumaticcraft.common.inventory.handler.BaseItemStackHandler
me.desht.pneumaticcraft.common.inventory.handler.ComparatorItemStackHandler
All Implemented Interfaces:
net.minecraftforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>, net.minecraftforge.items.IItemHandler, net.minecraftforge.items.IItemHandlerModifiable
Direct Known Subclasses:
SmartChestBlockEntity.SmartChestItemHandler

public class ComparatorItemStackHandler extends BaseItemStackHandler
An ItemStackHandler which also supports comparator signal level calculation. Smart enough to only recalculate the signal when the contents have changed.
  • Field Summary

    Fields inherited from class me.desht.pneumaticcraft.common.inventory.handler.BaseItemStackHandler

    te

    Fields inherited from class net.minecraftforge.items.ItemStackHandler

    stacks
  • Constructor Summary

    Constructors
    Constructor
    Description
    ComparatorItemStackHandler(net.minecraft.world.level.block.entity.BlockEntity te, int invSize)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    deserializeNBT(net.minecraft.nbt.CompoundTag nbt)
     
    int
    Get the comparator level for this inventory.
    void
    Force a recalculation of the comparator level.
    protected void
     

    Methods inherited from class me.desht.pneumaticcraft.common.inventory.handler.BaseItemStackHandler

    insertItem

    Methods inherited from class net.minecraftforge.items.ItemStackHandler

    extractItem, getSlotLimit, getSlots, getStackInSlot, getStackLimit, isItemValid, onLoad, serializeNBT, setSize, setStackInSlot, validateSlotIndex

    Methods inherited from class java.lang.Object

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

    • ComparatorItemStackHandler

      public ComparatorItemStackHandler(net.minecraft.world.level.block.entity.BlockEntity te, int invSize)
  • Method Details

    • onContentsChanged

      protected void onContentsChanged(int slot)
      Overrides:
      onContentsChanged in class BaseItemStackHandler
    • deserializeNBT

      public void deserializeNBT(net.minecraft.nbt.CompoundTag nbt)
      Specified by:
      deserializeNBT in interface net.minecraftforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>
      Overrides:
      deserializeNBT in class net.minecraftforge.items.ItemStackHandler
    • getComparatorValue

      public int getComparatorValue()
      Get the comparator level for this inventory. Follows the same rules as Container#calcRedstoneLevel()
      Returns:
      a redstone signal level based on the inventory fullness
    • invalidateComparatorValue

      public void invalidateComparatorValue()
      Force a recalculation of the comparator level. Recalculation will be done the next time getComparatorValue() is called. May be necessary to call this if the inventory has been changed indirectly, e.g. by modifying an ItemStack returned from getStackInSlot().