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

chevron-rightOfhashtag

Create a Machine object from a BlockEntity or BlockContainerarrow-up-right objects.

let machine = CustomMachine.of(blockEntity);
let machine = CustomMachine.of(blockContainer);
chevron-rightIdhashtag

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

chevron-rightDatahashtag

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++
chevron-rightOwnerhashtag
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;
chevron-rightPausehashtag

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

chevron-rightEnergyhashtag
chevron-rightFluidshashtag
chevron-rightItemshashtag
chevron-rightChunkloadhashtag
chevron-rightComponents IO confighashtag

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 herearrow-up-right. The usage of tools like ProbeJS arrow-up-righton the Javascript side is greatly encouraged.

Mekanism support

circle-info

The following methods are only available if Custom Machinery Mekanismarrow-up-right addon is installed.

chevron-rightChemicalshashtag

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.

chevron-rightHeat/Temperaturehashtag
chevron-rightRadiationshashtag

Create support

circle-info

The following methods are only available if Custom Machinery Createarrow-up-right addon is installed.

chevron-rightStresshashtag
chevron-rightSpeedhashtag

Last updated