Skip to content

Custom Value Integration

JohnSmith474 edited this page Sep 21, 2026 · 1 revision

If you need to introduce entirely new mathematical formulas or specialized configuration-aware logic (e.g., retrieving a value from a completely different mod's API), you can register custom LevelBasedValue codecs.

Because LevelBasedValue is a native Vanilla Minecraft concept, you register your custom implementations directly into BuiltInRegistries.ENCHANTMENT_LEVEL_BASED_VALUE_TYPE.

Example Registration

Assume you have written a custom SineWaveValue record that implements LevelBasedValue.

import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;

public class MyModValueRegistry {
    
    public static void initialize() {
        Registry.register(
            BuiltInRegistries.ENCHANTMENT_LEVEL_BASED_VALUE_TYPE, 
            ResourceLocation.fromNamespaceAndPath("my_mod", "sine_wave"), 
            SineWaveValue.CODEC
        );
    }
}

Import/Export Integration

If your custom LevelBasedValue represents a static mathematical curve, and you want to allow players to configure its parameters dynamically via Config Overhauled, you must also pair it with a configurable equivalent codec.

Refer to the guides for the Value Importer Registry and Value Exporter Registry to learn how to create dynamic equivalents that support the in-game datapack /enchantment_core transformation commands.

Clone this wiki locally