ZenCaster
A ZenCaster denotes a method that can be called using the as
token.
ZenCasters can be used to convert one type into another (e.g. Strings to IData).
Example
@ZenExpansion("crafttweaker.item.IItemStack")@ZenRegisterpublic class Expansion { @ZenMethod public static void print(IItemStack stack) { CraftTweakerAPI.logInfo("STACKKKKK: " + stack.getDisplayName()); }
@ZenCaster public static IOreDictEntry asOreDict(IItemStack stack) { return stack.getOres().get(0); }}
If someone now would call this, they would get an oreDictEntry:
val oreDict = <minecraft:iron_ingot> as IOreDictEntry;
What methods can be annotated || Additional Info
- You can annotate all nonstatic methods (unless in a ZenExpansion, as they only consist of statics)
- Annotated Methods need one parameter when in a ZenExpansion, none if they are in a ZenClass.
- Don’t rely on ZenCasters in ZenClasses, they only work reliably in ZenExpansions.