Class ValueImporterRegistry
java.lang.Object
johnsmith.enchantmentcore.api.registry.ValueImporterRegistry
Manages the interception of static
LevelBasedValue JSON nodes and coordinates their
transformation into dynamic configuration-bound structures during the /enchantment_core import phase.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional contract for converting a decoded staticLevelBasedValueinstance into its corresponding configurableLevelBasedValuecounterpart.static interfaceFunctional contract for mutating a staticLevelBasedValueJSON element into a configuration-backed JSON wrapper. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <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-drivenValueImporterRegistry.ValueImporterthat decodes the static JSON element viasourceCodec, transforms it withimporter, and encodes the resulting configurable instance viatargetCodec.static com.google.gson.JsonObjectbuildConfigObject(String modId, String group, String property) Utility method that constructs a serializedConfigDescriptionJSON object under the"enchantment"category.Retrieves theValueImporterRegistry.ValueImporterbound to the specified static type identifier.static com.google.gson.JsonElementimportLevelBasedValue(com.google.gson.JsonElement element, String modId, String group, String property) Intercepts a JSON element representing aLevelBasedValueand routes it through the appropriateValueImporterRegistry.ValueImporterbased on its"type"field (defaulting to"minecraft:constant"for primitives or objects lacking a type tag).static voidregister(String typeId, ValueImporterRegistry.ValueImporter importer) Registers aValueImporterRegistry.ValueImporterroutine for a specific staticLevelBasedValuetype identifier.
-
Constructor Details
-
ValueImporterRegistry
public ValueImporterRegistry()
-
-
Method Details
-
register
Registers aValueImporterRegistry.ValueImporterroutine for a specific staticLevelBasedValuetype identifier.- Parameters:
typeId- The resource location string of the static value type (e.g.,"minecraft:linear").importer- TheValueImporterRegistry.ValueImporterexecuted when transforming matching nodes.
-
get
Retrieves theValueImporterRegistry.ValueImporterbound to the specified static type identifier.- Parameters:
typeId- The resource location string of the static value type.- Returns:
- The registered
ValueImporterRegistry.ValueImporter, ornullif 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-drivenValueImporterRegistry.ValueImporterthat decodes the static JSON element viasourceCodec, transforms it withimporter, and encodes the resulting configurable instance viatargetCodec.- Type Parameters:
S- The static value class.T- The configurable output class.- Parameters:
sourceCodec- TheMapCodecmatching the original static format.targetCodec- TheMapCodecmatching 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 serializedConfigDescriptionJSON 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
JsonObjectrepresenting 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 aLevelBasedValueand routes it through the appropriateValueImporterRegistry.ValueImporterbased 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.
-