MutableDataComponentHolder

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.neoforge.api.component.MutableDataComponentHolder;

Description

An interface that stores DataComponents

Implements

MutableDataComponentHolder implements the following interfaces:

DataComponentHolder

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 MutableDataComponentHolder) as bool
myDataComponentType<?> in myMutableDataComponentHolder

Parameters:

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

Return Type: bool

Members

applyComponents(components as DataComponentMap)
script.zs
// MutableDataComponentHolder.applyComponents(components as DataComponentMap);
myMutableDataComponentHolder.applyComponents(myDataComponentMap);

Parameters:

applyComponents(patch as DataComponentPatch)
script.zs
// MutableDataComponentHolder.applyComponents(patch as DataComponentPatch);
myMutableDataComponentHolder.applyComponents(myDataComponentPatch);

Parameters:

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

Return Type: DataComponentMap

copyFrom(src as DataComponentHolder, componentTypes as DataComponentType<?>[])
script.zs
// MutableDataComponentHolder.copyFrom(src as DataComponentHolder, componentTypes as DataComponentType<?>[]);
myMutableDataComponentHolder.copyFrom(myDataComponentHolder, myDataComponentType<?>[]);

Parameters:

componentTypes Type: DataComponentType<?>[]
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
// MutableDataComponentHolder.getComponent<T>(type as DataComponentType<T>) as T;
myMutableDataComponentHolder.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
// MutableDataComponentHolder.getJsonComponent(type as DataComponentType<T>) as IData;
myMutableDataComponentHolder.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
// MutableDataComponentHolder.getOrDefault<T>(type as DataComponentType<T>, defaultValue as T) as T;
myMutableDataComponentHolder.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
// MutableDataComponentHolder.has(type as DataComponentType<?>) as bool;
myMutableDataComponentHolder.has(<componenttype:minecraft:stack_size>);

Parameters:

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

Return Type: bool

remove(componentType as DataComponentType<T>) as T?
script.zs
// MutableDataComponentHolder.remove<T>(componentType as DataComponentType<T>) as T?;
myMutableDataComponentHolder.remove<T>(myDataComponentType);

Parameters:

componentType Type: DataComponentType<T>

Return Type: T?

setComponent(componentType as DataComponentType<T>, value as T?) as T?
script.zs
// MutableDataComponentHolder.setComponent<T>(componentType as DataComponentType<T>, value as T?) as T?;
myMutableDataComponentHolder.setComponent<T>(myDataComponentType, myT);

Parameters:

componentType Type: DataComponentType<T>
value Type: T?

Return Type: T?

update(componentType as DataComponentType<T>, value as T, updater as UnaryOperator<T>) as T?
script.zs
// MutableDataComponentHolder.update<T>(componentType as DataComponentType<T>, value as T, updater as UnaryOperator<T>) as T?;
myMutableDataComponentHolder.update<T>(myDataComponentType, myT, myUnaryOperator);

Parameters:

componentType Type: DataComponentType<T>
value Type: T
updater Type: UnaryOperator<T>

Return Type: T?

update(componentType as DataComponentType<T>, value as T, updateContext as U, updater as BiFunction<T, T, U>) as T?
script.zs
// MutableDataComponentHolder.update<T, U>(componentType as DataComponentType<T>, value as T, updateContext as U, updater as BiFunction<T, T, U>) as T?;
myMutableDataComponentHolder.update<T, U>(myDataComponentType, myT, myU, myBiFunction);

Parameters:

componentType Type: DataComponentType<T>
value Type: T
updateContext Type: U
updater Type: BiFunction<T, T, U>

Return Type: T?