Interface FixedItemInv

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

public interface FixedItemInv extends FixedItemInvView
A FixedItemInvView that can have it's contents changed. Note that this does not imply that the contents can be changed to anything the caller wishes them to be, as implementations can limit the valid ItemStacks allowed.

The attribute is stored in ItemAttributes.FIXED_INV.

There are various classes of interest:

It is highly recommended that implementations always extend either FixedItemInv.CopyingFixedItemInv or FixedItemInv.ModifiableFixedItemInv. (One of the two, but never both - consumers who receive a FixedItemInv should feel free to throw an exception if it implements both, since it makes no sense. However it is always permitted to implement neither).
  • Method Details

    • getInvStack

      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:
      A modifiable version of the ItemStack that is stored in this inventory. Note that this *may* be a copy: changing the returned ItemStack might not change the next returned stack.
    • 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.

      Note that just because an ItemStack passes this validity test, and is stackable with the current stack, does not mean that you can insert the stack into this inventory..

      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).
      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.
    • setInvStack

      boolean setInvStack(int slot, net.minecraft.item.ItemStack to, Simulation simulation)
      Sets the stack in the given slot to the given stack.
      Parameters:
      to - The new ItemStack. It is not defined if you are allowed to modify this or not.
      Returns:
      True if the modification was allowed, false otherwise. (For example if the given stack doesn't pass the FixedItemInvView.isItemValidForSlot(int, ItemStack) test).
    • forceSetInvStack

      default void forceSetInvStack(int slot, net.minecraft.item.ItemStack to)
      Sets the stack in the given slot to the given stack, or throws an exception if it was not permitted.
    • modifySlot

      default void modifySlot(int slot, Function<net.minecraft.item.ItemStack,net.minecraft.item.ItemStack> function)
      Applies the given function to the stack held in the slot, and uses forceSetInvStack(int, ItemStack) on the result (Which will throw an exception if the returned stack is not valid for this inventory).
    • insertStack

      default net.minecraft.item.ItemStack insertStack(int slot, net.minecraft.item.ItemStack stack, Simulation simulation)
      Attempts to insert the given stack into the given slot, returning the excess.

      (This is a slot-based version of ItemInsertable.attemptInsertion(ItemStack, Simulation) - if you want to use any of the other slot specific methods then it's recommended you get an ItemInsertable from getSlot(int)).

      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 incoming stack. Must not be modified by this call.
      simulation - If Simulation.SIMULATE then this shouldn't modify anything.
      Returns:
      the excess ItemStack that wasn't accepted. This will be independent of this insertable, however it might be the given stack instead of a completely new object.
      Throws:
      RuntimeException - if the given slot wasn't a valid index.
    • extractStack

      default net.minecraft.item.ItemStack extractStack(int slot, @Nullable ItemFilter filter, net.minecraft.item.ItemStack mergeWith, int maxCount, Simulation simulation)
      Attempts to extract part of the stack that is held in the given slot.

      This is a slot based version of ItemExtractable, however it includes a number of additional arguments. If you want to use any of the simpler methods than it's recommenced that you get an ItemExtractable from getSlot(int).

      Parameters:
      slot - The slot index. Must be a value between 0 (inclusive) and FixedItemInvView.getSlotCount() (exclusive) to be valid. (Like in arrays, lists, etc).
      filter - If non-null then this will be checked against the stored stack to see if anything can be extracted.
      mergeWith - If non-empty then this will be merged with the extracted stack, and as such they should be equal.
      maxCount - The maximum number of items to extract. Note that if the "mergeWith" argument is non-empty then the actual limit should be the minimum of ItemStack.getMaxCount() and the given maxCount.
      simulation - If Simulation.SIMULATE then this shouldn't modify anything.
      Returns:
      mergeWith (if non-empty) or the extracted stack if mergeWith is empty.
    • getSlot

      default SingleItemSlot getSlot(int slot)
      Specified by:
      getSlot in interface FixedItemInvView
      Returns:
      A view of a single slot in this inventory.
    • slotIterable

      default Iterable<? extends SingleItemSlot> slotIterable()
      Specified by:
      slotIterable in interface FixedItemInvView
    • createLimitedFixedInv

      default LimitedFixedItemInv createLimitedFixedInv()
      Returns:
      A new LimitedFixedItemInv that provides a more controllable version of this FixedItemInv.
    • getInsertable

      default ItemInsertable getInsertable()
      Returns:
      An ItemInsertable for this inventory that will attempt to insert into any of the slots in this inventory. The default implementation delegates to getGroupedInv().
    • getExtractable

      default ItemExtractable getExtractable()
      Returns:
      An ItemExtractable for this inventory that will attempt to extract from any of the slots in this inventory. The default implementation delegates to getGroupedInv().
    • getTransferable

      default ItemTransferable getTransferable()
      Returns:
      An ItemTransferable for this inventory. The default implementation delegates to getGroupedInv().
    • getGroupedInv

      default GroupedItemInv getGroupedInv()
      Specified by:
      getGroupedInv in interface FixedItemInvView
      Returns:
      A GroupedItemInv for this inventory. The returned value must always be valid for the lifetime of this FixedItemInv object. (In other words it must always be valid to cache this returned value and use it alongside a cached instance of this object).
    • getSubInv

      default FixedItemInv 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

      default FixedItemInv 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]