Differences

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

Link to this comparison view

Next revision
Previous revision
component:inventory_controller:zh [2023/11/15 12:48]
hfsr created
component:inventory_controller:zh [2023/12/27 02:08] (current)
hfsr [组件:物品栏控制器]
Line 1: Line 1:
-Component: Inventory Controller+组件:物品栏控制器
 ========================== ==========================
-**Component name:** `inventory_controller`+**组件名:**`inventory_controller`
  
-This component is provided by the [[item:​inventory_controller_upgrade|inventory controller upgrade]].+此组件由[[item:​inventory_controller_upgrade:zh|物品栏控制器升级]]提供。
  
-With this API the robot can receive additional information about items or inventories and is able to put items into and take them from specific slots.+有了此API,机器人可以接收有关物品或物品栏的额外信息,并且可以向指定槽位放入物品或从中取出物品。
  
-Sides required for most operations are specified in the [[api:​sides|Sides API]]. If no or an invalid side is provided functions will usually throw an error. To interact with the robot'​s own inventory you need to use the side `back`, which however makes it impossible to interact with inventories behind the robot. Robots cannot access their left or right sides. You can interact with external inventories in front of, above, or below the robot.+大多数操作所需的方向(side)遵循[[api:sides:zh|Sides(方向面) ​API]]中的方向。若不指定方向或指定错误的方向,函数通常会报错。要与机器人自身的物品栏互动需要使用`back`方向,这也使得机器人无法与在其身后的物品容器互动。机器人也不能访问它们的左右两边。综上,你只能与机器人前方、上方或下方的物品容器互动。
  
-Callbacks:+回调函数:
  
 - `getInventorySize(side:​ number): number or nil[, string]`  ​ - `getInventorySize(side:​ number): number or nil[, string]`  ​
-Returns the size of the inventory at the specified side. +返回指定方向所对物品容器的大小。  ​ 
-**side** - must be a valid side.   +**side** - 须为某个有效的方向。 ​  
-**Returns:** the size of the inventory, or `nil` followed by a description why this function failed (usually ​`no inventory`).+**返回值:**物品容器的大小,或者`nil`与函数执行失败原因的描述(通常为`no inventory`,代表对应方向不存在物品容器)。 ​  
 +\\
 - `getStackInSlot(side:​number,​ slot:​number):​table`  ​ - `getStackInSlot(side:​number,​ slot:​number):​table`  ​
