Record Class TopologyEvaluator

java.lang.Object
java.lang.Record
johnsmith.enchantmentcore.api.enchantment.spellfield.math.TopologyEvaluator
Record Components:
threshold - An optional LevelBasedValue minimum scalar cutoff for deterministic activation.

public record TopologyEvaluator(Optional<net.minecraft.world.item.enchantment.LevelBasedValue> threshold) extends Record
Evaluates whether a discrete block or particle effect should trigger at a given coordinate based on its local topological multiplier scalar.

If a deterministic threshold() is present, the evaluator succeeds whenever $\text{scalar} \ge \text{threshold}$. Otherwise, it operates probabilistically, succeeding with probability equal to $\text{scalar}$.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.Codec<TopologyEvaluator>
    Codec for serializing and deserializing TopologyEvaluator instances from JSON.
    Supplies the JSON property keys holding LevelBasedValue definitions for data transformation.
    static final TopologyEvaluator
    Default probabilistic evaluator instance with no fixed threshold.
    static final String
    JSON field key for the deterministic scalar cutoff threshold.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TopologyEvaluator(Optional<net.minecraft.world.item.enchantment.LevelBasedValue> threshold)
    Creates an instance of a TopologyEvaluator record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    boolean
    evaluate(float scalar, int enchantmentLevel, net.minecraft.util.RandomSource random)
    Tests whether an effect should activate for the given topological scalar.
    float
    getThreshold(int enchantmentLevel)
    Returns the evaluated deterministic cutoff threshold at the given enchantment level, or 0.0F if this evaluator is probabilistic.
    final int
    Returns a hash code value for this object.
    Optional<net.minecraft.world.item.enchantment.LevelBasedValue>
    Returns the value of the threshold record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class Object

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

    • THRESHOLD

      public static final String THRESHOLD
      JSON field key for the deterministic scalar cutoff threshold.
      See Also:
    • KEY_PROVIDER

      public static final LevelBasedKeyProvider KEY_PROVIDER
      Supplies the JSON property keys holding LevelBasedValue definitions for data transformation.
    • CODEC

      public static final com.mojang.serialization.Codec<TopologyEvaluator> CODEC
      Codec for serializing and deserializing TopologyEvaluator instances from JSON.
    • PROBABILISTIC

      public static final TopologyEvaluator PROBABILISTIC
      Default probabilistic evaluator instance with no fixed threshold.
  • Constructor Details

    • TopologyEvaluator

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

    • evaluate

      public boolean evaluate(float scalar, int enchantmentLevel, net.minecraft.util.RandomSource random)
      Tests whether an effect should activate for the given topological scalar.
      Parameters:
      scalar - The local topological multiplier in $[0.0, 1.0]$.
      enchantmentLevel - The active level of the enchantment.
      random - The random source used when evaluating probabilistically.
      Returns:
      true if the threshold or random roll succeeds, false otherwise.
    • getThreshold

      public float getThreshold(int enchantmentLevel)
      Returns the evaluated deterministic cutoff threshold at the given enchantment level, or 0.0F if this evaluator is probabilistic.

      Used by SpellFieldBlockEffect.getPriority(int) so higher-threshold inner-core block effects execute before outer-ring effects.

      Parameters:
      enchantmentLevel - The active level of the enchantment.
      Returns:
      The threshold scalar, or 0.0F.
    • 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.
    • threshold

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