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 
FluidKeyrather 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 
FluidVolumes 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 intBASE_UNITDeprecated.Fluids now usefractionsinstead of a single base unit - which makes this completely deprecated with no replacement.static intBOTTLEDeprecated.Replaced byFluidAmount.BOTTLEstatic intBUCKETDeprecated.Replaced byFluidAmount.BUCKETstatic com.google.gson.JsonDeserializer<FluidVolume>DESERIALIZERFluidKeyfluidKey - 
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 voidaddFullTooltip(FluidAmount capacity, FluidTooltipContext context, java.util.List<net.minecraft.text.Text> tooltip)Adds the complete tooltip for thisFluidVolumeto the given tooltip.voidaddFullTooltip(FluidAmount capacity, java.util.List<net.minecraft.text.Text> tooltip)Adds the complete tooltip for thisFluidVolumeto the given tooltip.voidaddFullTooltip(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.voidaddTooltipExtras(FluidTooltipContext context, java.util.List<net.minecraft.text.Text> tooltip)Adds any additional data that thisFluidVolumehas.voidaddTooltipNameAmount(FluidAmount capacity, FluidTooltipContext context, java.util.List<net.minecraft.text.Text> tooltip)Adds the name and amount to the given tooltip.voidaddTooltipProperties(FluidTooltipContext context, java.util.List<net.minecraft.text.Text> tooltip)voidaddTooltipTemperature(FluidTooltipContext context, java.util.List<net.minecraft.text.Text> tooltip)FluidAmountamount()An alternate name forgetAmount_F().static booleanareEqualExceptAmounts(FluidVolume a, FluidVolume b)static booleanareFullyEqual(FluidVolume a, FluidVolume b)Deprecated.UseObject.equals(Object)instead of this.booleancanMerge(FluidVolume with)Checks to see if the givenFluidVolumecan merge into this one.FluidVolumecopy()protected FluidVolumecopy0()static FluidVolumecreate(FluidKey fluid, int amount)Deprecated.static FluidVolumecreate(net.minecraft.fluid.Fluid fluid, int amount)Deprecated.static FluidVolumecreate(net.minecraft.potion.Potion potion, int amount)Deprecated.booleanequals(java.lang.Object obj)static FluidVolumefromJson(com.google.gson.JsonObject json)static FluidVolumefromMcBuffer(net.minecraft.network.PacketByteBuf buffer)protected voidfromMcBufferInternal(net.minecraft.network.PacketByteBuf buffer)static FluidVolumefromTag(net.minecraft.nbt.CompoundTag tag)intgetAmount()Deprecated.Replaced bygetAmount_F()andamount().FluidAmountgetAmount_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.IdentifiergetFlowingSprite()Fallback forDefaultFluidVolumeRendererto use if it can't find one itself.FluidKeygetFluidKey()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.TextgetName()<T> TgetProperty(FluidProperty<T> property)protected intgetRawAmount()Deprecated.Replaced bygetRawAmount_F().protected FluidAmountgetRawAmount_F()net.minecraft.fluid.FluidgetRawFluid()intgetRenderColor()FluidVolumeRenderergetRenderer()Returns theFluidVolumeRendererto use for rendering this fluid.net.minecraft.util.IdentifiergetSprite()Fallback forDefaultFluidVolumeRendererto use if it can't find one itself.net.minecraft.util.IdentifiergetStillSprite()Fallback forDefaultFluidVolumeRendererto 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().inthashCode()booleanisEmpty()java.lang.StringlocalizeAmount()java.lang.StringlocalizeAmount(FluidTooltipContext ctx)java.lang.StringlocalizeInTank(FluidAmount capacity)java.lang.StringlocalizeInTank(FluidAmount capacity, FluidTooltipContext ctx)booleanmerge(FluidVolume other, FluidAmount.FluidMergeRounding rounding, Simulation simulation)static FluidVolumemerge(FluidVolume a, FluidVolume b)static FluidVolumemerge(FluidVolume a, FluidVolume b, FluidAmount.FluidMergeRounding rounding)booleanmerge(FluidVolume other, Simulation simulation)protected voidmerge0(FluidVolume other, FluidAmount.FluidMergeRounding rounding)Deprecated.becausemergeInternal(FluidVolume, FluidMergeResult)allows every method to share the sameFluidAmount.FluidMergeResultobject, which reduces the chance to make a mistake when merging the two amounts.protected voidmergeInternal(FluidVolume other, FluidAmount.FluidMergeResult mergedAmounts)Actually merges twoFluidVolume's together.static booleanmergeInto(FluidVolume source, FluidVolume target)Merges as much fluid as possible from the source into the target, leaving the result in thestatic booleanmergeInto(FluidVolume source, FluidVolume target, FluidAmount.FluidMergeRounding rounding)Merges as much fluid as possible from the source into the target, leaving the result in thestatic booleanmergeInto(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.FluidVolumemultiplyAmount(int by)Returns a newFluidVolumethat is a copy of this one, but with an amount multiplied by the given amount.static FluidAmountparseAmount(com.google.gson.JsonElement elem)voidrender(java.util.List<FluidRenderFace> faces, net.minecraft.client.render.VertexConsumerProvider vcp, net.minecraft.client.util.math.MatrixStack matrices)Delegate method togetRenderer().voidrenderGuiRect(double x0, double y0, double x1, double y1)protected voidsetAmount(int newAmount)Deprecated.protected voidsetAmount(FluidAmount newAmount)Protected to allow the implementation ofsplit(FluidAmount)andmerge0(FluidVolume, FluidMergeRounding)to set the amount.<T> voidsetProperty(FluidProperty<T> property, T value)FluidVolumesplit(int toRemove)Deprecated.Replaced bysplit(FluidAmount)FluidVolumesplit(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 returnedFluidVolumewill have an amount equal to this amount, and not the amount given.FluidVolumesplit(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 returnedFluidVolumewill have an amount equal to this amount, and not the amount given.protected FluidVolumesplit0(FluidAmount toTake, java.math.RoundingMode rounding)com.google.gson.JsonObjecttoJson()voidtoMcBuffer(net.minecraft.network.PacketByteBuf buffer)protected voidtoMcBufferInternal(net.minecraft.network.PacketByteBuf buffer)java.lang.StringtoString()net.minecraft.nbt.CompoundTagtoTag()net.minecraft.nbt.CompoundTagtoTag(net.minecraft.nbt.CompoundTag tag)FluidVolumewithAmount(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 usefractionsinstead 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 newFluidVolumefrom the given fluid, with the given amount stored. This just delegates internally toFluidKey.withAmount(int). - 
create
Deprecated.Creates a newFluidVolumefrom the given fluid, with the given amount stored. - 
create
Deprecated.Creates a newFluidVolumefrom the given potion, with the given amount stored. - 
equals
public boolean equals(java.lang.Object obj)- Overrides:
 equalsin classjava.lang.Object
 - 
hashCode
public int hashCode()- Overrides:
 hashCodein classjava.lang.Object
 - 
toString
public java.lang.String toString()- Overrides:
 toStringin 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 
FluidKeyfor 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 
Fluidinstance 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.ZEROif thisisEmpty(), otherwise this returns the fractional amount stored.
 - 
amount
An alternate name forgetAmount_F().- Returns:
 FluidAmount.ZEROif 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 thisFluidVolumecontains. - 
multiplyAmount
Returns a newFluidVolumethat 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
         
keysthen 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
         
keysthen 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
         
keysthen 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 givenFluidVolumecan 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.FluidMergeResultobject, 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 returnedFluidVolumewill 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 returnedFluidVolumewill 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 
FluidVolumewith 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 forDefaultFluidVolumeRendererto use if it can't find one itself.- Returns:
 - An 
Identifierfor 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 forDefaultFluidVolumeRendererto 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 
Identifierfor the still sprite that this fluid volume should render with in gui's and in-world. 
 - 
getFlowingSprite
public net.minecraft.util.Identifier getFlowingSprite()Fallback forDefaultFluidVolumeRendererto use if it can't find one itself.- Returns:
 - An 
Identifierfor the flowing sprite that this fluid volume should render with in gui's and in-world whenFluidRenderFace.flowingis 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 thisFluidVolumeto 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 thisFluidVolumeto 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 thisFluidVolumehas. - 
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 theFluidVolumeRendererto 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) 
 -