Variable Types
Link to variable-types
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 Copyvar 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
, which is the type used for items. Unfortunately, some types need to be imported first, and this is one of those.
ZenScript Copyimport 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) | 解释 | 例子 | 导入 |
---|---|---|---|
Name (Name in CT) Integer (int) | 解释 Integers are whole Numbers (e.g. 1,2,3,...), caps at 2 147 483 647 | 例子 var test = 10 as int; | 导入 |
Name (Name in CT) IItemstack | 解释 Single items | 例子 var test = <minecraft:dirt> as IItemStack; | 导入 import crafttweaker.item.IItemStack; |
Name (Name in CT) 材料(IIngredient) | 解释 Single or Multiple Items (e.g. <minecraft:dirt> , <ore:ingotIron> ,...) | 例子 var test = <minecraft:dirt> as IIngredient; | 导入 import crafttweaker.item.IIngredient; |
Name (Name in CT) IOreDictEntry | 解释 Multiple Items from an OreDict (e.g. <ore:ingotIron> , <ore:ingotGold> ,...) | 例子 var test = <ore:ingotIron> as IOreDictEntry; | 导入 import crafttweaker.oredict.IOreDictEntry |
Name (Name in CT) Boolean (bool) | 解释 Booleans are either true or false. | 例子 var test = false as bool; | 导入 |
Name (Name in CT) Byte (byte) | 解释 Bytes values are whole numbers from 0 to 255 () | 例子 var test = 125 as byte; | 导入 |
Name (Name in CT) Floating Point (float) | 解释 Decimals | 例子 var test = 1.25 as float; | 导入 |
Name (Name in CT) Double Precision (double) | 解释 Like Floating Points, just more precise and with a higher number range | 例子 var test = 1.25 as double; | 导入 |
Name (Name in CT) Long (long) | 解释 Like Integer, but with a higher number range (usually int is just fine) | 例子 var test = 30 as long; | 导入 |
Name (Name in CT) Null (null) | 解释 Null, nothing, nada. Not really a type but still useful | 例子 var test = null; | 导入 |
Name (Name in CT) Short (short) | 解释 Like Integer, but with a smaller number Range | 例子 var test = 16 as short; | 导入 |
Name (Name in CT) String (string) | 解释 A string is a text. Here you usually won't need the "as" as anything in "s is automatically a string. | 例子 var test = "Hello World!" as string; | 导入 |
Name (Name in CT) Void (void) | 解释 Even less than null. You will probably only need the void type when dealing with functions | 例子 var test as void; | 导入 |
Name (Name in CT) ILiquidStack | 解释 Same as IItemStack, only for liquids | 例子 var test = <liquid:water> as ILiquidStack; | 导入 import crafttweaker.liquid.ILiquidStack; |