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

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);
Items
Machine machine = ctx.machine;

//Return the item stored in the specified slot.
//The returned item is a CT IItemStack, see docs : https://docs.blamejared.com/1.16/en/vanilla/api/items/IItemStack
var item = machine.getItemStored("slotID");

//Return the capacity of the specified slot.
var capacity = machine.getItemCapacity("slotID");

//Add the specified item to the specified slot.
//Return the item that couldn't be added, or an empty ItemStack if all items were successfully added.
//The passed item must be a CT IItemStack, see docs : https://docs.blamejared.com/1.16/en/vanilla/api/items/IItemStack
//If simulate is `false` the item will really be inserted, otherwise it wont.
var remaining = machine.addItemToSlot("slotID", itemToAdd, simulate);

//Remove the specified amount of item from the specified slot.
//Return the item that were successfully removed, or an empty ItemStack if the slot was empty.
//The returned item is a CT IItemStack, see docs : https://docs.blamejared.com/1.16/en/vanilla/api/items/IItemStack
//The specified amount MUST be a positive integer value.
//If simulate is `false` the item will really be extracted, otherwise it wont.
var extracted = machine.removeItemFromSlot("slotID", amountToRemove, simulate);

Last updated