-
Notifications
You must be signed in to change notification settings - Fork 0
Value Importer Registry
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 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.
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.
Want to learn more about the configuration engine powering Enchantment Core?
Check out Config Understood, the official wiki for Config Overhauled, for a deep dive into dynamic property generation and state synchronization!