Package alexiil.mc.lib.attributes.item
Interface FixedItemInvView
- All Superinterfaces:
AbstractItemInvView
,Convertible
- All Known Subinterfaces:
FixedItemInv
,FixedItemInv.CopyingFixedItemInv
,FixedItemInv.ModifiableFixedItemInv
,LimitedFixedItemInv
- All Known Implementing Classes:
AbstractPartialFixedItemInvView
,CombinedFixedItemInv
,CombinedFixedItemInv.OfCopying
,CombinedFixedItemInv.OfModifiable
,CombinedFixedItemInvView
,DelegatingFixedItemInv
,DelegatingFixedItemInv.OfCopying
,DelegatingFixedItemInv.OfModifiable
,DirectFixedItemInv
,EmptyFixedItemInv
,FixedInventoryVanillaWrapper
,FixedInventoryViewVanillaWrapper
,FixedSidedInventoryVanillaWrapper
,FullFixedItemInv
,MappedFixedItemInv
,MappedFixedItemInv.OfCopying
,MappedFixedItemInv.OfModifiable
,MappedFixedItemInvView
,SimpleFixedItemInv
,SimpleLimitedFixedItemInv
,SimpleLimitedFixedItemInv.OfCopying
,SimpleLimitedFixedItemInv.OfModifiable
,SubFixedItemInv
,SubFixedItemInv.OfCopying
,SubFixedItemInv.OfModifiable
,SubFixedItemInvView
A view of a fixed inventory for items, where the size of the inventory never changes, and every slot is "simple":
- The amount of every slot will never exceed 64, the normal maximum stack size of minecraft.
- The stack will stay in the slot until it is removed or changed by something else. (So setting the stack in a slot
of an
FixedItemInv
will reflect that change ingetInvStack(int)
).
The attribute is stored in ItemAttributes.FIXED_INV_VIEW
.
There are various classes of interest:
- A modifiable version of this is
FixedItemInv
. - The null instance is
EmptyFixedItemInv
- A combined view of several sub-inventories is
CombinedFixedItemInvView
. - A partial view of a single inventory is
SubFixedItemInv
-
Nested Class Summary
Nested classes/interfaces inherited from interface alexiil.mc.lib.attributes.item.AbstractItemInvView
AbstractItemInvView.DefaultChangeTracker
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
areSlotArraysEqual(FixedItemInvView inv, int[] slots)
Used as a helper forgetMappedInv(int...)
, to see if it should return itself or not.default <T> T
Attempts to provide a variant of this in the given class form.default ItemFilter
getFilterForSlot(int slot)
ExposesisItemValidForSlot(int, ItemStack)
as a (potentially) readable filter.default FixedItemInvView
default GroupedItemInvView
net.minecraft.item.ItemStack
getInvStack(int slot)
default FixedItemInvView
getMappedInv(int... slots)
default int
getMaxAmount(int slot, net.minecraft.item.ItemStack stack)
default SingleItemSlotView
getSlot(int slot)
int
default FixedItemInvView
getSubInv(int fromIndex, int toIndex)
Equivalent toList.subList(int, int)
.static boolean
isFlatSlotArray(int[] slots, int count)
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
offerSelfAsAttribute(AttributeList<?> list, CacheInfo cacheInfo, net.minecraft.util.shape.VoxelShape shape)
Deprecated, for removal: This API element is subject to removal in a future version.default Iterable<? extends SingleItemSlotView>
default Iterable<net.minecraft.item.ItemStack>
Methods inherited from interface alexiil.mc.lib.attributes.item.AbstractItemInvView
addListener, getChangeValue
-
Method Details
-
getSlotCount
int getSlotCount()- Returns:
- The number of slots in this inventory.
-
getInvStack
net.minecraft.item.ItemStack getInvStack(int slot)- Parameters:
slot
- The slot index. Must be a value between 0 (inclusive) andgetSlotCount()
(exclusive) to be valid. (Like in arrays, lists, etc).- Returns:
- The ItemStack that is held in the inventory at the moment. It is unspecified whether you are allowed to
modify this returned
ItemStack
- however subinterfaces (likeFixedItemInv
) may have different limitations on this. Note that this stack might not be valid for this slot in eitherisItemValidForSlot(int, ItemStack)
orgetFilterForSlot(int)
. - Throws:
RuntimeException
- if the given slot wasn't a valid index.
-
getMaxAmount
default int getMaxAmount(int slot, net.minecraft.item.ItemStack stack)- Parameters:
slot
- The slot index. Must be a value between 0 (inclusive) andgetSlotCount()
(exclusive) to be valid. (Like in arrays, lists, etc).stack
- The stack to check for. May be anempty
stack to get the maximum amount that this can hold of any stack.- Returns:
- The maximum amount that the given slot can hold of the given stack. This method will ignore the current
stack in
getInvStack(int)
. The default implementation just delegates toItemStack.getMaxCount()
. Note that any setters that this object implements (likeFixedItemInv.setInvStack(int, ItemStack, Simulation)
should reject stacks that are greater than this value. (and callers should only call this if they need to check the amounts separately. Note that it is meaningless to return values greater than the maximum amount an item can be stacked to here, and callers are free to throw an exception if this is violated. (Basically huge single-slot inventories shouldn't implement this interface). - Throws:
RuntimeException
- if the given slot wasn't a valid index.
-
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.- Parameters:
slot
- The slot index. Must be a value between 0 (inclusive) andgetSlotCount()
(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.- Throws:
RuntimeException
- if the given slot wasn't a valid index.
-
getFilterForSlot
ExposesisItemValidForSlot(int, ItemStack)
as a (potentially) readable filter.- Parameters:
slot
- The slot index. Must be a value between 0 (inclusive) andgetSlotCount()
(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 aroundisItemValidForSlot(int, ItemStack)
. - Throws:
RuntimeException
- if the given slot wasn't a valid index.
-
getSlot
- Returns:
- A view of a single slot in this inventory.
-
slotIterable
-
stackIterable
-
getGroupedInv
- Returns:
- A
GroupedItemInvView
of this inventory.
-
getSubInv
Equivalent toList.subList(int, int)
.- 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
getSlotCount()
. - Throws:
RuntimeException
- if any of the given slots weren't valid.
-
getMappedInv
- 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, ...
getSlotCount()
-1] - Throws:
RuntimeException
- if any of the given slots weren't valid.
-
areSlotArraysEqual
Used as a helper forgetMappedInv(int...)
, to see if it should return itself or not. -
isFlatSlotArray
static boolean isFlatSlotArray(int[] slots, int count)- Returns:
- True if the given array is equal to [0, 1, 2 ... count-2, count-1].
-
offerSelfAsAttribute
@Deprecated(since="0.4.9", forRemoval=true) default void offerSelfAsAttribute(AttributeList<?> list, @Nullable CacheInfo cacheInfo, @Nullable net.minecraft.util.shape.VoxelShape shape)Deprecated, for removal: This API element is subject to removal in a future version.Because this functionality has been fully replaced byConvertible
and it's usage inAttributeList
, so you can always just offer this object directly to the attribute list.Offers this object andgetGroupedInv()
to the attribute list. (Which, in turn, addsFixedItemInv.getInsertable()
,FixedItemInv.getExtractable()
, andFixedItemInv.getTransferable()
to the list as well). -
convertTo
Description copied from interface:Convertible
Attempts to provide a variant of this in the given class form. This does not have to return "this" object if this is already an instance of the given class.Note: In order to be typesafe (and prevent crashes) it is recommended that you return
Class.cast(Object)
with the object you wish to return rather than just blindly cast to "T".- Specified by:
convertTo
in interfaceConvertible
-
getFixedView
- Returns:
- An object that only implements
FixedItemInvView
, and does not expose the modification methods thatFixedItemInv
does. Implementations that don't expose any modification methods themselves should override this method to just return themselves.
-
Convertible
and it's usage inAttributeList
, so you can always just offer this object directly to the attribute list.