Class FluidAmount
- All Implemented Interfaces:
- Comparable<FluidAmount>
whole +
 (numerator / denominator)". Negative values are indicated with both whole and
 numerator being negative - it is never permissible for only one of them to be less than 0 and the other to
 be greater than 0.
 Note: This class is intended to become a value-based class, so it will (eventually) obey the rules set out in https://openjdk.java.net/jeps/390.
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classstatic classSpecifies how mergedFluidAmount's should handle rounding.static class
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic FluidAmountA very large amount of fluid - one million buckets.static FluidAmountThe maximum possible value that a validFluidAmountcan hold.static FluidAmountThe minimum possible value that a validFluidAmountcan hold.static FluidAmountOne bottle is equal to a third of a bucket.static FluidAmountOne bucket of fluid - which is alwaysONE.longAlways greater than 0.static com.google.gson.JsonDeserializer<FluidAmount>static FluidAmountLong.MAX_VALUEof buckets.static FluidAmountDeprecated, for removal: This API element is subject to removal in a future version.static FluidAmountLong.MIN_VALUEof buckets.static FluidAmountDeprecated, for removal: This API element is subject to removal in a future version.AsMIN_BUCKETSshould generally be used instead, however if you really need the absolute minimum value then you can useABSOLUTE_MINIMUM.static FluidAmountlongstatic FluidAmountlongstatic FluidAmount
- 
Constructor SummaryConstructorsConstructorDescriptionFluidAmount(long whole)Deprecated, for removal: This API element is subject to removal in a future version.AsofWhole(long)should be used instead.
- 
Method SummaryModifier and TypeMethodDescriptionadd(long by)Adds the given long value to thisFluidAmount, without performing any checking or saturation.add(BigFluidAmount by)Directly adds the givenBigFluidAmountto this one.add(FluidAmount other)The recommended method for adding twoFluidAmount's together if you don't want to think about inexact answers.intas1620()intas1620(RoundingMode rounding)asBigInt()doubleintasInt(int base)intasInt(int base, RoundingMode rounding)longasLong(long base)longasLong(long base, RoundingMode rounding)bigAdd(FluidAmount by)Directly adds the givenFluidAmountto this one, returning the result as aBigFluidAmount.bigDiv(FluidAmount by)bigMul(FluidAmount by)checkedAdd(FluidAmount by)Directly adds the givenFluidAmountto this one.checkedDiv(long by)checkedDiv(FluidAmount by)checkedMul(long by)checkedMul(FluidAmount by)checkedSub(FluidAmount by)intcompareTo(FluidAmount o)Null is treated as zerodiv(long other)The recommended method for dividing this by aLongif you don't want to think about inexact answers.div(BigFluidAmount by)div(FluidAmount other)The recommended method for dividing this by anotherFluidAmountif you don't want to think about inexact answers.booleanequals(FluidAmount other)booleanstatic FluidAmountfromDouble(double value)Deprecated, for removal: This API element is subject to removal in a future version.Useparse(String)instead.static FluidAmountfromJson(com.google.gson.JsonElement json)static FluidAmountfromMcBuffer(net.minecraft.network.PacketByteBuf buffer)static FluidAmountfromNbt(net.minecraft.nbt.NbtCompound tag)static FluidAmountfromStdBuffer(io.netty.buffer.ByteBuf buffer)gcd(BigFluidAmount other)gcd(FluidAmount other)longgetCountOf(FluidAmount by)inthashCode()booleanisGreaterThan(FluidAmount other)Null is treated as zerobooleanisGreaterThanOrEqual(FluidAmount other)Null is treated as zerobooleanisLessThan(FluidAmount other)Null is treated as zerobooleanisLessThanOrEqual(FluidAmount other)Null is treated as zerobooleanbooleanbooleanbooleanisZero()lcm(FluidAmount other)max(FluidAmount other)static FluidAmount.FluidMergeResultmerge(FluidAmount target, FluidAmount toAdd)static FluidAmount.FluidMergeResultmerge(FluidAmount target, FluidAmount toAdd, long denominatorTarget, long denominatorAdd)static FluidAmount.FluidMergeResultmerge(FluidAmount target, FluidAmount toAdd, FluidAmount.FluidMergeRounding rounding)min(FluidAmount other)mul(long by)The recommended method for multiplying this by a long if you don't want to think about inexact answers.mul(BigFluidAmount by)mul(FluidAmount by)The recommended method for multiplying twoFluidAmount's together if you don't want to think about inexact answers.negate()static FluidAmountof(long numerator, long denominator)Creates a newFluidAmountwith the given values.static FluidAmountof(long whole, long numerator, long denominator)Creates a newFluidAmountwith the given values.static FluidAmountof1620(int amount)Legacy conversion method for creating a fraction with the given amount as it's numerator, and 1620 as it's denominatorstatic FluidAmountofWhole(long whole)Creates a newFluidAmountwith the given values.static FluidAmountAttempts to parse the given text as aFluidAmount.roundedAdd(FluidAmount other)roundedAdd(FluidAmount other, RoundingMode rounding)roundedDiv(long by)roundedDiv(long by, RoundingMode rounding)roundedDiv(FluidAmount by)roundedDiv(FluidAmount by, RoundingMode rounding)roundedMul(long by)roundedMul(long by, RoundingMode rounding)roundedMul(FluidAmount by)roundedMul(FluidAmount by, RoundingMode rounding)roundedSub(FluidAmount by)roundedSub(FluidAmount by, RoundingMode rounding)safeAdd(FluidAmount other)Safely adds the givenFluidAmountto this one, returning the merged result.safeAdd(FluidAmount other, RoundingMode rounding)Safely adds the givenFluidAmountto this one, returning the merged result.safeSub(FluidAmount by)safeSub(FluidAmount by, RoundingMode rounding)saturatedAdd(FluidAmount by)Similar tocheckedAdd(FluidAmount), but returns eitherMAX_BUCKETSorMIN_BUCKETSinstead of throwing an exception.saturatedDiv(long by)saturatedDiv(FluidAmount by)saturatedMul(long by)saturatedMul(FluidAmount by)saturatedSub(FluidAmount by)intsign()splitBalanced(int count)Splits thisFluidAmountevenly into the given count, but not letting the denominator exceed the default value (2000).splitBalanced(int count, long maxDenominator)Splits thisFluidAmountevenly into the given count, but not letting the denominator exceed the given value.splitBalanced(FluidAmount[] dest, long maxDenominator)Splits thisFluidAmountevenly into the given count, but not letting the denominator exceed the given value.sub(long by)sub(BigFluidAmount by)sub(FluidAmount other)The recommended method for subtracting anotherFluidAmountfrom this if you don't want to think about inexact answers.com.google.gson.JsonElementtoJson()voidtoMcBuffer(net.minecraft.network.PacketByteBuf buffer)net.minecraft.nbt.NbtCompoundtoNbt()voidtoStdBuffer(io.netty.buffer.ByteBuf buffer)toString()static ObjectAttempts to parse the given text as aFluidAmount.
- 
Field Details- 
ZERO
- 
ONE
- 
NEGATIVE_ONE
- 
A_MILLIONA very large amount of fluid - one million buckets. Used primarily in cases where we need to test if any fluid is insertable, so we go above normal values (without going so far out of range to make common calculations overflow intoBigFluidAmount).
- 
BUCKETOne bucket of fluid - which is alwaysONE.
- 
BOTTLEOne bottle is equal to a third of a bucket.
- 
MAX_BUCKETSLong.MAX_VALUEof buckets.
- 
MIN_BUCKETSLong.MIN_VALUEof buckets.
- 
ABSOLUTE_MAXIMUMThe maximum possible value that a validFluidAmountcan hold. It's not recommended to use this as it can cause headaches when adding or subtracting values from this.
- 
ABSOLUTE_MINIMUMThe minimum possible value that a validFluidAmountcan hold. It's not recommended to use this as it can cause headaches when adding or subtracting values from this.
- 
MAX_VALUEDeprecated, for removal: This API element is subject to removal in a future version.AsMAX_BUCKETSshould generally be used instead, however if you really need the absolute value then you can useABSOLUTE_MAXIMUM.The maximum possible value that a validFluidAmountcan hold. It's not recommended to use this as it can cause headaches when adding or subtracting values from this.
- 
MIN_VALUEDeprecated, for removal: This API element is subject to removal in a future version.AsMIN_BUCKETSshould generally be used instead, however if you really need the absolute minimum value then you can useABSOLUTE_MINIMUM.The minimum possible value that a validFluidAmountcan hold. It's not recommended to use this as it can cause headaches when adding or subtracting values from this.
- 
DESERIALIZER
- 
wholepublic final long whole
- 
numeratorpublic final long numerator
- 
denominatorpublic final long denominatorAlways greater than 0.
 
- 
- 
Constructor Details- 
FluidAmountDeprecated, for removal: This API element is subject to removal in a future version.AsofWhole(long)should be used instead.Constructs a newFluidAmountwith the given whole value. The numerator is set to 0, and the denominator is set to 1.
 
- 
- 
Method Details- 
ofWholeCreates a newFluidAmountwith the given values. This will reduce the fraction into it's simplest form.
- 
ofCreates a newFluidAmountwith the given values. This will reduce the fraction into it's simplest form.
- 
of1620Legacy conversion method for creating a fraction with the given amount as it's numerator, and 1620 as it's denominator
- 
ofCreates a newFluidAmountwith the given values. This will reduce the fraction into it's simplest form.- Throws:
- IllegalArgumentException- if either whole or numerator are negative, or if denominator is less than or equal to 0.
 
- 
fromDoubleDeprecated, for removal: This API element is subject to removal in a future version.Useparse(String)instead.
- 
parseAttempts to parse the given text as aFluidAmount.The text is parsed according to the following rules: - If the text is a valid Longthen that is parsed and returned as if fromofWhole(long).
 - (Optional) "-": The minus sign, which indicates that the whole part is negative.
- (Optional) "(": An opening bracket.
- A valid Long, that only contains [0-9] (FromLong.parseLong(String)). This is taken as thewhole
- Either a single "+" or "-", which indicates that the
- (Optional) "(": An opening bracket.
- A valid Long, that only contains [0-9] (FromLong.parseLong(String)). This is taken as thenumerator. This may be greater than thedenominator.
- A "/" symbol.
- A valid Long, that only contains [0-9], and doesn't equal 0. (FromLong.parseLong(String)). This is taken as thedenominator
- Either one or two ")" symbols, matching the two optional opening "(" symbols.
 Alternatively the first 4 items can be left off. For example these strings are all valid: - "1"
