Interface DataComponentType<C extends DataComponent<?>>
- Type Parameters:
C- The specific implementation ofDataComponentassociated 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 TypeMethodDescriptioncodec()Retrieves the codec used for serializing and deserializing this component type.default CcreateFromValue(Object value) Attempts to create a new component instance directly from a raw value.static <C extends DataComponent<?>>
DataComponentType<C> Creates a simple DataComponentType that relies solely on its codec for instantiation.static <C extends DataComponent<?>, V>
DataComponentType<C> Creates a valued DataComponentType with a factory function for direct instantiation.
-
Method Details
-
codec
-
createFromValue
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, ornullif this type does not support direct factory creation.
-
simple
Creates a simple DataComponentType that relies solely on its codec for instantiation.- Type Parameters:
C- The component type.- Parameters:
codec- TheCodecto handle data transformation.- Returns:
- A new
DataComponentTypeinstance.
-
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- TheCodecfor the component.factory- AFunctionthat accepts a raw value of typeVand returns a component of typeC.- Returns:
- A new
DataComponentTypeinstance with factory support.
-