Interface FixedItemInvView

All Superinterfaces:
AbstractItemInvView, Convertible
All Known Subinterfaces:
FixedItemInv, FixedItemInv.CopyingFixedItemInv, FixedItemInv.ModifiableFixedItemInv, LimitedFixedItemInv
All Known Implementing Classes:
AbstractPartialFixedItemInvView, CombinedFixedItemInv, CombinedFixedItemInv.OfCopying, CombinedFixedItemInv.OfModifiable, CombinedFixedItemInvView, DelegatingFixedItemInv, DelegatingFixedItemInv.OfCopying, DelegatingFixedItemInv.OfModifiable, DirectFixedItemInv, EmptyFixedItemInv, FixedInventoryVanillaWrapper, FixedInventoryViewVanillaWrapper, FixedSidedInventoryVanillaWrapper, FullFixedItemInv, MappedFixedItemInv, MappedFixedItemInv.OfCopying, MappedFixedItemInv.OfModifiable, MappedFixedItemInvView, SimpleFixedItemInv, SimpleLimitedFixedItemInv, SimpleLimitedFixedItemInv.OfCopying, SimpleLimitedFixedItemInv.OfModifiable, SubFixedItemInv, SubFixedItemInv.OfCopying, SubFixedItemInv.OfModifiable, SubFixedItemInvView

public interface FixedItemInvView extends Convertible, AbstractItemInvView
A view of a fixed inventory for items, where the size of the inventory never changes, and every slot is "simple":
  • The amount of every slot will never exceed 64, the normal maximum stack size of minecraft.
  • The stack will stay in the slot until it is removed or changed by something else. (So setting the stack in a slot of an FixedItemInv will reflect that change in getInvStack(int)).

The attribute is stored in ItemAttributes.FIXED_INV_VIEW.

There are various classes of interest:

  • Method Details

    • getSlotCount

      int getSlotCount()
      Returns:
      The number of slots in this inventory.
    • getInvStack

      net.minecraft.item.ItemStack getInvStack(int slot)
      Parameters:
      slot - The slot index. Must be a value between 0 (inclusive) and 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 isItemValidForSlot(int, ItemStack) or getFilterForSlot(int).
      Throws:
      RuntimeException - if the given slot wasn't a valid index.
    • getMaxAmount

      default int getMaxAmount(int slot, net.minecraft.item.ItemStack stack)
      Parameters:
      slot - The slot index. Must be a value between 0 (inclusive) and 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 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).
      Throws:
      RuntimeException - if the given slot wasn't a valid index.
    • isItemValidForSlot

      boolean isItemValidForSlot(int slot, net.minecraft.item.ItemStack stack)
      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.
      Parameters:
      slot - The slot index. Must be a value between 0 (inclusive) and getSlotCount() (exclusive) to be valid. (Like in arrays, lists, etc).
      stack - 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.
      Throws:
      RuntimeException - if the given slot wasn't a valid index.
    • getFilterForSlot

      default ItemFilter getFilterForSlot(int slot)
      Exposes isItemValidForSlot(int, ItemStack) as a (potentially) readable filter.
      Parameters:
      slot - The slot index. Must be a value between 0 (inclusive) and 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 isItemValidForSlot(int, ItemStack).
      Throws:
      RuntimeException - if the given slot wasn't a valid index.
    • getSlot

      default SingleItemSlotView getSlot(int slot)
      Returns:
      A view of a single slot in this inventory.
    • slotIterable

      default Iterable<? extends SingleItemSlotView> slotIterable()
    • stackIterable

      default Iterable<net.minecraft.item.ItemStack> stackIterable()
    • getGroupedInv

      default GroupedItemInvView getGroupedInv()
      Returns:
      A GroupedItemInvView of this inventory.
    • getSubInv

      default FixedItemInvView getSubInv(int fromIndex, int toIndex)
      Equivalent to List.subList(int, int).
      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 getSlotCount().
      Throws:
      RuntimeException - if any of the given slots weren't valid.
    • getMappedInv

      default FixedItemInvView getMappedInv(int... slots)
      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, ... getSlotCount()-1]
      Throws:
      RuntimeException - if any of the given slots weren't valid.
    • areSlotArraysEqual

      static boolean areSlotArraysEqual(FixedItemInvView inv, int[] slots)
      Used as a helper for getMappedInv(int...), to see if it should return itself or not.
    • isFlatSlotArray

      static boolean isFlatSlotArray(int[] slots, int count)
      Returns:
      True if the given array is equal to [0, 1, 2 ... count-2, count-1].
    • offerSelfAsAttribute

      @Deprecated(since="0.4.9", forRemoval=true) default void offerSelfAsAttribute(AttributeList<?> list, @Nullable CacheInfo cacheInfo, @Nullable net.minecraft.util.shape.VoxelShape shape)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Because this functionality has been fully replaced by Convertible and it's usage in AttributeList, so you can always just offer this object directly to the attribute list.
      Offers this object and getGroupedInv() to the attribute list. (Which, in turn, adds FixedItemInv.getInsertable(), FixedItemInv.getExtractable(), and FixedItemInv.getTransferable() to the list as well).
    • convertTo

      default <T> T convertTo(Class<T> otherType)
      Description copied from interface: Convertible
      Attempts to provide a variant of this in the given class form. This does not have to return "this" object if this is already an instance of the given class.

      Note: In order to be typesafe (and prevent crashes) it is recommended that you return Class.cast(Object) with the object you wish to return rather than just blindly cast to "T".

      Specified by:
      convertTo in interface Convertible
    • getFixedView

      default FixedItemInvView getFixedView()
      Returns:
      An object that only implements FixedItemInvView, and does not expose the modification methods that FixedItemInv does. Implementations that don't expose any modification methods themselves should override this method to just return themselves.