Skip to content
Matryoshika edited this page May 27, 2018 · 2 revisions

Syntax

Scripter's syntax makes use of Javascript for the actual language, however, Nashorn, the ScriptEngine that handles all Java<->Javascript adds some new functions when dealing with Java code.


Classes

One can import a Java class into scripts by calling var ArrayList = Java.type("java.util.ArrayList").
This is a static import. To create new instances you simply call the constructor with appropriate variables, for example var list = new ArrayList(otherList).

You will need to have a way of finding available methods & fields when utilizing Scripter.
When working with MinecraftForge, it is heavily adviced to have an IDE available with a dev-environment that you can use to navigate and search.


Super classes

You may find that your script can error with "undefined" when calling methods or accessing fields. This is caused by Nashorn not being able to properly call these Objects as they belong to a super class that your current object extends.
You need to cast your current object to it's super-class by calling var superObject = Java.super(Object).
If a method you want to use lies several layers up the parent-hierarchy, then you need to cast upwards till you arrive at your wanted Object.

Clone this wiki locally