Class CodecProperty<T>

java.lang.Object
net.darkhax.pricklemc.common.api.config.property.ObjectProperty<T>
net.darkhax.pricklemc.common.impl.config.property.CodecProperty<T>
Type Parameters:
T - The type of value serialized by the codec.
All Implemented Interfaces:
IConfigProperty<T>

public class CodecProperty<T> extends ObjectProperty<T>
A config property where the value is serialized using a Minecraft Codec.
  • Constructor Details

    • CodecProperty

      public CodecProperty(Field field, Object parent, T defaultValue, Value valueMeta, IComment comment, com.mojang.serialization.Codec<T> codec)
  • Method Details

    • writeValue

      public void writeValue(T value, com.google.gson.stream.JsonWriter writer, PropertyResolver resolver, org.slf4j.Logger logger) throws IOException
      Description copied from class: ObjectProperty
      Writes a value to the JSON writer.
      Overrides:
      writeValue in class ObjectProperty<T>
      Parameters:
      value - The value to be written.
      writer - A writer to write JSON data to.
      resolver - Resolves properties with GSON or config properties.
      logger - A log instance used to log warnings and errors encountered when saving the value.
      Throws:
      IOException - A fatal exception may be thrown if the value could not be written.
    • readValue

      public T readValue(com.google.gson.stream.JsonReader reader, PropertyResolver resolver, org.slf4j.Logger logger) throws IOException
      Description copied from class: ObjectProperty
      Reads a value from the JSON reader.
      Overrides:
      readValue in class ObjectProperty<T>
      Parameters:
      reader - A reader containing a stream of JSON data.
      resolver - Resolves properties with GSON or config properties.
      logger - A log instance used to log warnings and errors encountered when the value is read.
      Returns:
      The value that was read from the reader.
      Throws:
      IOException - A fatal exception may be thrown if the value could not be read.
    • of

      public static <T> CodecProperty.Adapter<T> of(Type classType, com.mojang.serialization.Codec<T> codec)
      Creates an adapter that will process a given type using a codec.
      Type Parameters:
      T - The type being adapted.
      Parameters:
      classType - The type to serialize using the codec.
      codec - The codec to serialize the value.
      Returns:
      An adapter that uses a codec to serialize data.