此组件由机器人提供。
下列函数可在Lua解释器中使用=component.robot.function()
的写法调用。想要以更直观的方式来调用机器人函数的话,可以使用Robot(机器人) API。它是组件函数的封装版本,还提供了额外的功能(在API页面中总结)。
组件名:robot
。
durability():number
turn(clockwise:boolean):boolean
name():string
swing(side:number):boolean[, string]
true
(可能需要时间,具取决于与其交互的方块,例如黑曜石需要一些时间来挖掘)。如果执行失败则返回false
以及失败原因。use(side: number[, sneaky: boolean[, duration: number]]): boolean[, string]
true
,否则返回 false
。若成功,会有第二个返回值,代表机器人交互的内容,可能取值为下列之一:block_activated
(激活方块)、item_placed
(放置物品)、item_used
(使用物品)、item_interacted
(与物品互动)、air
(空气)。block_activated
- 某个方块被激活(例如拉杆、开关以及门)item_interacted
- 装备的工具与世界进行了互动,例如在羊身上使用剪刀。item_placed
- 某个物品被放置到了世界中。此返回值不一定由可放置的方块触发,其他会导致方块或实体出现在世界上的物品也会触发(例如燧石或刷怪蛋)。item_used
- 装备的物品被激活,例如喷溅式药水。air
- 当前装备的物品需要目标才能使用,但并不存在。请注意如果你的机器人有天使升级,此返回值将永远不会出现,但一些操作可能仍然无效果。place(side: number[, sneaky: boolean]): boolean[, string]
sneaky
设置为true
,那么机器人将会模拟潜行放置(按住shift点击)。若成功放置则返回 true
,若操作失败则返回 false
。若使用不支持的值作为参数,则操作将会失败,并返回失败原因。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