Home Commands Examples Getting Started With Scripts Global Keywords

IData

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;

Implemented Interfaces

IData implements the following interfaces. That means all methods defined in these interfaces are also available in IData

Static Methods

Creates a collection of the given IData members.


This attempts to give the most accurate type for the given members, for example, if all the members are bytes, then it returns a ByteArrayData.

However if the types are mixed or do not have a *ArrayData version, then a ListData is returned.

Returns: A list of the given members.
Return Type: IData

script.zs
// IData.listOf(members as IData[]) as IData
IData.listOf(1, 2, 3);
ParameterTypeDescription
Parameter
members
Type
IData[]
Description
The members to put in the list.

Casters

Result TypeIs Implicit
Result Type
boolean
Is Implicit
false
Result Type
byte
Is Implicit
false
Result Type
byte[]
Is Implicit
false
Result Type
double
Is Implicit
false
Result Type
float
Is Implicit
false
Result Type
IData[string]
Is Implicit
false
Result Type
int
Is Implicit
false
Result Type
int[]
Is Implicit
false
Result Type
long
Is Implicit
false
Result Type
long[]
Is Implicit
false
Result Type
short
Is Implicit
false
Result Type
stdlib.List<IData>
Is Implicit
false
Result Type
string
Is Implicit
false

Methods

Adds the given IData to this IData.

Returns: A new IData after adding the other data.
Return Type: IData

script.zs
// IData.add(other as IData) as IData
(1 as IData).add(2);
ParameterTypeDescription
Parameter
other
Type
IData
Description
the other data to add.

Casts this IData to a boolean.

Returns: this data as a bool
Return Type: boolean

script.zs
// IData.asBool() as boolean
(1 as IData).asBool();

Casts this IData to a byte.

Returns: this data as a byte
Return Type: byte

script.zs
// IData.asByte() as byte
(1 as IData).asByte();

Casts this IData to a byte array.

Returns: this data as a byte array
Return Type: byte[]

script.zs
// IData.asByteArray() as byte[]
(1 as IData).asByteArray();

Casts this IData to a double.

Returns: this data as a double
Return Type: double

script.zs
// IData.asDouble() as double
(1 as IData).asDouble();

Casts this IData to a float.

Returns: this data as a float
Return Type: float

script.zs
// IData.asFloat() as float
(1 as IData).asFloat();

Casts this IData to an int.

Returns: this data as an int
Return Type: int

script.zs
// IData.asInt() as int
(1 as IData).asInt();

Casts this IData to an int array.

Returns: this data as an int array
Return Type: int[]

script.zs
// IData.asIntArray() as int[]
(1 as IData).asIntArray();

Casts this IData to a list.

Returns: this data as a list
Return Type: stdlib.List<IData>

script.zs
// IData.asList() as stdlib.List<IData>
(1 as IData).asList();

Casts this IData to a long.

Returns: this data as a long
Return Type: long

script.zs
// IData.asLong() as long
(1 as IData).asLong();

Casts this IData to a long array.

Returns: this data as a long array
Return Type: long[]

script.zs
// IData.asLongArray() as long[]
(1 as IData).asLongArray();

Casts this IData to a map.

Returns: this data as a map
Return Type: IData[string]

script.zs
// IData.asMap() as IData[string]
(1 as IData).asMap();

Casts this IData to a short.

Returns: this data as a short
Return Type: short

script.zs
// IData.asShort() as short
(1 as IData).asShort();

Gets an escaped string version of this IData, quotes are included in the output

E.G println(("hello" as IData).asString()) prints "hello"

Returns: The escaped string version of this IData.
Return Type: string

script.zs
// IData.asString() as string
(1 as IData).asString();

Compares this IData to the other IData

Returns: The comparison result.
Return Type: int

script.zs
// IData.compareTo(other as IData) as int
(1 as IData).compareTo(5);
ParameterTypeDescription
Parameter
other
Type
IData
Description
the data to be compared.

Return Type: IData

script.zs
// IData.copy() as IData
(1 as IData).copy();

Gets the literal string version of this IData.

E.G println(("hello" as IData).getAsString()) prints hello

Returns: The literal string version of this IData.
Return Type: string

script.zs
// IData.getAsString() as string
(1 as IData).getAsString();

Gets the internal ID of this data.

Returns: the intenral ID of this data.
Return Type: byte

