Class SimpleGroupedItemInv
- All Implemented Interfaces:
AbstractItemInvView,GroupedItemInv,GroupedItemInvView,ItemExtractable,ItemInsertable,ItemTransferable,LimitedConsumer<net.minecraft.item.ItemStack>,Saveable
GroupedItemInv that has a limit on both the number of different items that this can store, and the
total number of items that can be stored.-
Nested Class Summary
Nested classes/interfaces inherited from interface alexiil.mc.lib.attributes.item.AbstractItemInvView
AbstractItemInvView.DefaultChangeTrackerNested classes/interfaces inherited from interface alexiil.mc.lib.attributes.item.GroupedItemInvView
GroupedItemInvView.ItemInvStatistic -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddListener(ItemInvAmountChangeListener listener, ListenerRemovalToken removalToken) Adds the given listener to this inventory, such that theItemInvAmountChangeListener.onChange(GroupedItemInvView, ItemStack, int, int)will be called every time that this inventory changes.net.minecraft.item.ItemStackattemptExtraction(ItemFilter filter, int maxAmount, Simulation simulation) net.minecraft.item.ItemStackattemptInsertion(net.minecraft.item.ItemStack stack, Simulation simulation) Inserts the given stack into this insertable, and returns the excess.protected final voidfireAmountChange(net.minecraft.item.ItemStack stack, int previous, int current) voidfromTag(net.minecraft.nbt.NbtCompound tag) intgetStatistics(ItemFilter filter) Set<net.minecraft.item.ItemStack>intvoidvoidsetOwnerListener(ItemInvAmountChangeListener ownerListener) Sets the owner listener callback, which is never removed from the listener list wheninvalidateListeners()is called.net.minecraft.nbt.NbtCompoundtoTag(net.minecraft.nbt.NbtCompound tag) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface alexiil.mc.lib.attributes.item.GroupedItemInv
createLimitedGroupedInv, filteredMethods inherited from interface alexiil.mc.lib.attributes.item.GroupedItemInvView
addListener, getAmount, getAmount, getCapacity, getGroupedView, getSpace, getStatistics, isEmptyMethods inherited from interface alexiil.mc.lib.attributes.item.ItemExtractable
attemptAnyExtraction, couldExtractAnything, extract, extract, extract, getPureExtractableMethods inherited from interface alexiil.mc.lib.attributes.item.ItemInsertable
getInsertionFilter, getPureInsertable, insert, offer, offer, wouldAccept, wouldPartiallyAccept
-
Field Details
-
maxItemTypes
public final int maxItemTypes -
maxItems
public final int maxItems
-
-
Constructor Details
-
SimpleGroupedItemInv
public SimpleGroupedItemInv(int maxItemTypes, int maxItems)
-
-
Method Details
-
getStoredStacks
- Specified by:
getStoredStacksin interfaceGroupedItemInvView- Returns:
- a set containing all of the
ItemStack's that are stored in the inventory. NOTE: This must return a set using one of theHash.Strategy's inItemStackCollectionsotherwise comparison methods won't work correctly!
-
getTotalCapacity
public int getTotalCapacity()- Specified by:
getTotalCapacityin interfaceGroupedItemInvView- Returns:
- The total capacity for every
ItemStackthat can be stored in this inventory.NOTE: This value might not be equal to the sum of
GroupedItemInvView.getCapacity(ItemStack)overGroupedItemInvView.getStoredStacks()!
-
getStatistics
- Specified by:
getStatisticsin interfaceGroupedItemInvView- Parameters:
filter- The filter to check on.- Returns:
- Statistics about the currently stored amount, capacity, and space for everything that matches the given filter.
-
attemptInsertion
public net.minecraft.item.ItemStack attemptInsertion(net.minecraft.item.ItemStack stack, Simulation simulation) Description copied from interface:ItemInsertableInserts the given stack into this insertable, and returns the excess.- Specified by:
attemptInsertionin interfaceItemInsertable- Parameters:
stack- The incoming stack. Must not be modified by this call.simulation- IfSimulation.SIMULATEthen this shouldn't modify anything.- Returns:
- the excess
ItemStackthat wasn't accepted. This will be independent of this insertable, however it might be the given stack instead of a completely new object.
-
attemptExtraction
public net.minecraft.item.ItemStack attemptExtraction(ItemFilter filter, int maxAmount, Simulation simulation) Description copied from interface:ItemExtractable- Specified by:
attemptExtractionin interfaceItemExtractablemaxAmount- The maximum number of items that can be extracted. Negative numbers throw an exception.simulation- IfSimulation.SIMULATEthen this should return the same result that a call withSimulation.ACTIONwould do, but without modifying anything else.- Returns:
- A new, independent
ItemStackthat was extracted.
-
addListener
public ListenerToken addListener(ItemInvAmountChangeListener listener, ListenerRemovalToken removalToken) Description copied from interface:GroupedItemInvViewAdds the given listener to this inventory, such that theItemInvAmountChangeListener.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 nulltoken.The default implementation refuses to accept any listeners, but implementations are highly encouraged to override this if they are able to!
- Specified by:
addListenerin interfaceGroupedItemInvViewremovalToken- 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.
-
setOwnerListener
Sets the owner listener callback, which is never removed from the listener list wheninvalidateListeners()is called. -
invalidateListeners
public void invalidateListeners() -
getChangeValue
public int getChangeValue()- Specified by:
getChangeValuein interfaceAbstractItemInvView- 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
listenershighly 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 registeredInvMarkDirtyListener.The default implementation returns an ever-increasing value.
-
fireAmountChange
protected final void fireAmountChange(net.minecraft.item.ItemStack stack, int previous, int current) -
toTag
public net.minecraft.nbt.NbtCompound toTag(net.minecraft.nbt.NbtCompound tag) -
fromTag
public void fromTag(net.minecraft.nbt.NbtCompound tag)
-