Package alexiil.mc.lib.attributes.fluid
Interface FixedFluidInvView
- All Superinterfaces:
Convertible
- All Known Subinterfaces:
FixedFluidInv
,LimitedFixedFluidInv
- All Known Implementing Classes:
AbstractPartialFixedFluidInvView
,CombinedFixedFluidInv
,CombinedFixedFluidInvView
,DelegatingFixedFluidInv
,EmptyFixedFluidInv
,JumboFixedFluidInv
,MappedFixedFluidInv
,MappedFixedFluidInvView
,SimpleFixedFluidInv
,SimpleLimitedFixedFluidInv
,SubFixedFluidInv
,SubFixedFluidInvView
A view of a fixed inventory for fluids, where the number of tanks never changes, and every tank is "simple":
- The fluid will stay in the tank until it is removed or changed by something else. (So setting the fluid in a tank
of an
FixedFluidInv
will reflect that change ingetInvFluid(int)
).
The attribute is stored in FluidAttributes.FIXED_INV_VIEW
.
There are various classes of interest:
- A modifiable version of this is
FixedFluidInv
. - The null instance is
EmptyFixedFluidInv
- A combined view of several sub-inventories is
CombinedFixedFluidInvView
. - A partial view of a single inventory is
SubFixedFluidInv
-
Method Summary
Modifier and TypeMethodDescriptiondefault ListenerToken
addListener(FluidInvTankChangeListener listener, ListenerRemovalToken removalToken)
Adds the given listener to this inventory, such that theFluidInvTankChangeListener.onChange(FixedFluidInvView, int, FluidVolume, FluidVolume)
will be called every time that this inventory changes.default <T> T
Attempts to provide a variant of this in the given class form.default Iterable<FluidVolume>
default FluidFilter
getFilterForTank(int tank)
ExposesisFluidValidForTank(int, FluidKey)
as a (potentially) readable filter.default FixedFluidInvView
default GroupedFluidInvView
getInvFluid(int tank)
default FixedFluidInvView
getMappedInv(int... tanks)
default int
getMaxAmount(int tank)
Deprecated, for removal: This API element is subject to removal in a future version.default FluidAmount
getMaxAmount_F(int tank)
default FixedFluidInvView
getSubInv(int fromIndex, int toIndex)
Equivalent toList.subList(int, int)
.default SingleFluidTankView
getTank(int tank)
int
boolean
isFluidValidForTank(int tank, FluidKey fluid)
Checks to see if the given fluid would be valid for this tank, ignoring 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.Because this functionality has been fully replaced byConvertible
and it's usage inAttributeList
.default Iterable<? extends SingleFluidTankView>
static void
validateFixedFluidInvView(FixedFluidInvView instance)
-
Method Details
-
getTankCount
int getTankCount()- Returns:
- The number of tanks in this inventory.
-
getInvFluid
- Parameters:
tank
- The tank index. Must be a value between 0 (inclusive) andgetTankCount()
(exclusive) to be valid. (Like in arrays, lists, etc).- Returns:
- The FluidVolume that is held in the tank at the moment. The returned volume must never be modified!
- Throws:
RuntimeException
- if the given tank wasn't a valid index.
-
getMaxAmount
Deprecated, for removal: This API element is subject to removal in a future version.Replaced bygetMaxAmount_F(int)
- Parameters:
tank
- The tank index. Must be a value between 0 (inclusive) andgetTankCount()
(exclusive) to be valid. (Like in arrays, lists, etc).- Returns:
- The maximum amount that the given tank can hold of the given fluid. This method will ignore the current
stack in
getInvFluid(int)
. Note that any setters that this object implements (likeFixedFluidInv.setInvFluid(int, FluidVolume, 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 fluid can be stacked to here, and callers are free to throw an exception if this is violated. (Basically huge single-tank inventories shouldn't implement this interface). - Throws:
RuntimeException
- if the given tank wasn't a valid index.
-
getMaxAmount_F
- Parameters:
tank
- The tank index. Must be a value between 0 (inclusive) andgetTankCount()
(exclusive) to be valid. (Like in arrays, lists, etc).- Returns:
- The maximum amount that the given tank can hold of the given fluid. This method will ignore the current
stack in
getInvFluid(int)
. Note that any setters that this object implements (likeFixedFluidInv.setInvFluid(int, FluidVolume, 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 fluid can be stacked to here, and callers are free to throw an exception if this is violated. (Basically huge single-tank inventories shouldn't implement this interface). - Throws:
RuntimeException
- if the given tank wasn't a valid index.
-
isFluidValidForTank
Checks to see if the given fluid would be valid for this tank, ignoring current contents. Note that this method should adhere to the requirements ofFluidFilter.matches(FluidKey)
, so passingempty
fluids will generally not return useful results.- Parameters:
tank
- The tank index. Must be a value between 0 (inclusive) andgetTankCount()
(exclusive) to be valid. (Like in arrays, lists, etc).- Throws:
RuntimeException
- if the given tank wasn't a valid index.
-
getFilterForTank
ExposesisFluidValidForTank(int, FluidKey)
as a (potentially) readable filter.- Parameters:
tank
- The tank index. Must be a value between 0 (inclusive) andgetTankCount()
(exclusive) to be valid. (Like in arrays, lists, etc).- Returns:
- An
FluidFilter
for this tank. If this tank is filtered by anFluidFilter
internally then it is highly recommended that this be overridden to return that filter rather than the default opaque wrapper aroundisFluidValidForTank(int, FluidKey)
. - Throws:
RuntimeException
- if the given tank wasn't a valid index.
-
getTank
-
tankIterable
-
fluidIterable
-
getGroupedInv
- Returns:
- A statistical view of this inventory.
-
addListener
default ListenerToken addListener(FluidInvTankChangeListener listener, ListenerRemovalToken removalToken)Adds the given listener to this inventory, such that theFluidInvTankChangeListener.onChange(FixedFluidInvView, int, FluidVolume, FluidVolume)
will be called every time that this inventory changes. However if this inventory doesn't support listeners then this will return a nulltoken
.- Parameters:
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.
-
getSubInv
Equivalent toList.subList(int, int)
.- Parameters:
fromIndex
- The first tank to exposetoIndex
- The tank after the last tank to expose.- Returns:
- a view of this inventory that only exposes the given number of tanks. Might return "this" if fromIndex is
0 and toIndex is equal to
getTankCount()
. - Throws:
RuntimeException
- if any of the given tanks weren't valid.
-
getMappedInv
- Parameters:
tanks
- The tanks to expose.- Returns:
- a view of this inventory that only exposes the given number of tanks. Might return "this" if the tank
array is just [0,1, ...
getTankCount()
-1] - Throws:
RuntimeException
- if any of the given tanks weren't valid
-
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
.Offers this object andgetGroupedInv()
to the attribute list. (Which, in turn, addsFixedFluidInv.getInsertable()
,FixedFluidInv.getExtractable()
, andFixedFluidInv.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
-
validateFixedFluidInvView
-
getFixedView
- Returns:
- An object that only implements
FixedFluidInvView
, and does not expose the modification methods thatFixedFluidInv
does. Implementations that don't expose any modification methods themselves should override this method to just return themselves.
-
getMaxAmount_F(int)