Class ValueExporterRegistry

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

public class ValueExporterRegistry extends Object
Manages the reverse transformation of dynamic, configuration-backed LevelBasedValue JSON objects back into static vanilla or non-configurable representations during the /enchantment_core export phase.
  • Constructor Details

    • ValueExporterRegistry

      public ValueExporterRegistry()
  • Method Details

    • register

      public static void register(String configurableTypeId, ValueExporterRegistry.ValueExporter exporter)
      Registers a ValueExporterRegistry.ValueExporter for a specific configurable LevelBasedValue type identifier.
      Parameters:
      configurableTypeId - The resource location string of the configurable value type (e.g., "enchantment_core:configurable_linear").
      exporter - The ValueExporterRegistry.ValueExporter responsible for unwrapping that type.
    • get

      public static ValueExporterRegistry.ValueExporter get(String configurableTypeId)
      Retrieves the ValueExporterRegistry.ValueExporter registered for the specified configurable type identifier.
      Parameters:
      configurableTypeId - The resource location string of the configurable value type.
      Returns:
      The registered ValueExporterRegistry.ValueExporter, or null if none is bound.
    • bindCodecs

      public static <S,T> ValueExporterRegistry.ValueExporter bindCodecs(com.mojang.serialization.MapCodec<S> sourceCodec, com.mojang.serialization.MapCodec<T> targetCodec, String targetType, ValueExporterRegistry.CodecExporter<S,T> exporter)
      Constructs a codec-driven ValueExporterRegistry.ValueExporter that decodes the configurable JSON object via sourceCodec, transforms it with exporter, and encodes the resulting static instance via targetCodec.
      Type Parameters:
      S - The configurable source class.
      T - The static target class.
      Parameters:
      sourceCodec - The MapCodec for the configurable source structure.
      targetCodec - The MapCodec for the resulting static structure.
      targetType - The "type" identifier string written to the exported JSON object.
      exporter - The transformation function mapping the configurable instance to a static instance.
      Returns:
      A compiled ValueExporterRegistry.ValueExporter.
    • exportLevelBasedValue

      public static com.google.gson.JsonElement exportLevelBasedValue(com.google.gson.JsonElement element)
      Evaluates a JSON element representing a LevelBasedValue and recursively unwraps any configurable wrappers into static definitions.
      Parameters:
      element - The JSON element to export.
      Returns:
      The unwrapped static JSON element, or the original element if not a recognized configurable type.