Interface VariableAmount
- All Superinterfaces:
DataSerializable
- All Known Implementing Classes:
VariableAmount.BaseAndAddition
,VariableAmount.BaseAndVariance
,VariableAmount.Fixed
,VariableAmount.OptionalAmount
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Represents a value which may vary randomly.
Implementors of this interface using it in a fashion in which may ever be
serialized must implement the toContainer()
method.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
Represents a base amount with a random addition, the final amount will be the base amount plus a random amount between zero (inclusive) and the addition (exclusive).static class
Represents a base amount with a variance, the final amount will be the base amount plus or minus a random amount between zero (inclusive) and the variance (exclusive).static class
Represents a fixed amount, calls toVariableAmount.Fixed.amount
will always return the same fixed value.static class
Represents a variable amount which has a base and a chance of varying. -
Method Summary
Modifier and TypeMethodDescriptiondouble
Gets an instance of the variable amount depending on the given random object.static VariableAmount
baseWithOptionalAddition
(double base, double addition, double chance) Creates a new variable about which has a base and a chance to apply a random additional amount.static VariableAmount
baseWithOptionalAddition
(double base, VariableAmount addition, double chance) Creates a new variable about which has a base and a chance to apply a random additional amount.static VariableAmount
baseWithOptionalVariance
(double base, double variance, double chance) Creates a new variable about which has a base and a chance to apply a random variance.static VariableAmount
baseWithOptionalVariance
(double base, VariableAmount variance, double chance) Creates a new variable about which has a base and a chance to apply a random variance.static VariableAmount
baseWithRandomAddition
(double base, double addition) Creates a new variable amount which has a base and an additional amount.static VariableAmount
baseWithRandomAddition
(double base, VariableAmount addition) Creates a new variable amount which has a base and an additional amount.static VariableAmount
baseWithVariance
(double base, double variance) Creates a new variable about which has a base and variance.static VariableAmount
baseWithVariance
(double base, VariableAmount variance) Creates a new variable about which has a base and variance.default int
Gets the content version of thisDataSerializable
.static VariableAmount
fixed
(double value) Creates a new 'fixed' variable amount, calls toamount(java.util.Random)
will always return the fixed value.default int
flooredAmount
(Random rand) Gets the amount as if fromamount(Random)
but floored to the nearest integer equivalent.static VariableAmount
range
(double min, double max) Creates a new variable amount which return values between the given min (inclusive) and max (exclusive).default DataContainer
Serializes this object into a comprehensibleDataContainer
.
-
Method Details
-
fixed
Creates a new 'fixed' variable amount, calls toamount(java.util.Random)
will always return the fixed value.- Parameters:
value
- The fixed value- Returns:
- A variable amount representation
-
range
Creates a new variable amount which return values between the given min (inclusive) and max (exclusive).- Parameters:
min
- The minimum of the range (inclusive)max
- The maximum of the range (exclusive)- Returns:
- A variable amount representation
-
baseWithVariance
Creates a new variable about which has a base and variance. The final amount will be the base amount plus or minus a random amount between zero (inclusive) and the variance (exclusive).- Parameters:
base
- The base valuevariance
- The variance- Returns:
- A variable amount representation
-
baseWithVariance
Creates a new variable about which has a base and variance. The final amount will be the base amount plus or minus a random amount between zero (inclusive) and the variance (exclusive).- Parameters:
base
- The base valuevariance
- The variance- Returns:
- A variable amount representation
-
baseWithRandomAddition
Creates a new variable amount which has a base and an additional amount. The final amount will be the base amount plus a random amount between zero (inclusive) and the additional amount (exclusive).- Parameters:
base
- The base valueaddition
- The additional amount- Returns:
- A variable amount representation
-
baseWithRandomAddition
Creates a new variable amount which has a base and an additional amount. The final amount will be the base amount plus a random amount between zero (inclusive) and the additional amount (exclusive).- Parameters:
base
- The base valueaddition
- The additional amount- Returns:
- A variable amount representation
-
baseWithOptionalVariance
Creates a new variable about which has a base and a chance to apply a random variance. The chance should be between zero and one with a chance of one signifying that the variance will always be applied. If the chance succeeds then the final amount will be the base amount plus or minus a random amount between zero (inclusive) and the variance (exclusive). If the chance fails then the final amount will just be the base value.- Parameters:
base
- The base valuevariance
- The variancechance
- The chance to apply the variance- Returns:
- A variable amount representation
-
baseWithOptionalVariance
Creates a new variable about which has a base and a chance to apply a random variance. The chance should be between zero and one with a chance of one signifying that the variance will always be applied. If the chance succeeds then the final amount will be the base amount plus or minus a random amount between zero (inclusive) and the variance (exclusive). If the chance fails then the final amount will just be the base value.- Parameters:
base
- The base valuevariance
- The variancechance
- The chance to apply the variance- Returns:
- A variable amount representation
-
baseWithOptionalAddition
Creates a new variable about which has a base and a chance to apply a random additional amount. The chance should be between zero and one with a chance of one signifying that the additional amount will always be applied. If the chance succeeds then the final amount will be the base amount plus a random amount between zero (inclusive) and the additional amount (exclusive). If the chance fails then the final amount will just be the base value.- Parameters:
base
- The base valueaddition
- The additional amountchance
- The chance to apply the additional amount- Returns:
- A variable amount representation
-
baseWithOptionalAddition
Creates a new variable about which has a base and a chance to apply a random additional amount. The chance should be between zero and one with a chance of one signifying that the additional amount will always be applied. If the chance succeeds then the final amount will be the base amount plus a random amount between zero (inclusive) and the additional amount (exclusive). If the chance fails then the final amount will just be the base value.- Parameters:
base
- The base valueaddition
- The additional amountchance
- The chance to apply the additional amount- Returns:
- A variable amount representation
-
amount
Gets an instance of the variable amount depending on the given random object.- Parameters:
rand
- The random object- Returns:
- The amount
-
flooredAmount
Gets the amount as if fromamount(Random)
but floored to the nearest integer equivalent.- Parameters:
rand
- The random object- Returns:
- The floored amount
-
toContainer
Description copied from interface:DataSerializable
Serializes this object into a comprehensibleDataContainer
.- Specified by:
toContainer
in interfaceDataSerializable
- Returns:
- A newly created DataContainer
-
contentVersion
default int contentVersion()Description copied from interface:DataSerializable
Gets the content version of thisDataSerializable
. The version may differ between instances of plugins and implementations such that theDataView
fromDataSerializable.toContainer()
may include different information, or remove other information as they are no longer deemed necessary. The version goes hand in hand withDataContentUpdater
as it is required when there exists anyDataView
of thisDataSerializable
with an "older" version.- Specified by:
contentVersion
in interfaceDataSerializable
- Returns:
- The version of the content being serialized
-