-
Notifications
You must be signed in to change notification settings - Fork 0
Creating a Script
There are 3 requirements for Scripter to be able to see script-files:
- They have to be located in /config/Scripter, or a subdirectory therein
- They have to contain the word
scripter
in their file-name - They have to have the extension
.js
File-names need to contain scripter
as this allows one to create other JS scripts in the same folder, that will not be read by Scripter. This allows one to have a central file that houses commonly used functions across several scripts etc.
The very first line has to be a comment. This comment is read by Scripter as it maps what scripts to call during a specific event.
If one uses the comment //PlayerInteractEvent.RightClickBlock
on the first line, then Scripter will execute this script when this event is called.
For a full list of events one can use, please read [events].
There is one further limitation on scripts. Scripter will only call one function from each script-file, and this function has to be named onEvent
and it has to have a single parameter, for example: var onEvent = function(event){}
This function can be seen as a miniature main
method, for this script. You can call other functions from this, and they will be executed during the specified event.
//PlayerInteractEvent.RightClickBlock
var onEvent = function(event){
//Events with hands are often fired twice, once for each hand!
if(event.getHand().name() === "MAIN_HAND"){
var ItemStack = Java.type("net.minecraft.item.ItemStack");
var Helper = Java.type("matryoshika.scripter.HelperMethods");
var Item = Helper.getItem("minecraft:bone");
var EntityItem = Java.type("net.minecraft.entity.item.EntityItem");
var pos = Helper.getPosition(event.getEntityPlayer());
var Entity = new EntityItem(event.getWorld(), pos[0], pos[1], pos[2], new ItemStack(Item));
//func_72838_d = spawnEntity()
event.getWorld().func_72838_d(Entity);
}
}