Class MinecraftSerializers
java.lang.Object
ca.stellardrift.confabricate.typeserializers.MinecraftSerializers
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 Summary
Modifier and TypeMethodDescriptionstatic <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.static <V> @Nullable com.mojang.serialization.Codec<V>codec(io.leangen.geantyref.TypeToken<V> type, TypeSerializerCollection collection) Create a new codec based on a ConfigurateTypeSerializer.static TypeSerializerCollectionThe default collection of game serializers.static booleanisCommonCollection(TypeSerializerCollection collection) Check if a collection is our populated collection without attempting to initialize serializers.populate(TypeSerializerCollection.Builder collection) Register MinecraftTypeSerializers with the provided collection.static <T> voidpopulateRegistry(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.static <V> TypeSerializer<V>serializer(com.mojang.serialization.Codec<V> codec) Create a new serializer wrapping the providedCodec.
-
Method Details
-
serializer
Create a new serializer wrapping the providedCodec.- 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
TypeSerializercould 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 ConfigurateTypeSerializer.- Type Parameters:
V- value type- Parameters:
type- type to serializecollection- source for values- Returns:
- a codec, or null if an appropriate
TypeSerializercould 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
Holdersof values, and a serializer forHolderSets(tags) of values.- Type Parameters:
T- the type registered by the registry- Parameters:
builder- the builder to populateentryType- the type contained in the registryaccess- registry access to read the registry contents fromregistry- 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
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
public static TypeSerializerCollection.Builder populate(TypeSerializerCollection.Builder collection) Register MinecraftTypeSerializers with the provided collection.This will add serializers for:
resource locationsComponent(as a string)- Any individual elements in vanilla
registries, as raw values orHolder HolderSetof a combination of identifiers and tags for any taggable registryItemStackCompoundTaginstances
- Parameters:
collection- to populate- Returns:
- provided collection
- Since:
- 1.2.0
-