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.

@FunctionalInterface public interface VariableAmount extends DataSerializable
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.

  • Method Details

    • fixed

      static VariableAmount fixed(double value)
      Creates a new 'fixed' variable amount, calls to amount(java.util.random.RandomGenerator) will always return the fixed value.
      Parameters:
      value - The fixed value
      Returns:
      A variable amount representation
    • range

      static VariableAmount range(double min, double max)
      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

      static VariableAmount baseWithVariance(double base, double variance)
      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 value
      variance - The variance
      Returns:
      A variable amount representation
    • baseWithVariance

      static VariableAmount baseWithVariance(double base, VariableAmount variance)
      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 value
      variance - The variance
      Returns:
      A variable amount representation
    • baseWithRandomAddition

      static VariableAmount baseWithRandomAddition(double base, double addition)
      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 value
      addition - The additional amount
      Returns:
      A variable amount representation
    • baseWithRandomAddition

      static VariableAmount baseWithRandomAddition(double base, VariableAmount addition)
      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 value
      addition - The additional amount
      Returns:
      A variable amount representation
    • baseWithOptionalVariance

      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. 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 value
      variance - The variance
      chance - The chance to apply the variance
      Returns:
      A variable amount representation
    • baseWithOptionalVariance

      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. 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 value
      variance - The variance
      chance - The chance to apply the variance
      Returns:
      A variable amount representation
    • baseWithOptionalAddition

      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. 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 value
      addition - The additional amount
      chance - The chance to apply the additional amount
      Returns:
      A variable amount representation
    • baseWithOptionalAddition

      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. 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 value
      addition - The additional amount
      chance - The chance to apply the additional amount
      Returns:
      A variable amount representation
    • amount

      double amount(RandomGenerator rand)
      Gets an instance of the variable amount depending on the given random object.
      Parameters:
      rand - The random object
      Returns:
      The amount
    • flooredAmount

      default int flooredAmount(RandomGenerator rand)
      Gets the amount as if from amount(RandomGenerator) but floored to the nearest integer equivalent.
      Parameters:
      rand - The random object
      Returns:
      The floored amount
    • toContainer

      default DataContainer toContainer()
      Description copied from interface: DataSerializable
      Serializes this object into a comprehensible DataContainer.
      Specified by:
      toContainer in interface DataSerializable
      Returns:
      A newly created DataContainer
    • contentVersion

      default int contentVersion()
      Description copied from interface: DataSerializable
      Gets the content version of this DataSerializable. The version may differ between instances of plugins and implementations such that the DataView from DataSerializable.toContainer() may include different information, or remove other information as they are no longer deemed necessary. The version goes hand in hand with DataContentUpdater as it is required when there exists any DataView of this DataSerializable with an "older" version.
      Specified by:
      contentVersion in interface DataSerializable
      Returns:
      The version of the content being serialized