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).

java
Copy
@ZenExpansion("crafttweaker.item.IItemStack")
@ZenRegister
public 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:

ZenScript
Copy
val oreDict = <minecraft:iron_ingot> as IOreDictEntry;

What methods can be annotated || Additional Info

Link to 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.