Class ValueImporterRegistry

java.lang.Object
johnsmith.enchantmentcore.api.registry.ValueImporterRegistry

public class ValueImporterRegistry extends Object
Manages the interception of static LevelBasedValue JSON nodes and coordinates their transformation into dynamic configuration-bound structures during the /enchantment_core import phase.
  • Constructor Details

    • ValueImporterRegistry

      public ValueImporterRegistry()
  • Method Details

    • register

      public static void register(String typeId, ValueImporterRegistry.ValueImporter importer)
      Registers a ValueImporterRegistry.ValueImporter routine for a specific static LevelBasedValue type identifier.
      Parameters:
      typeId - The resource location string of the static value type (e.g., "minecraft:linear").
      importer - The ValueImporterRegistry.ValueImporter executed when transforming matching nodes.
    • get

      public static ValueImporterRegistry.ValueImporter get(String typeId)
      Retrieves the ValueImporterRegistry.ValueImporter bound to the specified static type identifier.
      Parameters:
      typeId - The resource location string of the static value type.
      Returns:
      The registered ValueImporterRegistry.ValueImporter, or null if no mapping exists.
    • bindCodecs

      public static <S, T> ValueImporterRegistry.ValueImporter bindCodecs(com.mojang.serialization.MapCodec<S> sourceCodec, com.mojang.serialization.MapCodec<T> targetCodec, String targetType, ValueImporterRegistry.CodecImporter<S,T> importer)
      Constructs a codec-driven ValueImporterRegistry.ValueImporter that decodes the static JSON element via sourceCodec, transforms it with importer, and encodes the resulting configurable instance via targetCodec.
      Type Parameters:
      S - The static value class.
      T - The configurable output class.
      Parameters:
      sourceCodec - The MapCodec matching the original static format.
      targetCodec - The MapCodec matching the new configurable target format.
      targetType - The "type" identifier string added to the encoded JSON wrapper.
      importer - The transformation logic mapping the static object to its configurable counterpart.
      Returns:
      A compiled ValueImporterRegistry.ValueImporter.
    • buildConfigObject

      public static com.google.gson.JsonObject buildConfigObject(String modId, String group, String property)
      Utility method that constructs a serialized ConfigDescription JSON object under the "enchantment" category.
      Parameters:
      modId - The target mod namespace.
      group - The target configuration group inside the "enchantment" category.
      property - The specific property identifier key.
      Returns:
      A populated JsonObject representing the configuration target.
    • importLevelBasedValue

      public static com.google.gson.JsonElement importLevelBasedValue(com.google.gson.JsonElement element, String modId, String group, String property)
      Intercepts a JSON element representing a LevelBasedValue and routes it through the appropriate ValueImporterRegistry.ValueImporter based on its "type" field (defaulting to "minecraft:constant" for primitives or objects lacking a type tag).
      Parameters:
      element - The source JSON value definition.
      modId - The target mod namespace for generated configuration properties.
      group - The configuration group name.
      property - The unique property identifier prefix.
      Returns:
      The transformed configurable JSON element, or the original element if no importer matches.