Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[opencomputers reactor IC2 mfsu control by serafim
- pastebin.com/LkNfzaQv update 05.07.21
- управление реактором IC2(1.12.2) поддерживая
- заряд в энергохранилище на уровне 97-100 %
- требования:
- компьютер 1-го уровня,
- адаптер, контроллер красного камня,
- реактор IC2, любая батарея IC2.
- пример сборки:
- https://i.imgur.com/xc8hrvH.png
- ]]--
- local heat = 130 --температура перегрева реактора до отключения
- local batlist = {
- "ic2_te_batbox",
- "ic2_te_cesu",
- "ic2_te_mfe",
- "ic2_te_mfsu",
- "ic2_te_chargepad_batbox",
- "ic2_te_chargepad_cesu",
- "ic2_te_chargepad_mfe",
- "ic2_te_chargepad_mfsu"
- }
- local com = require("component")
- local computer = require("computer")
- local event = require("event")
- local gpu = com.gpu
- local w, h = gpu.getResolution()
- local noFuel,sideRed,run,bat = 0,nil,true
- if not com.isAvailable("redstone") then
- print("нет контроллера красного камня")
- os.exit()
- end
- local red = com.redstone
- if com.isAvailable("reactor") then
- reactor = com.reactor
- elseif com.isAvailable("reactor_chamber") then
- reactor = com.reactor_chamber
- else
- print("реактор не найден")
- os.exit()
- end
- if reactor.getHeat() > heat then
- print("перегрев реактора")
- os.exit()
- end
- if reactor.producesEnergy() then
- print("остановите реактор !")
- for i = 0,5 do
- if red.getOutput(i) > 0 then
- red.setOutput(i, 0)
- end
- end
- os.exit()
- end
- for j, name in pairs(batlist) do
- local adress = com.list(name)()
- if adress then
- bat = com.proxy(adress)
- print("подключен "..name)
- break
- end
- if j == #batlist then
- print("батарея не найдена")
- os.exit()
- end
- end
- local capacity = math.floor(bat.getCapacity())
- print("пробный запуск")
- for i, n in pairs({3,2,4,5,0,1}) do
- red.setOutput(n, 15)
- if reactor.producesEnergy() then
- sideRed = n
- red.setOutput(sideRed, 0)
- print("реактор в стороне "..sideRed)
- os.sleep(1)
- break
- else
- red.setOutput(n, 0)
- end
- if i == 6 then
- print("\n".."реактор не запускается")
- os.exit()
- end
- end
- gpu.setResolution(18,6)
- gpu.setBackground(0x000000)
- gpu.fill(1,1,18,6," ")
- gpu.set(1,1,"всего "..capacity)
- gpu.set(1,2,"энергии")
- gpu.set(1,3,"хранит")
- gpu.set(1,4,"eu/t")
- gpu.set(1,5,"нагрев")
- gpu.set(1,6,"реактор остановлен")
- local function stop(wait)
- if event.pull(wait,"key_down") then
- red.setOutput(sideRed, 0)
- gpu.setResolution(w,h)
- gpu.fill(1,1,w,h," ")
- print("программа завершена")
- os.sleep(1)
- if reactor.producesEnergy() then
- print("ВНИМАНИЕ реактор по прежнему активен !!!")
- computer.beep(500, 1)
- else
- print("реактор остановлен")
- end
- run = false
- end
- end
- local function ReactorControl()
- local energy = math.floor(bat.getEnergy())
- local percent = math.floor(energy/capacity*100)
- local reactorHeat = math.floor(reactor.getHeat())
- gpu.set(9,2,energy.." ")
- gpu.set(9,3,percent.." % ")
- gpu.set(9,4,math.floor(reactor.getReactorEUOutput()).." ")
- if reactorHeat > heat then
- red.setOutput(sideRed, 0)
- gpu.set(1,6,"перегрев реактора")
- computer.beep(500, 1)
- stop(3)
- else
- gpu.set(9,5,reactorHeat.." ")
- if percent < 98 then
- red.setOutput(sideRed, 15)
- if not reactor.producesEnergy() then
- gpu.set(1,6,"нет запуска реактора")
- elseif reactor.getReactorEUOutput() == 0 then
- noFuel = noFuel + 1
- else
- noFuel = 0
- end
- if noFuel >= 3 then
- gpu.set(1,6,"нет топлива ! ")
- computer.beep(500, 1)
- stop(3)
- else
- gpu.set(1,6,"реактор активен ")
- end
- elseif percent >= 100 then
- red.setOutput(sideRed, 0)
- gpu.set(1,6,"реактор остановлен")
- end
- end
- end
- while run do
- local ok,err = pcall(ReactorControl)
- if not ok then
- red.setOutput(sideRed, 0)
- gpu.setResolution(w,h)
- gpu.setBackground(0x000000)
- gpu.setForeground(0xFFFFFF)
- os.execute("cls")
- print("программа аварийно завершена")
- io.stderr:write(err)
- run = false
- end
- stop(1)
- end
Add Comment
Please, Sign In to add comment