Class MinecraftSerializers

java.lang.Object
ca.stellardrift.confabricate.typeserializers.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 Details

    • 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:
    • 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:
    • codec

      public static <V> @Nullable com.mojang.serialization.Codec<V> codec(io.leangen.geantyref.TypeToken<V> type, TypeSerializerCollection collection)
      Create a new codec based on a Configurate TypeSerializer.
      Type Parameters:
      V - value type
      Parameters:
      type - type to serialize
      collection - source for values
      Returns:
      a codec, or null if an appropriate TypeSerializer could not be found for the TypeToken.
      Since:
      2.0.0
      See Also:
    • populateRegistry

      public static <T> void populateRegistry(TypeSerializerCollection.Builder builder, io.leangen.geantyref.TypeToken<T> entryType, net.minecraft.core.RegistryAccess access, net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> registry)
      Populate a type serializer collection with all applicable serializers for values in a registry.

      This includes a serializer for the literal values, a serializer for Holders of values, and a serializer for HolderSets (tags) of values.

      Type Parameters:
      T - the type registered by the registry
      Parameters:
      builder - the builder to populate
      entryType - the type contained in the registry
      access - registry access to read the registry contents from
      registry - the registry to query
      Since:
      3.0.0
    • collection

      The default collection of game serializers.

      While the collection is mutable, modifying it is discouraged in favor of working with a new child, created with TypeSerializerCollection.childBuilder() ()}. Collections of serializers will become immutable in Configurate 4.0

      Returns:
      minecraft serializers
      Since:
      1.2.0
      See Also:
    • 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
    • populate

      Register Minecraft TypeSerializers with the provided collection.

      This will add serializers for:

      • resource locations
      • Component (as a string)
      • Any individual elements in vanilla registries, as raw values or Holder
      • HolderSet of a combination of identifiers and tags for any taggable registry
      • ItemStack
      • CompoundTag instances
      Parameters:
      collection - to populate
      Returns:
      provided collection
      Since:
      1.2.0