Class SimpleFixedFluidInv
- All Implemented Interfaces:
Convertible
,FixedFluidInv
,FixedFluidInvView
,FluidExtractable
,FluidInsertable
,FluidTransferable
,LimitedConsumer<FluidVolume>
,Saveable
- Direct Known Subclasses:
JumboFixedFluidInv
public class SimpleFixedFluidInv extends java.lang.Object implements FixedFluidInv, FluidTransferable, Saveable
FixedFluidInv
exposes.
Extending classes should take care to override getFilterForTank(int)
if they also override
isFluidValidForTank(int, FluidKey)
.
Note: Generally it is better to extend JumboFixedFluidInv
for inventories with a large number of similar
tanks (like a chest).
-
Field Summary
Fields Modifier and Type Field Description int
tankCapacity
Deprecated.Replaced bytankCapacity_F
FluidAmount
tankCapacity_F
protected net.minecraft.util.collection.DefaultedList<FluidVolume>
tanks
-
Constructor Summary
Constructors Constructor Description SimpleFixedFluidInv(int invSize, int tankCapacity)
Deprecated.Replaced bySimpleFixedFluidInv(int, FluidAmount)
.SimpleFixedFluidInv(int invSize, FluidAmount tankCapacity)
-
Method Summary
Modifier and Type Method Description 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.FluidVolume
attemptAnyExtraction(FluidAmount maxAmount, Simulation simulation)
FluidVolume
attemptExtraction(FluidFilter filter, FluidAmount maxAmount, Simulation simulation)
FluidVolume
attemptInsertion(FluidVolume fluid, Simulation simulation)
Inserts the given stack into this insertable, and returns the excess.protected void
fireTankChange(int tank, FluidVolume previous, FluidVolume current)
void
fromTag(net.minecraft.nbt.CompoundTag tag)
FluidFilter
getFilterForTank(int tank)
ExposesFixedFluidInvView.isFluidValidForTank(int, FluidKey)
as a (potentially) readable filter.GroupedFluidInv
getGroupedInv()
FluidFilter
getInsertionFilter()
Returns anFluidFilter
to determine ifFluidInsertable.attemptInsertion(FluidVolume, Simulation)
could ever accept a fluid.FluidVolume
getInvFluid(int tank)
int
getMaxAmount(int tank)
Deprecated.Replaced bygetMaxAmount_F(int)
.FluidAmount
getMaxAmount_F(int tank)
FluidAmount
getMinimumAcceptedAmount()
int
getTankCount()
void
invalidateListeners()
boolean
isFluidValidForTank(int tank, FluidKey fluid)
Checks to see if the given fluid would be valid for this tank, ignoring current contents.boolean
setInvFluid(int tank, FluidVolume to, Simulation simulation)
Sets the fluid in the given tank to the given fluid.void
setOwnerListener(FluidInvTankChangeListener ownerListener)
Sets the owner listener callback, which is never removed from the listener list wheninvalidateListeners()
is called.net.minecraft.nbt.CompoundTag
toTag()
net.minecraft.nbt.CompoundTag
toTag(net.minecraft.nbt.CompoundTag tag)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface alexiil.mc.lib.attributes.fluid.FixedFluidInv
createLimitedFixedInv, extractFluid, forceSetInvFluid, getExtractable, getInsertable, getMappedInv, getSubInv, getTank, getTransferable, insertFluid, modifyTank, tankIterable
Methods inherited from interface alexiil.mc.lib.attributes.fluid.FixedFluidInvView
convertTo, fluidIterable, getFixedView, offerSelfAsAttribute
Methods inherited from interface alexiil.mc.lib.attributes.fluid.FluidExtractable
attemptAnyExtraction, attemptExtraction, couldExtractAnything, extract, extract, extract, extract, extract, extract, getPureExtractable
Methods inherited from interface alexiil.mc.lib.attributes.fluid.FluidInsertable
getPureInsertable, insert, offer, offer, wouldAccept
-
Field Details
-
tankCapacity
@Deprecated public final int tankCapacityDeprecated.Replaced bytankCapacity_F
-
tankCapacity_F
-
tanks
-
-
Constructor Details
-
SimpleFixedFluidInv
@Deprecated public SimpleFixedFluidInv(int invSize, int tankCapacity)Deprecated.Replaced bySimpleFixedFluidInv(int, FluidAmount)
. -
SimpleFixedFluidInv
-
-
Method Details
-
getTankCount
public final int getTankCount()- Specified by:
getTankCount
in interfaceFixedFluidInvView
- Returns:
- The number of tanks in this inventory.
-
getMaxAmount
@Deprecated public int getMaxAmount(int tank)Deprecated.Replaced bygetMaxAmount_F(int)
.- Specified by:
getMaxAmount
in interfaceFixedFluidInvView
- Parameters:
tank
- The tank index. Must be a value between 0 (inclusive) andFixedFluidInvView.getTankCount()
(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
FixedFluidInvView.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).
-
getMaxAmount_F
- Specified by:
getMaxAmount_F
in interfaceFixedFluidInvView
- Parameters:
tank
- The tank index. Must be a value between 0 (inclusive) andFixedFluidInvView.getTankCount()
(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
FixedFluidInvView.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).
-
getInvFluid
- Specified by:
getInvFluid
in interfaceFixedFluidInvView
- Parameters:
tank
- The tank index. Must be a value between 0 (inclusive) andFixedFluidInvView.getTankCount()
(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!
-
isFluidValidForTank
Description copied from interface:FixedFluidInv
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.Note that just because an
FluidKey
passes this validity test, and is mergable with the current fluid, does not mean that you can insert the fluid into this inventory.- Specified by:
isFluidValidForTank
in interfaceFixedFluidInv
- Specified by:
isFluidValidForTank
in interfaceFixedFluidInvView
- Parameters:
tank
- The tank index. Must be a value between 0 (inclusive) andFixedFluidInvView.getTankCount()
(exclusive) to be valid. (Like in arrays, lists, etc).
-
getFilterForTank
Description copied from interface:FixedFluidInvView
ExposesFixedFluidInvView.isFluidValidForTank(int, FluidKey)
as a (potentially) readable filter.- Specified by:
getFilterForTank
in interfaceFixedFluidInvView
- Parameters:
tank
- The tank index. Must be a value between 0 (inclusive) andFixedFluidInvView.getTankCount()
(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 aroundFixedFluidInvView.isFluidValidForTank(int, FluidKey)
.
-
setInvFluid
Description copied from interface:FixedFluidInv
Sets the fluid in the given tank to the given fluid.- Specified by:
setInvFluid
in interfaceFixedFluidInv
- Returns:
- True if the modification was allowed, false otherwise. (For example if the given stack doesn't pass the
FixedFluidInvView.isFluidValidForTank(int, FluidKey)
test).
-
getGroupedInv
- Specified by:
getGroupedInv
in interfaceFixedFluidInv
- Specified by:
getGroupedInv
in interfaceFixedFluidInvView
- Returns:
- A statistical view of this inventory.
-
addListener
public ListenerToken addListener(FluidInvTankChangeListener listener, ListenerRemovalToken removalToken)Description copied from interface:FixedFluidInvView
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
.- Specified by:
addListener
in interfaceFixedFluidInvView
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.
-
setOwnerListener
Sets the owner listener callback, which is never removed from the listener list wheninvalidateListeners()
is called. -
invalidateListeners
public void invalidateListeners() -
fireTankChange
-
toTag
public final net.minecraft.nbt.CompoundTag toTag() -
toTag
public net.minecraft.nbt.CompoundTag toTag(net.minecraft.nbt.CompoundTag tag) -
fromTag
public void fromTag(net.minecraft.nbt.CompoundTag tag) -
attemptInsertion
Description copied from interface:FluidInsertable
Inserts the given stack into this insertable, and returns the excess.- Specified by:
attemptInsertion
in interfaceFluidInsertable
- Parameters:
fluid
- The incoming fluid. Must not be modified by this call.simulation
- IfSimulation.SIMULATE
then this shouldn't modify anything.- Returns:
- the excess
FluidVolume
that wasn't accepted. This will be independent of this insertable, however it might be the given object instead of a completely new object.
-
getMinimumAcceptedAmount
- Specified by:
getMinimumAcceptedAmount
in interfaceFluidInsertable
- Returns:
- The minimum amount of fluid that
FluidInsertable.attemptInsertion(FluidVolume, Simulation)
will actually accept. Note that this only provides a guarantee thatfluid volumes
with anamount
less than this will never be accepted.A null return value indicates that there is no minimum value.
-
getInsertionFilter
Description copied from interface:FluidInsertable
Returns anFluidFilter
to determine ifFluidInsertable.attemptInsertion(FluidVolume, Simulation)
could ever accept a fluid. The default implementation is to returnConstantFluidFilter.ANYTHING
, and so it is recommended that custom insertables override this to return a more accurate filter.- Specified by:
getInsertionFilter
in interfaceFluidInsertable
- Returns:
- A filter to determine if the given fluid could ever be inserted.
-
attemptExtraction
public FluidVolume attemptExtraction(FluidFilter filter, FluidAmount maxAmount, Simulation simulation)Description copied from interface:FluidExtractable
- Specified by:
attemptExtraction
in interfaceFluidExtractable
maxAmount
- The maximum amount of fluid that can be extracted. Negative numbers throw an exception.simulation
- IfSimulation.SIMULATE
then this should return the same result that the exact same call withSimulation.ACTION
would do, except that the filter can be made more specific between calls if the previously simulated extracted fluid is used as a filter.For example the following code snippet should never throw an exception:
FluidExtractable
from = // Some extractable
FluidVolume
attempted = from.attemptAnyExtraction
(Integer.MAX_VALUE
,Simulation.SIMULATE
);
if (attempted.isEmpty()
) return;
FluidVolume
extracted = from.extract
(attempted.getFluidKey()
, attempted.getAmount()
);
assert !extracted.isEmpty
;
assert attempted.getAmount()
== extracted.getAmount()
;
assert attempted.getFluidKet()
== extracted.getFluidKet()
;
assert attempted.equals
(extracted);- Returns:
- A new, independent
FluidVolume
that was extracted.
-
attemptAnyExtraction
Description copied from interface:FluidExtractable
- Specified by:
attemptAnyExtraction
in interfaceFluidExtractable
-