Interface LevelScaling

All Known Implementing Classes:
ConstantScaling, DiminishingScaling, ExponentialScaling, LinearScaling, SteppedScaling
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 LevelScaling
Functional interface for calculating scaled values from enchantment levels.

Scaling formulas determine how enchantment effects grow with level. Common patterns include linear growth (like Sharpness), exponential growth, or diminishing returns for high-level enchantments.

Built-in Formulas:

Custom Formulas:


 LevelScaling custom = LevelScaling.of(level -> level * level * 0.5);
 
Since:
0.1.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    calculate(int level)
    Calculates the scaled value for a given enchantment level.
    static @NotNull LevelScaling
    constant(double value)
    Creates constant scaling: same value at all levels.
    static @NotNull LevelScaling
    diminishing(double maxValue, double scalingFactor)
    Creates diminishing scaling: maxValue * (level / (level + factor)).
    static @NotNull LevelScaling
    exponential(double base, double multiplier)
    Creates exponential scaling: base * multiplier^(level - 1).
    static @NotNull LevelScaling
    linear(double base, double increment)
    Creates linear scaling: base + (level - 1) * increment.
    static @NotNull LevelScaling
    of(@NotNull Function<Integer,Double> formula)
    Creates a scaling from a custom function.
    static @NotNull LevelScaling
    Creates stepped scaling with interpolation between defined levels.
  • Method Details

    • calculate

      double calculate(int level)
      Calculates the scaled value for a given enchantment level.
      Parameters:
      level - the enchantment level (>= 1)
      Returns:
      the calculated value
      Throws:
      IllegalArgumentException - if level is invalid
      Since:
      0.1.0
    • of

      @NotNull static @NotNull LevelScaling of(@NotNull @NotNull Function<Integer,Double> formula)
      Creates a scaling from a custom function.
      Parameters:
      formula - the formula function (level -> value)
      Returns:
      a LevelScaling wrapping the function
      Since:
      0.1.0
    • linear

      @NotNull static @NotNull LevelScaling linear(double base, double increment)
      Creates linear scaling: base + (level - 1) * increment.

      Example: Sharpness-style where each level adds constant damage.

      Parameters:
      base - the value at level 1
      increment - the amount added per level
      Returns:
      a linear scaling instance
      Since:
      0.1.0
    • exponential

      @NotNull static @NotNull LevelScaling exponential(double base, double multiplier)
      Creates exponential scaling: base * multiplier^(level - 1).

      Use with caution at high levels as values grow rapidly.

      Parameters:
      base - the value at level 1
      multiplier - the growth factor per level (1.0 = no growth)
      Returns:
      an exponential scaling instance
      Since:
      0.1.0
    • diminishing

      @NotNull static @NotNull LevelScaling diminishing(double maxValue, double scalingFactor)
      Creates diminishing scaling: maxValue * (level / (level + factor)).

      Values approach maxValue asymptotically. Higher factor means slower approach to the maximum.

      Parameters:
      maxValue - the asymptotic maximum value
      scalingFactor - controls how quickly values approach max
      Returns:
      a diminishing scaling instance
      Since:
      0.1.0
    • constant

      @NotNull static @NotNull LevelScaling constant(double value)
      Creates constant scaling: same value at all levels.
      Parameters:
      value - the constant value
      Returns:
      a constant scaling instance
      Since:
      0.1.0
    • stepped

      @NotNull static @NotNull LevelScaling stepped(@NotNull Map<Integer,Double> steps)
      Creates stepped scaling with interpolation between defined levels.

      Define exact values at specific levels. Values between steps are linearly interpolated. Values above the highest step use the max step value.

      Parameters:
      steps - map of level -> value pairs (must include level 1)
      Returns:
      a stepped scaling instance
      Since:
      0.1.0