Skip to content

Value Importer Registry

JohnSmith474 edited this page Sep 21, 2026 · 3 revisions

The ValueImporterRegistry manages the forward transformation of static LevelBasedValue JSON nodes into dynamic, configuration-bound structures during the /enchantment_core import command phase.

If your mod introduces entirely custom LevelBasedValue formulas (e.g., my_mod:sine_wave) and you want those formulas to become configurable via Config Overhauled, you must register a custom importer.

The Codec Importer

The most reliable way to register an importer is by using ValueImporterRegistry.bindCodecs(). This method takes your static formula's Codec, your dynamic formula's Codec, and a translation interface, automatically generating the JSON logic.

Example: Making a Custom Math Curve Configurable

Assume you have a SineWaveValue (static) and a ConfigurableSineWaveValue (dynamic).

import johnsmith.enchantmentcore.registry.ValueImporterRegistry;
import johnsmith.enchantmentcore.api.config.ConfigReference;
import johnsmith.configoverhauled.api.data.ConfigDescription;
import java.util.Optional;

public class MyModImporters {
    public static void init() {
        ValueImporterRegistry.register("my_mod:sine_wave", ValueImporterRegistry.bindCodecs(
            SineWaveValue.CODEC, 
            ConfigurableSineWaveValue.CODEC, 
            "my_mod:configurable_sine_wave", 
            (source, modId, group, prefix) -> {
                // 'source' is the parsed static SineWaveValue object
                // We construct the new dynamic object, binding its parameters to config references
                
                ConfigReference amplitudeRef = new ConfigReference(
                    new ConfigDescription(modId, "enchantment", group, prefix + "_amplitude"), 
                    Optional.empty()
                );
                
                return new ConfigurableSineWaveValue(amplitudeRef, source.getDefaultAmplitude());
            }
        ));
    }
}

Whenever the import command encounters a "type": "my_mod:sine_wave" JSON block, it will automatically execute your lambda, converting it to "type": "my_mod:configurable_sine_wave" and pointing its properties to your mod's config menu.

Clone this wiki locally