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

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.MapCodec<ConfigAwareValue>
    MapCodec for serializing and deserializing ConfigAwareValue instances 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
    ConfigAwareValue(johnsmith.configoverhauled.api.data.ConfigDescription target, Map<String,net.minecraft.world.item.enchantment.LevelBasedValue> cases, net.minecraft.world.item.enchantment.LevelBasedValue fallback)
    Constructs a ConfigAwareValue and attaches a change listener to the resolved configuration property.
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    calculate(int level)
    Calculates the level-based value by delegating to the currently active LevelBasedValue branch.
    @NotNull com.mojang.serialization.MapCodec<? extends net.minecraft.world.item.enchantment.LevelBasedValue>
     
    boolean
     
    int
     
     

    Methods inherited from class java.lang.Object

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

  • 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 a ConfigAwareValue and attaches a change listener to the resolved configuration property.
      Parameters:
      target - The ConfigDescription identifying the configuration property to monitor.
      cases - A map matching stringified configuration values to their respective LevelBasedValue delegates.
      fallback - The fallback LevelBasedValue used 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 active LevelBasedValue branch.
      Specified by:
      calculate in interface net.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:
      codec in interface net.minecraft.world.item.enchantment.LevelBasedValue
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object