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.
import crafttweaker.api.component.DataComponentHolder;
Description
An interface that stores DataComponentsImplements
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
myDataComponentType<?> in myDataComponentHolder
Parameters:
Return Type:
bool
Members
Getter
Gets the internal map of ComponentType -> Data script.zs
// DataComponentHolder.components as DataComponentMapmyDataComponentHolder.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.script.zs
Returns: The value if it exists or null.
myDataComponentHolder.getComponent<T>(<componenttype:minecraft:stack_size>);
Parameters:
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.script.zs
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
myDataComponentHolder.getJsonComponent(<componenttype:minecraft:stack_size>);
Parameters:
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.script.zs
Returns: The value if it exists or the default value.
myDataComponentHolder.getOrDefault<T>(<componenttype:minecraft:stack_size>, 64);
Parameters:
defaultValue: T
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. script.zs
Returns: Whether the holder contains the DataComponent.
myDataComponentHolder.has(<componenttype:minecraft:stack_size>);
Parameters:
Return Type:
bool