Class DelegatingGroupedItemInv

java.lang.Object
alexiil.mc.lib.attributes.item.impl.DelegatingGroupedItemInv
All Implemented Interfaces:
AbstractItemInvView, GroupedItemInv, GroupedItemInvView, ItemExtractable, ItemInsertable, ItemTransferable, LimitedConsumer<net.minecraft.item.ItemStack>
Direct Known Subclasses:
SimpleLimitedGroupedItemInv

public class DelegatingGroupedItemInv extends Object implements GroupedItemInv
  • Field Details

  • Constructor Details

    • DelegatingGroupedItemInv

      public DelegatingGroupedItemInv(GroupedItemInv delegate)
  • Method Details

    • getStoredStacks

      public Set<net.minecraft.item.ItemStack> getStoredStacks()
      Specified by:
      getStoredStacks in interface GroupedItemInvView
      Returns:
      a set containing all of the ItemStack's that are stored in the inventory. NOTE: This must return a set using one of the Hash.Strategy's in ItemStackCollections otherwise comparison methods won't work correctly!
    • getTotalCapacity

      public int getTotalCapacity()
      Specified by:
      getTotalCapacity in interface GroupedItemInvView
      Returns:
      The total capacity for every ItemStack that can be stored in this inventory.

      NOTE: This value might not be equal to the sum of GroupedItemInvView.getCapacity(ItemStack) over GroupedItemInvView.getStoredStacks()!

    • getStatistics

      public GroupedItemInvView.ItemInvStatistic getStatistics(ItemFilter filter)
      Specified by:
      getStatistics in interface GroupedItemInvView
      Parameters:
      filter - The filter to check on.
      Returns:
      Statistics about the currently stored amount, capacity, and space for everything that matches the given filter.
    • 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(ItemInvAmountChangeListener listener, ListenerRemovalToken removalToken)
      Description copied from interface: GroupedItemInvView
      Adds the given listener to this inventory, such that the ItemInvAmountChangeListener.onChange(GroupedItemInvView, ItemStack, int, int) will be called every time that this inventory changes. However if this inventory doesn't support listeners then this will return a null token.

      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 GroupedItemInvView
      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.
    • attemptInsertion

      public net.minecraft.item.ItemStack attemptInsertion(net.minecraft.item.ItemStack stack, Simulation simulation)
      Description copied from interface: ItemInsertable
      Inserts the given stack into this insertable, and returns the excess.
      Specified by:
      attemptInsertion in interface ItemInsertable
      Parameters:
      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.
    • getInsertionFilter

      public ItemFilter getInsertionFilter()
      Description copied from interface: ItemInsertable
      Returns an ItemFilter to determine if ItemInsertable.attemptInsertion(ItemStack, Simulation) will accept a stack. The default implementation is a call to attemptInsertion(stack, Simulation.SIMULATE), and it is only useful to override this if the resulting filter contains information that might be usable by the caller.
      Specified by:
      getInsertionFilter in interface ItemInsertable
      Returns:
      A filter to determine if ItemInsertable.attemptInsertion(ItemStack, Simulation) will accept the entirety of a given stack.
    • attemptExtraction

      public net.minecraft.item.ItemStack attemptExtraction(ItemFilter filter, int maxAmount, Simulation simulation)
      Description copied from interface: ItemExtractable
      Attempt to extract *any* ItemStack from this that matches the given ItemFilter.
      Specified by:
      attemptExtraction in interface ItemExtractable
      maxAmount - The maximum number of items that can be extracted. Negative numbers throw an exception.
      simulation - If Simulation.SIMULATE then this should return the same result that a call with Simulation.ACTION would do, but without modifying anything else.
      Returns:
      A new, independent ItemStack that was extracted.
    • attemptAnyExtraction

      public net.minecraft.item.ItemStack attemptAnyExtraction(int maxAmount, Simulation simulation)
      Description copied from interface: ItemExtractable
      Specified by:
      attemptAnyExtraction in interface ItemExtractable