Record Class PolynomialValue

java.lang.Object
java.lang.Record
johnsmith.enchantmentcore.api.enchantment.value.PolynomialValue
Record Components:
scale - The coefficient that multiplies the result of the power calculation. Defaults to 1.0f.
power - The exponent applied to the level calculation. Defaults to 1.0f (linear).
offset - A constant value added to the final result. Defaults to 0.0f.
levelOffset - A constant value added to the enchantment level before the power calculation. Defaults to 0.0f.
All Implemented Interfaces:
net.minecraft.world.item.enchantment.LevelBasedValue

public record PolynomialValue(float scale, float power, float offset, float levelOffset) extends Record implements net.minecraft.world.item.enchantment.LevelBasedValue
A specialized implementation of LevelBasedValue that calculates a final value using a generalized polynomial function.

The formula used is: $\text{value} = \text{offset} + \text{scale} \cdot (\text{level} + \text{levelOffset})^{\text{power}}$. This allows for custom growth curves, such as linear, quadratic, or fractional scaling, by adjusting the parameters.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface net.minecraft.world.item.enchantment.LevelBasedValue

    net.minecraft.world.item.enchantment.LevelBasedValue.Clamped, net.minecraft.world.item.enchantment.LevelBasedValue.Constant, net.minecraft.world.item.enchantment.LevelBasedValue.Exponent, net.minecraft.world.item.enchantment.LevelBasedValue.Fraction, net.minecraft.world.item.enchantment.LevelBasedValue.LevelsSquared, net.minecraft.world.item.enchantment.LevelBasedValue.Linear, net.minecraft.world.item.enchantment.LevelBasedValue.Lookup
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.MapCodec<PolynomialValue>
    The codec responsible for serializing and deserializing instances of this record from JSON.
    static final String
    Registry path identifier for this level based value.

    Fields inherited from interface net.minecraft.world.item.enchantment.LevelBasedValue

    DISPATCH_CODEC
  • Constructor Summary

    Constructors
    Constructor
    Description
    PolynomialValue(float scale, float power, float offset, float levelOffset)
    Creates an instance of a PolynomialValue record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    calculate(int level)
    Calculates the value using the defined polynomial formula: $\text{offset} + \text{scale} \cdot (\text{level} + \text{levelOffset})^{\text{power}}$.
    @NotNull com.mojang.serialization.MapCodec<? extends net.minecraft.world.item.enchantment.LevelBasedValue>
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    float
    Returns the value of the levelOffset record component.
    float
    Returns the value of the offset record component.
    float
    Returns the value of the power record component.
    float
    Returns the value of the scale record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • KEY

      public static final String KEY
      Registry path identifier for this level based value.
      See Also:
    • CODEC

      public static final com.mojang.serialization.MapCodec<PolynomialValue> CODEC
      The codec responsible for serializing and deserializing instances of this record from JSON. All fields are optional and default to linear scaling (scale=1.0, power=1.0, offset=0.0, levelOffset=0.0).
  • Constructor Details

    • PolynomialValue

      public PolynomialValue(float scale, float power, float offset, float levelOffset)
      Creates an instance of a PolynomialValue record class.
      Parameters:
      scale - the value for the scale record component
      power - the value for the power record component
      offset - the value for the offset record component
      levelOffset - the value for the levelOffset record component
  • Method Details

    • calculate

      public float calculate(int level)
      Calculates the value using the defined polynomial formula: $\text{offset} + \text{scale} \cdot (\text{level} + \text{levelOffset})^{\text{power}}$.
      Specified by:
      calculate in interface net.minecraft.world.item.enchantment.LevelBasedValue
      Parameters:
      level - The level of the enchantment to use in the calculation.
      Returns:
      The calculated float value.
    • codec

      @NotNull public @NotNull com.mojang.serialization.MapCodec<? extends net.minecraft.world.item.enchantment.LevelBasedValue> codec()
      Specified by:
      codec in interface net.minecraft.world.item.enchantment.LevelBasedValue
      Returns:
      The MapCodec for this class.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • scale

      public float scale()
      Returns the value of the scale record component.
      Returns:
      the value of the scale record component
    • power

      public float power()
      Returns the value of the power record component.
      Returns:
      the value of the power record component
    • offset

      public float offset()
      Returns the value of the offset record component.
      Returns:
      the value of the offset record component
    • levelOffset

      public float levelOffset()
      Returns the value of the levelOffset record component.
      Returns:
      the value of the levelOffset record component