DataComponentHolder

Importing the class

If you need to reference this type directly, like when casting an Array, or as a parameter, you will need to import it. Simply add the import at the top of the file.

script.zs
import crafttweaker.api.component.DataComponentHolder;

Description

An interface that stores DataComponents

Implements

Undocumented Interfaces

IDataComponentHolderExtension

Operators

in(type as DataComponentType<?>) as bool
Checks whether the holder contains the given DataComponent, which is indentified by the type.
script.zs
// ((type as DataComponentType<?>) in DataComponentHolder) as bool
myDataComponentType<?> in myDataComponentHolder

Parameters:

type Type: DataComponentType<?> - The componenttype to check for.

Return Type: bool

Members

Getter
Gets the internal map of ComponentType -> Data
script.zs
// DataComponentHolder.components as DataComponentMap
myDataComponentHolder.components

Return Type: DataComponentMap

getComponent(type as DataComponentType<T>) as T
Gets the data identified by the given DataComponentType. If the ComponentHolder does not have the Component, then null is returned.

Returns: The value if it exists or null.

script.zs
// DataComponentHolder.getComponent<T>(type as DataComponentType<T>) as T;
myDataComponentHolder.getComponent<T>(<componenttype:minecraft:stack_size>);

Parameters:

type Type: DataComponentType<T> - The componenttype to get

Return Type: T

getJsonComponent(type as DataComponentType<T>) as IData
Get an arbitrary component by type. This is useful to interact with components added by mods that do not have a CraftTweaker method.
If the ComponentAccess does not have the type, an exception is thrown. If the ComponentAccess is not serializable, an exception is thrown.

Returns: A IData representation of the Serialized DataComponent

script.zs
// DataComponentHolder.getJsonComponent(type as DataComponentType<T>) as IData;
myDataComponentHolder.getJsonComponent(<componenttype:minecraft:stack_size>);

Parameters:

type Type: DataComponentType<T> - The componenttype to target.

Return Type: IData

getOrDefault(type as DataComponentType<T>, defaultValue as T) as T
Gets the data identified by the given DataComponentType. If the ComponentHolder does not have the Component, then the default value is returned.

Returns: The value if it exists or the default value.

script.zs
// DataComponentHolder.getOrDefault<T>(type as DataComponentType<T>, defaultValue as T) as T;
myDataComponentHolder.getOrDefault<T>(<componenttype:minecraft:stack_size>, 64);

Parameters:

type Type: DataComponentType<T> - The componenttype to get
defaultValue Type: T - The default value to return in the event that the holder does not have the component.

Return Type: T

has(type as DataComponentType<?>) as bool
Checks whether the holder contains the given DataComponent, which is indentified by the type.

Returns: Whether the holder contains the DataComponent.

script.zs
// DataComponentHolder.has(type as DataComponentType<?>) as bool;
myDataComponentHolder.has(<componenttype:minecraft:stack_size>);

Parameters:

type Type: DataComponentType<?> - The componenttype to check for.

Return Type: bool