Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cell0Periph = peripheral.wrap("redstone_energy_cell_0")
- cell1Periph = peripheral.wrap("redstone_energy_cell_1")
- cell2Periph = peripheral.wrap("redstone_energy_cell_2")
- cell3Periph = peripheral.wrap("redstone_energy_cell_3")
- cell4Periph = peripheral.wrap("redstone_energy_cell_4")
- cell5Periph = peripheral.wrap("redstone_energy_cell_5")
- cell6Periph = peripheral.wrap("redstone_energy_cell_6")
- cell7Periph = peripheral.wrap("redstone_energy_cell_7")
- enginesOn = {1,1,1,1,1,1,1,1}
- energyPercentage = {0,0,0,0,0,0,0,0}
- rednetColors = {colors.white, colors.pink, colors.yellow, colors.magenta, colors.orange, colors.gray, colors.lime, colors.lightBlue}
- function getProviders()
- cell0 = cell0Periph.getPowerProvider()
- cell1 = cell1Periph.getPowerProvider()
- cell2 = cell2Periph.getPowerProvider()
- cell3 = cell3Periph.getPowerProvider()
- cell4 = cell4Periph.getPowerProvider()
- cell5 = cell5Periph.getPowerProvider()
- cell6 = cell6Periph.getPowerProvider()
- cell7 = cell7Periph.getPowerProvider()
- end
- function getEnergyLevels()
- energyPercentage[1] = (cell0.energyStored / cell0.maxEnergyStored) * 100
- energyPercentage[2] = (cell1.energyStored / cell1.maxEnergyStored) * 100
- energyPercentage[3] = (cell2.energyStored / cell2.maxEnergyStored) * 100
- energyPercentage[4] = (cell3.energyStored / cell3.maxEnergyStored) * 100
- energyPercentage[5] = (cell4.energyStored / cell4.maxEnergyStored) * 100
- energyPercentage[6] = (cell5.energyStored / cell5.maxEnergyStored) * 100
- energyPercentage[7] = (cell6.energyStored / cell6.maxEnergyStored) * 100
- energyPercentage[8] = (cell7.energyStored / cell7.maxEnergyStored) * 100
- end
- function writeBarGraph(cellNum, value, state)
- term.write("Cell "..cellNum..": [")
- w,h = term.getCursorPos()
- term.write(string.rep(".",20).."] "..state.." "..math.floor(value))
- term.setCursorPos(w,h)
- term.write(string.rep("*",value/5))
- end
- function writeStatus()
- term.clear()
- term.setCursorPos(1,1)
- writeBarGraph("0", energyPercentage[1], enginesOn[1])
- term.setCursorPos(1,2)
- writeBarGraph("1", energyPercentage[2], enginesOn[2])
- term.setCursorPos(1,3)
- writeBarGraph("2", energyPercentage[3], enginesOn[3])
- term.setCursorPos(1,4)
- writeBarGraph("3", energyPercentage[4], enginesOn[4])
- term.setCursorPos(1,5)
- writeBarGraph("4", energyPercentage[5], enginesOn[5])
- term.setCursorPos(1,6)
- writeBarGraph("5", energyPercentage[6], enginesOn[6])
- term.setCursorPos(1,7)
- writeBarGraph("6", energyPercentage[7], enginesOn[7])
- term.setCursorPos(1,8)
- writeBarGraph("7", energyPercentage[8], enginesOn[8])
- end
- function setOutput()
- curColors = 0
- if energyPercentage[1] < 50 then
- enginesOn[1] = 1
- elseif energyPercentage[1] > 90 then
- enginesOn[1] = 0
- end
- if energyPercentage[2] < 50 then
- enginesOn[2] = 1
- elseif energyPercentage[2] > 90 then
- enginesOn[2] = 0
- end
- if energyPercentage[3] < 50 then
- enginesOn[3] = 1
- elseif energyPercentage[3] > 90 then
- enginesOn[3] = 0
- end
- if energyPercentage[4] < 50 then
- enginesOn[4] = 1
- elseif energyPercentage[4] > 90 then
- enginesOn[4] = 0
- end
- if energyPercentage[5] < 50 then
- enginesOn[5] = 1
- elseif energyPercentage[5] > 90 then
- enginesOn[5] = 0
- end
- if energyPercentage[6] < 50 then
- enginesOn[6] = 1
- elseif energyPercentage[6] > 90 then
- enginesOn[6] = 0
- end
- if energyPercentage[7] < 50 then
- enginesOn[7] = 1
- elseif energyPercentage[7] > 90 then
- enginesOn[7] = 0
- end
- if energyPercentage[8] < 50 then
- enginesOn[8] = 1
- elseif energyPercentage[8] > 90 then
- enginesOn[8] = 0
- end
- curColors = enginesOn[1] * rednetColors[1] + enginesOn[2] * rednetColors[2] + enginesOn[3] * rednetColors[3] + enginesOn[4] * rednetColors[4] + enginesOn[5] * rednetColors[5] + enginesOn[6] * rednetColors[6]+ enginesOn[7] * rednetColors[7] + enginesOn[8] * rednetColors[8]
- rs.setBundledOutput("right", curColors)
- end
- function findMonitor()
- for i = 0,10 do
- local monitor = peripheral.wrap("monitor_" .. i)
- if monitor then return monitor end
- end
- return nil
- end
- function getTextColorForBackground(color)
- if (color == colors.white) then return colors.black
- elseif (color == colors.orange) then return colors.black
- elseif (color == colors.magenta) then return colors.black
- elseif (color == colors.lightBlue) then return colors.black
- elseif (color == colors.yellow) then return colors.black
- elseif (color == colors.lime) then return colors.black
- elseif (color == colors.pink) then return colors.black
- elseif (color == colors.gray) then return colors.white
- elseif (color == colors.lightGray) then return colors.black
- elseif (color == colors.cyan) then return colors.black
- elseif (color == colors.purple) then return colors.white
- elseif (color == colors.blue) then return colors.white
- elseif (color == colors.brown) then return colors.white
- elseif (color == colors.green) then return colors.black
- elseif (color == colors.red) then return colors.black
- elseif (color == colors.black) then return colors.white
- else return colors.black
- end
- end
- function paintSquare(x, y, w, h, monitor, color)
- monitor.setBackgroundColor(color)
- for i=x,x+w-1 do
- for j=y,y+h-1 do
- monitor.setCursorPos(i,j)
- monitor.write(" ")
- end
- end
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- end
- function renderGUI()
- local monitor = findMonitor() -- can be replaced with local monitor = peripheral.wrap("monitor_#") if you're certain of the ID
- if monitor then
- monitor.clear()
- local w, h = monitor.getSize()
- blockSize = math.floor((w - 4) / 8)
- for i=0,7 do
- -- display program title
- monitor.setBackgroundColor(colors.gray)
- monitor.setCursorPos(1, 1)
- monitor.write(" Force Core Status" .. string.rep(" ", w - 10))
- monitor.setBackgroundColor(colors.black)
- -- display cell IDs and the rednet color related to them
- monitor.setCursorPos(4+((i+1)*blockSize)-2, h-3)
- monitor.setBackgroundColor(rednetColors[i+1])
- monitor.setTextColor(getTextColorForBackground(rednetColors[i+1]))
- monitor.write(" " .. tostring(i) .. " ")
- -- display engine status
- if (enginesOn[i+1] == 1) then
- paintSquare(4+((i+1)*blockSize)-1, h-1, 1, 1, monitor, colors.lime)
- else
- paintSquare(4+((i+1)*blockSize)-1, h-1, 1, 1, monitor, colors.red)
- end
- -- display power levels as bars
- local powerLevel = math.floor(energyPercentage[i+1] / 10)
- local spaceAvailable = 10 - powerLevel
- paintSquare(4+((i+1)*blockSize)-2, h-14, 3, spaceAvailable, monitor, colors.gray)
- if (energyPercentage[i+1] > 90) then paintSquare(4+((i+1)*blockSize)-2, h-14+spaceAvailable, 3, powerLevel, monitor, colors.cyan)
- elseif (energyPercentage[i+1] > 75) then paintSquare(4+((i+1)*blockSize)-2, h-14+spaceAvailable, 3, powerLevel, monitor, colors.lime)
- elseif (energyPercentage[i+1] > 50) then paintSquare(4+((i+1)*blockSize)-2, h-14+spaceAvailable, 3, powerLevel, monitor, colors.yellow)
- elseif (energyPercentage[i+1] > 25) then paintSquare(4+((i+1)*blockSize)-2, h-14+spaceAvailable, 3, powerLevel, monitor, colors.orange)
- elseif (energyPercentage[i+1] > 0) then paintSquare(4+((i+1)*blockSize)-2, h-14+spaceAvailable, 3, powerLevel, monitor, colors.red)
- end
- -- display power levels as text
- if energyPercentage[i+1] >= 1 then
- local lengthOfLabel = math.floor(math.log10(energyPercentage[i+1]))
- monitor.setCursorPos(4+((i+1)*blockSize)-lengthOfLabel, h-16)
- monitor.write(tostring(math.floor(energyPercentage[i+1])))
- else
- monitor.setCursorPos(4+((i+1)*blockSize), h-16)
- monitor.write("0")
- end
- end
- else
- local ox, oy = term.getCursorPos()
- term.setCursorPos(1,10)
- term.setTextColor(colors.red)
- term.write("No Monitor Connected")
- term.setTextColor(colors.white)
- term.setCursorPos(ox, oy)
- end
- end
- while true do
- getProviders()
- getEnergyLevels()
- writeStatus()
- setOutput()
- renderGUI()
- sleep(2)
- end
Advertisement
Add Comment
Please, Sign In to add comment