Record Class DifficultyBasedValue

java.lang.Object
java.lang.Record
johnsmith.enchantingoverhauled.api.enchantment.value.DifficultyBasedValue
Record Components:
value - The inner LevelBasedValue evaluated against the difficulty-mapped level (1, 2, or 3).
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

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.MapCodec<DifficultyBasedValue>
    The MapCodec responsible for serializing and deserializing DifficultyBasedValue instances.

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

    DISPATCH_CODEC
  • Constructor Summary

    Constructors
    Constructor
    Description
    DifficultyBasedValue(net.minecraft.world.item.enchantment.LevelBasedValue value)
    Creates an instance of a DifficultyBasedValue record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    calculate(int level)
    Calculates the value by querying DifficultyContext.getDifficulty() and passing the corresponding difficulty tier (1 for Peaceful/Easy, 2 for Normal, 3 for Hard) into the wrapped value.
    com.mojang.serialization.MapCodec<DifficultyBasedValue>
    Retrieves the MapCodec for this level-based value type.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    final String
    Returns a string representation of this record class.
    net.minecraft.world.item.enchantment.LevelBasedValue
    Returns the value of the value record component.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • DifficultyBasedValue

      public DifficultyBasedValue(net.minecraft.world.item.enchantment.LevelBasedValue value)
      Creates an instance of a DifficultyBasedValue record class.
      Parameters:
      value - the value for the value record component
  • Method Details

    • calculate

      public float calculate(int level)
      Calculates the value by querying DifficultyContext.getDifficulty() and passing the corresponding difficulty tier (1 for Peaceful/Easy, 2 for Normal, 3 for Hard) into the wrapped value.
      Specified by:
      calculate in interface net.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

      public com.mojang.serialization.MapCodec<DifficultyBasedValue> codec()
      Retrieves the MapCodec for this level-based value type.
      Specified by:
      codec in interface net.minecraft.world.item.enchantment.LevelBasedValue
      Returns:
      The CODEC instance.
    • 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 Objects::equals(Object,Object).
      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.
    • value

      public net.minecraft.world.item.enchantment.LevelBasedValue value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component