Interface DataComponentType<C extends DataComponent<?>>

Type Parameters:
C - The specific implementation of DataComponent associated with this type.

public interface DataComponentType<C extends DataComponent<?>>
Represents the definition and serialization logic for a specific type of DataComponent.

This interface acts as a factory and a registry key, providing the necessary Codec to transform component data to and from various formats (NBT, JSON, etc.).

  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieves the codec used for serializing and deserializing this component type.
    default C
    Attempts to create a new component instance directly from a raw value.
    static <C extends DataComponent<?>>
    DataComponentType<C>
    simple(Codec<C> codec)
    Creates a simple DataComponentType that relies solely on its codec for instantiation.
    static <C extends DataComponent<?>, V>
    DataComponentType<C>
    valued(Codec<C> codec, Function<V,C> factory)
    Creates a valued DataComponentType with a factory function for direct instantiation.
  • Method Details

    • codec

      Codec<C> codec()
      Retrieves the codec used for serializing and deserializing this component type.
      Returns:
      The Codec instance for components of type C.
    • createFromValue

      @Nullable default C createFromValue(Object value)
      Attempts to create a new component instance directly from a raw value.

      This is primarily utilized by the library's internal systems to wrap vanilla Minecraft data components or raw values into the AbyssalLib component system.

      Parameters:
      value - The raw value to wrap (e.g., an Integer for MaxStackSize).
      Returns:
      A new instance of C, or null if this type does not support direct factory creation.
    • simple

      static <C extends DataComponent<?>> DataComponentType<C> simple(Codec<C> codec)
      Creates a simple DataComponentType that relies solely on its codec for instantiation.
      Type Parameters:
      C - The component type.
      Parameters:
      codec - The Codec to handle data transformation.
      Returns:
      A new DataComponentType instance.
    • valued

      static <C extends DataComponent<?>, V> DataComponentType<C> valued(Codec<C> codec, Function<V,C> factory)
      Creates a valued DataComponentType with a factory function for direct instantiation.

      This variant is specifically intended for components that map to vanilla Minecraft data components, allowing the library to quickly wrap NMS values into the API.

      Type Parameters:
      C - The component type.
      V - The raw value type (e.g., Boolean, String, or custom object).
      Parameters:
      codec - The Codec for the component.
      factory - A Function that accepts a raw value of type V and returns a component of type C.
      Returns:
      A new DataComponentType instance with factory support.