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 Object
An amount of a FluidKey, analogous to forge's FluidStack class or RebornCore's FluidInstance class. However there are a few key differences:
  1. 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 in FluidKey.
  2. 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 the FluidKey, or a FluidProperty that's already been registered with the FluidKey.
  3. 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 Details

    • BASE_UNIT

      @Deprecated(since="0.6.0", forRemoval=true) public static final int BASE_UNIT
      Deprecated, for removal: This API element is subject to removal in a future version.
      Fluids now use fractions 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(since="0.6.0", forRemoval=true) public static final int BUCKET
      Deprecated, for removal: This API element is subject to removal in a future version.
      Replaced by FluidAmount.BUCKET
      See Also:
      Constant Field Values
    • BOTTLE

      @Deprecated(since="0.6.0", forRemoval=true) public static final int BOTTLE
      Deprecated, for removal: This API element is subject to removal in a future version.
      Replaced by FluidAmount.BOTTLE
      See Also:
      Constant Field Values
    • DESERIALIZER

      public static final com.google.gson.JsonDeserializer<FluidVolume> DESERIALIZER
    • fluidKey

      public final FluidKey fluidKey
  • Constructor Details

    • FluidVolume

      @Deprecated(since="0.6.4", forRemoval=true) public FluidVolume(FluidKey key, int amount)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Parameters:
      amount - The amount, in (amount / 1620)
    • FluidVolume

      public FluidVolume(FluidKey key, FluidAmount amount)
    • FluidVolume

      public FluidVolume(FluidKey key, net.minecraft.nbt.NbtCompound tag)
    • FluidVolume

      public FluidVolume(FluidKey key, com.google.gson.JsonObject json) throws com.google.gson.JsonSyntaxException
      Throws:
      com.google.gson.JsonSyntaxException
  • Method Details

    • fromTag

      public static FluidVolume fromTag(net.minecraft.nbt.NbtCompound tag)
    • 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 new FluidVolume from the given fluid, with the given amount stored. This just delegates internally to FluidKey.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 new FluidVolume 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 new FluidVolume from the given potion, with the given amount stored.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • localizeAmount

      public String localizeAmount()
    • localizeAmount

      public final String localizeAmount(FluidTooltipContext ctx)
    • localizeInTank

      public String localizeInTank(FluidAmount capacity)
    • localizeInTank

      public final String localizeInTank(FluidAmount capacity, FluidTooltipContext ctx)
    • 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.
      Use Object.equals(Object) instead of this.
    • areEqualExceptAmounts

      public static boolean areEqualExceptAmounts(FluidVolume a, FluidVolume b)
    • isEmpty

      public final boolean isEmpty()
    • getFluidKey

      public FluidKey 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 (like Potion's).
    • copy

      public final FluidVolume copy()
    • copy0

      protected FluidVolume copy0()
    • getAmount

      @Deprecated(since="0.6.0", forRemoval=true) public final int getAmount()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Replaced by getAmount_F() and amount().
    • getAmount_F

      public final 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. Alternatively you can use amount() if you prefer a more reasonable name.
      Returns:
      FluidAmount.ZERO if this isEmpty(), otherwise this returns the fractional amount stored.
    • amount

      public FluidAmount amount()
      An alternate name for getAmount_F().
      Returns:
      FluidAmount.ZERO if this isEmpty(), otherwise this returns the fractional amount stored.
    • getRawAmount

      @Deprecated(since="0.6.0", forRemoval=true) protected final int getRawAmount()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Replaced by getRawAmount_F().
      Returns:
      The raw amount value, which might not be 0 if this is empty.
    • getRawAmount_F

      protected final FluidAmount getRawAmount_F()
      Returns:
      The fractional amount of fluid that this holds. This might not be FluidAmount.isZero() if this isEmpty().
    • setAmount

      @Deprecated(since="0.6.0", forRemoval=true) protected final void setAmount(int newAmount)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Protected to allow the implementation of split(int) and merge0(FluidVolume, FluidMergeRounding) to set the amount.
    • setAmount

      protected final void setAmount(FluidAmount newAmount)
      Protected to allow the implementation of split(FluidAmount) and merge0(FluidVolume, FluidMergeRounding) to set the amount.
    • withAmount

      public FluidVolume withAmount(FluidAmount newAmount)
      Creates a copy of this fluid with the given amount. Unlike calling FluidKey.withAmount(FluidAmount) this will preserve any extra data that this FluidVolume contains.
    • multiplyAmount

      public FluidVolume multiplyAmount(int by)
      Returns a new FluidVolume that is a copy of this one, but with an amount multiplied by the given amount.
      See Also:
      withAmount(FluidAmount)
    • mergeInto

      public static boolean mergeInto(FluidVolume source, FluidVolume target)
      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

      @Nullable public static FluidVolume merge(FluidVolume a, FluidVolume b)
      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

      public final boolean canMerge(FluidVolume with)
      Checks to see if the given FluidVolume can merge into this one. Returns false if either this fluid or the given fluid are empty.
    • merge

      public final boolean merge(FluidVolume other, Simulation simulation)
    • 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.
      because mergeInternal(FluidVolume, FluidMergeResult) allows every method to share the same FluidAmount.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 two FluidVolume's together. Only merge(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

      protected void mergeInternal(FluidVolume other, FluidAmount.FluidMergeResult mergedAmounts)
      Actually merges two FluidVolume's together. Only merge(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 FluidAmount.FluidMergeResult.excess.
    • split

      @Deprecated(since="0.6.0", forRemoval=true) public final FluidVolume split(int toRemove)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Replaced by split(FluidAmount)
    • split

      public final 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 returned FluidVolume 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

      public final FluidVolume 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 returned FluidVolume 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

      protected FluidVolume split0(FluidAmount toTake, RoundingMode rounding)
      Parameters:
      toTake - A valid subtractable amount.
      Returns:
      A new FluidVolume with the given amount that has been removed from this.
    • getProperty

      public final <T> T getProperty(FluidProperty<T> property)
      Throws:
      IllegalArgumentException - if the given property hasn't been registered to the FluidKey.
    • setProperty

      public final <T> void setProperty(FluidProperty<T> property, T value)
    • getSprite

      public net.minecraft.util.Identifier getSprite()
      Fallback for DefaultFluidVolumeRenderer 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 for DefaultFluidVolumeRenderer 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 of getSprite(). (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 for DefaultFluidVolumeRenderer 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 when FluidRenderFace.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 by getFullTooltip().
    • getFullTooltip

      public final List<net.minecraft.text.Text> getFullTooltip()
      Simple getter for retrieving the entire fluid tooltip, instead of adding it to an already-existing list.
      See Also:
      addFullTooltip(List), addFullTooltip(FluidAmount, FluidTooltipContext, List)
    • addFullTooltip

      public final 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.
      See Also:
      addFullTooltip(FluidAmount, FluidTooltipContext, List)
    • getFullTooltip

      public final 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, List<net.minecraft.text.Text> tooltip)
      Adds the complete tooltip for this FluidVolume 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 this FluidVolume 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

      public void addTooltipExtras(FluidTooltipContext context, List<net.minecraft.text.Text> tooltip)
      Adds any additional data that this FluidVolume 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

      @Environment(CLIENT) public FluidVolumeRenderer getRenderer()
      Returns the FluidVolumeRenderer 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)
    • renderGuiRect

      @Environment(CLIENT) public final void renderGuiRect(double x0, double y0, double x1, double y1)