Class FluidVolume
java.lang.Object
alexiil.mc.lib.attributes.fluid.volume.FluidVolume
- Direct Known Subclasses:
ColouredFluidVolume
,NormalFluidVolume
,PotionFluidVolume
,SimpleFluidVolume
,WeightedFluidVolume
public abstract class FluidVolume
extends java.lang.Object
An amount of a
FluidKey
, analogous to forge's FluidStack class or RebornCore's FluidInstance class. However
there are a few key differences:
- FluidVolume is abstract, and it's subclasses must be defined by the
FluidKey
rather than anyone else. As such you should always use the factory methods inFluidKey
. - LBA doesn't have any direct way to store arbitrary data in a
CompoundTag
/NBT, so instead all custom data must be stored in a way that's defined by theFluidKey
, or a FluidProperty that's already been registered with theFluidKey
. - The amount field cannot be modified directly - instead you should either split or merge with any of the public
split or merge/mergeInto methods in this class. That way the custom data can handle splitting and merging properly.
Note that the only requirement for merging two
FluidVolume
s is that they have identical keys. (And are of the same class, but that's implied by having the same key).
-
Field Summary
Fields Modifier and Type Field Description static int
BASE_UNIT
Deprecated.Fluids now usefractions
instead of a single base unit - which makes this completely deprecated with no replacement.static int
BOTTLE
Deprecated.Replaced byFluidAmount.BOTTLE
static int
BUCKET
Deprecated.Replaced byFluidAmount.BUCKET
static com.google.gson.JsonDeserializer<FluidVolume>
DESERIALIZER
FluidKey
fluidKey
-
Constructor Summary
Constructors Constructor Description FluidVolume(FluidKey key, int amount)
Deprecated.FluidVolume(FluidKey key, FluidAmount amount)
FluidVolume(FluidKey key, com.google.gson.JsonObject json)
FluidVolume(FluidKey key, net.minecraft.nbt.CompoundTag tag)
-
Method Summary
Modifier and Type Method Description void
addFullTooltip(FluidAmount capacity, FluidTooltipContext context, java.util.List<net.minecraft.text.Text> tooltip)
Adds the complete tooltip for thisFluidVolume
to the given tooltip.void
addFullTooltip(FluidAmount capacity, java.util.List<net.minecraft.text.Text> tooltip)
Adds the complete tooltip for thisFluidVolume
to the given tooltip.void
addFullTooltip(java.util.List<net.minecraft.text.Text> tooltip)
Adds the entire tooltip for this fluid (by itself, not in a tank) to the given list.void
addTooltipExtras(FluidTooltipContext context, java.util.List<net.minecraft.text.Text> tooltip)
Adds any additional data that thisFluidVolume
has.void
addTooltipNameAmount(FluidAmount capacity, FluidTooltipContext context, java.util.List<net.minecraft.text.Text> tooltip)
Adds the name and amount to the given tooltip.void
addTooltipProperties(FluidTooltipContext context, java.util.List<net.minecraft.text.Text> tooltip)
void
addTooltipTemperature(FluidTooltipContext context, java.util.List<net.minecraft.text.Text> tooltip)
FluidAmount
amount()
An alternate name forgetAmount_F()
.static boolean
areEqualExceptAmounts(FluidVolume a, FluidVolume b)
static boolean
areFullyEqual(FluidVolume a, FluidVolume b)
Deprecated.UseObject.equals(Object)
instead of this.boolean
canMerge(FluidVolume with)
Checks to see if the givenFluidVolume
can merge into this one.FluidVolume
copy()
protected FluidVolume
copy0()
static FluidVolume
create(FluidKey fluid, int amount)
Deprecated.static FluidVolume
create(net.minecraft.fluid.Fluid fluid, int amount)
Deprecated.static FluidVolume
create(net.minecraft.potion.Potion potion, int amount)
Deprecated.boolean
equals(java.lang.Object obj)
static FluidVolume
fromJson(com.google.gson.JsonObject json)
static FluidVolume
fromMcBuffer(net.minecraft.network.PacketByteBuf buffer)
protected void
fromMcBufferInternal(net.minecraft.network.PacketByteBuf buffer)
static FluidVolume
fromTag(net.minecraft.nbt.CompoundTag tag)
int
getAmount()
Deprecated.Replaced bygetAmount_F()
andamount()
.FluidAmount
getAmount_F()
Note: due to LBA's backwards compatibility with when it used to use a 1620-based fixed fraction integers this cannot use the name "getAmount", so instead this has "_F" added to the end.net.minecraft.util.Identifier
getFlowingSprite()
Fallback forDefaultFluidVolumeRenderer
to use if it can't find one itself.FluidKey
getFluidKey()
java.util.List<net.minecraft.text.Text>
getFullTooltip()
Simple getter for retrieving the entire fluid tooltip, instead of adding it to an already-existing list.java.util.List<net.minecraft.text.Text>
getFullTooltip(FluidAmount capacity)
Simple getter for retrieving the entire fluid tooltip, instead of adding it to an already-existing list.java.util.List<net.minecraft.text.Text>
getFullTooltip(FluidAmount capacity, FluidTooltipContext context)
Simple getter for retrieving the entire fluid tooltip, instead of adding it to an already-existing list.net.minecraft.text.Text
getName()
<T> T
getProperty(FluidProperty<T> property)
protected int
getRawAmount()
Deprecated.Replaced bygetRawAmount_F()
.protected FluidAmount
getRawAmount_F()
net.minecraft.fluid.Fluid
getRawFluid()
int
getRenderColor()
FluidVolumeRenderer
getRenderer()
Returns theFluidVolumeRenderer
to use for rendering this fluid.net.minecraft.util.Identifier
getSprite()
Fallback forDefaultFluidVolumeRenderer
to use if it can't find one itself.net.minecraft.util.Identifier
getStillSprite()
Fallback forDefaultFluidVolumeRenderer
to use if it can't find one itself.java.util.List<net.minecraft.text.Text>
getTooltipText(net.minecraft.client.item.TooltipContext ctx)
Deprecated.Replaced bygetFullTooltip()
.int
hashCode()
boolean
isEmpty()
java.lang.String
localizeAmount()
java.lang.String
localizeAmount(FluidTooltipContext ctx)
java.lang.String
localizeInTank(FluidAmount capacity)
java.lang.String
localizeInTank(FluidAmount capacity, FluidTooltipContext ctx)
boolean
merge(FluidVolume other, FluidAmount.FluidMergeRounding rounding, Simulation simulation)
static FluidVolume
merge(FluidVolume a, FluidVolume b)
static FluidVolume
merge(FluidVolume a, FluidVolume b, FluidAmount.FluidMergeRounding rounding)
boolean
merge(FluidVolume other, Simulation simulation)
protected void
merge0(FluidVolume other, FluidAmount.FluidMergeRounding rounding)
Deprecated.becausemergeInternal(FluidVolume, FluidMergeResult)
allows every method to share the sameFluidAmount.FluidMergeResult
object, which reduces the chance to make a mistake when merging the two amounts.protected void
mergeInternal(FluidVolume other, FluidAmount.FluidMergeResult mergedAmounts)
Actually merges twoFluidVolume
's together.static boolean
mergeInto(FluidVolume source, FluidVolume target)
Merges as much fluid as possible from the source into the target, leaving the result in thestatic boolean
mergeInto(FluidVolume source, FluidVolume target, FluidAmount.FluidMergeRounding rounding)
Merges as much fluid as possible from the source into the target, leaving the result in thestatic boolean
mergeInto(FluidVolume source, FluidVolume target, FluidAmount.FluidMergeRounding rounding, Simulation simulation)
Merges as much fluid as possible from the source into the target, leaving the result in the source.FluidVolume
multiplyAmount(int by)
Returns a newFluidVolume
that is a copy of this one, but with an amount multiplied by the given amount.static FluidAmount
parseAmount(com.google.gson.JsonElement elem)
void
render(java.util.List<FluidRenderFace> faces, net.minecraft.client.render.VertexConsumerProvider vcp, net.minecraft.client.util.math.MatrixStack matrices)
Delegate method togetRenderer()
.void
renderGuiRect(double x0, double y0, double x1, double y1)
protected void
setAmount(int newAmount)
Deprecated.protected void
setAmount(FluidAmount newAmount)
Protected to allow the implementation ofsplit(FluidAmount)
andmerge0(FluidVolume, FluidMergeRounding)
to set the amount.<T> void
setProperty(FluidProperty<T> property, T value)
FluidVolume
split(int toRemove)
Deprecated.Replaced bysplit(FluidAmount)
FluidVolume
split(FluidAmount toRemove)
Splits off the given amount of fluid and returns it, reducing this amount as well.
If the given amount is greater than this then the returnedFluidVolume
will have an amount equal to this amount, and not the amount given.FluidVolume
split(FluidAmount toRemove, java.math.RoundingMode rounding)
Splits off the given amount of fluid and returns it, reducing this amount as well.
If the given amount is greater than this then the returnedFluidVolume
will have an amount equal to this amount, and not the amount given.protected FluidVolume
split0(FluidAmount toTake, java.math.RoundingMode rounding)
com.google.gson.JsonObject
toJson()
void
toMcBuffer(net.minecraft.network.PacketByteBuf buffer)
protected void
toMcBufferInternal(net.minecraft.network.PacketByteBuf buffer)
java.lang.String
toString()
net.minecraft.nbt.CompoundTag
toTag()
net.minecraft.nbt.CompoundTag
toTag(net.minecraft.nbt.CompoundTag tag)
FluidVolume
withAmount(FluidAmount newAmount)
Creates a copy of this fluid with the given amount.
-
Field Details
-
BASE_UNIT
@Deprecated public static final int BASE_UNITDeprecated.Fluids now usefractions
instead of a single base unit - which makes this completely deprecated with no replacement.The base unit for all fluids. This is arbitrarily chosen to be 1 / 1620 of a bucket. NOTE: You should never tell the player what unit this is!- See Also:
- Constant Field Values
-
BUCKET
@Deprecated public static final int BUCKETDeprecated.Replaced byFluidAmount.BUCKET
- See Also:
- Constant Field Values
-
BOTTLE
@Deprecated public static final int BOTTLEDeprecated.Replaced byFluidAmount.BOTTLE
- See Also:
- Constant Field Values
-
DESERIALIZER
-
fluidKey
-
-
Constructor Details
-
FluidVolume
Deprecated.- Parameters:
amount
- The amount, in (amount / 1620)
-
FluidVolume
-
FluidVolume
-
FluidVolume
public FluidVolume(FluidKey key, com.google.gson.JsonObject json) throws com.google.gson.JsonSyntaxException- Throws:
com.google.gson.JsonSyntaxException
-
-
Method Details
-
fromTag
-
toTag
public final net.minecraft.nbt.CompoundTag toTag() -
toTag
public net.minecraft.nbt.CompoundTag toTag(net.minecraft.nbt.CompoundTag tag) -
parseAmount
public static FluidAmount parseAmount(com.google.gson.JsonElement elem) throws com.google.gson.JsonSyntaxException- Throws:
com.google.gson.JsonSyntaxException
-
toJson
public com.google.gson.JsonObject toJson() -
fromJson
public static FluidVolume fromJson(com.google.gson.JsonObject json) throws com.google.gson.JsonSyntaxException- Throws:
com.google.gson.JsonSyntaxException
-
toMcBuffer
public final void toMcBuffer(net.minecraft.network.PacketByteBuf buffer) -
toMcBufferInternal
protected void toMcBufferInternal(net.minecraft.network.PacketByteBuf buffer) -
fromMcBuffer
public static FluidVolume fromMcBuffer(net.minecraft.network.PacketByteBuf buffer) throws java.io.IOException- Throws:
java.io.IOException
-
fromMcBufferInternal
protected void fromMcBufferInternal(net.minecraft.network.PacketByteBuf buffer) -
create
Deprecated.Creates a newFluidVolume
from the given fluid, with the given amount stored. This just delegates internally toFluidKey.withAmount(int)
. -
create
Deprecated.Creates a newFluidVolume
from the given fluid, with the given amount stored. -
create
Deprecated.Creates a newFluidVolume
from the given potion, with the given amount stored. -
equals
public boolean equals(java.lang.Object obj)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
localizeAmount
public java.lang.String localizeAmount() -
localizeAmount
-
localizeInTank
-
localizeInTank
-
areFullyEqual
Deprecated.UseObject.equals(Object)
instead of this. -
areEqualExceptAmounts
-
isEmpty
public final boolean isEmpty() -
getFluidKey
- Returns:
- The
FluidKey
for this volume. Subclasses may override this to use a return type for their key class.
-
getRawFluid
@Nullable public net.minecraft.fluid.Fluid getRawFluid()- Returns:
- The minecraft
Fluid
instance that this contains, or null if this is based on something else (likePotion
's).
-
copy
-
copy0
-
getAmount
@Deprecated public final int getAmount()Deprecated.Replaced bygetAmount_F()
andamount()
. -
getAmount_F
Note: due to LBA's backwards compatibility with when it used to use a 1620-based fixed fraction integers this cannot use the name "getAmount", so instead this has "_F" added to the end. Alternatively you can useamount()
if you prefer a more reasonable name.- Returns:
FluidAmount.ZERO
if thisisEmpty()
, otherwise this returns the fractional amount stored.
-
amount
An alternate name forgetAmount_F()
.- Returns:
FluidAmount.ZERO
if thisisEmpty()
, otherwise this returns the fractional amount stored.
-
getRawAmount
@Deprecated protected final int getRawAmount()Deprecated.Replaced bygetRawAmount_F()
.- Returns:
- The raw amount value, which might not be 0 if this is
empty
.
-
getRawAmount_F
- Returns:
- The fractional amount of fluid that this holds. This might not be
FluidAmount.isZero()
if thisisEmpty()
.
-
setAmount
@Deprecated protected final void setAmount(int newAmount)Deprecated.Protected to allow the implementation ofsplit(int)
andmerge0(FluidVolume, FluidMergeRounding)
to set the amount. -
setAmount
Protected to allow the implementation ofsplit(FluidAmount)
andmerge0(FluidVolume, FluidMergeRounding)
to set the amount. -
withAmount
Creates a copy of this fluid with the given amount. Unlike callingFluidKey.withAmount(FluidAmount)
this will preserve any extra data that thisFluidVolume
contains. -
multiplyAmount
Returns a newFluidVolume
that is a copy of this one, but with an amount multiplied by the given amount.- See Also:
withAmount(FluidAmount)
-
mergeInto
Merges as much fluid as possible from the source into the target, leaving the result in the- Parameters:
source
- The source fluid. This will be modified if any is moved.target
- The destination fluid. This will be modified if any is moved.- Returns:
- True if the merge was successful, false otherwise. If either fluid is empty or if they have different
keys
then this will return false (and fail).
-
mergeInto
public static boolean mergeInto(FluidVolume source, FluidVolume target, FluidAmount.FluidMergeRounding rounding)Merges as much fluid as possible from the source into the target, leaving the result in the- Parameters:
source
- The source fluid. This will be modified if any is moved.target
- The destination fluid. This will be modified if any is moved.rounding
-- Returns:
- True if the merge was successful, false otherwise. If either fluid is empty or if they have different
keys
then this will return false (and fail).
-
mergeInto
public static boolean mergeInto(FluidVolume source, FluidVolume target, FluidAmount.FluidMergeRounding rounding, Simulation simulation)Merges as much fluid as possible from the source into the target, leaving the result in the source.- Parameters:
source
- The source fluid. This will be modified if any is moved.target
- The destination fluid. This will be modified if any is moved.rounding
-- Returns:
- True if the merge was successful, false otherwise. If either fluid is empty or if they have different
keys
then this will return false (and fail).
-
merge
- Parameters:
a
- The merge target. Might be modified and/or returned.b
- The other fluid. Might be modified, and might be returned.- Returns:
- the inTank fluid. Might be either a or b depending on
-
merge
@Nullable public static FluidVolume merge(FluidVolume a, FluidVolume b, FluidAmount.FluidMergeRounding rounding)- Parameters:
a
- The merge target. Might be modified and/or returned.b
- The other fluid. Might be modified, and might be returned.- Returns:
- the inTank fluid. Might be either a or b depending on
-
canMerge
Checks to see if the givenFluidVolume
can merge into this one. Returns false if either this fluid or the given fluid areempty
. -
merge
-
merge
public final boolean merge(FluidVolume other, FluidAmount.FluidMergeRounding rounding, Simulation simulation) -
merge0
Deprecated.becausemergeInternal(FluidVolume, FluidMergeResult)
allows every method to share the sameFluidAmount.FluidMergeResult
object, which reduces the chance to make a mistake when merging the two amounts. In addition it's a bit wasteful to re-compute the same value more than once.So instead of overriding this it's recommended that you only override
mergeInternal(FluidVolume, FluidMergeResult)
.Actually merges twoFluidVolume
's together. Onlymerge(FluidVolume, FluidMergeRounding, Simulation)
should call this. (Except for subclasses that override this method).- Parameters:
other
- The other fluid volume. This will always be the same class as this. This should change the amount of the other fluid to 0.
-
mergeInternal
Actually merges twoFluidVolume
's together. Onlymerge(FluidVolume, FluidMergeRounding, Simulation)
should call this. (Except for subclasses that override this method).- Parameters:
other
- The other fluid volume. This will always be the same class as this. This should change the amount of the other fluid toFluidAmount.FluidMergeResult.excess
.
-
split
Deprecated.Replaced bysplit(FluidAmount)
-
split
Splits off the given amount of fluid and returns it, reducing this amount as well.
If the given amount is greater than this then the returnedFluidVolume
will have an amount equal to this amount, and not the amount given.- Parameters:
toRemove
- If zero then the empty fluid is returned.- Throws:
java.lang.IllegalArgumentException
- if the given amount is negative.
-
split
Splits off the given amount of fluid and returns it, reducing this amount as well.
If the given amount is greater than this then the returnedFluidVolume
will have an amount equal to this amount, and not the amount given.- Parameters:
toRemove
- If zero then the empty fluid is returned.- Throws:
java.lang.IllegalArgumentException
- if the given amount is negative.
-
split0
- Parameters:
toTake
- A valid subtractable amount.- Returns:
- A new
FluidVolume
with the given amount that has been removed from this.
-
getProperty
- Throws:
java.lang.IllegalArgumentException
- if the given property hasn't been registered to theFluidKey
.
-
setProperty
-
getSprite
public net.minecraft.util.Identifier getSprite()Fallback forDefaultFluidVolumeRenderer
to use if it can't find one itself.- Returns:
- An
Identifier
for the still sprite that this fluid volume should render with in gui's and in-world.
-
getStillSprite
public final net.minecraft.util.Identifier getStillSprite()Fallback forDefaultFluidVolumeRenderer
to use if it can't find one itself.Provided for completeness with
getFlowingSprite()
. As this is final (and so cannot be overridden) it is always safe to call this instead ofgetSprite()
. (If getSprite() is ever deprecated it is recommended to that you call this instead).- Returns:
- An
Identifier
for the still sprite that this fluid volume should render with in gui's and in-world.
-
getFlowingSprite
public net.minecraft.util.Identifier getFlowingSprite()Fallback forDefaultFluidVolumeRenderer
to use if it can't find one itself.- Returns:
- An
Identifier
for the flowing sprite that this fluid volume should render with in gui's and in-world whenFluidRenderFace.flowing
is true.
-
getRenderColor
public int getRenderColor()- Returns:
- The colour tint to use when rendering this fluid volume in gui's or in-world. Note that this MUST be in
0xAA_RR_GG_BB format:
(r << 16) | (g << 8) | (b)
. Alpha may be omitted however - which should default it to 0xFF.
-
getName
public net.minecraft.text.Text getName() -
getTooltipText
@Deprecated @Environment(CLIENT) public java.util.List<net.minecraft.text.Text> getTooltipText(net.minecraft.client.item.TooltipContext ctx)Deprecated.Replaced bygetFullTooltip()
. -
getFullTooltip
public final java.util.List<net.minecraft.text.Text> getFullTooltip()Simple getter for retrieving the entire fluid tooltip, instead of adding it to an already-existing list. -
addFullTooltip
public final void addFullTooltip(java.util.List<net.minecraft.text.Text> tooltip)Adds the entire tooltip for this fluid (by itself, not in a tank) to the given list. -
getFullTooltip
public final java.util.List<net.minecraft.text.Text> getFullTooltip(@Nullable FluidAmount capacity)Simple getter for retrieving the entire fluid tooltip, instead of adding it to an already-existing list.- Parameters:
capacity
- If non-null then this will display as if this was in a tank, rather than by itself.
-
addFullTooltip
public final void addFullTooltip(@Nullable FluidAmount capacity, java.util.List<net.minecraft.text.Text> tooltip)Adds the complete tooltip for thisFluidVolume
to the given tooltip.- Parameters:
capacity
- If non-null then this will display as if this was in a tank, rather than by itself.
-
getFullTooltip
public final java.util.List<net.minecraft.text.Text> getFullTooltip(@Nullable FluidAmount capacity, FluidTooltipContext context)Simple getter for retrieving the entire fluid tooltip, instead of adding it to an already-existing list.- Parameters:
capacity
- If non-null then this will display as if this was in a tank, rather than by itself.
-
addFullTooltip
public final void addFullTooltip(@Nullable FluidAmount capacity, FluidTooltipContext context, java.util.List<net.minecraft.text.Text> tooltip)Adds the complete tooltip for thisFluidVolume
to the given tooltip.- Parameters:
capacity
- If non-null then this will display as if this was in a tank, rather than by itself.
-
addTooltipNameAmount
public final void addTooltipNameAmount(@Nullable FluidAmount capacity, FluidTooltipContext context, java.util.List<net.minecraft.text.Text> tooltip)Adds the name and amount to the given tooltip. This is only provided so that custom tooltip implementations can -
addTooltipExtras
public void addTooltipExtras(FluidTooltipContext context, java.util.List<net.minecraft.text.Text> tooltip)Adds any additional data that thisFluidVolume
has. -
addTooltipTemperature
public final void addTooltipTemperature(FluidTooltipContext context, java.util.List<net.minecraft.text.Text> tooltip) -
addTooltipProperties
public final void addTooltipProperties(FluidTooltipContext context, java.util.List<net.minecraft.text.Text> tooltip) -
getRenderer
Returns theFluidVolumeRenderer
to use for rendering this fluid. -
render
@Environment(CLIENT) public final void render(java.util.List<FluidRenderFace> faces, net.minecraft.client.render.VertexConsumerProvider vcp, net.minecraft.client.util.math.MatrixStack matrices)Delegate method togetRenderer()
.render(faces, vcp, matrices)
. -
renderGuiRect
@Environment(CLIENT) public final void renderGuiRect(double x0, double y0, double x1, double y1)
-