Class ComponentType
java.lang.Object
com.saicone.rtag.data.ComponentType
Class to invoke methods inside DataComponentType and handle types in a flexible way.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionall()Get all DataComponentType objects associated with its ID.static com.mojang.serialization.Codec<Object> Get declared codec from DataComponentType instance or ID.
Take in count that not all the component types provide a codec instance.static com.mojang.serialization.Codec<Object> Get declared codec from DataComponentType ID.
Take in count that not all the component types provide a codec instance.static <T> TcreateGlobalContext(Object dynamicOps) Create a serialization context using a globalized registry.static <T> TcreateSerializationContext(Object dynamicOps, Object provider) Create a serialization context using HolderLookup.Provider.static <T> Optional<T> Encode declared component object type into declared object from object provider type.encodeJava(Object type, Object component) Encode declared component object type into regular Java object.static Optional<com.google.gson.JsonElement> encodeJson(Object type, Object component) Encode declared component object type into json object.Encode declared component object type into tag object.static booleanCheck if the provided DataComponentType ID exists.static booleanCheck if the provided object is instance of DataComponentType.static StringParse provided component key into namespaced format.static ObjectGet provided DataComponentType or parse from ID.
This method may return a null object if the provided ID doesn't exist.static ObjectParse DataComponentType from ID.Parse provided object by object provider into new component declared type.Parse provided object into new component declared type.
This method allows any NBT, JsonElement and regular Java object to parse.Parse provided regular Java object into new component declared type.Parse provided json into new component declared type.Parse provided tag into new component declared type.
-
Field Details
-
NBT_OPS
NbtOps public instance from Minecraft code. -
JAVA_OPS
JavaOps public instance from DataFixerUpper library.
-
-
Method Details
-
of
-
of
-
all
-
codec
Get declared codec from DataComponentType instance or ID.
Take in count that not all the component types provide a codec instance.- Parameters:
type- the data type to get codec.- Returns:
- a codec from DataComponentType or from cache by ID.
-
codec
-
key
-
isType
Check if the provided object is instance of DataComponentType.- Parameters:
object- the object to check.- Returns:
- true if the object is a DataComponentType.
-
exists
Check if the provided DataComponentType ID exists.- Parameters:
name- the type name to check.- Returns:
- true if the component type exists.
-
createGlobalContext
-
createSerializationContext
Create a serialization context using HolderLookup.Provider.- Type Parameters:
T- the expected type of object.- Parameters:
dynamicOps- the DynamicOps instance to wrap.provider- the access provider.- Returns:
- a serialization context.
-
parse
Parse provided object into new component declared type.
This method allows any NBT, JsonElement and regular Java object to parse.- Parameters:
type- the DataComponentType instance or ID with declared type.object- the object to parse into component object type.- Returns:
- an optional object with the result of conversion.
-
parse
public static <T> Optional<Object> parse(Object type, com.mojang.serialization.DynamicOps<T> dynamicOps, T object) Parse provided object by object provider into new component declared type.- Type Parameters:
T- the declared type.- Parameters:
type- the DataComponentType instance or ID with declared type.dynamicOps- the object provider to parse object.object- the object to parse into component object type.- Returns:
- an optional object with the result of conversion.
-
parseNbt
Parse provided tag into new component declared type.- Parameters:
type- the DataComponentType instance or ID with declared type.nbt- the nbt object to parse into component object type.- Returns:
- an optional object with the result of conversion.
-
parseJson
Parse provided json into new component declared type.- Parameters:
type- the DataComponentType instance or ID with declared type.json- the json object to parse into component object type.- Returns:
- an optional object with the result of conversion.
-
parseJava
Parse provided regular Java object into new component declared type.- Parameters:
type- the DataComponentType instance or ID with declared type.object- the object to parse into component object type.- Returns:
- an optional object with the result of conversion.
-
encode
public static <T> Optional<T> encode(Object type, com.mojang.serialization.DynamicOps<T> dynamicOps, Object component) Encode declared component object type into declared object from object provider type.- Type Parameters:
T- the declared type.- Parameters:
type- the DataComponentType instance or ID with declared type.dynamicOps- the object provider to create objects from type.component- the declared component object to encode.- Returns:
- an optional object with the result of conversion.
-
encodeNbt
Encode declared component object type into tag object.- Parameters:
type- the DataComponentType instance or ID with declared type.component- the declared component object to encode.- Returns:
- an optional object with the result of conversion.
-
encodeJson
Encode declared component object type into json object.- Parameters:
type- the DataComponentType instance or ID with declared type.component- the declared component object to encode.- Returns:
- an optional object with the result of conversion.
-
encodeJava
Encode declared component object type into regular Java object.- Parameters:
type- the DataComponentType instance or ID with declared type.component- the declared component object to encode.- Returns:
- an optional object with the result of conversion.
-