ocsensors
OpenComputers 的传感器附加组件
类似于旧的 OpenCCSensors 模组,此模组添加了一个传感器方块,允许
计算机扫描周围的方块。
可用方法
| 方法 | 描述 |
|---|---|
| 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);
当所有附近的 Extra Utilities 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
<span>-- Is the generator already running?</span>
<span>local</span> alreadyRunning = info.data.extrautils2.processTime > <span>0</span>
<span>-- Is the Generator satisfied with items?</span>
<span>local</span> enoughItems = info.data.items.n == <span>0</span> <span>or</span> info.data.items.n == #info.data.items
<span>-- Is it satisfied with fluid?</span>
<span>local</span> enoughFluid = <span>true</span>
<span>if</span>(info.data.fluid.n > <span>0</span>) <span>then</span>
<span>for</span> _,tank <span>in</span> <span>ipairs</span>(info.data.fluid) <span>do</span>
<span>if</span>(tank.contents == <span>nil</span> <span>or</span> tank.contents.amount == <span>0</span>) <span>then</span>
enoughFluid = <span>false</span>
<span>end</span>
<span>end</span>
<span>end</span>
<span>if</span>(alreadyRunning <span>or</span> (enoughItems <span>and</span> enoughFluid)) <span>then</span>
<span>--print(info.block.label .. ": " .. serialization.serialize(info.data))</span>
<span>print</span>(<span>"Ready: "</span> .. info.block.label)
<span>else</span>
<span>print</span>(<span>"Missing: "</span> .. info.block.label)
<span>-- Immediately turn off all other generators</span>
redstone.setOutput(redstoneSide, <span>0</span>)
missing = missing + <span>1</span>
<span>end</span>
<span>end</span>
<span>-- React accordingly</span>
<span>if</span>(missing == <span>0</span>) <span>then</span>
<span>print</span>(<span>"--> All generators good to go"</span>)
redstone.setOutput(redstoneSide, <span>15</span>)
<span>else</span>
<span>print</span>(<span>"--> Missing "</span> .. missing .. <span>" generators"</span>)
<span>end</span>
<span>os</span>.sleep(<span>1</span>)
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))
-- {"岩浆", "岩浆", "岩浆", "水", "水", "岩浆"}
你是这个资源的作者?登录后可认领此资源。
相似资源
一个用于收集生物掉落物的多区块模组。
AE2:一款流行的自动化与存储模组
基于 GTCEu 1.12.2 的现代 GregTech
让你能够在世界中的任何位置定位结构。
高科技机械、强大的能量生成、炫酷的小工具以及更多内容。现已登陆 Modrinth!
一款轻量级模组,允许服务器管理员对抗透视作弊者。
评论 0
登录后参与评分
还没有评论,来抢沙发吧