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
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.
Machine machine = ctx.machine;
//Get the MapData from the machine.
var data = machine.data;
//Put something in the data :
data.put("power", 2)Energy
Machine machine = ctx.machine;
//Return the energy stored in the machine internal buffer.
var energy = machine.energyStored;
//Return the maximum capacity of the machine energy storage.
var energyCapacity = machine.energyCapacity;
//Return the amount of energy that was successfully added to the machine (or amountToAdd if all the energy was inserted).
//If simulate is `false` the energy will really be inserted, otherwise it wont.
//amountToAdd MUST be a positive value.
var addedEnergy = machine.addEnergy(amountToAdd, simulate);
//Return the amount of energy that was successfully removed from the machine (or amountToRemove if all the energy was extracted).
//If simulate is `false` the energy will really be extracted, otherwise it wont.
//amountToRemove MUST be a positive value.
var removedEnergy = machine.removeEnergy(amountToRemove, simulate);Fluids
Machine machine = ctx.machine;
//Return the fluid stored in the specified tank.
//The returned fluid is a CT IFluidStack, see docs : https://docs.blamejared.com/1.16/en/vanilla/api/fluid/IFluidStack
var fluid = machine.getFluidStored("tankID");
//Return the capacity of the specified tank.
var capacity = machine.getFluidCapacity("tankID");
//Add the specified fluid to the first available tank.
//Return the amount of fluid that couldn't be added.
//The passed fluid must be a CT IFluidStack, see docs : https://docs.blamejared.com/1.16/en/vanilla/api/fluid/IFluidStack
//If simulate is `false` the fluid will really be inserted, otherwise it wont.
var remaining = machine.addFluid(fluid, simulate);
//Add the specified fluid to the specified tank.
//Return the amount of fluid that couldn't be added.
//The passed fluid must be a CT IFluidStack, see docs : https://docs.blamejared.com/1.16/en/vanilla/api/fluid/IFluidStack
//If simulate is `false` the fluid will really be inserted, otherwise it wont.
var remaining = machine.addFluidToTank("tankID", fluid, simulate);
//Remove the specified fluid from the first available tank.
//Return the fluid that was successfully removed.
//Both passed and returned fluids must be a CT IFluidStack, see docs : https://docs.blamejared.com/1.16/en/vanilla/api/fluid/IFluidStack
//If simulate is `false` the fluid will really be removed, otherwise it wont.
var removedFluid = machine.removeFluid(fluid, simulate);
//Remove the specified amount of fluid from the specified tank.
//Return the fluid that was successfully removed.
//The returned fluid is a CT IFluidStack, see docs : https://docs.blamejared.com/1.16/en/vanilla/api/fluid/IFluidStack
//The specified amount MUST be a positive integer value.
//If simulate is `false` the fluid will really be removed, otherwise it wont.
var remaining = machine.removeFluidFromTank("tankID", amount, simulate);Last updated