Record Class DiminishingReturnsValue
java.lang.Object
java.lang.Record
johnsmith.enchantmentcore.api.enchantment.value.DiminishingReturnsValue
- Record Components:
base- The initial value added at the first level (Level 1).decrement- The amount by which the value added is reduced for each subsequent level.minimum- The floor value. The added value per level will never drop below this amount.
- All Implemented Interfaces:
net.minecraft.world.item.enchantment.LevelBasedValue
public record DiminishingReturnsValue(float base, float decrement, float minimum)
extends Record
implements net.minecraft.world.item.enchantment.LevelBasedValue
A specialized implementation of
LevelBasedValue that calculates a total value
based on an arithmetic progression where the increment decreases (diminishes) for each
subsequent level until a defined minimum value is reached (the "floor").
The value added at level $N$ is calculated as: $\max(\text{base} - (N - 1) \cdot \text{decrement}, \text{minimum})$. The final result is the sum of these diminishing terms up to the given level.
-
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<DiminishingReturnsValue> 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
ConstructorsConstructorDescriptionDiminishingReturnsValue(float base, float decrement, float minimum) Creates an instance of aDiminishingReturnsValuerecord class. -
Method Summary
Modifier and TypeMethodDescriptionfloatbase()Returns the value of thebaserecord component.floatcalculate(int level) Calculates the cumulative total value up to the given enchantment level using diminishing returns.@NotNull com.mojang.serialization.MapCodec<? extends net.minecraft.world.item.enchantment.LevelBasedValue> codec()floatReturns the value of thedecrementrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.floatminimum()Returns the value of theminimumrecord 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.
-
-
Constructor Details
-
DiminishingReturnsValue
public DiminishingReturnsValue(float base, float decrement, float minimum) Creates an instance of aDiminishingReturnsValuerecord class.
-
-
Method Details
-
calculate
public float calculate(int level) Calculates the cumulative total value up to the given enchantment level using diminishing returns.For efficiency, this method uses the closed-form formula for the sum of an arithmetic progression for the initial terms (where reduction occurs) and then adds the constant floor value for any remaining terms. If the decrement is zero or negative, it falls back to an iterative calculation to ensure correct non-diminishing behavior.
- Specified by:
calculatein interfacenet.minecraft.world.item.enchantment.LevelBasedValue- Parameters:
level- The enchantment level for which to calculate the cumulative value.- Returns:
- The total float value. Returns
0iflevel <= 0.
-
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. -
base
-
decrement
-
minimum
-