距离显示结果还剩5票~
暂无日志..
暂无管理组..
暂无编辑组..
暂无开发组..
ocsensors
开放式电脑的传感器扩展。
类似于开放式电脑传感器,本模组增加了一个传感器方块,允许扫描周围的方块。
可行方法
方法 | 简介 |
scan(x:number, y:number, z:number, [side:number]) | 扫描一格临近传感器的方块 |
search([name:string=”“], [meta:number=-1], [section:string=”“], [range:number=]) | 寻找已定范围内符合条件的方块 |
searchEntities(x1:number, y1:number, z1:number, x2:number, y2:number, z3:number) | 扫描临近传感器区域里的实体 |
例子
获取附近的可储能方块的储能量
local component = require('component')
local sensor = component.sensor
local totalCapacity = 0
local totalStored = 0
print("Searching for blocks handling energy")
local positions = sensor.search("", -1, "energy")
print("Scanning " .. #positions .. " blocks")
for _,pos in ipairs(positions) do
local info = sensor.scan(pos.x, pos.y, pos.z)
print(" " .. info.block.label .. " @ " .. pos.x .. "," .. pos.y .. "," .. pos.z)
totalStored = totalStored + info.data.energy.energyStored
totalCapacity = totalCapacity + info.data.energy.maxEnergyStored
end
print("")
print("Energy summary:")
print(" Total capacity: " .. totalCapacity);
print(" Total stored: " .. totalStored);
当所有附近的更多实用设备2发电机准备好运行时,输出红石信号
local component = require("component")
local sides = require("sides")
local sensor = component.sensor
local redstone = component.redstone
local redstoneSide = sides.back
-- Search for generators once
local generators = sensor.search("", -1, "extrautils2")
while(true) do
-- Loop over nearby machines and see if they are all satisfied
local missing = 0
for _,pos in ipairs(generators) do
local info = sensor.scan(pos.x, pos.y, pos.z)
local xu = info.data.extrautils2
-- Is the generator already running?
local alreadyRunning = info.data.extrautils2.processTime > 0
-- Is the Generator satisfied with items?
local enoughItems = info.data.items.n == 0 or info.data.items.n == #info.data.items
-- Is it satisfied with fluid?
local enoughFluid = true
if(info.data.fluid.n > 0) then
for _,tank in ipairs(info.data.fluid) do
if(tank.contents == nil or tank.contents.amount == 0) then
enoughFluid = false
end
end
end
if(alreadyRunning or (enoughItems and enoughFluid)) then
--print(info.block.label .. ": " .. serialization.serialize(info.data))
print("Ready: " .. info.block.label)
else
print("Missing: " .. info.block.label)
-- Immediately turn off all other generators
redstone.setOutput(redstoneSide, 0)
missing = missing + 1
end
end
-- React accordingly
if(missing == 0) then
print("--> All generators good to go")
redstone.setOutput(redstoneSide, 15)
else
print("--> Missing " .. missing .. " generators")
end
os.sleep(1)
end
丢弃所有附近的MooFluid牛的流体
local component = require('component')
local serialization = require('serialization')
local sensor = component.sensor
local range = 5
local foundFluids = {}
for _, entity in ipairs(sensor.searchEntities(-range, -range, -range, range, range, range)) do
if(entity.type == "neutral" and entity.moofluids ~= nil) then
foundFluids[#foundFluids+1] = entity.moofluids.fluid.name
end
end
print(serialization.serialize(foundFluids))
-- {"lava", "lava", "lava", "water", "water", "lava"}