Differences

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

Link to this comparison view

Next revision
Previous revision
component:redstone:zh [2023/11/23 01:23]
hfsr created
component:redstone:zh [2023/12/27 03:22] (current)
hfsr [组件:红石]
Line 1: Line 1:
-Component: Redstone+组件:红石
 ================== ==================
-This component represents a [[item:​redstone_card|Redstone card]]+此组件由[[item:​redstone_card:zh|红石卡]]提供。
  
-The tier one Redstone Card only supports vanilla redstone functionality (single-line analog redstone). Tier two provides interoperation with other mods' redstone systems (bundled, wireless). For bundled input/​output we currently only support ProjectRed for Minecraft 1.12. In older versions we supported: ​RedLogicProject Red (with Version ​1.1), MineFactory Reloaded. For wireless redstone, the following mods are supported: ​WR-CBESlimeVoid'​s WR.+1级红石卡仅支持MC原版红石功能(单路模拟红石信号)。2级红石卡提供与其他模组红石系统的联动(集束红石和无线红石)。对于集束红石,在Minecraft 1.12版本我们仅支持Project Red(红石计划),在更低版本我们支持:RedLogicProject Red1.1版本)、MineFactory Reloaded(我的工厂重制版)。无线红石方面支持以下模组:WR-CBESlimeVoid'​s WR
  
-===get* ​and set* method overloads===+===get*set*方法重载===
  
-Starting in patch release 1.7.3 the redstone component provides overloaded flavors of `getInput``getOuput``setInput``getBundledInput``getBundledOutput`, and `setBundledOutput`.+patch release 1.7.3起,红石组件提供以下函数的重载版本:`getInput``getOuput``setInput``getBundledInput``getBundledOutput`以及`setBundledOutput`
  
-===get* ​and set* call costs===+===get*set*调用开销===
  
-The **get** ​methods are "​direct"​ calls and are practically free. From testing I was able to call `getInput` ​20,000 to 22,000 times per second.+**get**方法为“直接”调用,且几乎无开销。实验中我每秒可以调用20000到22000次`getInput`方法。
  
-The **set** ​methods are not "​direct",​ and thus can only be called once per tick, at most. Thus, ~20 times per second. In addition to their indirect cost (consuming the rest of the tick) if the **set** ​call changes any output levels, there is an additional delay imposed on the machine. By default ​**set** ​calls can change outputs approximately ​times per second.+**set**方法并非为“直接”调用,因此每tick最多只能调用一次。也就是说每秒钟可以调用约20次。除了间接成本(消耗剩余的tick)之外,调用**set**改变了输出的强度等级后机器上还会有额外的延迟。默认情况下,调用**set**每秒可以改变输出约6次。
  
-One of the significant advantages of using these overloaded variants is that any api call cost is paid once per call, not once per each value set.+使用这些重载变体的显著优势之一是,API调用开销为每次调用后结算,而不是每次设定数值后结算。
  
-Component name: `redstone`.  ​ +组件名:`redstone` 
-Callbacks:+ 
 +回调函数:
  
 - `getInput(side:​ number): number`  ​ - `getInput(side:​ number): number`  ​
   `getInput():​ table`  ​   `getInput():​ table`  ​
  
-  Returns current incoming (non-bundled) redstone values. ​`getInput(side)` ​returns the redstone level from the specified ​[[api:​sides|side]]`getInput()` ​returns a table of redstone levels from all sides. +返回当前输入的(非集束)红石信号值。`getInput(side)`会返回指定[[api:sides:zh|方向]]上的红石信号等级。`getInput()`会返回包含所有方向上红石信号等级的表。  ​ 
- +请注意返回的表的索引从0开始。因为表的索引其实是方向的原始值,`sides.bottom`对应了0。   
-  Note that the table returned is zero based. That is because the keys of the table are the ordinal values of the sides, and `sides.bottom` ​is 0  +还需注意此函数用到的方向是相对于电脑而言的。即`sides.south`**电脑的前方**,而不是世界的南方。类似还有`sides.left`为电脑的左侧,也就是说如果你站在电脑面前的话,在你的右侧。 ​  
- +如果使用了例如RedLogic这样的模组,输入值可能会超出MC原版的[0, 15]范围。
-  Note also that the side is relative to the computer'​s orientation,​ i.e. `sides.south` ​is *in front of the computer*, not south in the world. Likewise, ​`sides.left` ​is to the left of the computer, so when you look at the computer'​s front, it'll be to your right. ​  +
- +
-  If you use mods such as RedLogic ​the input may exceed the vanilla values of [0, 15].+
  
 ```lua ```lua
