Skip to content

GlobalFunctions

youyihj edited this page Oct 25, 2023 · 8 revisions

GlobalFunctions

Global functions to zenscript added by ZenUtils.

  • typeof: get an object's type. Returns String.
  • toString: Returns a string representation of the object.
  • addRegexLogFilter: takes a string regex, log messages that match the regex won't be log and sent to players. (totally suppressed)
  • arrayOf: takes an int and an optional object, creates a new object array with given length, and filled with an optional element.
  • intArrayOf: takes an int and an optional int, creates a new int array with given length, and filled with an optional element.
  • byteArrayOf: takes an int and an optional byte, creates a new byte array with given length, and filled with an optional element.
  • shortArrayOf: takes an int and an optional short, creates a new short array with given length, and filled with an optional element.
  • longArrayOf: takes an int and an optional long, creates a new long array with given length, and filled with an optional element.
  • floatArrayOf: takes an int and an optional float, creates a new float array with given length, and filled with an optional element.
  • doubleArrayOf: takes an int and an optional double, creates a new double array with given length, and filled with an optional element.
  • boolArrayOf: takes an int and an optional float, creates a new bool array with given length, and filled with an optional element.
  • scriptStatus: no argument, Returns an int representing the phase of the game. 0 -> initializing game. 1 -> Reloading scripts. 2 -> the game has started.

Example

import crafttweaker.item.IItemStack;

print(typeof(<ore:ingotIron>));
print(toString(<ore:ingotIron>));

// arrayOf returns Object[], which ZS doesn't expose. It is supposed to unchecked cast the result array with "left as"
val item as IItemStack = <item:minecraft:apple>;
val items as IItemStack[] = arrayOf(64, item);
print(items[15].commandString);

It will print:

[INITIALIZATION][CLIENT][INFO] crafttweaker.mc1120.oredict.MCOreDictEntry
[INITIALIZATION][CLIENT][INFO] <ore:ingotIron>
[INITIALIZATION][CLIENT][INFO] <minecraft:apple>

One more thing

These method can also be called in package mods.zenutils.ZenUtils. And due to internal limitation, the global function typeof cannot receive primitive classes (int, double, etc.) as the parameter. You can only use typeof method in the package to check the type of primitive classes.

Clone this wiki locally