Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
component:robot [2016/03/29 18:55]
spacetimevortex Apparently a lot of methods need 'side' argument, which makes sense, else the Robot API couldn't do sideway stuff either
component:robot [2018/09/27 02:08]
payonel
Line 1: Line 1:
-Component: Robot +====Component: Robot====
-==========+
 This component is provided by the [[block:​robot|Robot]]. The functions below can be called in the Lua interpreter using `=component.robot.function()`. To make robot function calls more intuitive, a [[api:​robot|Robot API]] exists as a wrapper around the component functions, providing additional functionality (which is summarized in the API page).  ​ This component is provided by the [[block:​robot|Robot]]. The functions below can be called in the Lua interpreter using `=component.robot.function()`. To make robot function calls more intuitive, a [[api:​robot|Robot API]] exists as a wrapper around the component functions, providing additional functionality (which is summarized in the API page).  ​
  
 Component name: `robot`.  ​ Component name: `robot`.  ​
  
-Callbacks:+===Base Methods=== 
 +{{page>​component:agent#Robot Component API&​noheader&​nofooter}} 
 +{{page>​component:​agent#​Agent Trait API&​noheader&​nofooter}} 
 + 
 +====WorldControl Trait API====
  
-- `compare():​boolean`  ​ 
-  Compares the block in front 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. ​ 
-- `compareFluid():​boolean`  ​ 
-  Compares fluid in the selected tank (requires a [[item:​tank_upgrade|Tank upgrade]]) to fluid in the world or in an external tank in front of the robot. ​ 
-- `compareFluidTo(tank:​number):​boolean`  ​ 
-  Tests whether the fluid in the selected tank (in the robot inventory) is the same as in the specified tank (requires [[item:​tank_upgrade|Tank upgrade]]). 
-- `compareTo(otherSlot:​number):​boolean`  ​ 
-Compare the contents of the selected slot (in the robot inventory) to the contents of the specified slot (also in the robot inventory). 
-- `count([slot:​number]):​number`  ​ 
-  Get the number of items in the specified slot, otherwise in the selected slot. 
 - `detect(side:​number):​boolean`  ​ - `detect(side:​number):​boolean`  ​
   Detects the block on the given side, relative to the robot, and returns whether or not the robot can move into the block, as well as a general description of the block. Returns `true` if the block will prevent the robot from moving forward, `false` otherwise. Drones return `true` even if the block is passable.   Detects the block on the given side, relative to the robot, and returns whether or not the robot can move into the block, as well as a general description of the block. Returns `true` if the block will prevent the robot from moving forward, `false` otherwise. Drones return `true` even if the block is passable.
Line 22: Line 15:
  ​**side** - See the [[api:​sides|Sides API]] for a list of possible sides.  ​**side** - See the [[api:​sides|Sides API]] for a list of possible sides.
  
 +====TankWorldControl Trait API====
 +
 +- `compareFluid(side:​number):​boolean`
 +  Compares fluid in the selected tank (requires a [[item:​tank_upgrade|Tank upgrade]]) to fluid in the world or in an external tank on the specified side of the robot. ​
 - `drain([count:​number]):​boolean`  ​ - `drain([count:​number]):​boolean`  ​
   Extracts the specified amount of fluid from the world or a tank in front of the robot. If no amount is specified, the robot will try to drain 1000mB. If the tank is unable to store the specified amount of fluid, the operation will fail (no fluid is lost in the process).   Extracts the specified amount of fluid from the world or a tank in front of the robot. If no amount is specified, the robot will try to drain 1000mB. If the tank is unable to store the specified amount of fluid, the operation will fail (no fluid is lost in the process).
-- `drop(side:​number[,​ count:​number]):​boolean`  ​ 
-  Drops the specified number of items from the currently selected slot. Returns `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). ​ 
-- `durability():​number`  ​ 
-  Get the durability of the currently equipped tool. 
 - `fill([count:​number]):​boolean`  ​ - `fill([count:​number]):​boolean`  ​
   Fills the specified amount of fluid from the selected tank (requires a [[item:​tank_upgrade|Tank upgrade]]) into the world or a tank in front of the robot. If no amount is specified, the robot will try to fill the target tank with 1000mB of fluid. If there is not enough fluid to fill a block, or not enough space in the target tank, the operation will fail with no fluids lost.   Fills the specified amount of fluid from the selected tank (requires a [[item:​tank_upgrade|Tank upgrade]]) into the world or a tank in front of the robot. If no amount is specified, the robot will try to fill the target tank with 1000mB of fluid. If there is not enough fluid to fill a block, or not enough space in the target tank, the operation will fail with no fluids lost.
-- `getLightColor():​number`  ​ + 
-  Get the current color of the activity light as an integer encoded RGB value (0xRRGGBB). +====Agent Trait API==== 
-- `inventorySize():​number` ​  +
-  Returns the size of the device'​s internal inventory. +
-- `move(direction:​number):​boolean` ​  +
-  Move in the specified direction.+
 - `name():​string`  ​ - `name():​string`  ​
   Get the name of the robot.   Get the name of the robot.
-- `place(side:​ number[, sneaky: boolean]): boolean[, string]`  ​ 
-  Tries to place the block in the currently selected inventory slot on the specified side of the robot (if the side is supported). If **sneaky** is set to `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. ​ 
-- `select([slot:​number]):​number`  ​ 
-  Get the currently selected slot; set the selected slot if specified. 
-- `selectTank(tank:​number)`  ​ 
-  Selects the specified tank (if robot contains more than one [[item:​tank_upgrade|Tank upgrade]]). Any tank operations will use this tank.  
-- `setLightColor(value:​number):​number`  ​ 
-  Set the color of the activity light to the specified integer encoded RGB value (0xRRGGBB). 
-- `space([slot:​number]):​number`  ​ 
-  Get the remaining space in the specified slot, otherwise in the selected slot. 
-- `suck(side:​number[,​ count:​number]):​boolean`  ​ 
-  Tries to pick up the specified number of items and place it in the selected slot. If the selected slot is occupied, items will be placed in the first available slot.  
 - `swing(side:​number):​boolean[,​ string]`  ​ - `swing(side:​number):​boolean[,​ string]`  ​
   Lets the robot use the currently equipped item in the tool slot against the block or space directly in front of the robot. Returns `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.   Lets the robot use the currently equipped item in the tool slot against the block or space directly in front of the robot. Returns `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.
-- `tankCount():​number`  ​ 
-  Returns the number of tanks installed in the robot. ​ 
-- `tankLevel([tank:​number]):​number`  ​ 
-  Returns the fluid level in the specified tank. If no tank specified, returns the fluid level in the selected tank (using `selectTank()`). 
-- `tankSpace(function arguments)`  ​ 
-  Returns the remaining fluid capacity (empty space) in the specified tank. If not tank specified, returns the  remaining capacity in the selected tank.  
-- `transferFluidTo(tank:​number[,​ count:​number]):​boolean`  ​ 
-  Transfer the specified amount of fluid in the selected tank into the specified tank. If no volume is specified, the  robot will attempt to transfer 1000mB. 
-- `transferTo(toSlot:​number[,​ amount:​number]):​boolean`  ​ 
-  Move the specified amount of items from the selected slot into the specified slot. If no amount is specified, the entire stack is moved to the target slot.  
-- `turn(clockwise:​boolean):​boolean`  ​ 
-  Rotate in the specified direction. 
 - `use(side: number[, sneaky: boolean[, duration: number]]): boolean[, string]`  ​ - `use(side: number[, sneaky: boolean[, duration: number]]): boolean[, string]`  ​
   Attempts to use the item currently equipped in the tool slot in the same way as if the player would make a right-click.  ​   Attempts to use the item currently equipped in the tool slot in the same way as if the player would make a right-click.  ​
Line 77: Line 43:
   - `item_used` - the equipped was activated, like a splash-potion.   - `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.   - `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]`  ​
 +  Tries to place the block in the currently selected inventory slot on the specified side of the robot (if the side is supported). If **sneaky** is set to `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`  ​
 +  Get the current color of the activity(robot) or flap(drone) light as an integer encoded RGB value (0xRRGGBB).
 +- `setLightColor(value:​number):​number`  ​
 +  Set the color of the activity(robot) or flap(drone) light to the specified integer encoded RGB value (0xRRGGBB).
  
-----+====TankControl Trait API====
  
 +- `tankCount():​number`  ​
 +  Returns the number of tanks installed in the robot. ​
 +- `selectTank(tank:​number)`  ​
 +  Selects the specified tank (if robot contains more than one [[item:​tank_upgrade|Tank upgrade]]). Any tank operations will use this tank. 
 +- `tankLevel([tank:​number]):​number`  ​
 +  Returns the fluid level in the specified tank. If no tank specified, returns the fluid level in the selected tank (using `selectTank()`).
 +- `tankSpace([tank:​number]):​number`  ​
 +  Returns the remaining fluid capacity (empty space) in the specified tank. If not tank specified, returns the  remaining capacity in the selected tank. 
 +- `compareFluidTo(tank:​number):​boolean`  ​
 +  Tests whether the fluid in the selected tank (in the robot inventory) is the same as in the specified tank (requires [[item:​tank_upgrade|Tank upgrade]]).
 +- `transferFluidTo(tank:​number[,​ count:​number]):​boolean`  ​
 +  Transfer the specified amount of fluid in the selected tank into the specified tank. If no volume is specified, the  robot will attempt to transfer 1000mB.
 +
 +====InventoryWorldController trait API====
 +
 +- `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`  ​
 +  Drops the specified number of items from the currently selected slot. Returns `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`  ​
 +  Tries to pick up the specified number of items and place it in the selected slot. If the selected slot is occupied, items will be placed in the first available slot. 
 +
 +====Robot Component API====
 +
 +- `durability():​number`  ​
 +  Get the durability of the currently equipped tool.
 +- `move(direction:​number):​boolean`  ​
 +  Move in the specified direction. Valid movement sides are: front, back, top, bottom.
 +- `turn(clockwise:​boolean):​boolean`  ​
 +  Rotate in the specified direction.
 +
 +====Drone Component API====
 +
 +- `getStatusText():​string`  ​
 +  Get the status text currently being displayed in the GUI.
 +- `setStatusText(value:​string):​string`  ​
 +  Set the status text to display in the GUI, returns new value.
 +- `move(dx:​number,​ dy:number, dz:​number)`  ​
 +  Change the target position by the specified offset.
 +- `getOffset():​number`  ​
 +  Get the current distance to the target position.
 +- `getVelocity():​number`  ​
 +  Get the current velocity in m/s.
 +- `getMaxVelocity():​number`  ​
 +  Get the maximum velocity, in m/s.
 +- `getAcceleration():​number`  ​
 +  Get the currently set acceleration.
 +- `setAcceleration(value:​number):​number`  ​
 +  Try to set the acceleration to the specified value and return the new acceleration.
 +
 +Contents
 +----
 {{page>​component:​contents&​noheader&​noeditbutton&​nouser&​nofooter}} {{page>​component:​contents&​noheader&​noeditbutton&​nouser&​nofooter}}
 +