Class ConfigAwareValue
java.lang.Object
johnsmith.enchantmentcore.api.enchantment.value.configurable.ConfigAwareValue
- All Implemented Interfaces:
net.minecraft.world.item.enchantment.LevelBasedValue
public class ConfigAwareValue
extends Object
implements net.minecraft.world.item.enchantment.LevelBasedValue
A dynamic switch-like implementation of
LevelBasedValue that selects its active delegate
LevelBasedValue based on the current stringified value of a target configuration Property.
Registers a Property.Listener on the resolved configuration property so that the active
delegate is cached in a volatile reference and only re-evaluated when the configuration changes,
avoiding map lookups during per-tick enchantment calculations.
-
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.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<ConfigAwareValue> MapCodec for serializing and deserializingConfigAwareValueinstances from JSON.static final StringRegistry path identifier for this level based value.Fields inherited from interface net.minecraft.world.item.enchantment.LevelBasedValue
DISPATCH_CODEC -
Constructor Summary
ConstructorsConstructorDescriptionConfigAwareValue(johnsmith.configoverhauled.api.data.ConfigDescription target, Map<String, net.minecraft.world.item.enchantment.LevelBasedValue> cases, net.minecraft.world.item.enchantment.LevelBasedValue fallback) Constructs aConfigAwareValueand attaches a change listener to the resolved configuration property. -
Method Summary
Modifier and TypeMethodDescriptionfloatcalculate(int level) Calculates the level-based value by delegating to the currently activeLevelBasedValuebranch.@NotNull com.mojang.serialization.MapCodec<? extends net.minecraft.world.item.enchantment.LevelBasedValue> codec()booleaninthashCode()toString()
-
Field Details
-
KEY
Registry path identifier for this level based value.- See Also:
-
CODEC
MapCodec for serializing and deserializingConfigAwareValueinstances from JSON.
-
-
Constructor Details
-
ConfigAwareValue
public ConfigAwareValue(johnsmith.configoverhauled.api.data.ConfigDescription target, Map<String, net.minecraft.world.item.enchantment.LevelBasedValue> cases, net.minecraft.world.item.enchantment.LevelBasedValue fallback) Constructs aConfigAwareValueand attaches a change listener to the resolved configuration property.- Parameters:
target- TheConfigDescriptionidentifying the configuration property to monitor.cases- A map matching stringified configuration values to their respectiveLevelBasedValuedelegates.fallback- The fallbackLevelBasedValueused when no case matches or the property cannot be resolved.
-
-
Method Details
-
calculate
public float calculate(int level) Calculates the level-based value by delegating to the currently activeLevelBasedValuebranch.- Specified by:
calculatein interfacenet.minecraft.world.item.enchantment.LevelBasedValue- Parameters:
level- The active level of the enchantment.- Returns:
- The calculated float value from the active delegate.
-
codec
@NotNull public @NotNull com.mojang.serialization.MapCodec<? extends net.minecraft.world.item.enchantment.LevelBasedValue> codec()- Specified by:
codecin interfacenet.minecraft.world.item.enchantment.LevelBasedValue
-
toString
-
equals
-
hashCode
public int hashCode()
-