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.


SRG names & Obfuscation

When dealing with classes from net.minecraft & com.mojang, you need to be careful as Mojang has Obfuscated their finished code, so that it is not as easily to read for humans. This affects methods & fields.
However, due to the nature of the Nashorn engine, one must call a method or field with their actual name, which isn't handled as a string.
world.spawnEntity(entity) must be referenced in scripts as world.func_72838_d(entity) instead. Please peruse the field & method.csv files located in /config/Scripter as you create your scripts.
These have been downloaded by Scripter from MCPBot, the Forge community's attempt of centralizing the work of translating the obfuscated names back to humanly readable ones.
This only affects Vanilla methods & fields!

Clone this wiki locally