script.zs
// IData.getId() as byte
(1 as IData).getId();

Gets the keys of this IData

Returns: The keys of this IData.
Return Type: Set<string>

script.zs
// IData.getKeys() as Set<string>
(1 as IData).getKeys();

Checks if this data is empty.

Returns: True if empty.
Return Type: boolean

script.zs
// IData.isEmpty() as boolean
(1 as IData).isEmpty();

Gets the length of this IData.

Returns: The length of this IData.
Return Type: int

script.zs
// IData.length() as int
(1 as IData).length();

Maps this IData to another IData based on the given operation.

Returns: A new IData from the operation
Return Type: IData

script.zs
// IData.map(operation as Function<IData,IData>) as IData
(1 as IData).map((data) => 3);
ParameterTypeDescription
Parameter
operation
Type
Function<IData,IData>
Description
The operation to apply to this IData

Merges the given data with this data.

Returns: the result of merging the datas.
Return Type: IData

script.zs
IData.merge(other as IData) as IData
ParameterTypeDescription
Parameter
other
Type
IData
Description
the data to merge

Puts the given value inside this IData at the given index.

script.zs
// IData.put(index as string, value as IData?)
new MapData().put("key", "value");
ParameterTypeDescription
Parameter
index
Type
string
Description
The key to store the data at
Parameter
value
Type
IData?
Description
The data to store.

Removes the stored data at the given index.

script.zs
// IData.remove(index as int)
[1, 2, 3] as IData.remove(0);
ParameterTypeDescription
Parameter
index
Type
int
Description
The index to remove.

Removes the stored data at the given key.

script.zs
// IData.remove(key as string)
{key: "value"} as IData.remove("key");
ParameterTypeDescription
Parameter
key
Type
string
Description
The key to remove.

Sets the given value inside this IData at the given index.

script.zs
IData.setAt(name as string, data as IData?)
ParameterTypeDescription
Parameter
name
Type
string
Description
The key to store the data at
Parameter
data
Type
IData?
Description
The data to store.

Operators

Adds the given IData to this IData.

script.zs
myIData + other as IData
(1 as IData) + 2

Applies a bitwise AND (&) operation to this IData and the other IData

script.zs
myIData & other as IData
(1 as IData) & 2

Concatenates the given IData to this IData.

script.zs
myIData ~ other as IData
(1 as IData) ~ 2

Compares this IData to the other IData

script.zs
myIData < other as IData
(1 as IData) < 5

Checks if this IData contains the other IData


For most data types, this will check equality of the data, but for map data, it will check if the other data is a string, and then check if it contains a key with that name

script.zs
other as IData in myIData

Divides the given IData from this IData.

script.zs
myIData / other as IData
(1 as IData) / 2

Checks if this IData is equal to the other IData.

script.zs
myIData == other as IData

Gets the data at the given index.

script.zs
[myIData]
[[1, 2, 3] as IData]

Puts the given value inside this IData at the given index.

script.zs
[myIData] = index as string
[new MapData()] = "key"

Applies a modulo operation to this IData against the other IData.

script.zs
myIData % other as IData
(1 as IData) % 2

Multiplies the given IData to this IData.

script.zs
myIData * other as IData
(1 as IData) * 2

Negates this IData.

script.zs
-myIData
-(1 as IData)

Applies a NOT (!) operation to this IData.

script.zs
!myIData
!true

Applies a bitwise OR (|) operation to this IData and the other IData

script.zs
myIData | other as IData
(1 as IData) | 2

Applies a SHL (<<) operation to this data by the other data

script.zs
myIData << other as IData
(1 as IData) << 2

Applies a SHR (>>) operation to this data by the other data

script.zs
myIData >> other as IData
(1 as IData) >> 2

Subtracts the given IData from this IData.

script.zs
myIData - other as IData
(1 as IData) - 2

Applies a bitwise XOR (^) operation to this IData and the other IData

script.zs
myIData ^ other as IData
(1 as IData) ^ 2

Properties

NameTypeHas GetterHas SetterDescription
Name
isEmpty
Type
boolean
Has Getter
true
Has Setter
false
Description
Checks if this data is empty.
Name
keys
Type
Set<string>
Has Getter
true
Has Setter
false
Description
Gets the keys of this IData
Name
length
Type
int
Has Getter
true
Has Setter
false
Description
Gets the length of this IData.