Scripts

A simple explanation on how to use scripting in Iris. You find & create scripts in the 'scripts' folder.

Defining Scripts

You will need to understand a bit about Plugins & Java before diving head first into this. While it is JavaScript, it's really just a scripting medium to access & modify Java code / variables.

You can define scripts in your project under the scripts folder. Scripts have a .js file extension and are written in JavaScript.

Iris.info("Hello World!");

You can then run this script with /iris studio execute <script>

Data Preprocessors

Any Iris data type (except scripts & objects) can have preprocessors added to them. Take this biome for example

{
    "preprocessors": [
        "name-prefixer"
    ],
    "name": "Flat",
    "derivative": "PLAINS",
    "layers": [
        {
            "palette": [
                {
                    "block": "minecraft:glass"
                }
            ]
        }
    ],
    "generators": [
        {
            "generator": "flat",
            "min": 60,
            "max": 60
        }
    ]
}

Notice that we have added the preprocessor name-prefixer.js . This script will be called when this json file is loaded into an IrisBiome class. You can then change properties about this biome object right before it's actually used by the generator. Let's prefix it with the dimension name!

// Get the object iris is currently loading
biome = Iris.getPreprocessorObject();

// Get the dimension file the current engine is using
dimension = Iris.getEngine().getDimension();

// Change the biome name to "Overworld Plains" (instead of "Plains")
biome.setName(dimension.getName() + " " + biome.getName());

Documentation & Methods

We are using Rhino by Mozilla to run JS. Because of this, you are capable of actually running anything that exists on the JVM (mc server). For example, you could use the Bukkit API just like any plugin would... send a message to every player?

// It's easier to loop over a list in JS instead of a collection
players = org.bukkit.bukkit.getOnlinePlayers().stream().toList();

for(i = 0; i < players.size(); i++)
{
    player = players.get(i);
    player.sendMessage("Hello " + player.getName() + "!");
}

Using the Iris API

The Iris api is given to you via the namespace Iris. However it's actually pointing to the IrisScriptingAPI class. Take a look at that class, and you will see it has methods in it to access parts of Iris specifically.

Avoid accessing fields in the IrisScriptingAPI class, Instead of using Iris.location, use Iris.getLocation().

Last updated