Skip to content

Spell Field Registrar

JohnSmith474 edited this page Sep 21, 2026 · 4 revisions

The Spell Field API is entirely modular, allowing you to create custom SpellFieldShape geometries, DistanceScalingFunction mathematics, and operational SpellFieldEffects (Block, Entity, Volume, or Visual).

The SpellFieldRegistrar is a specialized registration utility designed to safely bind these components to their internal dispatch codecs while guaranteeing that any dynamic JSON keys they introduce are properly logged with the DataTransformerRegistry.

Registration Usage

Instead of accessing the dynamic Spell Field registries directly, you utilize the static helper methods provided by the SpellFieldRegistrar. These methods accept a BiConsumer, allowing you to dictate exactly where the codec maps while the registrar handles the background key extraction.

Registering Custom Effects

If you write a custom SpellFieldBlockEffect (or Entity/Volume/Visual effect), use registerEffects.

If your effect provides a LevelBasedKeyProvider interface, the registrar automatically pushes your properties to the transformer.

import johnsmith.enchantmentcore.registry.SpellFieldRegistrar;
import johnsmith.enchantmentcore.registry.EnchantmentCoreRegistries;
import net.minecraft.core.Registry;

public class MySpellFieldAddons {
    public static void init() {
        SpellFieldRegistrar.registerEffects((id, codec) -> {
            Registry.register(EnchantmentCoreRegistries.SPELL_FIELD_EFFECTS.get(), id, codec);
        });
        
        // Example execution inside the registrar:
        // registerEffect(registrar, CustomWaterEffect.KEY, CustomWaterEffect.CODEC, CustomWaterEffect.KEY_PROVIDER);
    }
}

(Note: Because the Spell Field API uses its own custom registries wrapped by EnchantmentCore, you map them using the suppliers found in EnchantmentCoreRegistries.)

Registering Shapes and Functions

Similarly, you can register custom geometric shapes (e.g., Pyramids, Cylinders) or new mathematical falloff curves:

// Shapes
SpellFieldRegistrar.registerShapes((id, codec) -> {
    Registry.register(EnchantmentCoreRegistries.SPELL_FIELD_SHAPES.get(), id, codec);
});

// Distance Scaling Functions
SpellFieldRegistrar.registerFunctions((id, codec) -> {
    Registry.register(EnchantmentCoreRegistries.DISTANCE_SCALING_FUNCTIONS.get(), id, codec);
});

By strictly utilizing the SpellFieldRegistrar and KEY_PROVIDER architecture, your custom Spell Field modules gain the exact same level of data-driven configurability as the core library features.

Clone this wiki locally