Class CodecHelper

java.lang.Object
org.moddingx.libx.codec.CodecHelper

public class CodecHelper extends Object
Some utilities to deal with codecs.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final CodecOps<JsonElement>
    CodecOps for json.
    static final CodecOps<net.minecraft.nbt.Tag>
    CodecOps for nbt.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> com.mojang.serialization.DataResult<T>
    Wraps a value into a DataResult.
    static <T> com.mojang.serialization.DataResult<T>
    nonNull(T value, String error)
    Wraps a value into a DataResult.
    static <T> com.mojang.serialization.DataResult<T>
    nonNull(T value, Supplier<String> error)
    Wraps a value into a DataResult.
    static <T> com.mojang.serialization.DataResult<T>
    or(Supplier<com.mojang.serialization.DataResult<T>>... results)
    Takes a number of DataResults and returns the first result that is a success.
    static <T> com.mojang.serialization.DataResult<T>
    orPartial(Supplier<com.mojang.serialization.DataResult<T>>... results)
    Takes a number of DataResults and returns the first result that is either a success or a partial success.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • CodecHelper

      public CodecHelper()
  • Method Details

    • nonNull

      public static <T> com.mojang.serialization.DataResult<T> nonNull(@Nullable T value, String error)
      Wraps a value into a DataResult. If the value is non-null, the result will be successful and contain the value. If the value is null, the result will be a failure with the given error message.
    • nonNull

      public static <T> com.mojang.serialization.DataResult<T> nonNull(@Nullable T value, Supplier<String> error)
      Wraps a value into a DataResult. If the value is non-null, the result will be successful and contain the value. If the value is null, the result will be a failure with the given error message.
    • doesNotThrow

      public static <T> com.mojang.serialization.DataResult<T> doesNotThrow(Callable<T> value)
      Wraps a value into a DataResult. If the Supplier does not throw, the result will be successful and contain the value. If the Supplier throws an exception, the result will be a failure with the error message of the exception.
    • or

      @SafeVarargs public static <T> com.mojang.serialization.DataResult<T> or(Supplier<com.mojang.serialization.DataResult<T>>... results)
      Takes a number of DataResults and returns the first result that is a success. If there is no success in all the parameters, returns the first DataResult that has a partial success. If all DataResults are failures, the last failure is returned.
    • orPartial

      @SafeVarargs public static <T> com.mojang.serialization.DataResult<T> orPartial(Supplier<com.mojang.serialization.DataResult<T>>... results)
      Takes a number of DataResults and returns the first result that is either a success or a partial success. If there is no success in all the parameters, the last failure is returned.