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 ItemStacks
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
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceThe "complex" variant ofFixedItemInvthat always returns copies of the stack held.static interfaceThe "simpler" variant ofFixedItemInvwhich allows callers to freely modify the currentItemStackcontained in it's inventory.Nested classes/interfaces inherited from interface alexiil.mc.lib.attributes.item.AbstractItemInvView
AbstractItemInvView.DefaultChangeTracker -
Method Summary
Modifier and TypeMethodDescriptiondefault LimitedFixedItemInvdefault net.minecraft.item.ItemStackextractStack(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 voidforceSetInvStack(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 ItemExtractabledefault GroupedItemInvdefault ItemInsertablenet.minecraft.item.ItemStackgetInvStack(int slot) default FixedItemInvgetMappedInv(int... slots) default SingleItemSlotgetSlot(int slot) default FixedItemInvgetSubInv(int fromIndex, int toIndex) Equivalent toList.subList(int, int).default ItemTransferabledefault net.minecraft.item.ItemStackinsertStack(int slot, net.minecraft.item.ItemStack stack, Simulation simulation) Attempts to insert the given stack into the given slot, returning the excess.booleanisItemValidForSlot(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 voidmodifySlot(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).booleansetInvStack(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, getChangeValueMethods 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:
getInvStackin 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
ItemStackthat is stored in this inventory. Note that this *may* be acopy: changing the returnedItemStackmight 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(). Passingemptystacks will generally not return useful results.Note that just because an
ItemStackpasses this validity test, and is stackable with the current stack, does not mean that you can insert the stack into this inventory..- Specified by:
isItemValidForSlotin 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- TheItemStackto check. It's undefined what is returned if anemptystack 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 anItemInsertablefromgetSlot(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.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. - 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 anItemExtractablefromgetSlot(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.SIMULATEthen this shouldn't modify anything.- Returns:
- mergeWith (if non-empty) or the extracted stack if mergeWith is empty.
-
getSlot
- Specified by:
getSlotin interfaceFixedItemInvView- Returns:
- A view of a single slot in this inventory.
-
slotIterable
- Specified by:
slotIterablein interfaceFixedItemInvView
-
createLimitedFixedInv
- Returns:
- A new
LimitedFixedItemInvthat provides a more controllable version of thisFixedItemInv.
-
getInsertable
- Returns:
- An
ItemInsertablefor this inventory that will attempt to insert into any of the slots in this inventory. The default implementation delegates togetGroupedInv().
-
getExtractable
- Returns:
- An
ItemExtractablefor this inventory that will attempt to extract from any of the slots in this inventory. The default implementation delegates togetGroupedInv().
-
getTransferable
- Returns:
- An
ItemTransferablefor this inventory. The default implementation delegates togetGroupedInv().
-
getGroupedInv
- Specified by:
getGroupedInvin interfaceFixedItemInvView- Returns:
- A
GroupedItemInvfor this inventory. The returned value must always be valid for the lifetime of thisFixedItemInvobject. (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:FixedItemInvViewEquivalent toList.subList(int, int).- Specified by:
getSubInvin 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:
getMappedInvin 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]
-