Line 49: Line 47:
 - `getOutput(side:​ number): number`  ​ - `getOutput(side:​ number): number`  ​
   `getOutput():​ table`  ​   `getOutput():​ table`  ​
-  Gets the currently set output on the specified side, or the set value of all sides if called with no arguments+获取指定方向上输出的设定值,若不含参数调用则返回所有方向上的设定值。
  
 ```lua ```lua
Line 60: Line 58:
 - `setOutput(side:​ number, value: number): number`  ​ - `setOutput(side:​ number, value: number): number`  ​
   `setOutput(values:​ table): table`  ​   `setOutput(values:​ table): table`  ​
- +设定要发出的红石信号强度。返回**旧的**值。配合支持的mod时可以为很大的值。此方法的参数为[[api:sides:zh|方向]]以及要应用到此方向的红石信号强度。`setOutput(values)`这种写法可以在一次调用内设定所有方向(或数个方向)上的红石信号强度。  ​ 
-  Sets the strength of the redstone signal to emit. Returns the **old** value. This can be an arbitrarily large number for mods that support this. The first variant of this method takes a [[api:​sides|side]] and the redstone strength to apply to just that side. `setOutput(values)` ​allows you to set the redstone strength of all sides (or a subset of sides) in a single call. +\\
 - `getBundledInput(side:​ number, color: number): number`  ​ - `getBundledInput(side:​ number, color: number): number`  ​
   `getBundledInput(side:​ number): table`  ​   `getBundledInput(side:​ number): table`  ​
   `getBundledInput():​ table`  ​   `getBundledInput():​ table`  ​
- +`getInput`类似,但适用于集束输入。读取指定[[api:​colors:zh|颜色]]对应通道的值。  ​ 
-  Like `getInput`, but for bundled input, reading the value for the channel with the specified ​[[api:​colors|API/Colors]].\\ +**对OC 1.3而言:**仅可用于2级红石卡。  ​ 
-  //As of OC 1.3: only available on a tier two redstone card.// +  `getBundledInput(side,​ color)`返回指定方向上输入的指定颜色红石信号强度值。 ​  
- +  `getBundledInput(side)`返回一个表(格式为Map[Int, Int]这样的表结构),整合了指定方向上红石信号值,索引值为颜色。 ​  
-  `getBundledInput(side,​ color)` ​returns the strength of the incoming redstone value on the specified side on the specified color channel. ​  +  `getBundledInput()`返回所有的红石信号值,包括所有方向以及所有颜色。格式为Map[Int, Map[Int, Int]]这样的两层表结构。外层表的索引值范围是[0, 5],值为[[api:sides:zh|方向]](请记住`sides.bottom`为0)。每个方向对应内层表的数据结构与`getBundledInput(side)`返回值相同。  ​ 
-  `getBundledInput(side)` ​returns a table (Map[Int, Int] structure) of redstone values on the specified side in a bundled pack, indexed by color. ​  +\\
-  `getBundledInput()` ​returns all redstone values, of all sides and all colors. It is a Map[Int, Map[Int, Int]] structure. The top level keys are in [0, 5] range, values of [[api:​sides|sides]] (keep in mind sides.bottom ​is zero). The child map of each side is the same data structure returned by `getBundledInput(side)`. +
 - `getBundledOutput(side:​ number, color: number): number`  ​ - `getBundledOutput(side:​ number, color: number): number`  ​
   `getBundledOutput(side:​ number): table`  ​   `getBundledOutput(side:​ number): table`  ​
   `getBundledOutput():​ table`  ​   `getBundledOutput():​ table`  ​
-  Like `getOutput`, but for bundled output, getting the values previously set that the device is emitting.\\ +类似`getOutput`,但是适用于集束输出。用于获取先前设定的输出值。 ​  
-  //As of OC 1.3: only available on a tier two redstone card.//+**对OC 1.3而言:**仅可用于2级红石卡。 ​  
 +\\
 - `setBundledOutput(side:​ number, color: number, value: number): number`  ​ - `setBundledOutput(side:​ number, color: number, value: number): number`  ​
