Package org.moddingx.libx.codec
Class CodecHelper
java.lang.Object
org.moddingx.libx.codec.CodecHelper
Some utilities to deal with
codecs
.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> com.mojang.serialization.DataResult
<T> doesNotThrow
(Callable<T> value) Wraps a value into aDataResult
.static <T> com.mojang.serialization.DataResult
<T> Wraps a value into aDataResult
.static <T> com.mojang.serialization.DataResult
<T> Wraps a value into aDataResult
.static <T> com.mojang.serialization.DataResult
<T> Takes a number ofDataResult
s and returns the first result that is a success.static <T> com.mojang.serialization.DataResult
<T> Takes a number ofDataResult
s and returns the first result that is either a success or a partial success.
-
Constructor Details
-
CodecHelper
public CodecHelper()
-
-
Method Details
-
nonNull
Wraps a value into aDataResult
. If the value is non-null
, the result will be successful and contain the value. If the value isnull
, 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 aDataResult
. If the value is non-null
, the result will be successful and contain the value. If the value isnull
, the result will be a failure with the given error message. -
doesNotThrow
-
or
@SafeVarargs public static <T> com.mojang.serialization.DataResult<T> or(Supplier<com.mojang.serialization.DataResult<T>>... results) Takes a number ofDataResult
s and returns the first result that is a success. If there is no success in all the parameters, returns the firstDataResult
that has a partial success. If allDataResult
s 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 ofDataResult
s 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.
-