Class CombinedFixedItemInvView<InvType extends FixedItemInvView>

java.lang.Object
alexiil.mc.lib.attributes.misc.AbstractCombined<InvType>
alexiil.mc.lib.attributes.item.impl.CombinedFixedItemInvView<InvType>
All Implemented Interfaces:
Convertible, AbstractItemInvView, FixedItemInvView, Combined
Direct Known Subclasses:
CombinedFixedItemInv

public class CombinedFixedItemInvView<InvType extends FixedItemInvView> extends AbstractCombined<InvType> implements FixedItemInvView
An FixedItemInvView that delegates to a list of them instead of storing items directly.
  • Field Details

    • views

      public final List<? extends InvType extends FixedItemInvView> views
    • subSlotStartIndex

      protected final int[] subSlotStartIndex
    • invSize

      protected final int invSize
  • Constructor Details

    • CombinedFixedItemInvView

      public CombinedFixedItemInvView(List<? extends InvType> views)
  • Method Details

    • createView

      public static FixedItemInvView createView(List<? extends FixedItemInvView> list)
    • getSlotCount

      public int getSlotCount()
      Specified by:
      getSlotCount in interface FixedItemInvView
      Returns:
      The number of slots in this inventory.
    • getInvIndex

      protected int getInvIndex(int slot)
    • getInv

      protected InvType getInv(int slot)
    • getSubSlot

      protected int getSubSlot(int slot)
    • getInvStack

      public net.minecraft.item.ItemStack getInvStack(int slot)
      Specified by:
      getInvStack in interface FixedItemInvView
      Parameters:
      slot - The slot index. Must be a value between 0 (inclusive) and FixedItemInvView.getSlotCount() (exclusive) to be valid. (Like in arrays, lists, etc).
      Returns:
      The ItemStack that is held in the inventory at the moment. It is unspecified whether you are allowed to modify this returned ItemStack - however subinterfaces (like FixedItemInv) may have different limitations on this. Note that this stack might not be valid for this slot in either FixedItemInvView.isItemValidForSlot(int, ItemStack) or FixedItemInvView.getFilterForSlot(int).
    • isItemValidForSlot

      public boolean isItemValidForSlot(int slot, net.minecraft.item.ItemStack item)
      Description copied from interface: FixedItemInvView
      Checks to see if the given stack would be valid for this slot, ignoring the current contents. Note that this method should adhere to the requirements of ItemFilter.matches(ItemStack), so this must not care about the ItemStack.getCount(). Passing empty stacks will generally not return useful results.
      Specified by:
      isItemValidForSlot in interface FixedItemInvView
      Parameters:
      slot - The slot index. Must be a value between 0 (inclusive) and FixedItemInvView.getSlotCount() (exclusive) to be valid. (Like in arrays, lists, etc).
      item - The ItemStack to check. It's undefined what is returned if an empty stack is passed in, but it is not generally expected to be useful.
    • getFilterForSlot

      public ItemFilter getFilterForSlot(int slot)
      Description copied from interface: FixedItemInvView
      Exposes FixedItemInvView.isItemValidForSlot(int, ItemStack) as a (potentially) readable filter.
      Specified by:
      getFilterForSlot in interface FixedItemInvView
      Parameters:
      slot - The slot index. Must be a value between 0 (inclusive) and FixedItemInvView.getSlotCount() (exclusive) to be valid. (Like in arrays, lists, etc).
      Returns:
      An ItemFilter for what may be present in this slot. If this slot is filtered by an ItemFilter internally then it is highly recommended that this be overridden to return that filter rather than the default opaque wrapper around FixedItemInvView.isItemValidForSlot(int, ItemStack).
    • getMaxAmount

      public int getMaxAmount(int slot, net.minecraft.item.ItemStack stack)
      Specified by:
      getMaxAmount in interface FixedItemInvView
      Parameters:
      slot - The slot index. Must be a value between 0 (inclusive) and FixedItemInvView.getSlotCount() (exclusive) to be valid. (Like in arrays, lists, etc).
      stack - The stack to check for. May be an empty stack to get the maximum amount that this can hold of any stack.
      Returns:
      The maximum amount that the given slot can hold of the given stack. This method will ignore the current stack in FixedItemInvView.getInvStack(int). The default implementation just delegates to ItemStack.getMaxCount(). Note that any setters that this object implements (like FixedItemInv.setInvStack(int, ItemStack, Simulation) should reject stacks that are greater than this value. (and callers should only call this if they need to check the amounts separately. Note that it is meaningless to return values greater than the maximum amount an item can be stacked to here, and callers are free to throw an exception if this is violated. (Basically huge single-slot inventories shouldn't implement this interface).
    • getChangeValue

      public int getChangeValue()
      Specified by:
      getChangeValue in interface AbstractItemInvView
      Returns:
      A value that indicates whether an inventory might have changed if it differs from the last value returned. This number doesn't have to start at 0, but it must change every time that the inventory is changed, although it can change even without any observable changes to this inventory.

      Inventories that don't support this might increment the change number every time that this is called - so you should never write a loop that depends on the returned value settling down on a particular value.

      Inventories that support listeners highly encouraged to support this - by definition if an inventory knows when it changed then it should be able to count the number of changes. It is also implied that any changes to this value will also invoke every registered InvMarkDirtyListener.

      The default implementation returns an ever-increasing value.

    • addListener

      public ListenerToken addListener(InvMarkDirtyListener listener, ListenerRemovalToken removalToken)
      Description copied from interface: AbstractItemInvView
      Adds the given listener to this inventory, such that InvMarkDirtyListener.onMarkDirty(AbstractItemInvView) will be called every time that any stored stack is changed (either from FixedItemInv.setInvStack(int, ItemStack, Simulation) or FixedItemInv.ModifiableFixedItemInv.markDirty()).

      If the listener is registered (and thus this returns null) then it implies that AbstractItemInvView.getChangeValue() will change every time that the given listener is invoked, always just-before it is invoked.

      The default implementation refuses to accept any listeners, but implementations are highly encouraged to override this if they are able to!

      Specified by:
      addListener in interface AbstractItemInvView
      removalToken - A token that will be called whenever the given listener is removed from this inventory (or if this inventory itself is unloaded or otherwise invalidated).
      Returns:
      A token that represents the listener, or null if the listener could not be added.
    • getSubInv

      public FixedItemInvView getSubInv(int fromIndex, int toIndex)
      Description copied from interface: FixedItemInvView
      Equivalent to List.subList(int, int).
      Specified by:
      getSubInv in interface FixedItemInvView
      Parameters:
      fromIndex - The first slot to expose
      toIndex - The slot after the last slot to expose.
      Returns:
      a view of this inventory that only exposes the given number of slots. Might return "this" if fromIndex is 0 and toIndex is equal to FixedItemInvView.getSlotCount().
    • getMappedInv

      public FixedItemInvView getMappedInv(int... slots)
      Specified by:
      getMappedInv in interface FixedItemInvView
      Parameters:
      slots - The slots to expose.
      Returns:
      a view of this inventory that only exposes the given slots. Might return "this" if the slot array is just [0,1, ... FixedItemInvView.getSlotCount()-1]