Skip to content

JS Machine

Frinn38 edited this page Apr 28, 2022 · 1 revision

Context is the object provided in the function requirement using the KubeJS integration.

It contains various methods for interacting with the machine.

Methods

Energy

var 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

var machine = ctx.machine;

//Return the fluid stored in the specified tank.
//The returned fluid is a KubeJS FluidStackJS, see code: https://github.com/KubeJS-Mods/KubeJS/blob/1.16/main/common/src/main/java/dev/latvian/kubejs/fluid/FluidStackJS.java
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 KubeJS FluidStackJS, create one with Fluid.of("namespace:fluidID", amount)
//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 KubeJS FluidStackJS, create one with Fluid.of("namespace:fluidID", amount)
//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 KubeJS FluidStackJS, see code: https://github.com/KubeJS-Mods/KubeJS/blob/1.16/main/common/src/main/java/dev/latvian/kubejs/fluid/FluidStackJS.java
//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 KubeJS FluidStackJS, see code: https://github.com/KubeJS-Mods/KubeJS/blob/1.16/main/common/src/main/java/dev/latvian/kubejs/fluid/FluidStackJS.java
//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 KubeJS ItemStackJS, see docs : https://kubejs.com/wiki/kubejs/ItemStackJS/
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 KubeJS ItemStackJS, create one using Item.of("namespace:itemID", amount)
//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 KubeJS ItemStackJS, see docs : https://kubejs.com/wiki/kubejs/ItemStackJS/
//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);

Clone this wiki locally