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
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.
var machine = ctx.machine;
//Return the machine id as a string.
var id = machine.id;
//Change the machine ID
machine.id = "namespace:machine_id"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.
In a CT script the data is retrieved as a MapData.
var machine = ctx.machine;
//Get the MapData from the machine.
var data = machine.data;
//Put something in the data :
data.put("power", 2)Owner
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;Pause
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;Mekanism support
The following methods are only available if Custom Machinery Mekanism addon is installed.
Chemicals
All chemicals used here must be a Crafttweaker ChemicalStack.
Examples :
Put 500mB of steam gas in the first available tank.
Remove all the slurry stored in the "slurry" tank.
Last updated