Class MinecraftSerializers


  • public final class MinecraftSerializers
    extends Object
    Access serializers for Minecraft types.

    The collection() provides an easily accessible collection of built-in type serializers, while other factory methods allow creating custom type serializers that interact with game serialization mechanisms.

    Since:
    1.2.0
    • Method Detail

      • serializer

        public static <V> TypeSerializer<V> serializer​(com.mojang.serialization.Codec<V> codec)
        Create a new serializer wrapping the provided Codec.
        Type Parameters:
        V - value type
        Parameters:
        codec - codec to use for the serialization operation
        Returns:
        a new serializer
        Since:
        2.0.0
        See Also:
        for more information
      • codec

        public static <S> @Nullable com.mojang.serialization.Codec<S> codec​(io.leangen.geantyref.TypeToken<S> type)
        Create a new codec that uses the default type serializer collection to serialize an object of the provided type.
        Type Parameters:
        S - value type
        Parameters:
        type - token representing a value type
        Returns:
        a codec for the type, or null if an appropriate TypeSerializer could not be found.
        Since:
        2.0.0
        See Also:
        for more information
      • forRegistry

        public static <T> TypeSerializer<T> forRegistry​(Registry<T> registry)
        Create a TypeSerializer than can interpret values in the provided registry.
        Type Parameters:
        T - the type registered by the registry
        Parameters:
        registry - the registry
        Returns:
        a serializer for the registry
        Since:
        1.2.0
      • isCommonCollection

        public static boolean isCommonCollection​(TypeSerializerCollection collection)
        Check if a collection is our populated collection without attempting to initialize serializers.

        This helps to integrate with Confabricate in test environments.

        Parameters:
        collection - collection to test
        Returns:
        if tested collection is the confabricate default collection
        Since:
        1.2.0