Machine

Interact directly with the machine in JS scripts

Machine is one of the object provided in the function requirement event.

It contains various methods for interacting with the machine.

Methods

Of

Create a Machine object from a BlockEntity or BlockContainer objects.

let machine = CustomMachine.of(blockEntity);
let machine = CustomMachine.of(blockContainer);
Id

Get the id of the machine, the id is a String of the format : namespace:path.

You can also change the machine id, the machine will switch to the specified machine, inventory will be preserved as long as machines have similar inventories.

let machine = ctx.machine

//Get the machine ID
let id = machine.id

//Change the machine ID
machine.id = "namespace:machine_id"

Reminder : A machine stored in data/namespace/machines/machine.json will have the id : namespace:machine

Data

Add a way to store custom data in the machine.

The stored data will be stored in the machine as NBT and saved when the machine is unloaded, preventing loosing the data, for example, when the game is quitted.

KubeJS will treat the data as a Map.

//Get the data :
let data = ctx.machine.data;

//Put a number in the data :
data.power = 2;

//Increment that number : 
data.power++
Owner
let machine = ctx.machine;

//Get the machine owner name as a Component, or null if the machine doesn't have an owner.
let ownerName = machine.ownerName;

//Get the machine owner UUID, or null if the machine doesn't have an owner.
let ownerId = machine.ownerId;

//Check if an entity is the owner of the machine.
let isOwner = machine.isOwner(entity);

//Get the owner as a LivingEntity, or null if the machine doesn't have an owner.
//This only works if the entity that own the machine is loaded.
//If the owner is a player they must be connected.
//IF the owner is a mob it must be in a loaded chunk.
let owner = machine.owner;

//Set a LivingEntity as the new machine owner.
machine.owner = entity;
Pause

Allow to check if the machine is paused, and pause or resume it.

Energy
Fluids
Items
Chunkload
Components IO config

The following methods let you access and change the IO (input/output) config of any components of the machine (energy/fluid/item or addons).

Not all methods will be shown there, as this method expose java internals of Custom Machinery, a solid understanding of Javascript and/or Java code will be needed.

The source code can be viewed here. The usage of tools like ProbeJS on the Javascript side is greatly encouraged.

Mekanism support

The following methods are only available if Custom Machinery Mekanism addon is installed.

Chemicals

You can make a chemical stack with the following syntax : "100x mekanism:steam" where 100 is the amount in mB of the stack.

Examples :

Put 500mB of steam gas in the first available tank.

Remove all the slurry stored in the "slurry" tank.

Heat/Temperature
Radiations

Create support

The following methods are only available if Custom Machinery Create addon is installed.

Stress
Speed

Last updated