The IterableAnnotation can be applied to a class to allow ZS Iterating over it.
There are three kinds of IterableAnnotations:

  • @IterableSimple (needs to implement Iterable)
  • @IterableList (needs to implement List)
  • @IterableMap (needs to implement Map)

CraftTweaker's IOreDict

java
Copy
@ZenClass("crafttweaker.oredict.IOreDict")
@IterableSimple("crafttweaker.oredict.IOreDictEntry")
@ZenRegister
public interface IOreDict extends Iterable<IOreDictEntry> {


    @ZenMemberGetter
    @ZenOperator(OperatorType.INDEXGET)
    @ZenMethod
    IOreDictEntry get(String name);

    @ZenGetter("entries")
    List<IOreDictEntry> getEntries();

    @ZenOperator(OperatorType.CONTAINS)
    @ZenMethod
    boolean contains(String name);
}

MCOreDict (implementation)

java
Copy
    @Override
    public Iterator<IOreDictEntry> iterator() {
        return Arrays.asList(OreDictionary.getOreNames())
                .stream()
                .map(CraftTweakerMC::getOreDict)
                .iterator();

    }

How would that be useable in ZS?

Link to how-would-that-be-useable-in-zs

ZenScript
Copy
for oreDictEntry in oreDict {
    print(oreDictEntry.name);
}

What Classes can be annotated || Additional Info

Link to what-classes-can-be-annotated--additional-info

You can annotate all classes that implement the required interface.
You need to provide a String value that refers to the Iterated ZenScript's class name.