- +返回一个描述指定槽位中物品信息的表,或`nil`。用此函数获取机器人自身物品栏中物品信息的做法已经过时,请使用`getStackInInternalSlot`代替。 ​  
-Returns a table describing the item in the specified slot or nil. Deprecated for getting info about robot'​s own inventory, see `getStackInInternalSlot`  +**side** - 须为某个有效的方向。 ​  
-**side** - must be a valid side.   +**slot** - 要分析的槽位。此参数不会检查物品容器大小,而是会将超出物品栏范围的槽位当作空槽位。 ​  
-**slot** - the slot to analyze. This does not check the inventory size and will consider slots outside the inventory bounds to be empty. ​  +**返回值:**若槽位为空(或超出物品栏范围)则返回`nil`,否则返回一个表,其中包含槽位中物品的以下信息:  ​ 
-**Returns:** `nil` if the slot was empty (or outside the inventory'​s bounds), a table otherwise with the following information about the item in that slot: +  - **damage**:​number - 物品的当前损害值。 
-  - **damage**:​number - the current damage value of the item. +  - **maxDamage**:​number - 此物品在损坏前能承受的最大损害值。 
-  - **maxDamage**:​number - the maximum damage this item can have before it breaks. +  - **size**:​number - 此物品的当前堆叠数量。 
-  - **size**:​number - the current stack size of the item. +  - **maxSize**:​number - 此物品的最大堆叠数量。 
-  - **maxSize**:​number - the maximum stack size of this item. +  - **id**:​number - 此物品的Minecraft id。请注意只有在配置文件中设置`insertIdsInConverters=true`才会出现此字段,可能因服务端设定而不同! 
-  - **id**:​number - the Minecraft id of the item. Note that this field is only included if `insertIdsInConverters=true` ​in the configs, and can vary between servers! +  - **name**:​string - **“未翻译的”**物品名,也就是Minecraft的内部值,例如`oc:​item.FloppyDisk` 
-  - **name**:​string - the **untranslated** item name, which is an internal ​Minecraft ​value like `oc:​item.FloppyDisk` +  - **label**:​string - **“翻译后的”**物品名。 
-  - **label**:​string - the **translated** item name +  - **hasTag**:​boolean - 此物品是否包含NBT标签。\\ 
-  - **hasTag**:​boolean - whether or not the item has an NBT tag associated with it.+\\
 - `getStackInInternalSlot(slot:​number):​table`  ​ - `getStackInInternalSlot(slot:​number):​table`  ​
-  Gets Itemstack description of item in specified or selected slot (if no input provided) of robot inventory.+获取机器人物品栏中指定(若不指定为当前选中)槽位中物品的物品堆信息。 ​  
 +\\
 - `dropIntoSlot(side:​number,​ slot:​number[,​ count:​number]):​boolean[,​ string]`  ​ - `dropIntoSlot(side:​number,​ slot:​number[,​ count:​number]):​boolean[,​ string]`  ​
-Puts up to count items from the currently selected slot into the specified slot of the inventory at the specified side.   +从机器人物品栏的当前选中槽位向外转移物品,目标为指定方向处物品容器的指定槽位,至多指定数量个。 ​  
-**side** - a valid side.   +**side** - 某个有效方向。 ​  
-**slot** - the slot to drop the item into.  ​ +**slot** - 要放置物品的目标槽位。 
-**count** - how many items to transfer. ​  +**count** - 要转移多少物品。 ​  
-**Returns:** `true` ​if at least one item was moved, ​`false` ​and a secondary result that describes the error otherwise. ​  +**返回值:**若至少移动了一个物品则返回`true`,否则返回`false`与报错信息。 ​  
-Note that the robot cannot drop items into it's own inventory, attempting to do so will cause this to throw an error. You need to use `robot.transferTo` from the [[api:​robot|Robot API]] to do so.+请注意此函数中机器人不能将物品放入自身物品栏,试图这样做会抛出错误。你需要使用[[api:robot:zh|Robot(机器人) ​API]]中的`robot.transferTo`函数来进行此操作。 ​  
 +\\
 - `suckFromSlot(side:​number,​ slot:​number[,​ count:​number]):​boolean`  ​ - `suckFromSlot(side:​number,​ slot:​number[,​ count:​number]):​boolean`  ​
-Takes up to count items from the specified slot of the inventory at the specified side and puts them into the currently selected slot.   +从指定方向处物品容器的指定槽位获取物品,转移到机器人物品栏的当前选中槽位,至多指定数量个。 ​  
-**side** - a valid side.   +**side** - 某个有效方向。 ​  
-**slot** - the slot to take the item from.   +**slot** - 用于获取物品的槽位。 ​  
-**count** - how many items to transfer.  ​ +**count** - 要转移多少物品。 ​   
-**Returns:** `true` ​if at least one item was moved, ​`false` ​otherwise. ​  +**返回值:**若至少移动了一个物品则返回`true`,否则返回`false`。   
-If the currently selected slot is occupied, then the items will be stacked with similar items in the robot'​s inventory or moved to the next free slot if available. If no slot is available this operation will fail.   +若机器人物品栏的当前选中槽位被占用,则传入的物品会被合并到物品栏中的相同物品堆中,或移动到下一个空闲槽位(有的话)。若没有可用槽位则操作会失败。 ​  
-Note that the robot cannot suck items from it's own inventory, attempting to do so will cause this to throw an error. You need to use `robot.transferTo` from the [[api:​robot|Robot API]] to do so.+请注意此函数中给机器人不能从自身物品栏提取物品,试图这样做会抛出错误。你需要使用[[api:robot:zh|Robot(机器人) ​API]]中的`robot.transferTo`函数来进行此操作。 ​  
 +\\
 - `equip():​boolean`  ​ - `equip():​boolean`  ​
-Swaps the content of the robot'​s tool slot with the content of the currently selected inventory slot.   +将机器人工具槽位中内容与其物品栏的选中槽位中内容互换。 ​  
-**Returns:** `true` ​if the items were swapped, ​`false` ​otherwise. This operation usually succeeds. ​  +**返回值:**若物品成功交换则返回`true`,否则返回`false`。此操作通常都会成功。 ​  
-Note that you can put any kind of item into the robot'​s tool slot, not only tools, even items that the robot cannot use at all.+请注意,你可以将任何类型的物品放进机器人的工具槽位,不只是工具,就算是机器人根本不能使用的物品也行。 ​  
 +\\
 - `store(side:​number,​ slot:​number,​ dbAddress:​string,​ dbSlot:​number):​boolean`  ​ - `store(side:​number,​ slot:​number,​ dbAddress:​string,​ dbSlot:​number):​boolean`  ​
-  Stores the Itemstack description of the item from the specified slot in an inventory on the specified side, into a specified database slot with the specified address.+获取指定方向处物品容器指定槽位的物品堆信息,将其存入指定地址对应数据库的指定槽位。 ​  
 +\\
 - `storeInternal(slot:​number,​ dbAddress:​string,​ dBslot:​number):​boolean`  ​ - `storeInternal(slot:​number,​ dbAddress:​string,​ dBslot:​number):​boolean`  ​
-  Stores Itemstack description of item in specified robot inventory slot into specified database slot with the specified database address.+获取机器人物品栏指定槽位的物品堆信息,将其存入指定地址对应数据库的指定槽位。 ​  
 +\\
 - `compareToDatabase(slot:​number,​ dBaddress:​string,​ dBslot:​number):​boolean`  ​ - `compareToDatabase(slot:​number,​ dBaddress:​string,​ dBslot:​number):​boolean`  ​
-  Compare Itemstack description in specified slot with one in specified slot of a database with specified address. Returns **true** if items match.+获取机器人物品栏指定槽位的物品堆信息,与指定地址对应数据库的指定槽位内容对比。若物品信息相符则返回`true`。   
 +\\
 - `compareStacks(side:​number,​ slotA:​number,​ slotB:​number):​boolean`  ​ - `compareStacks(side:​number,​ slotA:​number,​ slotB:​number):​boolean`  ​
-  Checks to see if Itemstack descriptions in specified ​slotA and slotB of inventory on specified side match. Returns **true** if identical.+检查指定方向处物品容器中,槽位A(slotA)和槽位B(slotB)的物品信息是否相同。若相同则返回`true`。   
 +\\
 - `getSlotMaxStackSize(side:​number,​ slot:​number):​number`  ​ - `getSlotMaxStackSize(side:​number,​ slot:​number):​number`  ​
-  Gets maximum number of items in specified slot in inventory on the specified side.+获取指定方向处物品容器的指定槽位中物品的堆叠上限。 ​  
 +\\
 - `getSlotStackSize(side:​number,​ slot:​number):​number`  ​ - `getSlotStackSize(side:​number,​ slot:​number):​number`  ​
-  Gets number of items in specified slot in inventory on the specified side.+获取指定方向处物品容器的指定槽位中物品的数量。 ​  
  
 +样例:
  
-Example:+输出[[http://​ocdoc.cil.li/​api:​robot:​zh|slot]]所指示位置的物品元数据。
  
-Print meta-info about the item in the position indicated by [[http://​ocdoc.cil.li/​api:​robot|slot]] 
  
 ```lua ```lua
Line 83: Line 94:
 end end
 ``` ```
 +`
 目录 目录
 --------------------------- ---------------------------
 {{page>​component:​contents:​zh&​noheader&​noeditbutton&​nouser&​nofooter}} {{page>​component:​contents:​zh&​noheader&​noeditbutton&​nouser&​nofooter}}