介绍
介绍由机器翻译自 CurseForge 原页面,仅供参考。
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
-- 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"}
常见问题
OC Sensors 支持哪些 Minecraft 版本?
OC Sensors 支持 Minecraft Java 版 1.10.2–1.12.2,共 4 个版本,可用的加载器:Forge。下载时注意选择和你游戏版本一致的文件。
OC Sensors 怎么安装?
先用 PCL2 或 HMCL 启动器安装对应版本的 Forge,再把下载的 .jar 文件放进游戏目录的 mods 文件夹,重新启动游戏即可。开启了版本隔离的,mods 文件夹在 versions/版本名 下面。
davenonymous 的其他作品
查看全部 →Compact Machines
by davenonymous, RobotGryphon
添加了一个简单的游戏机制:方块内部的小房间。它基本上让你能在单个方块内建造你的装置。
1亿
7 个月前
CurseForge
Bonsai Trees 4
by davenonymous
种出小树!
6039万
1 年前
CurseForge
OC XNet Driver
by davenonymous
允许 OpenComputers 利用 XNet 网络向连接的方块传输物品、流体和能量。
147万
8 年前
CurseForge
Libnonymous
by davenonymous
Davenonymous 制作的模组前置库
132万
2 年前
CurseForge
评论
登录后评论和评分