Class CodecOps<E>

java.lang.Object
org.moddingx.libx.codec.CodecOps<E>

public class CodecOps<E> extends Object
Provides some utility methods to encode and decode thing using a codec for a specific DynamicOps. CodecOps for json and nbt can be found in CodecHelper.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CodecOps(Class<E> baseClass, com.mojang.serialization.DynamicOps<E> ops)
    Creates new CodecOps.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    read(com.mojang.serialization.Codec<T> codec, E value)
    Reads a value using a codec.
    <T> T
    read(com.mojang.serialization.Codec<T> codec, E value, net.minecraft.core.HolderLookup.Provider registries)
    Reads a value using a codec.
    <T> E
    write(com.mojang.serialization.Codec<T> codec, T value)
    Writes an element using a code.
    <T, R extends E>
    R
    write(com.mojang.serialization.Codec<T> codec, T value, Class<R> resultType)
    Writes an element using a code.
    <T, R extends E>
    R
    write(com.mojang.serialization.Codec<T> codec, T value, Class<R> resultType, net.minecraft.core.HolderLookup.Provider registries)
    Writes an element using a code.
    <T> E
    write(com.mojang.serialization.Codec<T> codec, T value, net.minecraft.core.HolderLookup.Provider registries)
    Writes an element using a code.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CodecOps

      public CodecOps(Class<E> baseClass, com.mojang.serialization.DynamicOps<E> ops)
      Creates new CodecOps.
      Parameters:
      baseClass - The base value class of the DynamicOps to use.
      ops - The base DynamicOps to use.
  • Method Details

    • write

      public <T> E write(com.mojang.serialization.Codec<T> codec, T value)
      Writes an element using a code.
    • write

      public <T> E write(com.mojang.serialization.Codec<T> codec, T value, net.minecraft.core.HolderLookup.Provider registries)
      Writes an element using a code.
      Parameters:
      registries - The RegistryAccess to provide for registry aware codecs.
    • write

      public <T, R extends E> R write(com.mojang.serialization.Codec<T> codec, T value, Class<R> resultType)
      Writes an element using a code.
      Parameters:
      resultType - The class that the result is expected to have. It is ensured, that the result is of this class. If the codec produces data of another class, an exception will be thrown.
    • write

      public <T, R extends E> R write(com.mojang.serialization.Codec<T> codec, T value, Class<R> resultType, net.minecraft.core.HolderLookup.Provider registries)
      Writes an element using a code.
      Parameters:
      resultType - The class that the result is expected to have. It is ensured, that the result is of this class. If the codec produces data of another class, an exception will be thrown.
      registries - The RegistryAccess to provide for registry aware codecs.
    • read

      public <T> T read(com.mojang.serialization.Codec<T> codec, E value)
      Reads a value using a codec.
    • read

      public <T> T read(com.mojang.serialization.Codec<T> codec, E value, net.minecraft.core.HolderLookup.Provider registries)
      Reads a value using a codec.
      Parameters:
      registries - The RegistryAccess to provide for registry aware codecs.