Record Class DifficultyBasedValue
java.lang.Object
java.lang.Record
johnsmith.enchantingoverhauled.api.enchantment.value.DifficultyBasedValue
- Record Components:
value- The innerLevelBasedValueevaluated against the difficulty-mapped level (1,2, or3).
- All Implemented Interfaces:
net.minecraft.world.item.enchantment.LevelBasedValue
public record DifficultyBasedValue(net.minecraft.world.item.enchantment.LevelBasedValue value)
extends Record
implements net.minecraft.world.item.enchantment.LevelBasedValue
A custom
LevelBasedValue implementation that evaluates an inner LevelBasedValue
using the active world Difficulty rather than the raw enchantment level.
Maps Peaceful and Easy to level 1, Normal to level 2, and Hard to level 3.
This allows AI spell fields (such as Obliteration's explosion radius) to scale dynamically with world difficulty.
- See Also:
-
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<DifficultyBasedValue> TheMapCodecresponsible for serializing and deserializingDifficultyBasedValueinstances.Fields inherited from interface net.minecraft.world.item.enchantment.LevelBasedValue
DISPATCH_CODEC -
Constructor Summary
ConstructorsConstructorDescriptionDifficultyBasedValue(net.minecraft.world.item.enchantment.LevelBasedValue value) Creates an instance of aDifficultyBasedValuerecord class. -
Method Summary
Modifier and TypeMethodDescriptionfloatcalculate(int level) Calculates the value by queryingDifficultyContext.getDifficulty()and passing the corresponding difficulty tier (1for Peaceful/Easy,2for Normal,3for Hard) into the wrappedvalue.com.mojang.serialization.MapCodec<DifficultyBasedValue> codec()Retrieves theMapCodecfor this level-based value type.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.final StringtoString()Returns a string representation of this record class.net.minecraft.world.item.enchantment.LevelBasedValuevalue()Returns the value of thevaluerecord component.
-
Field Details
-
CODEC
TheMapCodecresponsible for serializing and deserializingDifficultyBasedValueinstances.
-
-
Constructor Details
-
DifficultyBasedValue
public DifficultyBasedValue(net.minecraft.world.item.enchantment.LevelBasedValue value) Creates an instance of aDifficultyBasedValuerecord class.- Parameters:
value- the value for thevaluerecord component
-
-
Method Details
-
calculate
public float calculate(int level) Calculates the value by queryingDifficultyContext.getDifficulty()and passing the corresponding difficulty tier (1for Peaceful/Easy,2for Normal,3for Hard) into the wrappedvalue.- Specified by:
calculatein interfacenet.minecraft.world.item.enchantment.LevelBasedValue- Parameters:
level- The nominal enchantment level (ignored in favor of world difficulty).- Returns:
- The calculated float value for the current world difficulty.
-
codec
Retrieves theMapCodecfor this level-based value type.- Specified by:
codecin interfacenet.minecraft.world.item.enchantment.LevelBasedValue- Returns:
- The
CODECinstance.
-
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. -
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. -
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 withObjects::equals(Object,Object). -
value
public net.minecraft.world.item.enchantment.LevelBasedValue value()Returns the value of thevaluerecord component.- Returns:
- the value of the
valuerecord component
-