-
Notifications
You must be signed in to change notification settings - Fork 0
Data Transformer Registry
The DataTransformerRegistry is the centralized engine that manages the bidirectional transformation of enchantment JSON data. When you run the /enchantment_core import or export commands, this registry dictates which JSON properties are dynamically wrapped and which are ignored.
If your mod introduces custom enchantment effects containing LevelBasedValue parameters, those JSON keys must be registered here so the import command knows to wrap them.
While you can technically call DataTransformerRegistry.registerEffectProperty("my_key") anywhere during initialization, doing so loosely leads to disorganized code and missing keys.
The recommended best practice is to couple your transformer registrations directly to your Effect Component registration.
By defining a LevelBasedKeyProvider inside your custom effect record and processing it via a helper method during registry initialization, you ensure that every LevelBasedValue you define is automatically tracked by the transformer.
For a complete code example of this architecture, see the Custom Effect Component Integration guide.
Sometimes you have JSON structures that coincidentally share names with registered effect properties, or complex vanilla effects that crash if forced into dynamic LevelBasedValue configurations (e.g., effects utilizing restricted FloatProviders).
Bypass transformation for an entire effect component based on its type identifier. This prevents the DataFixerUpper from crashing if a component uses strict primitive parsing instead of flexible codecs.
// Prevents any properties inside "minecraft:play_sound" from being dynamically wrapped
DataTransformerRegistry.registerTypeExclusion("minecraft:play_sound");Bypass transformation for a specific JSON structural node, isolating it during recursive tree traversal. This prevents the transformer from entering specific arrays or objects where key names might overlap with effect keys.
// Prevents the transformer from entering any "requirements" JSON object arrays
DataTransformerRegistry.registerStructuralExclusion("requirements");For extreme edge-cases where standard primitive wrapping is insufficient (e.g., composite objects like minimum/maximum costs), you can register a custom Transformer implementation to execute bespoke JSON mutation logic during the import/export phases.
DataTransformerRegistry.registerTransformer(new DataTransformerRegistry.Transformer() {
@Override
public void applyImport(JsonObject root, String targetNamespace, String enchantmentName) {
// Custom JSON wrapping logic
}
@Override
public void applyExport(JsonObject root) {
// Custom JSON flattening logic
}
});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!