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 to1.0f.power- The exponent applied to the level calculation. Defaults to1.0f(linear).offset- A constant value added to the final result. Defaults to0.0f.levelOffset- A constant value added to the enchantment level before the power calculation. Defaults to0.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
FieldsModifier and TypeFieldDescriptionstatic final com.mojang.serialization.MapCodec<PolynomialValue> The codec responsible for serializing and deserializing instances of this record from JSON.static final StringRegistry path identifier for this level based value.Fields inherited from interface net.minecraft.world.item.enchantment.LevelBasedValue
DISPATCH_CODEC -
Constructor Summary
ConstructorsConstructorDescriptionPolynomialValue(float scale, float power, float offset, float levelOffset) Creates an instance of aPolynomialValuerecord class. -
Method Summary
Modifier and TypeMethodDescriptionfloatcalculate(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> codec()final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.floatReturns the value of thelevelOffsetrecord component.floatoffset()Returns the value of theoffsetrecord component.floatpower()Returns the value of thepowerrecord component.floatscale()Returns the value of thescalerecord component.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
KEY
-
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 aPolynomialValuerecord class.- Parameters:
scale- the value for thescalerecord componentpower- the value for thepowerrecord componentoffset- the value for theoffsetrecord componentlevelOffset- the value for thelevelOffsetrecord 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:
calculatein interfacenet.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:
codecin interfacenet.minecraft.world.item.enchantment.LevelBasedValue- Returns:
- The
MapCodecfor this class.
-
toString
-
hashCode
-
equals
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 thecomparemethod from their corresponding wrapper classes. -
scale
-
power
-
offset
-
levelOffset
public float levelOffset()Returns the value of thelevelOffsetrecord component.- Returns:
- the value of the
levelOffsetrecord component
-