Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cells = {peripheral.wrap("tile_blockcapacitorbank_name_1"),
- peripheral.wrap("tile_blockcapacitorbank_name_3"),
- peripheral.wrap("tile_blockcapacitorbank_name_4"),
- peripheral.wrap("tile_blockcapacitorbank_name_5")
- }
- local energyTable = {}
- local maxEnergyTable = {}
- local previousEnergyTotal = 0
- local reactor = peripheral.wrap("BigReactors-Reactor_1")
- local monitor = peripheral.wrap("monitor_1")
- local enableReactorAt = 20
- function getLength(text)
- length = string.len(text)
- return length
- end
- function centerCursor(text)
- textLength = getLength(text)
- x, y = monitor.getSize()
- x2, y2 = monitor.getCursorPos()
- term.setCursorPos(math.round((x / 2) - (textLength / 2)), y2)
- end
- 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
- centerCursor(text[i])
- monitor.write(text[i])
- monitorNewLine()
- end
- end
- function writeText(text, color)
- monitor.setTextColor(color)
- centerCursor(text[i])
- monitor.write(text)
- monitorNewLine()
- end
- function energyUse(totalEnergyStored)
- reactorEnergyInput = 0
- if reactor.getActive() then
- reactorEnergyInput = reactor.getEnergyProducedLastTick()
- end
- energyTick = ((previousEnergyTotal - totalEnergyStored) / 20) + reactorEnergyInput
- return energyTick
- end
- function monitorUpdate(totalEnergyStored, totalEnergyCapacity)
- text = {}
- strStart = "Energy Cell "
- for i = 1, #energyTable do
- p = math.round((energyTable[i] / maxEnergyTable[i]) * 100)
- text[i] = strStart .. tostring(i) .. ": " .. tostring(energyTable[i]) .. "/" .. tostring(maxEnergyTable[i]) .. " : " .. p .. "%"
- end
- writeTextTable(text)
- p = math.round((totalEnergyStored / totalEnergyCapacity) * 100)
- textTotal = "Total Energy : " .. tostring(totalEnergyStored) .. "/" .. tostring(totalEnergyCapacity) .. " : " .. p .. "%"
- writeText(textTotal, colors.orange)
- usingEnergy = energyUse(totalEnergyStored)
- textUsing = "Using : " .. tostring(usingEnergy) .. " RF per tick"
- writeText(textUsing, colors.red)
- end
- function disableReactor()
- reactor.setActive(false)
- end
- function enableReactor()
- reactor.setActive(true)
- end
- function checkPower(totalEnergyStored, totalEnergyCapacity)
- isReactorActive = reactor.getActive()
- p = math.ceil((totalEnergyStored / totalEnergyCapacity) * 100)
- if isReactorActive then
- if p == 100 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)
- previousEnergyTotal = totalEnergyStored
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement