Class ValueExporterRegistry
java.lang.Object
johnsmith.enchantmentcore.api.registry.ValueExporterRegistry
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional contract for reconstructing a staticLevelBasedValueinstance from a parsed configurable instance during DFU codec evaluation.static interfaceFunctional contract for collapsing a configurable JSON object into its static JSON representation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <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-drivenValueExporterRegistry.ValueExporterthat decodes the configurable JSON object viasourceCodec, transforms it withexporter, and encodes the resulting static instance viatargetCodec.static com.google.gson.JsonElementexportLevelBasedValue(com.google.gson.JsonElement element) Evaluates a JSON element representing aLevelBasedValueand recursively unwraps any configurable wrappers into static definitions.Retrieves theValueExporterRegistry.ValueExporterregistered for the specified configurable type identifier.static voidregister(String configurableTypeId, ValueExporterRegistry.ValueExporter exporter) Registers aValueExporterRegistry.ValueExporterfor a specific configurableLevelBasedValuetype identifier.
-
Constructor Details
-
ValueExporterRegistry
public ValueExporterRegistry()
-
-
Method Details
-
register
public static void register(String configurableTypeId, ValueExporterRegistry.ValueExporter exporter) Registers aValueExporterRegistry.ValueExporterfor a specific configurableLevelBasedValuetype identifier.- Parameters:
configurableTypeId- The resource location string of the configurable value type (e.g.,"enchantment_core:configurable_linear").exporter- TheValueExporterRegistry.ValueExporterresponsible for unwrapping that type.
-
get
Retrieves theValueExporterRegistry.ValueExporterregistered for the specified configurable type identifier.- Parameters:
configurableTypeId- The resource location string of the configurable value type.- Returns:
- The registered
ValueExporterRegistry.ValueExporter, ornullif 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-drivenValueExporterRegistry.ValueExporterthat decodes the configurable JSON object viasourceCodec, transforms it withexporter, and encodes the resulting static instance viatargetCodec.- Type Parameters:
S- The configurable source class.T- The static target class.- Parameters:
sourceCodec- TheMapCodecfor the configurable source structure.targetCodec- TheMapCodecfor 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 aLevelBasedValueand 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.
-