-  Like `setOutput`, but for bundled output, setting the value for the channel with the specified ​[[api:​colors|API/Colors]]. Returns the previous values set. +类似`setOutput`,但是适用于集束输出。用于设定指定[[api:​colors:zh|颜色]]对应通道的输出值。返回之前设定的值。  ​ 
-  `setBundledOutput(side,​ values)` ​sets a pack of color-indexed redstone values, ​[0, 15]`colors.white` ​is zero. The values table doesn'​t have to be contiguous, and values omitted are left unchanged. +  `setBundledOutput(side,​ values)`设定一组红石信号值,以颜色为索引,颜色取值范围为[0, 15]`colors.white`为0。提供的值不一定要连续,省略的值将会保持不变。  ​ 
-  `setBundledOutput(values)` ​allows you to set redstone levels for any side and any color in a single api call.\\ +  `setBundledOutput(values)`让你能在单次API调用中修改所有方向上所有颜色的红石信号值。  ​ 
-  //As of OC 1.3: only available on a tier two redstone card.//+**对OC 1.3而言:**仅可用于2级红石卡。\\
  
 ```lua ```lua
Line 91: Line 87:
  
 - `getComparatorInput(side:​number):​number`  ​ - `getComparatorInput(side:​number):​number`  ​
-  ​Get the comparator input on the specified side.+  ​获取指定方向上的比较器输入。 ​  
 +\\
 - `getWirelessInput():​number`  ​ - `getWirelessInput():​number`  ​
-  ​Get the wireless redstone input.\\ +  ​获取无线红石输入值。 ​  
-  //Added in OC 1.3. Only available on tier two redstone cards.//+**自OC 1.3起添加:**仅可用于2级红石卡。\\ 
 +\\
 - `getWirelessOutput():​boolean`  ​ - `getWirelessOutput():​boolean`  ​
-  ​Get the wireless redstone output.\\ +  ​获取无线红石输出值。 ​  
-  //Added in OC 1.3. Only available on tier two redstone cards.//+**自OC 1.3起添加:**仅可用于2级红石卡。\\ 
 +\\
 - `setWirelessOutput(value:​boolean):​boolean`  ​ - `setWirelessOutput(value:​boolean):​boolean`  ​
-  ​Set the wireless redstone output.\\ +  ​设定无线红石输出值。 ​  
-  //Added in OC 1.3. Only available on tier two redstone cards.//+**自OC 1.3起添加:**仅可用于2级红石卡。\\ 
 +\\
 - `getWirelessFrequency():​number`  ​ - `getWirelessFrequency():​number`  ​
-  ​Get the currently set wireless redstone frequency.\\ +  ​获取当前设定的无线红石频率。 ​  
-  //Added in OC 1.3. Only available on tier two redstone cards.//+**自OC 1.3起添加:**仅可用于2级红石卡。\\ 
 +\\
 - `setWirelessFrequency(frequency:​number):​number`  ​ - `setWirelessFrequency(frequency:​number):​number`  ​
-  ​Set the wireless redstone frequency to use.\\ +  ​设定要使用的无线红石频率。 ​  
-  //Added in OC 1.3. Only available on tier two redstone cards.//+**自OC 1.3起添加:**仅可用于2级红石卡。\\ 
 +\\
 - `getWakeThreshold():​number`  ​ - `getWakeThreshold():​number`  ​
-  ​Gets the current wake-up threshold.+  ​获取当前唤醒阈值。 ​  
 +\\
 - `setWakeThreshold(threshold:​number):​number`  ​ - `setWakeThreshold(threshold:​number):​number`  ​
-  ​Sets the wake-up threshold to the specified number.+  ​将唤醒阈值设定为给定数字。\\
  
-Note that for mods such as ProjectRed, low values (such as the vanilla maximum of 15) may not function as expected for simple on/off values (opening a door for example), because they have a larger value range. You may need to use a higher value, such as 255.+请注意对于如ProjectRed(红石计划)这样的模组而言,较低的强度值(例如原版最高为15的强度值)可能不会像预期一样起到简单开/关信号的作用(例如用于开门)。因为这些模组的红石信号值范围更大。你可能需要指定一个更大的值,例如255。\\
  
-Example use:+使用例:
 ```lua ```lua
 local component = require("​component"​) local component = require("​component"​)
 local sides = require("​sides"​) local sides = require("​sides"​)
 local colors = require("​colors"​) local colors = require("​colors"​)
-local rs = component.redstone -- get primary redstone component+local rs = component.redstone --获取首选红石组件
 print(rs.getInput(sides.back)) print(rs.getInput(sides.back))
 rs.setBundledOutput(sides.bottom,​ colors.green,​ rs.getBundledInput(sides.top,​ colors.red)) rs.setBundledOutput(sides.bottom,​ colors.green,​ rs.getBundledInput(sides.top,​ colors.red))
 ``` ```
 +`
 目录 目录
 ---- ----
 {{page>​component:​contents:​zh&​noheader&​noeditbutton&​nouser&​nofooter}} {{page>​component:​contents:​zh&​noheader&​noeditbutton&​nouser&​nofooter}}