Class SameSizeCombinedInvWrapper

java.lang.Object
net.neoforged.neoforge.items.wrapper.CombinedInvWrapper
com.simibubi.create.foundation.utility.SameSizeCombinedInvWrapper
All Implemented Interfaces:
net.neoforged.neoforge.items.IItemHandler, net.neoforged.neoforge.items.IItemHandlerModifiable

public class SameSizeCombinedInvWrapper extends net.neoforged.neoforge.items.wrapper.CombinedInvWrapper
Specialized combined inventory wrapper with faster slot -> inv lookup for the case when all inventories are the same size.

For context, CombinedInvWrapper implements this lookup by doing a linear scan of base indices per-inventory. We could optimize this by using a binary search, however for vaults we control all the inventories going into this and know that they all have the same number of slots. Just dividing by the number of slots per inventory is sufficient to get the inventory index.

Throw in some sanity checks and fallbacks so this isn't obscenely fragile.

  • Field Summary

    Fields inherited from class net.neoforged.neoforge.items.wrapper.CombinedInvWrapper

    baseIndex, itemHandler, slotCount
  • Method Summary

    Modifier and Type
    Method
    Description
    static net.neoforged.neoforge.items.wrapper.CombinedInvWrapper
    create(net.neoforged.neoforge.items.IItemHandlerModifiable... itemHandler)
    Create a SameSizeCombinedInvWrapper if all item handlers actually have the same size.
    protected int
    getIndexForSlot(int slot)
     

    Methods inherited from class net.neoforged.neoforge.items.wrapper.CombinedInvWrapper

    extractItem, getHandlerFromIndex, getSlotFromIndex, getSlotLimit, getSlots, getStackInSlot, insertItem, isItemValid, setStackInSlot

    Methods inherited from class java.lang.Object

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

    • create

      public static net.neoforged.neoforge.items.wrapper.CombinedInvWrapper create(net.neoforged.neoforge.items.IItemHandlerModifiable... itemHandler)
      Create a SameSizeCombinedInvWrapper if all item handlers actually have the same size. Otherwise, falls back to the parent class.
    • getIndexForSlot

      protected int getIndexForSlot(int slot)
      Overrides:
      getIndexForSlot in class net.neoforged.neoforge.items.wrapper.CombinedInvWrapper