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

组件:红石

此组件由红石卡提供。

1级红石卡仅支持MC原版红石功能(单路模拟红石信号)。2级红石卡提供与其他模组红石系统的联动(集束红石和无线红石)。对于集束红石,在Minecraft 1.12版本我们仅支持Project Red(红石计划),在更低版本我们支持:RedLogic、Project Red(1.1版本)、MineFactory Reloaded(我的工厂重制版)。无线红石方面,支持以下模组:WR-CBE、SlimeVoid's WR。

get*与set*方法重载

自patch release 1.7.3起,红石组件提供以下函数的重载版本:getInputgetOuputsetInputgetBundledInputgetBundledOutput以及setBundledOutput

get*与set*调用开销

get方法为“直接”调用,且几乎无开销。实验中我每秒可以调用20000到22000次getInput方法。

set方法并非为“直接”调用,因此每tick最多只能调用一次。也就是说每秒钟可以调用约20次。除了间接成本(消耗剩余的tick)之外,调用set改变了输出的强度等级后机器上还会有额外的延迟。默认情况下,调用set每秒可以改变输出约6次。

使用这些重载变体的显著优势之一是,API调用开销为每次调用后结算,而不是每次设定数值后结算。

组件名:redstone

回调函数:

  • getInput(side: number): number
    getInput(): table
    返回当前输入的(非集束)红石信号值。getInput(side)会返回指定方向上的红石信号等级。getInput()会返回包含所有方向上红石信号等级的表。

请注意返回的表的索引从0开始。因为表的索引其实是方向的原始值,sides.bottom对应了0。

还需注意此函数用到的方向是相对于电脑而言的。即sides.south电脑的前方,而不是世界的南方。类似还有sides.left为电脑的左侧,也就是如果你站在电脑面前的话,就是你的右侧。

如果使用了例如RedLogic这样的模组,输入值可能会超出MC原版的[0, 15]范围。

snippet.lua
lua> component.redstone.getInput(sides.left)
15
lua> component.redstone.getInput(sides.right)
4
lua> component.redstone.getInput()
{[0]=7,
 0,
 0,
 0,
 4,
 15}
lua> component.redstone.getInput()[sides.bottom]
7
  • getOutput(side: number): number
    getOutput(): table
    获取指定方向上输出的设定值,若不含参数调用则返回所有方向上的设定值。
snippet.lua
lua> component.redstone.getOutput(sides.left)
7
lua> component.redstone.getOutput() [sides.left]
7
  • setOutput(side: number, value: number): number
    setOutput(values: table): table
    设定要发出的红石信号强度。返回旧的值。配合支持的mod时可以为很大的值。此方法的参数为方向以及要应用到此方向的红石信号强度。setOutput(values)这种写法可以在一次调用内设定所有方向(或数个方向)上的红石信号强度。
  • getBundledInput(side: number, color: number): number
    getBundledInput(side: number): table
    getBundledInput(): table
    getInput类似,但适用于集束输入。读取指定颜色对应通道的值。
    对OC 1.3而言:仅可用于2级红石卡。

    getBundledInput(side, color) returns the strength of the incoming redstone value on the specified side on the specified color channel.
    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 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): table
    getBundledOutput(): table
    Like getOutput, but for bundled output, getting the values previously set that the device is emitting.
    As of OC 1.3: only available on a tier two redstone card.
  • 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. Returns the previous values set. 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(values) allows you to set redstone levels for any side and any color in a single api call.
    As of OC 1.3: only available on a tier two redstone card.
snippet.lua
lua> component.redstone.setBundledOutput(sides.left, { [colors.white] = 15 } ) -- only sets 1 output
lua> component.redstone.setBundledOutput({ [sides.left] = { [colors.white] = 15 } } ) -- same as above
  • getComparatorInput(side:number):number
    Get the comparator input on the specified side.
  • getWirelessInput():number
    Get the wireless redstone input.
    Added in OC 1.3. Only available on tier two redstone cards.
  • getWirelessOutput():boolean
    Get the wireless redstone output.
    Added in OC 1.3. Only available on tier two redstone cards.
  • setWirelessOutput(value:boolean):boolean
    Set the wireless redstone output.
    Added in OC 1.3. Only available on tier two redstone cards.
  • getWirelessFrequency():number
    Get the currently set wireless redstone frequency.
    Added in OC 1.3. Only available on tier two redstone cards.
  • setWirelessFrequency(frequency:number):number
    Set the wireless redstone frequency to use.
    Added in OC 1.3. Only available on tier two redstone cards.
  • getWakeThreshold():number
    Gets the current wake-up threshold.
  • 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.

Example use: ```lua local component = require(“component”) local sides = require(“sides”) local colors = require(“colors”) local rs = component.redstone – get primary redstone component print(rs.getInput(sides.back)) rs.setBundledOutput(sides.bottom, colors.green, rs.getBundledInput(sides.top, colors.red)) `` `

目录