Package alexiil.mc.lib.attributes.item
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
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 ItemStack
s
allowed.
The attribute is stored in ItemAttributes.FIXED_INV
.
There are various classes of interest:
- The null instance is
EmptyFixedItemInv
- A combined view of several sub-inventories is
CombinedFixedItemInv
.
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).-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
The "complex" variant ofFixedItemInv
that always returns copies of the stack held.static interface
The "simpler" variant ofFixedItemInv
which allows callers to freely modify the currentItemStack
contained in it's inventory.Nested classes/interfaces inherited from interface alexiil.mc.lib.attributes.item.AbstractItemInvView
AbstractItemInvView.DefaultChangeTracker
-
Method Summary
Modifier and TypeMethodDescriptiondefault LimitedFixedItemInv
default net.minecraft.item.ItemStack
extractStack(int slot, 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.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.default ItemExtractable
default GroupedItemInv
default ItemInsertable
net.minecraft.item.ItemStack
getInvStack(int slot)
default FixedItemInv
getMappedInv(int... slots)
default SingleItemSlot
getSlot(int slot)
default FixedItemInv
getSubInv(int fromIndex, int toIndex)
Equivalent toList.subList(int, int)
.default ItemTransferable
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.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.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 usesforceSetInvStack(int, ItemStack)
on the result (Which will throw an exception if the returned stack is not valid for this inventory).boolean
setInvStack(int slot, net.minecraft.item.ItemStack to, Simulation simulation)
Sets the stack in the given slot to the given stack.default Iterable<? extends SingleItemSlot>
Methods inherited from interface alexiil.mc.lib.attributes.item.AbstractItemInvView
addListener, getChangeValue
Methods inherited from interface alexiil.mc.lib.attributes.item.FixedItemInvView
convertTo, getFilterForSlot, getFixedView, getMaxAmount, getSlotCount, offerSelfAsAttribute, stackIterable
-
Method Details
-
getInvStack
net.minecraft.item.ItemStack getInvStack(int slot)- Specified by:
getInvStack
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:
- A modifiable version of the
ItemStack
that is stored in this inventory. Note that this *may* be acopy
: changing the returnedItemStack
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 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 interfaceFixedItemInvView
- Parameters:
slot
- The slot index. Must be a value between 0 (inclusive) andFixedItemInvView.getSlotCount()
(exclusive) to be valid. (Like in arrays, lists, etc).stack
- TheItemStack
to check. It's undefined what is returned if anempty
stack is passed in, but it is not generally expected to be useful.
-
setInvStack
Sets the stack in the given slot to the given stack.- Parameters:
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).
-
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 usesforceSetInvStack(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 anItemInsertable
fromgetSlot(int)
).- Parameters:
slot
- The slot index. Must be a value between 0 (inclusive) andFixedItemInvView.getSlotCount()
(exclusive) to be valid. (Like in arrays, lists, etc).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. - 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 anItemExtractable
fromgetSlot(int)
.- Parameters:
slot
- The slot index. Must be a value between 0 (inclusive) andFixedItemInvView.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 ofItemStack.getMaxCount()
and the given maxCount.simulation
- IfSimulation.SIMULATE
then this shouldn't modify anything.- Returns:
- mergeWith (if non-empty) or the extracted stack if mergeWith is empty.
-
getSlot
- Specified by:
getSlot
in interfaceFixedItemInvView
- Returns:
- A view of a single slot in this inventory.
-
slotIterable
- Specified by:
slotIterable
in interfaceFixedItemInvView
-
createLimitedFixedInv
- Returns:
- A new
LimitedFixedItemInv
that provides a more controllable version of thisFixedItemInv
.
-
getInsertable
- Returns:
- An
ItemInsertable
for this inventory that will attempt to insert into any of the slots in this inventory. The default implementation delegates togetGroupedInv()
.
-
getExtractable
- Returns:
- An
ItemExtractable
for this inventory that will attempt to extract from any of the slots in this inventory. The default implementation delegates togetGroupedInv()
.
-
getTransferable
- Returns:
- An
ItemTransferable
for this inventory. The default implementation delegates togetGroupedInv()
.
-
getGroupedInv
- 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).
-
getSubInv
Description copied from interface:FixedItemInvView
Equivalent toList.subList(int, int)
.- Specified by:
getSubInv
in interfaceFixedItemInvView
- Parameters:
fromIndex
- The first slot to exposetoIndex
- 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
- Specified by:
getMappedInv
in interfaceFixedItemInvView
- 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]
-