Record Class NegateValue

java.lang.Object
java.lang.Record
johnsmith.enchantmentcore.api.enchantment.value.NegateValue
Record Components:
value - The inner LevelBasedValue whose calculated result will be negated.
All Implemented Interfaces:
net.minecraft.world.item.enchantment.LevelBasedValue

public record NegateValue(net.minecraft.world.item.enchantment.LevelBasedValue value) extends Record implements net.minecraft.world.item.enchantment.LevelBasedValue
A specialized implementation of LevelBasedValue that calculates the negative additive inverse of the value returned by an inner value value provider.

This is primarily useful for creating diminishing or negative effects (e.g., charge time reduction) where the underlying value calculation naturally yields a positive number.

  • 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<NegateValue>
    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
    NegateValue(net.minecraft.world.item.enchantment.LevelBasedValue value)
    Creates an instance of a NegateValue record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    calculate(int level)
    Calculates the value by retrieving the result from the nested value provider and inverting its sign (multiplying by $-1$).
    @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.
    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

    • KEY

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

      public static final com.mojang.serialization.MapCodec<NegateValue> CODEC
      The codec responsible for serializing and deserializing instances of this record from JSON. It maps the nested value field to a generic LevelBasedValue.
  • Constructor Details

    • NegateValue

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

    • calculate

      public float calculate(int level)
      Calculates the value by retrieving the result from the nested value provider and inverting its sign (multiplying by $-1$).
      Specified by:
      calculate in interface net.minecraft.world.item.enchantment.LevelBasedValue
      Parameters:
      level - The level of the enchantment.
      Returns:
      The negated 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 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