此组件由红石卡提供。
1级红石卡仅支持MC原版红石功能(单路模拟红石信号)。2级红石卡提供与其他模组红石系统的联动(集束红石和无线红石)。对于集束红石,在Minecraft 1.12版本我们仅支持Project Red(红石计划),在更低版本我们支持:RedLogic、Project Red(1.1版本)、MineFactory Reloaded(我的工厂重制版)。无线红石方面,支持以下模组:WR-CBE、SlimeVoid's WR。
自patch release 1.7.3起,红石组件提供以下函数的重载版本:getInput
、getOuput
、setInput
、getBundledInput
、getBundledOutput
以及setBundledOutput
。
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]范围。
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
lua> component.redstone.getOutput(sides.left) 7 lua> component.redstone.getOutput() [sides.left] 7
setOutput(side: number, value: number): number
setOutput(values: table): table
setOutput(values)
这种写法可以在一次调用内设定所有方向(或数个方向)上的红石信号强度。
getBundledInput(side: number, color: number): number
getBundledInput(side: number): table
getBundledInput(): table
getInput
类似,但适用于集束输入。读取指定颜色对应通道的值。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
getOutput
, but for bundled output, getting the values previously set that the device is emitting.setBundledOutput(side: number, color: number, value: number): number
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.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
getWirelessInput():number
getWirelessOutput():boolean
setWirelessOutput(value:boolean):boolean
getWirelessFrequency():number
setWirelessFrequency(frequency:number):number
getWakeThreshold():number
setWakeThreshold(threshold:number):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)) `` `