Class ComponentType

java.lang.Object
com.saicone.rtag.data.ComponentType

@Experimental public class ComponentType extends Object
Class to invoke methods inside DataComponentType and handle types in a flexible way.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Object
    JavaOps public instance from DataFixerUpper library.
    static final Object
    NbtOps public instance from Minecraft code.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Map<String,Object>
    all()
    Get all DataComponentType objects associated with its ID.
    static com.mojang.serialization.Codec<Object>
    codec(Object type)
    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>
    codec(String name)
    Get declared codec from DataComponentType ID.
    Take in count that not all the component types provide a codec instance.
    static <T> T
    Create a serialization context using a globalized registry.
    static <T> T
    createSerializationContext(Object dynamicOps, Object provider)
    Create a serialization context using HolderLookup.Provider.
    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.
    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.
    encodeNbt(Object type, Object component)
    Encode declared component object type into tag object.
    static boolean
    exists(String name)
    Check if the provided DataComponentType ID exists.
    static boolean
    isType(Object object)
    Check if the provided object is instance of DataComponentType.
    static String
    key(String name)
    Parse provided component key into namespaced format.
    static Object
    of(Object type)
    Get provided DataComponentType or parse from ID.
    This method may return a null object if the provided ID doesn't exist.
    static Object
    of(String name)
    Parse DataComponentType from ID.
    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.
    parse(Object type, Object object)
    Parse provided object into new component declared type.
    This method allows any NBT, JsonElement and regular Java object to parse.
    parseJava(Object type, Object object)
    Parse provided regular Java object into new component declared type.
    parseJson(Object type, com.google.gson.JsonElement json)
    Parse provided json into new component declared type.
    parseNbt(Object type, Object nbt)
    Parse provided tag into new component declared type.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NBT_OPS

      @Experimental public static final Object NBT_OPS
      NbtOps public instance from Minecraft code.
    • JAVA_OPS

      @Experimental public static final Object JAVA_OPS
      JavaOps public instance from DataFixerUpper library.
  • Method Details

    • of

      public static Object of(Object type)
      Get provided DataComponentType or parse from ID.
      This method may return a null object if the provided ID doesn't exist.
      Parameters:
      type - the type to get.
      Returns:
      the same DataComponentType or a new one from cache.
    • of

      public static Object of(String name)
      Parse DataComponentType from ID.
      Parameters:
      name - the type name to get.
      Returns:
      a DataComponentType from cache or null if provided ID doesn't exist.
    • all

      public static Map<String,Object> all()
      Get all DataComponentType objects associated with its ID.
      Returns:
      an unmodifiable view of all types.
    • codec

      public static com.mojang.serialization.Codec<Object> codec(Object type)
      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

      public static com.mojang.serialization.Codec<Object> codec(String name)
      Get declared codec from DataComponentType ID.
      Take in count that not all the component types provide a codec instance.
      Parameters:
      name - the type name to get codec.
      Returns:
      a codec from cache by type ID.
    • key

      public static String key(String name)
      Parse provided component key into namespaced format.
      Parameters:
      name - the name key to parse.
      Returns:
      a namespaced key.
    • isType

      public static boolean isType(Object object)
      Check if the provided object is instance of DataComponentType.
      Parameters:
      object - the object to check.
      Returns:
      true if the object is a DataComponentType.
    • exists

      public static boolean exists(String name)
      Check if the provided DataComponentType ID exists.
      Parameters:
      name - the type name to check.
      Returns:
      true if the component type exists.
    • createGlobalContext

      @Internal public static <T> T createGlobalContext(Object dynamicOps)
      Create a serialization context using a globalized registry.
      Type Parameters:
      T - the expected type of object.
      Parameters:
      dynamicOps - the DynamicOps instance to wrap.
      Returns:
      a serialization context.
    • createSerializationContext

      @Internal public static <T> T createSerializationContext(Object dynamicOps, Object provider)
      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

      public static Optional<Object> parse(Object type, Object object)
      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

      public static Optional<Object> parseNbt(Object type, Object nbt)
      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

      public static Optional<Object> parseJson(Object type, com.google.gson.JsonElement json)
      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

      public static Optional<Object> parseJava(Object type, Object object)
      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

      public static Optional<Object> encodeNbt(Object type, Object component)
      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

      public static Optional<com.google.gson.JsonElement> encodeJson(Object type, Object component)
      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

      public static Optional<Object> encodeJava(Object type, Object component)
      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.