Class FullFixedItemInv
- All Implemented Interfaces:
Convertible
,AbstractItemInvView
,FixedItemInv
,FixedItemInv.CopyingFixedItemInv
,FixedItemInvView
,ItemExtractable
,ItemInsertable
,ItemTransferable
,LimitedConsumer<net.minecraft.item.ItemStack>
,Saveable
- Direct Known Subclasses:
SimpleFixedItemInv
FixedItemInv.CopyingFixedItemInv
exposes.
Extending classes should take care to override getFilterForSlot(int)
if they also override
isItemValidForSlot(int, ItemStack)
.
-
Nested Class Summary
Nested classes/interfaces inherited from interface alexiil.mc.lib.attributes.item.AbstractItemInvView
AbstractItemInvView.DefaultChangeTracker
Nested classes/interfaces inherited from interface alexiil.mc.lib.attributes.item.FixedItemInv
FixedItemInv.CopyingFixedItemInv, FixedItemInv.ModifiableFixedItemInv
-
Field Summary
Modifier and TypeFieldDescriptionprotected final net.minecraft.util.collection.DefaultedList<net.minecraft.item.ItemStack>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddListener
(ItemInvSlotChangeListener listener, ListenerRemovalToken removalToken) Adds the given listener to this inventory, such that theItemInvSlotChangeListener.onChange(FixedItemInvView, int, ItemStack, ItemStack)
will be called every time that this inventory changes.net.minecraft.item.ItemStack
attemptAnyExtraction
(int maxAmount, Simulation simulation) net.minecraft.item.ItemStack
attemptExtraction
(ItemFilter filter, int maxAmount, Simulation simulation) net.minecraft.item.ItemStack
attemptInsertion
(net.minecraft.item.ItemStack stack, Simulation simulation) Inserts the given stack into this insertable, and returns the excess.protected final void
fireSlotChange
(int slot, net.minecraft.item.ItemStack previous, net.minecraft.item.ItemStack current) void
fromTag
(net.minecraft.nbt.NbtCompound tag) int
getFilterForSlot
(int slot) ExposesFixedItemInvView.isItemValidForSlot(int, ItemStack)
as a (potentially) readable filter.Returns anItemFilter
to determine ifItemInsertable.attemptInsertion(ItemStack, Simulation)
will accept a stack.final int
net.minecraft.item.ItemStack
getUnmodifiableInvStack
(int slot) void
boolean
isItemValidForSlot
(int slot, net.minecraft.item.ItemStack item) Checks to see if the given stack would be valid for this slot, ignoring the current contents.boolean
setInvStack
(int slot, net.minecraft.item.ItemStack to, Simulation simulation) Sets the stack in the given slot to the given stack.void
setOwnerListener
(ItemInvSlotChangeListener ownerListener) Sets the owner listener callback, which is never removed from the listener list wheninvalidateListeners()
is called.final net.minecraft.nbt.NbtCompound
toTag()
net.minecraft.nbt.NbtCompound
toTag
(net.minecraft.nbt.NbtCompound tag) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface alexiil.mc.lib.attributes.item.FixedItemInv
createLimitedFixedInv, extractStack, forceSetInvStack, getExtractable, getInsertable, getMappedInv, getSubInv, getTransferable, insertStack, modifySlot, slotIterable
Methods inherited from interface alexiil.mc.lib.attributes.item.FixedItemInv.CopyingFixedItemInv
addListener, getInvStack, getSlot
Methods inherited from interface alexiil.mc.lib.attributes.item.FixedItemInvView
convertTo, getFixedView, getMaxAmount, offerSelfAsAttribute, stackIterable
Methods inherited from interface alexiil.mc.lib.attributes.item.ItemExtractable
couldExtractAnything, extract, extract, extract, getPureExtractable
Methods inherited from interface alexiil.mc.lib.attributes.item.ItemInsertable
getPureInsertable, insert, offer, offer, wouldAccept, wouldPartiallyAccept
Methods inherited from interface alexiil.mc.lib.attributes.item.ItemTransferable
filtered
-
Field Details
-
slots
protected final net.minecraft.util.collection.DefaultedList<net.minecraft.item.ItemStack> slots
-
-
Constructor Details
-
FullFixedItemInv
public FullFixedItemInv(int invSize)
-
-
Method Details
-
getSlotCount
public final int getSlotCount()- Specified by:
getSlotCount
in interfaceFixedItemInvView
- Returns:
- The number of slots in this inventory.
-
getUnmodifiableInvStack
public net.minecraft.item.ItemStack getUnmodifiableInvStack(int slot) - Specified by:
getUnmodifiableInvStack
in interfaceFixedItemInv.CopyingFixedItemInv
- Returns:
- The
ItemStack
that is held by this inventory. Modifying the returnedItemStack
in any way will (most likely - depending on the implementation) throw an exception (at some point).
-
isItemValidForSlot
public boolean isItemValidForSlot(int slot, net.minecraft.item.ItemStack item) 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 ofItemFilter.matches(ItemStack)
, so this must not care about theItemStack.getCount()
. Passingempty
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 interfaceFixedItemInv
- Specified by:
isItemValidForSlot
in interfaceFixedItemInvView
- Parameters:
slot
- The slot index. Must be a value between 0 (inclusive) andFixedItemInvView.getSlotCount()
(exclusive) to be valid. (Like in arrays, lists, etc).item
- TheItemStack
to check. It's undefined what is returned if anempty
stack is passed in, but it is not generally expected to be useful.
-
getFilterForSlot
Description copied from interface:FixedItemInvView
ExposesFixedItemInvView.isItemValidForSlot(int, ItemStack)
as a (potentially) readable filter.- Specified by:
getFilterForSlot
in interfaceFixedItemInvView
- Parameters:
slot
- The slot index. Must be a value between 0 (inclusive) andFixedItemInvView.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 anItemFilter
internally then it is highly recommended that this be overridden to return that filter rather than the default opaque wrapper aroundFixedItemInvView.isItemValidForSlot(int, ItemStack)
.
-
getGroupedInv
- Specified by:
getGroupedInv
in interfaceFixedItemInv
- Specified by:
getGroupedInv
in interfaceFixedItemInvView
- Returns:
- A
GroupedItemInv
for this inventory. The returned value must always be valid for the lifetime of thisFixedItemInv
object. (In other words it must always be valid to cache this returned value and use it alongside a cached instance of this object).
-
getChangeValue
public int getChangeValue()- Specified by:
getChangeValue
in 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
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 registeredInvMarkDirtyListener
.The default implementation returns an ever-increasing value.
-
addListener
public ListenerToken addListener(ItemInvSlotChangeListener listener, ListenerRemovalToken removalToken) Description copied from interface:FixedItemInv.CopyingFixedItemInv
Adds the given listener to this inventory, such that theItemInvSlotChangeListener.onChange(FixedItemInvView, int, ItemStack, ItemStack)
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:
addListener
in interfaceFixedItemInv.CopyingFixedItemInv
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.
-
setOwnerListener
Sets the owner listener callback, which is never removed from the listener list wheninvalidateListeners()
is called. -
invalidateListeners
public void invalidateListeners() -
fireSlotChange
protected final void fireSlotChange(int slot, net.minecraft.item.ItemStack previous, net.minecraft.item.ItemStack current) -
setInvStack
Description copied from interface:FixedItemInv
Sets the stack in the given slot to the given stack.- Specified by:
setInvStack
in interfaceFixedItemInv
to
- The newItemStack
. 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).
-
toTag
public final net.minecraft.nbt.NbtCompound toTag() -
toTag
public net.minecraft.nbt.NbtCompound toTag(net.minecraft.nbt.NbtCompound tag) -
fromTag
public void fromTag(net.minecraft.nbt.NbtCompound tag) -
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 interfaceItemInsertable
- Parameters:
stack
- The incoming stack. Must not be modified by this call.simulation
- IfSimulation.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
Description copied from interface:ItemInsertable
Returns anItemFilter
to determine ifItemInsertable.attemptInsertion(ItemStack, Simulation)
will accept a stack. The default implementation is a call toattemptInsertion
(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 interfaceItemInsertable
- 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
- Specified by:
attemptExtraction
in interfaceItemExtractable
maxAmount
- The maximum number of items that can be extracted. Negative numbers throw an exception.simulation
- IfSimulation.SIMULATE
then this should return the same result that a call withSimulation.ACTION
would do, but without modifying anything else.- Returns:
- A new, independent
ItemStack
that was extracted.
-
attemptAnyExtraction
Description copied from interface:ItemExtractable
- Specified by:
attemptAnyExtraction
in interfaceItemExtractable
-