Interface Codec<T>

Type Parameters:
T - The type to be represented by this codec
All Superinterfaces:
Decoder<T>, Encoder<T>
All Known Subinterfaces:
DataComponent<T>, StructCodec<R>

@Experimental public interface Codec<T> extends Encoder<T>, Decoder<T>

A Codec represents a combined Encoder and Decoder for a value.

Heavily inspired by Mojang/DataFixerUpper, licensed under the MIT license.

  • Field Details

    • RAW_VALUE

      @NotNull static final @NotNull Codec<Codec.RawValue> RAW_VALUE
    • UNIT

      @NotNull static final @NotNull Codec<Unit> UNIT
    • BOOLEAN

      @NotNull static final @NotNull Codec<Boolean> BOOLEAN
    • BYTE

      @NotNull static final @NotNull Codec<Byte> BYTE
    • SHORT

      @NotNull static final @NotNull Codec<Short> SHORT
    • INT

      @NotNull static final @NotNull Codec<Integer> INT
    • LONG

      @NotNull static final @NotNull Codec<Long> LONG
    • FLOAT

      @NotNull static final @NotNull Codec<Float> FLOAT
    • DOUBLE

      @NotNull static final @NotNull Codec<Double> DOUBLE
    • STRING

      @NotNull static final @NotNull Codec<String> STRING
    • KEY

      @NotNull static final @NotNull Codec<net.kyori.adventure.key.Key> KEY
    • BYTE_ARRAY

      @NotNull static final @NotNull Codec<byte[]> BYTE_ARRAY
    • INT_ARRAY

      @NotNull static final @NotNull Codec<int[]> INT_ARRAY
    • LONG_ARRAY

      @NotNull static final @NotNull Codec<long[]> LONG_ARRAY
    • UUID

      @NotNull static final @NotNull Codec<UUID> UUID
    • UUID_COERCED

      @NotNull static final @NotNull Codec<UUID> UUID_COERCED
    • COMPONENT

      @NotNull static final @NotNull Codec<Component> COMPONENT
    • BLOCK_POSITION

      @NotNull static final @NotNull Codec<Point> BLOCK_POSITION
    • VECTOR3D

      @NotNull static final @NotNull Codec<Point> VECTOR3D
    • NBT

      @NotNull static final @NotNull Codec<net.kyori.adventure.nbt.BinaryTag> NBT
    • NBT_COMPOUND

      @NotNull static final @NotNull Codec<net.kyori.adventure.nbt.CompoundBinaryTag> NBT_COMPOUND
  • Method Details

    • Enum

      @NotNull static <E extends Enum<E>> @NotNull Codec<E> Enum(@NotNull @NotNull Class<E> enumClass)
    • Recursive

      @NotNull static <T> @NotNull Codec<T> Recursive(@NotNull @NotNull Function<Codec<T>,Codec<T>> func)
    • ForwardRef

      @NotNull static <T> @NotNull Codec<T> ForwardRef(@NotNull @NotNull Supplier<Codec<T>> func)
    • RegistryTaggedUnion

      @NotNull static <T> @NotNull StructCodec<T> RegistryTaggedUnion(@NotNull Registries.Selector<StructCodec<? extends T>> registrySelector, @NotNull @NotNull Function<T, StructCodec<? extends T>> serializerGetter, @NotNull @NotNull String key)
    • Either

      @NotNull static <L,R> @NotNull Codec<Either<L,R>> Either(@NotNull @NotNull Codec<L> leftCodec, @NotNull @NotNull Codec<R> rightCodec)
    • optional

      @NotNull default @NotNull Codec<@Nullable T> optional()
    • optional

      @NotNull default @NotNull Codec<T> optional(@NotNull T defaultValue)
    • transform

      @NotNull default <S> @NotNull Codec<S> transform(@NotNull @NotNull ThrowingFunction<T,S> to, @NotNull @NotNull ThrowingFunction<S,T> from)
    • list

      @NotNull default @NotNull Codec<List<T>> list(int maxSize)
    • list

      @NotNull default @NotNull Codec<List<T>> list()
    • listOrSingle

      @NotNull default @NotNull Codec<List<T>> listOrSingle(int maxSize)
    • listOrSingle

      @NotNull default @NotNull Codec<List<T>> listOrSingle()
    • set

      @NotNull default @NotNull Codec<Set<T>> set(int maxSize)
    • set

      @NotNull default @NotNull Codec<Set<T>> set()
    • mapValue

      @NotNull default <V> @NotNull Codec<Map<T,V>> mapValue(@NotNull @NotNull Codec<V> valueCodec, int maxSize)
    • mapValue

      @NotNull default <V> @NotNull Codec<Map<T,V>> mapValue(@NotNull @NotNull Codec<V> valueCodec)
    • unionType

      default <R, T1 extends T, TR extends R> StructCodec<R> unionType(@NotNull @NotNull Function<T, StructCodec<TR>> serializers, @NotNull @NotNull Function<R,T1> keyFunc)
    • unionType

      default <R, T1 extends T, TR extends R> StructCodec<R> unionType(@NotNull @NotNull String keyField, @NotNull @NotNull Function<T, StructCodec<TR>> serializers, @NotNull @NotNull Function<R,T1> keyFunc)
    • orElse

      default Codec<T> orElse(@NotNull @NotNull Codec<T> other)