Machine

Interact directly with the machine in CT scripts

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

It contains various methods for interacting with the machine.

Methods

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.

var machine = ctx.machine;

//Return the machine id as a string.
var id = machine.id;

//Change the machine ID
machine.id = "namespace:machine_id"
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.

In a CT script the data is retrieved as a MapDataarrow-up-right.

var machine = ctx.machine;

//Get the MapData from the machine.
var data = machine.data;

//Put something in the data : 
data.put("power", 2)
chevron-rightOwnerhashtag
var machine = ctx.machine;

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

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

//Check if an entity is the owner of the machine.
var 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.
var 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.

var machine = ctx.machine;

//Return true if the machine is paused, false otherwise
var paused = machine.paused;

//Pause the machine
machine.paused = true;

//Resume the machine
machine.pause = false;
chevron-rightEnergyhashtag
chevron-rightFluidshashtag
chevron-rightItemshashtag
chevron-rightChunkloadhashtag

Mekanism support

circle-info

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

chevron-rightChemicals (Gas, Infusion, Pigment, Slurry)hashtag

The following methods are available for all supported chemical types, simply change 'XXX' by the type of chemical you want to manipulate : 'Gas', 'Infusion', 'Pigment', 'Slurry'

All chemicals used here must be a Crafttweaker ChemicalStackarrow-up-right corresponding to the used chemical type.

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

Last updated