Home Migration Guide Getting Started With Scripts Commands Examples
BracketHandlers

IData

The IData interface is a generic Interface for handling Data like NBT. You can cast about all primitives (short, double, string, int, …) as well as certain arrays to IData. Remember that while they offer similar features, IData and their counterparts are NOT the same, which is why they will be referred to as DataTypes (e.g. ByteData).

Importing the class

It might be required for you to import the package if you encounter any issues (like casting an Array), so better be safe than sorry and add the import at the very top of the file.

script.zs
import crafttweaker.api.data.IData;

Casters

Result typeIs Implicit
Result type
boolean
Is Implicit
false
Result type
ICollectionData
Is Implicit
false
Result type
INumberData
Is Implicit
false

Methods

Return Type: boolean

script.zs
// IData.asBoolean() as boolean
{Display: {lore: ["Hello", "World"]}}.asBoolean();

Return Type: ICollectionData

script.zs
// IData.asCollection() as ICollectionData
{Display: {lore: ["Hello", "World"]}}.asCollection();

Return Type: MCTextComponent

script.zs
IData.asFormattedText(indentation as string, indentDepth as int) as MCTextComponent
ParameterTypeDescription
Parameter
indentation
Type
string
Description
No Description Provided
Parameter
indentDepth
Type
int
Description
No Description Provided

Gets a List representation of this IData, returns null on anything but ListData.

Returns: null if this IData is not a list.
Return Type: stdlib.List<IData>

script.zs
// IData.asList() as stdlib.List<IData>
{Display: {lore: ["Hello", "World"]}}.asList();

Gets a Map<String, IData> representation of this IData, returns null on anything but MapData.

Returns: null if this IData is not a map.
Return Type: IData[string]

script.zs
// IData.asMap() as IData[string]
{Display: {lore: ["Hello", "World"]}}.asMap();

Return Type: INumberData

script.zs
// IData.asNumber() as INumberData
{Display: {lore: ["Hello", "World"]}}.asNumber();

Gets the String representation of this IData

Returns: String that represents this IData (value and type).
Return Type: string

script.zs
// IData.asString() as string
{Display: {lore: ["Hello", "World"]}}.asString();

Checks if this IData contains another IData, mainly used in subclasses of ICollectionData, is the same as an equals check on other IData types

Returns: true if the given IData is contained in this IData
Return Type: boolean

script.zs
// IData.contains(data as IData) as boolean
{Display: {lore: ["Hello", "World"]}}.contains("Display");
ParameterTypeDescription
Parameter
data
Type
IData
Description
data to check if it is contained

Makes a copy of this IData.

IData is immutable by default, use this to create a proper copy of the object.

Returns: a copy of this IData.
Return Type: IData

script.zs
// IData.copy() as IData
{Display: {lore: ["Hello", "World"]}}.copy();

Gets the ID of the internal NBT tag.

Used to determine what NBT type is stored (in a list for example)

Returns: ID of the NBT tag that this data represents.
Return Type: byte

script.zs
// IData.getId() as byte
{Display: {lore: ["Hello", "World"]}}.getId();

Gets the String representation of the internal INBT tag

Returns: String that represents the internal INBT of this IData.
Return Type: string

script.zs
// IData.getString() as string
{Display: {lore: ["Hello", "World"]}}.getString();