Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cells = {peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_10"),
- peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_11"),
- peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_12"),
- peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_13"),
- peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_14"),
- peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_15"),
- peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_16")
- }
- local energyTable = {}
- local maxEnergyTable = {}
- local reactor = peripheral.wrap("BigReactors-Reactor_1")
- local monitor = peripheral.wrap("monitor_1")
- local enableReactorAt = 20
- function monitorClear()
- monitor.setTextColor(colors.white)
- monitor.clear()
- monitor.setCursorPos(1,1)
- end
- function monitorNewLine()
- x, y = monitor.getCursorPos()
- newY = y + 1
- monitor.setCursorPos(1, newY)
- end
- function writeTextTable(text)
- monitorClear()
- for i = 1, #text do
- monitor.write(text[i])
- monitorNewLine()
- end
- end
- function writeText(text, color)
- monitor.setTextColor(color)
- monitor.write(text)
- monitorNewLine()
- end
- function monitorUpdate(totalEnergyStored, totalEnergyCapacity)
- text = {}
- strStart = "Energy Cell "
- for i = 1, #energyTable do
- text[i] = strStart .. tostring(i) .. " : " .. tostring(energyTable[i]) .. "/" .. tostring(maxEnergyTable[i])
- end
- writeTextTable(text)
- textTotal = "Total Energy : " .. tostring(totalEnergyStored) .. " / " .. tostring(totalEnergyCapacity)
- writeText(textTotal, colors.orange)
- end
- function disableReactor()
- reactor.setActive(false)
- end
- function enableReactor()
- reactor.setActive(true)
- end
- function checkPower(totalEnergyStored, totalEnergyCapacity)
- isReactorActive = reactor.isActive()
- p = math.floor((totalEnergyStored / totalEnergyCapacity) * 100)
- if isReactorActive then
- if totalEnergyStored == totalEnergyCapacity then
- disableReactor()
- else
- return
- end
- elseif p <= enableReactorAt then
- enableReactor()
- end
- end
- while true do
- totalEnergyStored = 0
- totalEnergyCapacity = 0
- for i = 1, #cells do
- energyStored = cells[i].getEnergyStored()
- maxEnergyStored = cells[i].getMaxEnergyStored()
- energyTable[i] = energyStored
- maxEnergyTable[i] = maxEnergyStored
- totalEnergyStored = totalEnergyStored + tonumber(energyStored)
- totalEnergyCapacity = totalEnergyCapacity + tonumber(maxEnergyStored)
- end
- monitorUpdate(totalEnergyStored, totalEnergyCapacity)
- checkPower(totalEnergyStored, totalEnergyCapacity)
- sleep(2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement