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 Summary
Modifier and TypeClassDescriptionstatic final class
static enum
Specifies how mergedFluidAmount
's should handle rounding.static final class
-
Field Summary
Modifier and TypeFieldDescriptionstatic final FluidAmount
A very large amount of fluid - one million buckets.static final FluidAmount
The maximum possible value that a validFluidAmount
can hold.static final FluidAmount
The minimum possible value that a validFluidAmount
can hold.static final FluidAmount
One bottle is equal to a third of a bucket.static final FluidAmount
One bucket of fluid - which is alwaysONE
.final long
Always greater than 0.static final com.google.gson.JsonDeserializer<FluidAmount>
static final FluidAmount
Long.MAX_VALUE
of buckets.static final FluidAmount
Deprecated, for removal: This API element is subject to removal in a future version.static final FluidAmount
Long.MIN_VALUE
of buckets.static final FluidAmount
Deprecated, for removal: This API element is subject to removal in a future version.AsMIN_BUCKETS
should generally be used instead, however if you really need the absolute minimum value then you can useABSOLUTE_MINIMUM
.static final FluidAmount
final long
static final FluidAmount
final long
static final FluidAmount
-
Constructor Summary
ConstructorDescriptionFluidAmount
(long whole) Deprecated, for removal: This API element is subject to removal in a future version.AsofWhole(long)
should be used instead. -
Method Summary
Modifier and TypeMethodDescriptionadd
(long by) Adds the given long value to thisFluidAmount
, without performing any checking or saturation.add
(BigFluidAmount by) Directly adds the givenBigFluidAmount
to this one.add
(FluidAmount other) The recommended method for adding twoFluidAmount
's together if you don't want to think about inexact answers.int
as1620()
int
as1620
(RoundingMode rounding) asBigInt()
double
int
asInt
(int base) int
asInt
(int base, RoundingMode rounding) long
asLong
(long base) long
asLong
(long base, RoundingMode rounding) bigAdd
(FluidAmount by) Directly adds the givenFluidAmount
to this one, returning the result as aBigFluidAmount
.bigDiv
(FluidAmount by) bigMul
(FluidAmount by) Directly adds the givenFluidAmount
to this one.checkedDiv
(long by) checkedMul
(long by) int
Null is treated as zerodiv
(long other) The recommended method for dividing this by aLong
if you don't want to think about inexact answers.div
(BigFluidAmount by) div
(FluidAmount other) The recommended method for dividing this by anotherFluidAmount
if you don't want to think about inexact answers.boolean
equals
(FluidAmount other) boolean
static FluidAmount
fromDouble
(double value) Deprecated, for removal: This API element is subject to removal in a future version.Useparse(String)
instead.static FluidAmount
fromJson
(com.google.gson.JsonElement json) static FluidAmount
fromMcBuffer
(net.minecraft.network.PacketByteBuf buffer) static FluidAmount
fromNbt
(net.minecraft.nbt.NbtCompound tag) static FluidAmount
fromStdBuffer
(io.netty.buffer.ByteBuf buffer) gcd
(BigFluidAmount other) gcd
(FluidAmount other) long
int
hashCode()
boolean
isGreaterThan
(FluidAmount other) Null is treated as zeroboolean
isGreaterThanOrEqual
(FluidAmount other) Null is treated as zeroboolean
isLessThan
(FluidAmount other) Null is treated as zeroboolean
isLessThanOrEqual
(FluidAmount other) Null is treated as zeroboolean
boolean
boolean
boolean
isZero()
lcm
(FluidAmount other) max
(FluidAmount other) static FluidAmount.FluidMergeResult
merge
(FluidAmount target, FluidAmount toAdd) static FluidAmount.FluidMergeResult
merge
(FluidAmount target, FluidAmount toAdd, long denominatorTarget, long denominatorAdd) static FluidAmount.FluidMergeResult
merge
(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 FluidAmount
of
(long numerator, long denominator) Creates a newFluidAmount
with the given values.static FluidAmount
of
(long whole, long numerator, long denominator) Creates a newFluidAmount
with the given values.static FluidAmount
of1620
(int amount) Legacy conversion method for creating a fraction with the given amount as it's numerator, and 1620 as it's denominatorstatic FluidAmount
ofWhole
(long whole) Creates a newFluidAmount
with the given values.static FluidAmount
Attempts 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, RoundingMode rounding) roundedMul
(long by) roundedMul
(long by, RoundingMode rounding) roundedMul
(FluidAmount by, RoundingMode rounding) roundedSub
(FluidAmount by, RoundingMode rounding) safeAdd
(FluidAmount other) Safely adds the givenFluidAmount
to this one, returning the merged result.safeAdd
(FluidAmount other, RoundingMode rounding) Safely adds the givenFluidAmount
to this one, returning the merged result.safeSub
(FluidAmount by) safeSub
(FluidAmount by, RoundingMode rounding) Similar tocheckedAdd(FluidAmount)
, but returns eitherMAX_BUCKETS
orMIN_BUCKETS
instead of throwing an exception.saturatedDiv
(long by) saturatedMul
(long by) int
sign()
splitBalanced
(int count) Splits thisFluidAmount
evenly into the given count, but not letting the denominator exceed the default value (2000).splitBalanced
(int count, long maxDenominator) Splits thisFluidAmount
evenly into the given count, but not letting the denominator exceed the given value.splitBalanced
(FluidAmount[] dest, long maxDenominator) Splits thisFluidAmount
evenly 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 anotherFluidAmount
from this if you don't want to think about inexact answers.com.google.gson.JsonElement
toJson()
void
toMcBuffer
(net.minecraft.network.PacketByteBuf buffer) net.minecraft.nbt.NbtCompound
toNbt()
void
toStdBuffer
(io.netty.buffer.ByteBuf buffer) toString()
static Object
Attempts to parse the given text as aFluidAmount
.
-
Field Details
-
ZERO
-
ONE
-
NEGATIVE_ONE
-
A_MILLION
A 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
). -
BUCKET
One bucket of fluid - which is alwaysONE
. -
BOTTLE
One bottle is equal to a third of a bucket. -
MAX_BUCKETS
Long.MAX_VALUE
of buckets. -
MIN_BUCKETS
Long.MIN_VALUE
of buckets. -
ABSOLUTE_MAXIMUM
The maximum possible value that a validFluidAmount
can hold. It's not recommended to use this as it can cause headaches when adding or subtracting values from this. -
ABSOLUTE_MINIMUM
The minimum possible value that a validFluidAmount
can hold. It's not recommended to use this as it can cause headaches when adding or subtracting values from this. -
MAX_VALUE
Deprecated, for removal: This API element is subject to removal in a future version.AsMAX_BUCKETS
should generally be used instead, however if you really need the absolute value then you can useABSOLUTE_MAXIMUM
.The maximum possible value that a validFluidAmount
can hold. It's not recommended to use this as it can cause headaches when adding or subtracting values from this. -
MIN_VALUE
Deprecated, for removal: This API element is subject to removal in a future version.AsMIN_BUCKETS
should generally be used instead, however if you really need the absolute minimum value then you can useABSOLUTE_MINIMUM
.The minimum possible value that a validFluidAmount
can hold. It's not recommended to use this as it can cause headaches when adding or subtracting values from this. -
DESERIALIZER
-
whole
public final long whole -
numerator
public final long numerator -
denominator
public final long denominatorAlways greater than 0.
-
-
Constructor Details
-
FluidAmount
Deprecated, for removal: This API element is subject to removal in a future version.AsofWhole(long)
should be used instead.Constructs a newFluidAmount
with the given whole value. The numerator is set to 0, and the denominator is set to 1.
-
-
Method Details
-
ofWhole
Creates a newFluidAmount
with the given values. This will reduce the fraction into it's simplest form. -
of
Creates a newFluidAmount
with the given values. This will reduce the fraction into it's simplest form. -
of1620
Legacy conversion method for creating a fraction with the given amount as it's numerator, and 1620 as it's denominator -
of
Creates a newFluidAmount
with 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.
-
fromDouble
Deprecated, for removal: This API element is subject to removal in a future version.Useparse(String)
instead. -
parse
Attempts to parse the given text as aFluidAmount
.The text is parsed according to the following rules:
- If the text is a valid
Long
then 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
-
tryParse
Attempts 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 parsedFluidAmount
if the text could be parsed.
-
fromNbt
-
toNbt
public net.minecraft.nbt.NbtCompound toNbt() -
fromStdBuffer
-
toStdBuffer
public void toStdBuffer(io.netty.buffer.ByteBuf buffer) -
fromMcBuffer
-
toMcBuffer
public void toMcBuffer(net.minecraft.network.PacketByteBuf buffer) -
fromJson
public static FluidAmount fromJson(com.google.gson.JsonElement json) throws com.google.gson.JsonSyntaxException - Throws:
com.google.gson.JsonSyntaxException
-
toJson
public com.google.gson.JsonElement toJson() -
isZero
public boolean isZero() -
isNegative
public boolean isNegative() -
isPositive
public boolean isPositive() -
sign
public int sign()- Returns:
- The sign: Either -1 if this is negative, +1 if this is positive, or 0 if this is zero.
-
isOverflow
public boolean isOverflow()- Returns:
- True if this
FluidAmount
has potentially overflowed out of a long. This will return true if eitherwhole
ornumerator
isLong.MIN_VALUE
orLong.MAX_VALUE
, or ifdenominator
isLong.MAX_VALUE
.
-
getDivisor
- Returns:
- The denominator represented in a new fraction, as 1/this.denominator.
-
as1620
public int as1620()- Returns:
- Rounded-up value of this
FluidAmount
using a base of 1620.
-
as1620
- Returns:
- Rounded-up value of this
FluidAmount
using a base of 1620.
-
asInt
public int asInt(int base) - Returns:
- Rounded-up integer value of this
FluidAmount
using the given base. ReturnsInteger.MAX_VALUE
orInteger.MIN_VALUE
if the true value is out-of-range.
-
asInt
-
asLong
public long asLong(long base) - Returns:
- Rounded-up long value of this
FluidAmount
using the given base. ReturnsLong.MAX_VALUE
orLong.MIN_VALUE
if the true value is out-of-range.
-
asLong
- Returns:
- Rounded-up long value of this
FluidAmount
using the given base. ReturnsLong.MAX_VALUE
orLong.MIN_VALUE
if the true value is out-of-range.
-
equals
-
hashCode
public int hashCode() -
toDisplayString
- Returns:
- A string version of this
FluidAmount
that should be shown to players.
-
toString
-
toParseableString
- Returns:
- This
FluidAmount
represented as a string that could be parsed byparse(String)
to return anotherFluidAmount
equal to itself.
-
equals
- Returns:
- True if the number that this
FluidAmount
represents is equal to the number that the givenFluidAmount
represents.
-
compareTo
Null is treated as zero- Specified by:
compareTo
in interfaceComparable<FluidAmount>
-
asInexactDouble
public double asInexactDouble() -
negate
-
lcm
-
add
The 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 otherFluidAmount
. Null values will return "this".
-
safeAdd
Safely adds the givenFluidAmount
to this one, returning the merged result. UnlikecheckedAdd(FluidAmount)
this will only throw anArithmeticException
if 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)
) -
safeAdd
Safely adds the givenFluidAmount
to this one, returning the merged result. UnlikecheckedAdd(FluidAmount)
this will never throw anArithmeticException
if 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
.
-
add
Adds the given long value to thisFluidAmount
, without performing any checking or saturation. -
checkedAdd
Directly adds the givenFluidAmount
to 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 aFluidAmount
.
-
saturatedAdd
Similar tocheckedAdd(FluidAmount)
, but returns eitherMAX_BUCKETS
orMIN_BUCKETS
instead of throwing an exception. -
bigAdd
Directly adds the givenFluidAmount
to 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 aBigFluidAmount
.
-
add
Directly adds the givenBigFluidAmount
to this one.- Parameters:
by
- The amount to add. If it's null or zero then this will be returned, converted into aBigFluidAmount
.
-
sub
-
sub
The recommended method for subtracting anotherFluidAmount
from 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 otherFluidAmount
. Null values will return "this".
-
checkedSub
- Parameters:
by
- Either Null or a value that will benegated
and then passed tocheckedAdd(FluidAmount)
.- Throws:
ArithmeticException
- if the result doesn't fit into aFluidAmount
.
-
saturatedSub
- Parameters:
by
- Either Null or a value that will benegated
and then passed tosaturatedAdd(FluidAmount)
.
-
safeSub
- Parameters:
by
- Either Null or a value that will benegated
and then passed tosafeAdd(FluidAmount, RoundingMode)
.
-
safeSub
- Parameters:
by
- Either Null or a value that will benegated
and then passed tosafeAdd(FluidAmount)
.
-
roundedSub
- Parameters:
by
- Either Null or a value that will benegated
and then passed tosafeAdd(FluidAmount, RoundingMode)
.- Returns:
- The
FluidAmount.SafeAddResult.roundedResult
.
-
roundedSub
- Parameters:
by
- Either Null or a value that will benegated
and then passed tosafeAdd(FluidAmount)
.- Returns:
- The
FluidAmount.SafeAddResult.roundedResult
.
-
sub
- Parameters:
by
- Either Null or a value that will benegated
and then passed toadd(BigFluidAmount)
.
-
merge
-
merge
public static FluidAmount.FluidMergeResult merge(FluidAmount target, FluidAmount toAdd, FluidAmount.FluidMergeRounding rounding) - Parameters:
target
-toAdd
-rounding
- TheFluidAmount.FluidMergeRounding
to use if the addition doesn't result in an exactFluidAmount
.- Returns:
-
merge
public 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.
-
mul
The 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). -
mul
The 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
whole
value fromsaturatedDiv(FluidAmount)
.
-
div
The recommended method for dividing this by aLong
if you don't want to think about inexact answers.(Internally this calls
roundedDiv(long)
if you want to know the details). -
div
The recommended method for dividing this by anotherFluidAmount
if 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
-
splitBalanced
Splits thisFluidAmount
evenly 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.
-
splitBalanced
Splits thisFluidAmount
evenly 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.
-
splitBalanced
Splits thisFluidAmount
evenly 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 theFluidAmount
s 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 notisZero()
.
-
asLongIntExact
-
asBigInt
-
isGreaterThan
Null is treated as zero -
isGreaterThanOrEqual
Null is treated as zero -
isLessThan
Null is treated as zero -
isLessThanOrEqual
Null 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_BUCKETS
should generally be used instead, however if you really need the absolute value then you can useABSOLUTE_MAXIMUM
.