- "-1"
- "-1 - 3 / 4"
- "-(1 + 3 / 4)"
- "1 + 3 / 4"
- "12 / 4"
- "6 + 12 / 4"
- "6+12/4"
- "-(6+12/4)"
- "-(6+(12/4))"
- "-6-(12/4)"
 - Throws:
- NumberFormatException- if the input text was not a valid fraction.
 
- If the text is a valid 
- 
tryParseAttempts to parse the given text as aFluidAmount. This uses the same parsing rules asparse(String), except that this returns either aFluidAmount(if it parsed correctly) or aString(if it didn't parse correctly). This will never throw an exception.- Returns:
- String(if there's an error and _throw is false) or the parsed- FluidAmountif the text could be parsed.
 
- 
fromNbt
- 
toNbtpublic net.minecraft.nbt.NbtCompound toNbt()
- 
fromStdBuffer
- 
toStdBufferpublic void toStdBuffer(io.netty.buffer.ByteBuf buffer)
- 
fromMcBuffer
- 
toMcBufferpublic void toMcBuffer(net.minecraft.network.PacketByteBuf buffer)
- 
fromJsonpublic static FluidAmount fromJson(com.google.gson.JsonElement json) throws com.google.gson.JsonSyntaxException- Throws:
- com.google.gson.JsonSyntaxException
 
- 
toJsonpublic com.google.gson.JsonElement toJson()
- 
isZeropublic boolean isZero()
- 
isNegativepublic boolean isNegative()
- 
isPositivepublic boolean isPositive()
- 
signpublic int sign()- Returns:
- The sign: Either -1 if this is negative, +1 if this is positive, or 0 if this is zero.
 
- 
isOverflowpublic boolean isOverflow()- Returns:
- True if this FluidAmounthas potentially overflowed out of a long. This will return true if eitherwholeornumeratorisLong.MIN_VALUEorLong.MAX_VALUE, or ifdenominatorisLong.MAX_VALUE.
 
- 
getDivisor- Returns:
- The denominator represented in a new fraction, as 1/this.denominator.
 
- 
as1620public int as1620()- Returns:
- Rounded-up value of this FluidAmountusing a base of 1620.
 
- 
as1620- Returns:
- Rounded-up value of this FluidAmountusing a base of 1620.
 
- 
asIntpublic int asInt(int base)- Returns:
- Rounded-up integer value of this FluidAmountusing the given base. ReturnsInteger.MAX_VALUEorInteger.MIN_VALUEif the true value is out-of-range.
 
- 
asInt
- 
asLongpublic long asLong(long base)- Returns:
- Rounded-up long value of this FluidAmountusing the given base. ReturnsLong.MAX_VALUEorLong.MIN_VALUEif the true value is out-of-range.
 
- 
asLong- Returns:
- Rounded-up long value of this FluidAmountusing the given base. ReturnsLong.MAX_VALUEorLong.MIN_VALUEif the true value is out-of-range.
 
- 
equals
- 
hashCodepublic int hashCode()
- 
toDisplayString- Returns:
- A string version of this FluidAmountthat should be shown to players.
 
- 
toString
- 
toParseableString- Returns:
- This FluidAmountrepresented as a string that could be parsed byparse(String)to return anotherFluidAmountequal to itself.
 
- 
equals- Returns:
- True if the number that this FluidAmountrepresents is equal to the number that the givenFluidAmountrepresents.
 
- 
compareToNull is treated as zero- Specified by:
- compareToin interface- Comparable<FluidAmount>
 
- 
asInexactDoublepublic double asInexactDouble()
- 
negate
- 
lcm
- 
addThe recommended method for adding twoFluidAmount's together if you don't want to think about inexact answers.(Internally this calls safeAdd(FluidAmount)if you want to know the details).- Parameters:
- other- The other- FluidAmount. Null values will return "this".
 
- 
safeAddSafely adds the givenFluidAmountto this one, returning the merged result. UnlikecheckedAdd(FluidAmount)this will only throw anArithmeticExceptionif the result is out-of-range and the rounding mode isRoundingMode.UNNECESSARY, instead it will round the real answer to the nearest validFluidAmount(usingBigFluidAmount.asLongIntRounded(RoundingMode))
- 
safeAddSafely adds the givenFluidAmountto this one, returning the merged result. UnlikecheckedAdd(FluidAmount)this will never throw anArithmeticExceptionif the result is out-of-range, instead it will round the real answer to the nearest validFluidAmount(usingBigFluidAmount.asLongIntRounded(RoundingMode)with a rounding mode ofHALF_EVEN).
- 
roundedAdd- Returns:
- the result of safeAdd(FluidAmount, RoundingMode).roundedResult.
 
- 
roundedAdd- Returns:
- the result of safeAdd(FluidAmount).roundedResult.
 
- 
addAdds the given long value to thisFluidAmount, without performing any checking or saturation.
- 
checkedAddDirectly adds the givenFluidAmountto this one.- Parameters:
- by- The amount to add. If it's null or zero then "this" will be returned.
- Throws:
- ArithmeticException- if the result doesn't fit into a- FluidAmount.
 
- 
saturatedAddSimilar tocheckedAdd(FluidAmount), but returns eitherMAX_BUCKETSorMIN_BUCKETSinstead of throwing an exception.
- 
bigAddDirectly adds the givenFluidAmountto this one, returning the result as aBigFluidAmount.- Parameters:
- by- The amount to add. If it's null or zero then this will be returned, converted to a- BigFluidAmount.
 
- 
addDirectly adds the givenBigFluidAmountto this one.- Parameters:
- by- The amount to add. If it's null or zero then this will be returned, converted into a- BigFluidAmount.
 
- 
sub
- 
subThe recommended method for subtracting anotherFluidAmountfrom this if you don't want to think about inexact answers.(Internally this calls roundedSub(FluidAmount)if you want to know the details).- Parameters:
- other- The other- FluidAmount. Null values will return "this".
 
- 
checkedSub- Parameters:
- by- Either Null or a value that will be- negatedand then passed to- checkedAdd(FluidAmount).
- Throws:
- ArithmeticException- if the result doesn't fit into a- FluidAmount.
 
- 
saturatedSub- Parameters:
- by- Either Null or a value that will be- negatedand then passed to- saturatedAdd(FluidAmount).
 
- 
safeSub- Parameters:
- by- Either Null or a value that will be- negatedand then passed to- safeAdd(FluidAmount, RoundingMode).
 
- 
safeSub- Parameters:
- by- Either Null or a value that will be- negatedand then passed to- safeAdd(FluidAmount).
 
- 
roundedSub- Parameters:
- by- Either Null or a value that will be- negatedand then passed to- safeAdd(FluidAmount, RoundingMode).
- Returns:
- The FluidAmount.SafeAddResult.roundedResult.
 
- 
roundedSub- Parameters:
- by- Either Null or a value that will be- negatedand then passed to- safeAdd(FluidAmount).
- Returns:
- The FluidAmount.SafeAddResult.roundedResult.
 
- 
sub- Parameters:
- by- Either Null or a value that will be- negatedand then passed to- add(BigFluidAmount).
 
- 
merge
- 
mergepublic static FluidAmount.FluidMergeResult merge(FluidAmount target, FluidAmount toAdd, FluidAmount.FluidMergeRounding rounding)- Parameters:
- target-
- toAdd-
- rounding- The- FluidAmount.FluidMergeRoundingto use if the addition doesn't result in an exact- FluidAmount.
- Returns:
 
- 
mergepublic static FluidAmount.FluidMergeResult merge(FluidAmount target, FluidAmount toAdd, long denominatorTarget, long denominatorAdd)- Parameters:
- target-
- toAdd-
- denominatorTarget- The denominator that the target must be under (a multiple of it's reciprocal), or 0 if the target doesn't need to stay under a particular denominator.
- denominatorAdd- The denominator that the excess must be under (a multiple of it's reciprocal), or 0 if the excess doesn't need to stay under a particular denominator.
 
- 
mulThe recommended method for multiplying twoFluidAmount's together if you don't want to think about inexact answers.(Internally this calls roundedMul(FluidAmount)if you want to know the details).
- 
mulThe recommended method for multiplying this by a long if you don't want to think about inexact answers.(Internally this calls roundedMul(long)if you want to know the details).
- 
checkedMul
- 
saturatedMul
- 
roundedMul
- 
roundedMul
- 
checkedMul
- 
saturatedMul
- 
roundedMul
- 
roundedMul
- 
mul
- 
bigMul
- 
reciprocal- Returns:
- This fraction, but inverted. (With the numerator and denominator swapped).
 
- 
bigReciprocal
- 
getCountOf- Returns:
- The wholevalue fromsaturatedDiv(FluidAmount).
 
- 
divThe recommended method for dividing this by aLongif you don't want to think about inexact answers.(Internally this calls roundedDiv(long)if you want to know the details).
- 
divThe recommended method for dividing this by anotherFluidAmountif you don't want to think about inexact answers.(Internally this calls roundedDiv(FluidAmount)if you want to know the details).
- 
checkedDiv
- 
saturatedDiv
- 
roundedDiv
- 
roundedDiv
- 
checkedDiv
- 
saturatedDiv
- 
roundedDiv
- 
roundedDiv
- 
div
- 
bigDiv
- 
splitBalancedSplits thisFluidAmountevenly into the given count, but not letting the denominator exceed the default value (2000). If the denominator is bigger than the default then some of the entries might beZERO.- Returns:
- An array with length "count" containing the split fluids. May contain duplicates.
 
- 
splitBalancedSplits thisFluidAmountevenly into the given count, but not letting the denominator exceed the given value. If the denominator is bigger than the default then some of the entries might beZERO.- Returns:
- An array with length "count" containing the split fluids. May contain duplicates.
 
- 
splitBalancedSplits thisFluidAmountevenly into the given count, but not letting the denominator exceed the given value. If the denominator is bigger than the default then some of the entries might beZERO.- Parameters:
- dest- The array to place the- FluidAmounts into, which will also be returned.
- Returns:
- The "dest" array, which will contain the split fluids. May contain duplicates.
- Throws:
- IllegalArgumentException- if "dest" is an array of length 0 and this is not- isZero().
 
- 
asLongIntExact
- 
asBigInt
- 
isGreaterThanNull is treated as zero
- 
isGreaterThanOrEqualNull is treated as zero
- 
isLessThanNull is treated as zero
- 
isLessThanOrEqualNull is treated as zero
- 
gcd
- 
gcd
- 
min- Returns:
- The smaller of this value and then given value.
 
- 
max- Returns:
- The greater of this value and then given value.
 
 
- 
MAX_BUCKETSshould generally be used instead, however if you really need the absolute value then you can useABSOLUTE_MAXIMUM.