This API wraps the functionality of the component robot to allow more intuitive interaction with the robot.
While the component robot has more generic functions like move([side: number])
or drop([side: number])
, this API has more intuitive and failsafe functions like turnRight
, dropDown
, forward
. Which one you use is up to you, you can even use both at the same time.
Note that a Robot is an OpenComputer like any other with just an additional robot component included, so the normal APIs are available as usual.
See Robot Block for additional information on the actual Robot.
The Robot's GUI displays the slots of a robot aligned from top-left to bottom-right. So for example the slot at index 1 is displayed in the top-left corner, the slot at index 2 is the next to the right and the first slot on the 2nd row is index 5.
How many slots a robot has available depends on it's setup. If a slot is specified in a function that exceeds the amount of slots a robot has available an error is thrown.
Robots are capable of complex movements, but some you may want to understand some nuances.
Robots have a flight-height limitation. The general movement rules for robots go like this:
flightHeight
above a solid block are valid (limited flight capabilities, default is 8).
Violating these rules will result in a the error impossible move
to be returned
You can install hover upgrades to increase (tier 1) and pretty much circumvent (tier 2) this limitation. Or you can disable this in the config, by setting limitFlightHeight
to 256 or so.
robot.name(): string
robot.detect(): boolean, string
true
if the robot if whatever is in front of the robot would prevent him from moving forward (a block or an entity) (Note: Drones return true
even if the block is passable
), false
otherwise. The second parameter describes what is in front in general and is one of either entity
, solid
, replaceable
, liquid
, passable
or air
.robot.detectUp(): boolean, string
robot.detect()
except that it scans the block directly above the robot.robot.detectDown(): boolean, string
robot.detect()
except that it scans the block directly below the robot.robot.select([slot: number]): number
robot.inventorySize(): number
robot.count([slot: number]): number
robot.space([slot: number]): number
robot.transferTo(slot: number[, count: number]): boolean
true
if exchanging the content between those slots was successful, false
otherwise.robot.compareTo(slot: number): boolean
true
if the item type in the specified slot and the currently selected slot are equal, false
otherwise.robot.compare(): boolean
robot.detect()
beforehand to determine if there is actually a block in front of the robot.robot.compareUp(): boolean
robot.compare
just for the block directly above the robot.robot.compareDown(): boolean
robot.compare
just for the block directly below the robot.robot.drop([count: number]): boolean
true
if at least one item was dropped, false
otherwise.robot.use
function to interact with those types of blocks.robot.dropUp(): boolean
robot.drop
just for the block directly above the robot.robot.dropDown(): boolean
robot.drop
just for the block directly below the robot.robot.suck([count: number]): boolean
true
if at least one item was picked up, false otherwise.robot.drop
and will interact with item inventories in the same way. However this will only take the first item available in that inventory. For more precise inventory management you need to install an inventory controller upgrade into the robot.false
.robot.suckUp([count: number]): boolean
robot.suck
except that it tries to pick up items from directly above the robot.robot.suckDown([count: number]): boolean
robot.suck
except that it tries to pick up items from directly below the robot.robot.place([side: number[, sneaky: boolean]]): boolean[, string]
true
the robot will simulate a sneak-placement (like if the player would be using shift during placement), which is usually not necessary and only included for compatibility to other mods.true
if an item could be placed, false
otherwise. If placement failed, the secondary return parameter will describe why the placement failed.robot.placeUp([side: number[, sneaky: boolean]]): boolean[, string]
robot.place
except that the robot tries to place the item into the space directly above it.robot.placeDown([side: number[, sneaky: boolean]]): boolean[, string]
robot.place
except that the robot tries to place the item into the space directly below it.robot.durability(): number, number, number or nil, string
nil
and an error message describing why no durability could be returned. The error message is one of no tool equipped
or tool cannot be damaged
.robot.swing([side: number, [sneaky:boolean]]): boolean[, string]
robot.swingUp([side: number, [sneaky:boolean]]): boolean[, string]
robot.swing
except that the block or entity directly above the robot will be the target.robot.swingDown([side: number, [sneaky:boolean]]): boolean[, string]
robot.swing
except that the block or entity directly below the robot will be the target.robot.use([side: number[, sneaky: boolean[, duration: number]]]): boolean[, string]
true
the robot will simulate a sneak-right-click (like if the player would be using shift during a right-click). Some items (like buckets) will behave differently if this is set to true.block_activated
- a block was activated (like levers, switches or doors).item_interacted
- the equipped tool interacted with the world, for example sheers when used on a sheep.item_placed
- something was placed into the world. This is not only caused by placeable blocks, but as well by items that cause blocks or entities to appear in the world (like flint and stone or mob eggs).item_used
- the equipped was activated, like a splash-potion.air
- the equipped item requires a target but there was none. Note that if your robot has an Angel upgrade, this will never be returned, however some actions might still cause no effect.robot.useUp([side: number[, sneaky: boolean[, duration: number]]]): boolean[, string]
robot.use
except that the item is used aiming at the area above the robot.robot.useDown([side: number[, sneaky: boolean[, duration: number]]]): boolean[, string]
robot.use
except that the item is used aiming at the area below the robot.robot.forward(): boolean[, string]
true
if the robot successfully moved, nil
otherwise. If movement fails a secondary result will be returned describing why it failed, which will either be 'impossible move', 'not enough energy' or the description of the obstacle as robot.detect
would return.robot.back(): boolean[, string]
robot.forward()
except that the robot tries to move backward.robot.up(): boolean[, string]
robot.forward()
except that the robot tries to move upwards.robot.down(): boolean[, string]
robot.forward()
except that the robot tries to move downwards.robot.turnLeft()
robot.turnRight()
robot.turnLeft
except that the robot turns 90° to the right.robot.turnAround()
robot.turnRight
twice.robot.level(): number
component.experience.level()
instead (only available if the experience upgrade is installed).1.5
, then the robot is level one, and 50% towards achieving level two.robot.tankCount():number
robot.selectTank(tank)
robot.tankLevel([tank:number]):number
robot.tankSpace():number
robot.compareFluidTo(tank:number):boolean
robot.transferFluidTo(tank:number[, count:number]):boolean
robot.compareFluid():boolean
robot.compareFluidUp():boolean
compareFluid
, but operates on the block above the robot.robot.compareFluidDown():boolean
compareFluid
, but operates on the block below the robot.robot.drain([count:number]):boolean
robot.drainUp([count:number]):boolean
drain
, but operates on the block above the robot.robot.drainDown([count:number]):boolean
drain
, but operates on the block below the robot.robot.fill([count:number]):boolean
robot.fillUp([count:number]):boolean
fill
, but operates on the block above the robot.robot.fillDown([count:number]):boolean
fill
, but operates on the block below the robot.durability():number
move(direction:number):boolean
turn(clockwise:boolean):boolean
name():string
swing(side:number):boolean[, string]
true
if successful (may take time depending on block being interacted with - e.g.. Obsidian takes time to mine). Returns false
if the operation fails with a description of why it failed.use(side: number[, sneaky: boolean[, duration: number]]): boolean[, string]
true
the robot will simulate a sneak-right-click (like if the player would be using shift during a right-click). Some items (like buckets) will behave differently if this is set to true.block_activated
- a block was activated (like levers, switches or doors).item_interacted
- the equipped tool interacted with the world, for example sheers when used on a sheep.item_placed
- something was placed into the world. This is not only caused by placeable blocks, but as well by items that cause blocks or entities to appear in the world (like flint and stone or mob eggs).item_used
- the equipped was activated, like a splash-potion.air
- the equipped item requires a target but there was none. Note that if your robot has an Angel upgrade, this will never be returned, however some actions might still cause no effect.place(side: number[, sneaky: boolean]): boolean[, string]
true
, the robot will simulate a sneak-placement (shift-click). Returns true
if successfully placed. Returns false
if the operation fails. If an unsupported value is provided as a parameter, the operation will fail with a description of why it failed. getLightColor():number
setLightColor(value:number):number
inventorySize():number
select([slot:number]):number
count([slot:number]):number
space([slot:number]):number
compareTo(otherSlot:number):boolean
transferTo(toSlot:number[, amount:number]):boolean
tankCount():number
selectTank(tank:number)
tankLevel([tank:number]):number
selectTank()
).tankSpace([tank:number]):number
compareFluidTo(tank:number):boolean
transferFluidTo(tank:number[, count:number]):boolean
detect(side:number):boolean
true
if the block will prevent the robot from moving forward, false
otherwise. Drones return true
even if the block is passable.
side - See the Sides API for a list of possible sides.
compareFluid(side:number):boolean
Compares fluid in the selected tank (requires a Tank upgrade) to fluid in the world or in an external tank on the specified side of the robot. drain(side:number[, count:number]):boolean
fill(side:number[, count:number]):boolean
compare(side:number[, fuzzy:boolean=false]):boolean
Compares the block on the specified side of the robot with the item in the currently selected slot and returns whether they are the same or not. Blocks are considered identical if the type and metadata match; additional ItemStack information is not checked. Empty blocks are considered as air blocks, which cannot be compared to an empty inventory slot; the detect()
function can be used to determine if there is a block in front of the robot. For blocks that drop a different item, the compare()
method won't work (eg: Diamond block dropping diamond items); for these cases, use silk-touch to obtain a block for comparison. drop(side:number[, count:number]):boolean
true
if at least one item is dropped, false
otherwise. If the block in front of the robot is an inventory, the robot will try to place the item into the inventory. If the inventory doesn't accept the item, the item is not dropped into the world (the operation will fail and return false
). Robots themselves are considered blocks with an inventory, and items can be moved into them using the drop()
function. The drop()
function will not work on non-item inventories, such as fluid tanks (the use()
function works for these cases). suck(side:number[, count:number]):boolean