Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- By Serious07 in 2021 y. Twitter @Serious_07 VK: serious07
- -- My server is https://gregtechrus.ru
- -- How to use example: https://imgur.com/a/kdM0ZOT?
- -- Require:
- -- Monitor and GPU tear 2
- -- Adapter, Transposer, Redstone controller
- -- Container for rods and coolants
- -- Vars rod rodDeplited cool used to find items for replacement in nuclear reactor
- -- Change them if you need to
- -- Localization
- -- Now on Russian you can translate it tou your language
- local str_not_enought_free_slots = " Ошибка в сундуке остутствуют свободные слоты!!!"
- local str_not_enought_fuel_rods = " Ошибка в сундуке недостаточно обогощённых стержней!!!"
- local str_reactor_is_active = " Реактор активен "
- local str_current_step = " Шаг проверки: "
- local str_to_close_program_press_E = " Для выхода из программы нажимайте клавишу E"
- local str_reactor_overheat = " ПЕРЕГРЕВ РЕАКТОРА!!! Ждём остужения!!!"
- local str_rod_replacement = " Замена стержней!!!"
- local str_coolant_replacement = " Замена охладителей!!!"
- local str_replace = " Заменяем: "
- local str_slot_x = " Слот x: "
- local str_program_closed = " Программа завершена"
- local str_reactor_stopped = " Реактор остановлен"
- local str_warning_reactor_is_running = " ВНИМАНИЕ реактор по прежнему активен !!!"
- local str_transposer_not_found = " Нет транспосера!"
- local str_redstone_controller_not_found = " Нет контроллера красного камня!"
- local str_nuclear_reactor_chamber_not_found = " Камера реактора не найдена, установите Adapter!"
- local str_nuclear_reactor_side_not_found = "Реактор не найден! Измените сторону в nuclearSide!"
- local str_chest_side_not_found = "Сундук не найден! Измените сторону в containerSide!"
- local str_chest_not_enought_space = "Не найдено свободного места в сундуке!"
- local str_chest_dont_have_coolant = "Не найден охладитель в сундуке!"
- local str_chest_dont_have_rod = "Не найден стержень в сундуке!"
- local component = require("component")
- if not component.isAvailable("transposer") then
- print(str_transposer_not_found)
- os.exit()
- end
- local transposer = component.transposer
- if not component.isAvailable("redstone") then
- print(str_redstone_controller_not_found)
- os.exit()
- end
- local red = component.redstone
- if not component.isAvailable("reactor_chamber") then
- print(str_nuclear_reactor_chamber_not_found)
- os.exit()
- end
- local reactor = component.reactor_chamber
- local term = require("term")
- local event = require("event")
- local colors = require("colors")
- local sides = require("sides")
- local computer = require("computer")
- local keyboard = require("keyboard")
- local gpu = component.gpu
- local nuclearSide = sides.south; -- расположение реактора
- local containerSide = sides.east; -- расположение контейнера с элементами
- if not nuclearSide then
- print("\n"..str_nuclear_reactor_side_not_found)
- os.exit()
- end
- if not containerSide then
- print("\n"..str_chest_side_not_found)
- os.exit()
- end
- local const coolChar = "c" -- обозначение для куланта в реакторе
- local const rodChar = "r" -- обозначение для рода в реакторе
- local rectWidth = 9 -- ширина сетки реактора
- local reactHeight = 6 -- высота сетки реактора
- local reactorSlotsCount = rectWidth * reactHeight -- общее количество слотов
- local chestMax = transposer.getInventorySize(containerSide) -- количествослотов сундука
- local maxDmgCool = 70 -- Условие для замены охлаждающих элементов
- local offReac = 6500 -- Температура реактора
- local stepsToReplaceCells = 9 -- Условие отображающее количества шагов для замены стержней
- -- Информация для поиска стержней
- local rod = "gregtech:gt.reactorMOXQuad"
- local rodDeplited = "IC2:reactorMOXQuaddepleted"
- local cool = "gregtech:gt.360k_NaK_Coolantcell"
- local reactorSlotsList = {"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""}
- local firstCheck = true
- local checksCounter = 0
- isRunning = true
- local currentResolution = gpu.getViewport()
- local function EmmitRedstone(signal)
- for sideRed = 0, 5 do
- red.setOutput(sideRed, signal)
- end
- end
- local function gui()
- term.clear() -- убирает с экрана все символы
- term.setCursor(1,1) -- переносит курсор направо наверх
- gpu.setBackground(0x000000)
- gpu.fill(1,1,28,15," ")
- gpu.setForeground(0x669999)
- gpu.set(1,1,"┌──────────────────────────┐")
- gpu.set(1,2,"│ │ │ │ │ │ │ │ │ │")
- gpu.set(1,3,"│──────────────────────────│")
- gpu.set(1,4,"│ │ │ │ │ │ │ │ │ │")
- gpu.set(1,5,"│──────────────────────────│")
- gpu.set(1,6,"│ │ │ │ │ │ │ │ │ │")
- gpu.set(1,7,"│──────────────────────────│")
- gpu.set(1,8,"│ │ │ │ │ │ │ │ │ │")
- gpu.set(1,9,"│──────────────────────────│")
- gpu.set(1,10,"│ │ │ │ │ │ │ │ │ │")
- gpu.set(1,11,"│──────────────────────────│")
- gpu.set(1,12,"│ │ │ │ │ │ │ │ │ │")
- gpu.set(1,13,"└──────────────────────────┘")
- end
- function getGUIX(x)
- return 2 + (3 * (x - 1))
- end
- function getGUIY(y)
- return 2 + (2 * (y - 1))
- end
- local function stop()
- EmmitRedstone(0)
- term.clear() -- убирает с экрана все символы
- term.setCursor(1,1) -- переносит курсор направо наверх
- gpu.setBackground(0x000000)
- gpu.setForeground(0xFFFFFF)
- print("\n"..str_program_closed)
- os.sleep(1)
- if reactor.producesEnergy() then
- print(str_warning_reactor_is_running)
- else
- print(str_reactor_stopped)
- end
- if tMain ~= nil then tMain:kill() end
- if tInterrapt ~= nil then tInterrapt:kill() end
- if tKeyEvent ~= nil then tKeyEvent:kill() end
- term.setCursor(1,1) -- переносит курсор направо наверх
- isRunning = false
- os.exit()
- end
- local function alert(message)
- gpu.setForeground(0xFF0000)
- gpu.set(1,15,message)
- computer.beep(500, 1)
- local e = {event.pull(0.03,"key_down")}
- if e[4] == 18 or e[4] == 20 then
- stop()
- end
- end
- local function clearAlert()
- gpu.set(1,14," ")
- gpu.set(1,15," ")
- end
- -- Функция возвращающая X координату из простого числа
- function getReactorXSlot(simpleNumber)
- return (simpleNumber % rectWidth)
- end
- -- Функция возвращающая Y координату из простого числа
- function getReactorYSlot(simpleNumber)
- return math.floor(simpleNumber / rectWidth) + 1
- end
- -- Функция возвращает одномерную позицию слота в сетке слотов
- function getReactorSimpleSlotNumber(x, y)
- rowCoords = (y - 1);
- return (rowCoords * rectWidth) + x;
- end
- function dump(o)
- if type(o) == 'table' then
- local s = '{ '
- for k,v in pairs(o) do
- if type(k) ~= 'number' then k = '"'..k..'"' end
- s = s .. '['..k..'] = ' .. dump(v) .. ','
- end
- return s .. '} '
- else
- return tostring(o)
- end
- end
- function findFreeChestSlot()
- for i = 1, chestMax do
- local stack = transposer.getStackInSlot(containerSide, i)
- if stack == nil then
- return i
- end
- local e = {event.pull(0.03,"key_down")}
- if e[4] == 18 or e[4] == 20 then
- stop()
- end
- end
- return -1
- end
- function findNewCool()
- for i = 1, chestMax do
- local stack = transposer.getStackInSlot(containerSide, i)
- if stack ~= nil then
- if stack.name == cool and stack.damage == 0 then
- return i
- end
- end
- local e = {event.pull(0.03,"key_down")}
- if e[4] == 18 or e[4] == 20 then
- stop()
- end
- end
- return -1
- end
- function findNewRod()
- for i = 1, chestMax do
- local stack = transposer.getStackInSlot(containerSide, i)
- if stack ~= nil then
- if stack.name == rod then
- return i
- end
- end
- local e = {event.pull(0.03,"key_down")}
- if e[4] == 18 or e[4] == 20 then
- stop()
- end
- end
- return -1
- end
- function updateGUIInCheckProcess(x, y, stack)
- gpu.set(getGUIX(x), getGUIY(y), "██")
- gpu.setForeground(0xFF9900)
- gpu.set(1,17," ")
- gpu.set(1,18," ")
- gpu.set(1,17,str_slot_x..x.." y: "..y)
- gpu.set(1,18,str_replace..stack.name)
- end
- function replaceCoolant(slotNumber, freeChestSlot, newCoolSlot)
- local fcs = freeChestSlot
- local ncl = newCoolSlot
- if fcs == -1 then
- alert(str_chest_not_enought_space)
- -- Убрать редстоун сигнал
- EmmitRedstone(0)
- while fcs == -1 do
- fcs = findFreeChestSlot()
- os.sleep(0.5)
- end
- elseif ncl == -1 then
- alert(str_chest_dont_have_coolant)
- -- Убрать редстоун сигнал
- EmmitRedstone(0)
- while ncl == -1 do
- ncl = findNewCool()
- os.sleep(0.5)
- end
- fcs = findFreeChestSlot()
- if fcs == -1 then
- alert(str_chest_not_enought_space)
- -- Убрать редстоун сигнал
- EmmitRedstone(0)
- while fcs == -1 do
- fcs = findFreeChestSlot()
- os.sleep(0.5)
- end
- end
- end
- -- Вынуть охладитель переложить в сундук
- repeat until transposer.transferItem(nuclearSide, containerSide, 1, slotNumber, fcs)
- -- Из сундука достать первый целый охладитель и поместить в реактор
- repeat until transposer.transferItem(containerSide, nuclearSide, 1, ncl, slotNumber)
- end
- function replaceRod(slotNumber, freeChestSlot, newRodSlot)
- local fcs = freeChestSlot
- local nrs = newRodSlot
- if fcs == -1 then
- alert(str_chest_not_enought_space)
- -- Убрать редстоун сигнал
- EmmitRedstone(0)
- while fcs == -1 do
- fcs = findFreeChestSlot()
- os.sleep(0.5)
- end
- elseif nrs == -1 then
- alert(str_chest_dont_have_rod)
- -- Убрать редстоун сигнал
- EmmitRedstone(0)
- while nrs == -1 do
- nrs = findNewRod()
- os.sleep(0.5)
- end
- fcs = findFreeChestSlot()
- if fcs == -1 then
- alert(str_chest_not_enought_space)
- -- Убрать редстоун сигнал
- EmmitRedstone(0)
- while fcs == -1 do
- fcs = findFreeChestSlot()
- os.sleep(0.5)
- end
- end
- end
- -- Вынуть стержень переложить в сундук
- repeat until transposer.transferItem(nuclearSide, containerSide, 1, slotNumber, fcs)
- -- Из сундука достать первый целый стержень и поместить в реактор
- repeat until transposer.transferItem(containerSide, nuclearSide, 1, nrs, slotNumber)
- end
- function checkCoolants()
- local needEmmit = false
- for x = 1, rectWidth do
- for y = 1, reactHeight do
- local slotNumber = getReactorSimpleSlotNumber(x, y)
- if reactorSlotsList[slotNumber] == coolChar then
- local stack = transposer.getStackInSlot(nuclearSide, slotNumber)
- if stack ~= nil then
- if stack.name == cool and stack.damage >= maxDmgCool then
- if freeChestSlot ~= -1 and newCoolSlot ~= -1 then
- local freeChestSlot = findFreeChestSlot()
- local newCoolSlot = findNewCool()
- alert(str_coolant_replacement)
- -- Убрать редстоун сигнал
- EmmitRedstone(0)
- needEmmit = true
- -- Обновить GUI
- updateGUIInCheckProcess(x, y, stack)
- -- Замена охладителя
- replaceCoolant(slotNumber, freeChestSlot, newCoolSlot)
- clearAlert()
- elseif freeChestSlot == -1 then
- print(str_not_enought_free_slots)
- elseif newCoolSlot == -1 then
- print(str_not_enought_fuel_rods)
- end
- end
- end
- end
- local e = {event.pull(0.03,"key_down")}
- if e[4] == 18 or e[4] == 20 then
- break
- stop()
- end
- end
- end
- if needEmmit then
- -- Подать редстоун сигнал
- EmmitRedstone(15)
- end
- updateGUI()
- end
- function checkRoads()
- local needEmmit = false
- for x = 1, rectWidth do
- for y = 1, reactHeight do
- local slotNumber = getReactorSimpleSlotNumber(x, y)
- if reactorSlotsList[slotNumber] == rodChar then
- local stack = transposer.getStackInSlot(nuclearSide, slotNumber)
- if stack ~= nil and stack.name == rodDeplited then
- if freeChestSlot ~= -1 and newRodSlot ~= -1 then
- local freeChestSlot = findFreeChestSlot()
- local newRodSlot = findNewRod()
- alert(str_rod_replacement)
- -- Убрать редстоун сигнал
- needEmmit = true
- EmmitRedstone(0)
- -- Обновить GUI
- updateGUIInCheckProcess(x, y, stack)
- -- Замена стержня
- replaceRod(slotNumber, freeChestSlot, newRodSlot)
- clearAlert()
- elseif freeChestSlot == -1 then
- print(str_not_enought_free_slots)
- elseif newRodSlot == -1 then
- print(str_not_enought_fuel_rods)
- end
- end
- end
- local e = {event.pull(0.03,"key_down")}
- if e[4] == 18 or e[4] == 20 then
- break
- stop()
- end
- end
- end
- if needEmmit then
- -- Подать редстоун сигнал
- EmmitRedstone(15)
- end
- updateGUI()
- end
- function checkReactor()
- local needEmmit = false
- for x = 1, rectWidth do
- for y = 1, reactHeight do
- local slotNumber = getReactorSimpleSlotNumber(x, y)
- local stack = transposer.getStackInSlot(nuclearSide, slotNumber)
- if stack ~= nil then
- if stack.name == cool then
- if firstCheck == true then
- reactorSlotsList[slotNumber] = coolChar
- end
- if freeChestSlot ~= -1 and newCoolSlot ~= -1 and stack.damage >= maxDmgCool then
- local freeChestSlot = findFreeChestSlot()
- local newCoolSlot = findNewCool()
- alert(str_coolant_replacement)
- -- Убрать редстоун сигнал
- EmmitRedstone(0)
- needEmmit = true
- -- Обновить GUI
- gpu.set(getGUIX(x), getGUIY(y), "██")
- -- Замена охладителя
- replaceCoolant(slotNumber, freeChestSlot, newCoolSlot)
- clearAlert()
- elseif freeChestSlot == -1 then
- print(str_not_enought_free_slots)
- elseif newCoolSlot == -1 then
- print(str_not_enought_fuel_rods)
- end
- elseif stack.name == rodDeplited then
- if firstCheck == true then
- reactorSlotsList[slotNumber] = rodChar
- end
- if freeChestSlot ~= -1 and newRodSlot ~= -1 then
- local freeChestSlot = findFreeChestSlot()
- local newRodSlot = findNewRod()
- alert(str_rod_replacement)
- -- Убрать редстоун сигнал
- EmmitRedstone(0)
- needEmmit = true
- -- Обновить GUI
- gpu.set(getGUIX(x), getGUIY(y), "██")
- -- Замена стержня
- replaceRod(slotNumber, freeChestSlot, newRodSlot)
- clearAlert()
- elseif freeChestSlot == -1 then
- print(str_not_enought_free_slots)
- elseif newRodSlot == -1 then
- print(str_not_enought_fuel_rods)
- end
- elseif stack.name == rod then
- if firstCheck == true then
- reactorSlotsList[slotNumber] = rodChar
- end
- end
- end
- local e = {event.pull(0.03,"key_down")}
- if e[4] == 18 or e[4] == 20 then
- break
- stop()
- end
- end
- end
- if needEmmit then
- -- Подать редстоун сигнал
- EmmitRedstone(15)
- end
- updateGUI()
- firstCheck = false
- end
- function updateGUI()
- gpu.setForeground(0x23b825)
- for x = 1, rectWidth do
- for y = 1, reactHeight do
- local slotNumber = getReactorSimpleSlotNumber(x, y)
- local stack = transposer.getStackInSlot(nuclearSide, slotNumber)
- if stack ~= nil then
- -- Обновить GUI
- if stack.damage < 100 then
- if stack.name == cool then
- gpu.setForeground(0x124be6)
- elseif stack.name == rod then
- gpu.setForeground(0x22bf2a)
- end
- local dur = tostring(math.floor(stack.damage))
- if string.len(dur) == 1 then
- dur = "0"..dur
- end
- gpu.set(getGUIX(x), getGUIY(y), dur)
- end
- end
- end
- end
- OutputEUt = math.ceil(reactor.getReactorEUOutput())
- gpu.setForeground(0x00FF00)
- gpu.set(1,14, " Eu/t = "..OutputEUt.." ")
- gpu.set(1,15, str_reactor_is_active)
- gpu.set(1,16, " ")
- gpu.set(1,16, str_current_step..checksCounter)
- gpu.set(1,17, " ")
- gpu.set(1,18, " ")
- gpu.set(1,19, str_to_close_program_press_E)
- end
- EmmitRedstone(0)
- gui()
- if firstCheck == true then
- checkReactor()
- EmmitRedstone(15)
- end
- -- Цикл программы
- while isRunning do
- local e = {event.pull(0.03,"key_down")}
- if e[4] == 18 or e[4] == 20 then
- stop()
- else
- if reactor.getHeat() > offReac then
- alert(str_reactor_overheat)
- EmmitRedstone(0)
- os.sleep(1)
- else
- EmmitRedstone(15)
- checkCoolants()
- if checksCounter == stepsToReplaceCells then
- checkRoads()
- checksCounter = 0
- end
- checksCounter = checksCounter + 1
- os.sleep(0.03)
- end
- end
- end
Add Comment
Please, Sign In to add comment