Package org.moddingx.libx.config.mapper
Interface ValueMapper<T,E extends JsonElement>
- Type Parameters:
T
- The type that this mapper can serialise.E
- The JSON element type this mapper uses.
public interface ValueMapper<T,E extends JsonElement>
A way to serialise values of a specific type for a config file. See
ConfigManager
for
more info.-
Method Summary
Modifier and TypeMethodDescriptioncomment()
Returns a list of comment lines that will be added to the values specified in@Config
.correct
(JsonElement json, ConfigCorrection<T> correction) Corrects a config value.createEditor
(ValidatorInfo<?> validator) Creates aConfigEditor
for this value mapper to display this config in the config menu.element()
Gets the class of the JSON element type this mapper uses.Reads an object from JSON.default T
fromNetwork
(net.minecraft.network.FriendlyByteBuf buffer) Reads a value from aFriendlyByteBuf
.Serialises a value to JSON.default void
Writes a value to aFriendlyByteBuf
.type()
Gets the class of the type that this mapper can serialise.
-
Method Details
-
type
Gets the class of the type that this mapper can serialise. -
element
Gets the class of the JSON element type this mapper uses. -
fromJson
Reads an object from JSON. If the json is invalid you may either throw anIllegalStateException
or aJsonParseException
to end config parsing with an error, or just correct errors yourself and return default values.- Parameters:
json
- The json data- Returns:
- The value read.
-
toJson
Serialises a value to JSON.- Parameters:
value
- The value to serialise- Returns:
- The resulting json data.
-
fromNetwork
Reads a value from aFriendlyByteBuf
. The default implementation expects a JSON string and gives this string tofromJSON
. -
toNetwork
Writes a value to aFriendlyByteBuf
. The default implementation callstoJSON
and writes the resulting JSON as a string. -
comment
Returns a list of comment lines that will be added to the values specified in@Config
. -
correct
Corrects a config value. This is only called iffromJson(JsonElement)
fails. Here the raw json for the config value is passed. Also aConfigCorrection
is passed that allows to correct json of types contained in this value. For example a list value mapper can use theConfigCorrection
to try to get as many values as possible out of a json array. -
createEditor
Creates aConfigEditor
for this value mapper to display this config in the config menu. To display that this value can't be edited through the GUI, useConfigEditor.unsupported(Object)
with a default value that is used if for example elements of this type are created in a list.- Parameters:
validator
- Access to the current validator used. Can be used to create different editors based on validators.
-