Class DelegatingFixedItemInv

java.lang.Object
alexiil.mc.lib.attributes.item.impl.DelegatingFixedItemInv
All Implemented Interfaces:
Convertible, AbstractItemInvView, FixedItemInv, FixedItemInvView
Direct Known Subclasses:
DelegatingFixedItemInv.OfCopying, DelegatingFixedItemInv.OfModifiable, SimpleLimitedFixedItemInv

public class DelegatingFixedItemInv
extends java.lang.Object
implements FixedItemInv
A simple delegate base class for FixedItemInv.
  • Field Details

  • Constructor Details

  • Method Details

    • createDelegate

      public static DelegatingFixedItemInv createDelegate​(FixedItemInv inv)
    • getSlotCount

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

      public net.minecraft.item.ItemStack getInvStack​(int slot)
      Specified by:
      getInvStack in interface FixedItemInv
      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

      public boolean isItemValidForSlot​(int slot, net.minecraft.item.ItemStack stack)
      Description copied from interface: FixedItemInv
      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 FixedItemInv
      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.
    • 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).
    • 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).
    • 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.

    • setInvStack

      public boolean setInvStack​(int slot, net.minecraft.item.ItemStack to, Simulation simulation)
      Description copied from interface: FixedItemInv
      Sets the stack in the given slot to the given stack.
      Specified by:
      setInvStack in interface FixedItemInv
      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).
    • insertStack

      public net.minecraft.item.ItemStack insertStack​(int slot, net.minecraft.item.ItemStack stack, Simulation simulation)
      Description copied from interface: FixedItemInv
      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 FixedItemInv.getSlot(int)).

      Specified by:
      insertStack in interface FixedItemInv
      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.
    • extractStack

      public net.minecraft.item.ItemStack extractStack​(int slot, ItemFilter filter, net.minecraft.item.ItemStack mergeWith, int maxCount, Simulation simulation)
      Description copied from interface: FixedItemInv
      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 FixedItemInv.getSlot(int).

      Specified by:
      extractStack in interface FixedItemInv
      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.
    • 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.