Record Class TopologyEvaluator
java.lang.Object
java.lang.Record
johnsmith.enchantmentcore.api.enchantment.spellfield.math.TopologyEvaluator
- Record Components:
threshold- An optionalLevelBasedValueminimum 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
FieldsModifier and TypeFieldDescriptionstatic final com.mojang.serialization.Codec<TopologyEvaluator> Codec for serializing and deserializingTopologyEvaluatorinstances from JSON.static final LevelBasedKeyProviderSupplies the JSON property keys holdingLevelBasedValuedefinitions for data transformation.static final TopologyEvaluatorDefault probabilistic evaluator instance with no fixed threshold.static final StringJSON field key for the deterministic scalar cutoff threshold. -
Constructor Summary
ConstructorsConstructorDescriptionTopologyEvaluator(Optional<net.minecraft.world.item.enchantment.LevelBasedValue> threshold) Creates an instance of aTopologyEvaluatorrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.booleanevaluate(float scalar, int enchantmentLevel, net.minecraft.util.RandomSource random) Tests whether an effect should activate for the given topologicalscalar.floatgetThreshold(int enchantmentLevel) Returns the evaluated deterministic cutoff threshold at the given enchantment level, or0.0Fif this evaluator is probabilistic.final inthashCode()Returns a hash code value for this object.Optional<net.minecraft.world.item.enchantment.LevelBasedValue> Returns the value of thethresholdrecord component.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
THRESHOLD
JSON field key for the deterministic scalar cutoff threshold.- See Also:
-
KEY_PROVIDER
Supplies the JSON property keys holdingLevelBasedValuedefinitions for data transformation. -
CODEC
Codec for serializing and deserializingTopologyEvaluatorinstances from JSON. -
PROBABILISTIC
Default probabilistic evaluator instance with no fixed threshold.
-
-
Constructor Details
-
TopologyEvaluator
Creates an instance of aTopologyEvaluatorrecord class.- Parameters:
threshold- the value for thethresholdrecord 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 topologicalscalar.- 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:
trueif the threshold or random roll succeeds,falseotherwise.
-
getThreshold
public float getThreshold(int enchantmentLevel) Returns the evaluated deterministic cutoff threshold at the given enchantment level, or0.0Fif 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
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). -
threshold
Returns the value of thethresholdrecord component.- Returns:
- the value of the
thresholdrecord component
-