组件:红石

此组件由红石卡提供。

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

回调函数:

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
snippet.lua
lua> component.redstone.getOutput(sides.left)
7
lua> component.redstone.getOutput() [sides.left]
7
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

请注意对于如ProjectRed(红石计划)这样的模组而言,较低的强度值(例如原版最高为15的强度值)可能不会像预期一样起到简单开/关信号的作用(例如用于开门)。因为这些模组的红石信号值范围更大。你可能需要指定一个更大的值,例如255。

使用例:

snippet.lua
local component = require("component")
local sides = require("sides")
local colors = require("colors")
local rs = component.redstone --获取首选红石组件
print(rs.getInput(sides.back))
rs.setBundledOutput(sides.bottom, colors.green, rs.getBundledInput(sides.top, colors.red))

`

目录