Class SimpleLimitedFixedItemInv
java.lang.Object
alexiil.mc.lib.attributes.item.impl.DelegatingFixedItemInv
alexiil.mc.lib.attributes.item.impl.SimpleLimitedFixedItemInv
- All Implemented Interfaces:
Convertible,AbstractItemInvView,FixedItemInv,FixedItemInvView,LimitedFixedItemInv
- Direct Known Subclasses:
SimpleLimitedFixedItemInv.OfCopying,SimpleLimitedFixedItemInv.OfModifiable
public class SimpleLimitedFixedItemInv
extends DelegatingFixedItemInv
implements LimitedFixedItemInv
A simple implementation of
LimitedFixedItemInv that makes no assumptions about the backing
FixedItemInv.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classNested classes/interfaces inherited from interface alexiil.mc.lib.attributes.item.AbstractItemInvView
AbstractItemInvView.DefaultChangeTrackerNested classes/interfaces inherited from interface alexiil.mc.lib.attributes.item.FixedItemInv
FixedItemInv.CopyingFixedItemInv, FixedItemInv.ModifiableFixedItemInvNested classes/interfaces inherited from interface alexiil.mc.lib.attributes.item.LimitedFixedItemInv
LimitedFixedItemInv.ItemSlotLimitRule -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ItemFilter[]protected final ItemFilter[]protected final byte[]protected final byte[]Fields inherited from class alexiil.mc.lib.attributes.item.impl.DelegatingFixedItemInv
delegate -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcopy()Creates a copy of thisLimitedFixedItemInv(with the same backing inventory and the same rules).static SimpleLimitedFixedItemInvnet.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.getFilterForSlot(int slot) ExposesFixedItemInvView.isItemValidForSlot(int, ItemStack)as a (potentially) readable filter.intgetMaxAmount(int slot, net.minecraft.item.ItemStack stack) getRule(int slot) getSubRule(int from, int to) 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.Marks this object as final, and disallows any further changes to this.booleansetInvStack(int slot, net.minecraft.item.ItemStack to, Simulation simulation) Sets the stack in the given slot to the given stack.Methods inherited from class alexiil.mc.lib.attributes.item.impl.DelegatingFixedItemInv
addListener, createDelegate, getChangeValue, getInvStack, getSlotCountMethods 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.AbstractItemInvView
addListener, getChangeValueMethods inherited from interface alexiil.mc.lib.attributes.item.FixedItemInv
createLimitedFixedInv, forceSetInvStack, getExtractable, getGroupedInv, getInsertable, getInvStack, getMappedInv, getSlot, getSubInv, getTransferable, modifySlot, slotIterableMethods inherited from interface alexiil.mc.lib.attributes.item.FixedItemInvView
convertTo, getFixedView, getSlotCount, offerSelfAsAttribute, stackIterableMethods inherited from interface alexiil.mc.lib.attributes.item.LimitedFixedItemInv
asUnmodifiable, getAllRule, reset
-
Field Details
-
insertionFilters
-
extractionFilters
-
maxInsertionAmounts
protected final byte[] maxInsertionAmounts -
minimumAmounts
protected final byte[] minimumAmounts
-
-
Constructor Details
-
SimpleLimitedFixedItemInv
-
-
Method Details
-
createLimited
-
markFinal
Description copied from interface:LimitedFixedItemInvMarks this object as final, and disallows any further changes to this. If this is called thenLimitedFixedItemInv.asUnmodifiable()will return this object.- Specified by:
markFinalin interfaceLimitedFixedItemInv- Returns:
- this.
-
assertMutable
protected void assertMutable() -
copy
Description copied from interface:LimitedFixedItemInvCreates a copy of thisLimitedFixedItemInv(with the same backing inventory and the same rules). If this has been marked as final (LimitedFixedItemInv.markFinal()) then the copy will be marked as final as well..- Specified by:
copyin interfaceLimitedFixedItemInv
-
isItemValidForSlot
public boolean isItemValidForSlot(int slot, net.minecraft.item.ItemStack stack) Description copied from interface:FixedItemInvChecks 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 interfaceFixedItemInv- Specified by:
isItemValidForSlotin interfaceFixedItemInvView- Overrides:
isItemValidForSlotin classDelegatingFixedItemInv- 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.
-
getFilterForSlot
Description copied from interface:FixedItemInvViewExposesFixedItemInvView.isItemValidForSlot(int, ItemStack)as a (potentially) readable filter.- Specified by:
getFilterForSlotin interfaceFixedItemInvView- Overrides:
getFilterForSlotin classDelegatingFixedItemInv- 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
ItemFilterfor what may be present in this slot. If this slot is filtered by anItemFilterinternally then it is highly recommended that this be overridden to return that filter rather than the default opaque wrapper aroundFixedItemInvView.isItemValidForSlot(int, ItemStack).
-
setInvStack
Description copied from interface:FixedItemInvSets the stack in the given slot to the given stack.- Specified by:
setInvStackin interfaceFixedItemInv- Overrides:
setInvStackin classDelegatingFixedItemInvto- 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).
-
insertStack
public net.minecraft.item.ItemStack insertStack(int slot, net.minecraft.item.ItemStack stack, Simulation simulation) Description copied from interface:FixedItemInvAttempts 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 anItemInsertablefromFixedItemInv.getSlot(int)).- Specified by:
insertStackin interfaceFixedItemInv- Overrides:
insertStackin classDelegatingFixedItemInv- 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.
-
extractStack
public net.minecraft.item.ItemStack extractStack(int slot, @Nullable ItemFilter filter, net.minecraft.item.ItemStack mergeWith, int maxCount, Simulation simulation) Description copied from interface:FixedItemInvAttempts 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 anItemExtractablefromFixedItemInv.getSlot(int).- Specified by:
extractStackin interfaceFixedItemInv- Overrides:
extractStackin classDelegatingFixedItemInv- 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.
-
getMaxAmount
public int getMaxAmount(int slot, net.minecraft.item.ItemStack stack) - Specified by:
getMaxAmountin interfaceFixedItemInvView- Overrides:
getMaxAmountin classDelegatingFixedItemInv- 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 stack to check for. May be anemptystack 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
FixedItemInvView.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).
-
getRule
- Specified by:
getRulein interfaceLimitedFixedItemInv- Returns:
- A rule for the single slot.
-
getSubRule
- Specified by:
getSubRulein interfaceLimitedFixedItemInv- Parameters:
from- The first slot (inclusive)to- The last slot (exclusive).- Returns:
- A rule that applies to every slot between from and to.
-