OC Sensors
Активный0.0
Установок
Последнее обновление
OC Sensors
Аддон с сенсорными устройствами для модификации 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("Поиск энергоблоков")
local positions = sensor.search("", -1, "energy")
print("Сканирование " .. #positions .. " блоков")
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("Энергетическая сводка:")
print(" Общая емкость: " .. totalCapacity);
print(" Накоплено: " .. totalStored);
Автоматизация работы генераторов
local component = require("component")
local sides = require("sides")
local sensor = component.sensor
local redstone = component.redstone
local redstoneSide = sides.back
-- Одноразовый поиск генераторов
local generators = sensor.search("", -1, "extrautils2")
while(true) do
-- Проверка готовности всех устройств
local missing = 0
for ,pos in ipairs(generators) do
local info = sensor.scan(pos.x, pos.y, pos.z)
local xu = info.data.extrautils2
-- Активен ли генератор?
local alreadyRunning = info.data.extrautils2.processTime > 0
-- Достаточно ли предметов?
local enoughItems = info.data.items.n == 0 or info.data.items.n == #info.data.items
-- Достаточно ли жидкости?
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("Готов: " .. info.block.label)
else
print("Не готов: " .. info.block.label)
-- Мгновенное отключение остальных генераторов
redstone.setOutput(redstoneSide, 0)
missing = missing + 1
end
end
-- Реакция системы
if(missing == 0) then
print("--> Все генераторы готовы")
redstone.setOutput(redstoneSide, 15)
else
print("--> Не готово " .. missing .. " генераторов")
end
os.sleep(1)
end
Анализ жидкостей у специальных коров
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"}