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
FixedFluidInvwill 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 ListenerTokenaddListener(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> TAttempts to provide a variant of this in the given class form.default Iterable<FluidVolume>default FluidFiltergetFilterForTank(int tank) ExposesisFluidValidForTank(int, FluidKey)as a (potentially) readable filter.default FixedFluidInvViewdefault GroupedFluidInvViewgetInvFluid(int tank) default FixedFluidInvViewgetMappedInv(int... tanks) default intgetMaxAmount(int tank) Deprecated, for removal: This API element is subject to removal in a future version.default FluidAmountgetMaxAmount_F(int tank) default FixedFluidInvViewgetSubInv(int fromIndex, int toIndex) Equivalent toList.subList(int, int).default SingleFluidTankViewgetTank(int tank) intbooleanisFluidValidForTank(int tank, FluidKey fluid) Checks to see if the given fluid would be valid for this tank, ignoring current contents.default voidofferSelfAsAttribute(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 byConvertibleand it's usage inAttributeList.default Iterable<? extends SingleFluidTankView>static voidvalidateFixedFluidInvView(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 passingemptyfluids 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
FluidFilterfor this tank. If this tank is filtered by anFluidFilterinternally 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 byConvertibleand 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:ConvertibleAttempts 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:
convertToin interfaceConvertible
-
validateFixedFluidInvView
-
getFixedView
- Returns:
- An object that only implements
FixedFluidInvView, and does not expose the modification methods thatFixedFluidInvdoes. Implementations that don't expose any modification methods themselves should override this method to just return themselves.
-
getMaxAmount_F(int)