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
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
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
FluidVolumes is that they have identical keys. (And are of the same class, but that's implied by having the same key).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDeprecated, for removal: This API element is subject to removal in a future version.static final intDeprecated, for removal: This API element is subject to removal in a future version.Replaced byFluidAmount.BOTTLEstatic final intDeprecated, for removal: This API element is subject to removal in a future version.Replaced byFluidAmount.BUCKETstatic final com.google.gson.JsonDeserializer<FluidVolume>final FluidKey -
Constructor Summary
ConstructorsConstructorDescriptionFluidVolume(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 TypeMethodDescriptionfinal voidaddFullTooltip(FluidAmount capacity, FluidTooltipContext context, List<net.minecraft.text.Text> tooltip) Adds the complete tooltip for thisFluidVolumeto the given tooltip.final voidaddFullTooltip(FluidAmount capacity, List<net.minecraft.text.Text> tooltip) Adds the complete tooltip for thisFluidVolumeto the given tooltip.final voidaddFullTooltip(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, List<net.minecraft.text.Text> tooltip) Adds any additional data that thisFluidVolumehas.final voidaddTooltipNameAmount(FluidAmount capacity, FluidTooltipContext context, List<net.minecraft.text.Text> tooltip) Adds the name and amount to the given tooltip.final voidaddTooltipProperties(FluidTooltipContext context, List<net.minecraft.text.Text> tooltip) final voidaddTooltipTemperature(FluidTooltipContext context, List<net.minecraft.text.Text> tooltip) amount()An alternate name forgetAmount_F().static booleanstatic booleanDeprecated, for removal: This API element is subject to removal in a future version.UseObject.equals(Object)instead of this.final booleancanMerge(FluidVolume with) Checks to see if the givenFluidVolumecan merge into this one.final FluidVolumecopy()protected FluidVolumecopy0()static FluidVolumeDeprecated, for removal: This API element is subject to removal in a future version.static FluidVolumecreate(net.minecraft.fluid.Fluid fluid, int amount) Deprecated, for removal: This API element is subject to removal in a future version.static FluidVolumecreate(net.minecraft.potion.Potion potion, int amount) Deprecated, for removal: This API element is subject to removal in a future version.booleanstatic 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.NbtCompound tag) final intDeprecated, for removal: This API element is subject to removal in a future version.Replaced bygetAmount_F()andamount().final FluidAmountNote: 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.IdentifierFallback forDefaultFluidVolumeRendererto use if it can't find one itself.final List<net.minecraft.text.Text>Simple getter for retrieving the entire fluid tooltip, instead of adding it to an already-existing list.final 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.final 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()final <T> TgetProperty(FluidProperty<T> property) protected final intDeprecated, for removal: This API element is subject to removal in a future version.Replaced bygetRawAmount_F().protected final FluidAmountnet.minecraft.fluid.FluidintReturns theFluidVolumeRendererto use for rendering this fluid.net.minecraft.util.IdentifierFallback forDefaultFluidVolumeRendererto use if it can't find one itself.final net.minecraft.util.IdentifierFallback forDefaultFluidVolumeRendererto 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().inthashCode()final booleanisEmpty()final StringlocalizeInTank(FluidAmount capacity) final StringlocalizeInTank(FluidAmount capacity, FluidTooltipContext ctx) final booleanmerge(FluidVolume other, FluidAmount.FluidMergeRounding rounding, Simulation simulation) static FluidVolumemerge(FluidVolume a, FluidVolume b) static FluidVolumemerge(FluidVolume a, FluidVolume b, FluidAmount.FluidMergeRounding rounding) final booleanmerge(FluidVolume other, Simulation simulation) protected voidmerge0(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.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.multiplyAmount(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) final voidrender(List<FluidRenderFace> faces, net.minecraft.client.render.VertexConsumerProvider vcp, net.minecraft.client.util.math.MatrixStack matrices) Delegate method togetRenderer().final voidrenderGuiRect(double x0, double y0, double x1, double y1) protected final voidsetAmount(int newAmount) Deprecated, for removal: This API element is subject to removal in a future version.protected final voidsetAmount(FluidAmount newAmount) Protected to allow the implementation ofsplit(FluidAmount)andmerge0(FluidVolume, FluidMergeRounding)to set the amount.final <T> voidsetProperty(FluidProperty<T> property, T value) final FluidVolumesplit(int toRemove) Deprecated, for removal: This API element is subject to removal in a future version.Replaced bysplit(FluidAmount)final 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.final FluidVolumesplit(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 returnedFluidVolumewill have an amount equal to this amount, and not the amount given.protected FluidVolumesplit0(FluidAmount toTake, RoundingMode rounding) com.google.gson.JsonObjecttoJson()final voidtoMcBuffer(net.minecraft.network.PacketByteBuf buffer) protected voidtoMcBufferInternal(net.minecraft.network.PacketByteBuf buffer) toString()final net.minecraft.nbt.NbtCompoundtoTag()net.minecraft.nbt.NbtCompoundtoTag(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 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:
-
BUCKET
Deprecated, for removal: This API element is subject to removal in a future version.Replaced byFluidAmount.BUCKET- See Also:
-
BOTTLE
Deprecated, for removal: This API element is subject to removal in a future version.Replaced byFluidAmount.BOTTLE- See Also:
-
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 newFluidVolumefrom 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 newFluidVolumefrom 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 newFluidVolumefrom 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
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, 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.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, 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 thisFluidVolumecontains. -
multiplyAmount
Returns a newFluidVolumethat is a copy of this one, but with an amount multiplied by the given amount.- See Also:
-
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(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.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, 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 returnedFluidVolumewill 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 returnedFluidVolumewill 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
FluidVolumewith 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 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(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 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 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 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, 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 thisFluidVolumehas. -
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 theFluidVolumeRendererto 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)
-
fractionsinstead of a single base unit - which makes this completely deprecated with no replacement.