As you surely already messed a bit with variables and values, you must've wondered, how CraftTweaker knows whether it's dealing with an Integer, an Item or an oreDic entry?

The easiest way of declaring a variable is using var name = value;. This creates the variable and casts it to the value it thinks is most fitting for the situation.

Casting a variable to a specific type

Link to casting-a-variable-to-a-specific-type

More complex scripts might require you to cast a variable as a specific type. For example, this would fail:

ZenScript
Copy
var test;

test = <minecraft:dirt>;
recipes.remove(test);

So why does this fail? This is because CT casts variables that aren't given a start value to the IAny Type. That type was made to facilitate some recipe handlers, though never really implemented, so it sometimes does more harm than good. It was originally intended as a type that can take the form of most other types so you don't need to change variables all the time, but the interface never got implemented.

Back to the topic: How can we fix this issue? By casting the variable test to [IItemStack](/Vanilla/Items/IItemStack/), which is the type used for items. Unfortunately, some types need to be imported first, and this is one of those.

ZenScript
Copy
import crafttweaker.item.IItemStack;
var test as IItemStack;

test = <minecraft:dirt>;
recipes.remove(test);

List of Variable Types

Link to list-of-variable-types

Here's an (incomplete) List of most variable types

Name (Name in CT)ExplanationExampleImport
Name (Name in CT)
Integer (int)
Explanation
Integers are whole Numbers (e.g. 1,2,3,...), caps at 2 147 483 647
Example
var test = 10 as int;
Import
Name (Name in CT)
IItemStack
Explanation
Single items
Example
var test = <minecraft:dirt> as IItemStack;
Import
import crafttweaker.item.IItemStack;
Name (Name in CT)
IIngredient
Explanation
Single or Multiple Items (e.g. <minecraft:dirt>, <ore:ingotIron>,...)
Example
var test = <minecraft:dirt> as IIngredient;
Import
import crafttweaker.item.IIngredient;
Name (Name in CT)
IOreDictEntry
Explanation
Multiple Items from an OreDict (e.g. <ore:ingotIron>, <ore:ingotGold>,...)
Example
var test = <ore:ingotIron> as IOreDictEntry;
Import
import crafttweaker.oredict.IOreDictEntry
Name (Name in CT)
Boolean (bool)
Explanation
Booleans are either true or false.
Example
var test = false as bool;
Import
Name (Name in CT)
Byte (byte)
Explanation
Bytes values are whole numbers from 0 to 255 ()
Example
var test = 125 as byte;
Import
Name (Name in CT)
Floating Point (float)
Explanation
Decimals
Example
var test = 1.25 as float;
Import
Name (Name in CT)
Double Precision (double)
Explanation
Like Floating Points, just more precise and with a higher number range
Example
var test = 1.25 as double;
Import
Name (Name in CT)
Long (long)
Explanation
Like Integer, but with a higher number range (usually int is just fine)
Example
var test = 30 as long;
Import
Name (Name in CT)
Null (null)
Explanation
Null, nothing, nada. Not really a type but still useful
Example
var test = null;
Import
Name (Name in CT)
Short (short)
Explanation
Like Integer, but with a smaller number Range
Example
var test = 16 as short;
Import
Name (Name in CT)
String (string)
Explanation
A string is a text. Here you usually won't need the "as" as anything in "s is automatically a string.
Example
var test = "Hello World!" as string;
Import
Name (Name in CT)
Void (void)
Explanation
Even less than null. You will probably only need the void type when dealing with functions
Example
var test as void;
Import
Name (Name in CT)
ILiquidStack
Explanation
Same as IItemStack, only for liquids
Example
var test = <liquid:water> as ILiquidStack;
Import
import crafttweaker.liquid.ILiquidStack;