Class FluidVolume
java.lang.Object
alexiil.mc.lib.attributes.fluid.volume.FluidVolume
- Direct Known Subclasses:
ColouredFluidVolume
,NormalFluidVolume
,PotionFluidVolume
,SimpleFluidVolume
,WeightedFluidVolume
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
NbtCompound
/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
Modifier and TypeFieldDescriptionstatic int
Deprecated, for removal: This API element is subject to removal in a future version.static int
Deprecated, for removal: This API element is subject to removal in a future version.Replaced byFluidAmount.BOTTLE
static int
Deprecated, for removal: This API element is subject to removal in a future version.Replaced byFluidAmount.BUCKET
static com.google.gson.JsonDeserializer<FluidVolume>
-
Constructor Summary
ConstructorDescriptionFluidVolume(FluidKey key, int amount)
Deprecated, for removal: This API element is subject to removal in a future version.FluidVolume(FluidKey key, FluidAmount amount)
FluidVolume(FluidKey key, com.google.gson.JsonObject json)
FluidVolume(FluidKey key, net.minecraft.nbt.NbtCompound tag)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addFullTooltip(FluidAmount capacity, FluidTooltipContext context, List<net.minecraft.text.Text> tooltip)
Adds the complete tooltip for thisFluidVolume
to the given tooltip.void
addFullTooltip(FluidAmount capacity, List<net.minecraft.text.Text> tooltip)
Adds the complete tooltip for thisFluidVolume
to the given tooltip.void
addFullTooltip(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, List<net.minecraft.text.Text> tooltip)
Adds any additional data that thisFluidVolume
has.void
addTooltipNameAmount(FluidAmount capacity, FluidTooltipContext context, List<net.minecraft.text.Text> tooltip)
Adds the name and amount to the given tooltip.void
addTooltipProperties(FluidTooltipContext context, List<net.minecraft.text.Text> tooltip)
void
addTooltipTemperature(FluidTooltipContext context, List<net.minecraft.text.Text> tooltip)
amount()
An alternate name forgetAmount_F()
.static boolean
static boolean
areFullyEqual(FluidVolume a, FluidVolume b)
Deprecated, for removal: This API element is subject to removal in a future version.UseObject.equals(Object)
instead of this.boolean
canMerge(FluidVolume with)
Checks to see if the givenFluidVolume
can merge into this one.copy()
protected FluidVolume
copy0()
static FluidVolume
Deprecated, for removal: This API element is subject to removal in a future version.static FluidVolume
create(net.minecraft.fluid.Fluid fluid, int amount)
Deprecated, for removal: This API element is subject to removal in a future version.static FluidVolume
create(net.minecraft.potion.Potion potion, int amount)
Deprecated, for removal: This API element is subject to removal in a future version.boolean
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.NbtCompound tag)
int
Deprecated, for removal: This API element is subject to removal in a future version.Replaced bygetAmount_F()
andamount()
.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
Fallback forDefaultFluidVolumeRenderer
to use if it can't find one itself.List<net.minecraft.text.Text>
Simple getter for retrieving the entire fluid tooltip, instead of adding it to an already-existing list.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.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
Deprecated, for removal: This API element is subject to removal in a future version.Replaced bygetRawAmount_F()
.protected FluidAmount
net.minecraft.fluid.Fluid
int
Returns theFluidVolumeRenderer
to use for rendering this fluid.net.minecraft.util.Identifier
Fallback forDefaultFluidVolumeRenderer
to use if it can't find one itself.net.minecraft.util.Identifier
Fallback forDefaultFluidVolumeRenderer
to use if it can't find one itself.List<net.minecraft.text.Text>
getTooltipText(net.minecraft.client.item.TooltipContext ctx)
Deprecated, for removal: This API element is subject to removal in a future version.Replaced bygetFullTooltip()
.int
hashCode()
boolean
isEmpty()
localizeInTank(FluidAmount capacity)
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, for removal: This API element is subject to removal in a future version.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.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(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, for removal: This API element is subject to removal in a future version.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)
split(int toRemove)
Deprecated, for removal: This API element is subject to removal in a future version.Replaced bysplit(FluidAmount)
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.split(FluidAmount toRemove, 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, RoundingMode rounding)
com.google.gson.JsonObject
toJson()
void
toMcBuffer(net.minecraft.network.PacketByteBuf buffer)
protected void
toMcBufferInternal(net.minecraft.network.PacketByteBuf buffer)
toString()
net.minecraft.nbt.NbtCompound
toTag()
net.minecraft.nbt.NbtCompound
toTag(net.minecraft.nbt.NbtCompound tag)
withAmount(FluidAmount newAmount)
Creates a copy of this fluid with the given amount.
-
Field Details
-
BASE_UNIT
Deprecated, for removal: This API element is subject to removal in a future version.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, for removal: This API element is subject to removal in a future version.Replaced byFluidAmount.BUCKET
- See Also:
- Constant Field Values
-
BOTTLE
Deprecated, for removal: This API element is subject to removal in a future version.Replaced byFluidAmount.BOTTLE
- See Also:
- Constant Field Values
-
DESERIALIZER
-
fluidKey
-
-
Constructor Details
-
FluidVolume
Deprecated, for removal: This API element is subject to removal in a future version.- 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.NbtCompound toTag() -
toTag
public net.minecraft.nbt.NbtCompound toTag(net.minecraft.nbt.NbtCompound 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 IOException- Throws:
IOException
-
fromMcBufferInternal
protected void fromMcBufferInternal(net.minecraft.network.PacketByteBuf buffer) -
create
@Deprecated(since="0.6.4", forRemoval=true) public static FluidVolume create(FluidKey fluid, int amount)Deprecated, for removal: This API element is subject to removal in a future version.Creates a newFluidVolume
from the given fluid, with the given amount stored. This just delegates internally toFluidKey.withAmount(int)
. -
create
@Deprecated(since="0.6.4", forRemoval=true) public static FluidVolume create(net.minecraft.fluid.Fluid fluid, int amount)Deprecated, for removal: This API element is subject to removal in a future version.Creates a newFluidVolume
from the given fluid, with the given amount stored. -
create
@Deprecated(since="0.6.4", forRemoval=true) public static FluidVolume create(net.minecraft.potion.Potion potion, int amount)Deprecated, for removal: This API element is subject to removal in a future version.Creates a newFluidVolume
from the given potion, with the given amount stored. -
equals
-
hashCode
public int hashCode() -
toString
-
localizeAmount
-
localizeAmount
-
localizeInTank
-
localizeInTank
-
areFullyEqual
@Deprecated(since="0.1.11", forRemoval=true) public static boolean areFullyEqual(FluidVolume a, FluidVolume b)Deprecated, for removal: This API element is subject to removal in a future version.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, for removal: This API element is subject to removal in a future version.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, for removal: This API element is subject to removal in a future version.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, for removal: This API element is subject to removal in a future version.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(since="0.7.0", forRemoval=true) protected void merge0(FluidVolume other, FluidAmount.FluidMergeRounding rounding)Deprecated, for removal: This API element is subject to removal in a future version.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, for removal: This API element is subject to removal in a future version.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:
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:
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:
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(since="0.7.0", forRemoval=true) @Environment(CLIENT) public List<net.minecraft.text.Text> getTooltipText(net.minecraft.client.item.TooltipContext ctx)Deprecated, for removal: This API element is subject to removal in a future version.Replaced bygetFullTooltip()
. -
getFullTooltip
Simple getter for retrieving the entire fluid tooltip, instead of adding it to an already-existing list. -
addFullTooltip
Adds the entire tooltip for this fluid (by itself, not in a tank) to the given list. -
getFullTooltip
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, 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 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, 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, 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
Adds any additional data that thisFluidVolume
has. -
addTooltipTemperature
public final void addTooltipTemperature(FluidTooltipContext context, List<net.minecraft.text.Text> tooltip) -
addTooltipProperties
public final void addTooltipProperties(FluidTooltipContext context, List<net.minecraft.text.Text> tooltip) -
getRenderer
Returns theFluidVolumeRenderer
to use for rendering this fluid. -
render
@Environment(CLIENT) public final void render(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)
-
fractions
instead of a single base unit - which makes this completely deprecated with no replacement.