**This is an old revision of the document!**

注意:不要翻译这个页面的段落标题!

有很多页面通过段落标题链接到这个页面,翻译段落标题会导致链接混乱!

InventoryController Trait API

  • inventorySize():number
    Returns the size of the device's internal inventory.
  • select([slot:number]):number
    Get the currently selected slot; set the selected slot if specified.
  • count([slot:number]):number
    Get the number of items in the specified slot, otherwise in the selected slot.
  • space([slot:number]):number
    Get the remaining space in the specified slot, otherwise in the selected slot.
  • 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).
  • 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.

WorldControl Trait API

  • detect(side:number):boolean
    检测给定面相对于机器人的方块,并返回机器人是否可以移动到方块中,以及方块的描述。如果方块会阻挡机器人向前移动,则返回 true,否则返回 false。即使该方块是可通过的,无人机也会返回true。

    side - 请参阅 sides API 以获取可能的面列表。

TankWorldControl Trait API

  • compareFluid(side:number):boolean 将选定储罐中的液体(需要 储罐升级)与世界上的流体或机器人指定一侧的外部储罐中的流体进行比较。
  • drain(side:number[, count:number]):boolean
    令机器人(无人机)通过指定面在世界或储罐中提取一定数量的流体。如果未指定数量,机器人将尝试提取 1000mB。如果储罐无法存储指定数量的流体,则操作将会执行失败(该过程不会损失流体)。
  • fill(side:number[, count:number]):boolean
    从选定的储罐(需要 储罐升级)中将指定量的流体填充到世界或机器人前面的储罐中。如果未指定数量,机器人将尝试用 1000mB 的液体填充目标储罐。如果没有足够的流体来填充方块或者目标储罐没有足够的空间,则该操作将执行失败且流体不会损失。

Agent Trait API

  • name():string
    获取机器人的名称。
  • swing(side:number):boolean[, string]
    让机器人使用当前自身工具栏装备的物品来与与正前方的方块、空气(空间)交互。如果成功则返回 true(可能需要时间,具体时间取决于与其交互的方块——例如黑曜石需要一些时间来挖掘)。如果执行失败则返回 false 同时返回失败的原因。
  • use(side: number[, sneaky: boolean[, duration: number]]): boolean[, string]
    尝试以玩家相同的方式:右键(单击)来使用当前装备在工具栏中的物品。
    side - 如果指定该值,则机器人尝试仅在指定面上单击右键,否则机器人会尝试所有面,请查阅 Sides API 以获取可能的面列表。
    sneaky - 如果设置为true,机器人将会模拟玩家的“潜行右击”。如果设置为true,则某些物品(例如桶)的行为会有所不同。 duration - 使用该物品的时间。这在使用弓等持续使用物品时很有用。
    返回值:如果机器人可以与它前面的方块交互,则返回 true,否则返回 false。如果成功,第二个参数将会描述机器人与之交互的内容,并且将是 block_activateditem_placeditem_useditem_interactedair 之一。 此函数用途非常广泛,因为机器人可以模拟大多数物品的单击右键。与玩家的唯一区别是机器人不能使用特别要求用户是实体的物品,因为机器人是一个方块。所以喝药水、吃食物或扔末影珍珠都会失败。 这个函数的次要返回值可以用来判断右键单击的结果是什么造成的。返回项目结果并不总是很明显,需要事先进行一些测试。另请注意,虽然机器人不受有害药水的影响,但它们可能会被爆炸摧毁,因此在使用此功能放置、投掷或激活任何形式的炸药时要小心。第二个返回值的可能值:
    • block_activated - 一个被激活的方块(例如拉杆、开关、门)
    • item_interacted - 用装备的工具与世界互动,例如在羊上使用剪刀。
    • item_placed - 某个东西被放置在世界中。这不仅仅是有可放置的方块引起的,但也可以通过方块或实体出现在世界中的物品(例如燧石或刷怪蛋)。
    • item_used - 装备物品被激活,如同喷溅药水一样。
    • air - 当前装备的物品(包括空手)需要对着一个目标物体才能使用。请注意如果你的机器人有天使方块升级,这个值将永远不会被返回,但是一些操作可能仍然无效果。
  • place(side: number[, sneaky: boolean]): boolean[, string]
    尝试将物品栏中已选定格子的方块放置在指定面(如果支持这面)如果 sneaky 设置为true,那么机器人将会模拟潜行放置(Shift+点击)。如果成功放置,则返回 true。 如果操作执行失败,则返回 false。如果使用一个不被支持的值作为参数,则操作将会执行失败并说明失败的原因。
  • getLightColor():number
    获取襟翼或状态活动灯的颜色,并用整数编码 RGB 值(0xRRGGBB)形式表示。
  • setLightColor(value:number):number
    将活动或襟翼灯的颜色设置为指定的整数编码 RGB 值 (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 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 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
    将机器人指定侧的方块与当前选择的格子中的物品进行比较,并返回它们是否相同。如果二者元数据匹配,则认为方块(物品)相同;不检查其他 ItemStack 信息。空气被视为空气方块,不能与物品栏中的空格子进行比较;detect() 函数可用于确定机器人前面是否有块。 对于掉落不同物品的方块,compare() 方法将不能工作(例如:钻石矿石掉落钻石);对于这些情况,请使用精准采集来获取方块进行比较。
  • 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. Returns the number of items sucked else false.

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 (see Sides).
  • turn(clockwise:boolean):boolean
    Rotate in the specified direction.

Drone Component API

  • getStatusText():string
    获取当前在 GUI 中显示的状态文字(文本)。
  • setStatusText(value:string):string
    设置在 GUI 显示的状态文字(文本),并返回一个新的值。
  • move(dx:number, dy:number, dz:number)
    通过指定的位移量移动到目标位置。
  • getOffset():number
    获取到当前目标位置的距离。
  • getVelocity():number
    获取目标的当前速度。(单位:m/s)
  • getMaxVelocity():number
    获取到目标的最大速度。(单位:m/s)
  • getAcceleration():number
    获取到当前设置的加速度。
  • setAcceleration(value:number):number
    尝试把加速设置到指定值并返回新的加速度的值。