Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local confModemSide = "right"
- local confMonitorSide = "bottom"
- local confModemPort = 1000
- local confTankModemPort = 1001
- local confAeModemPort = 1002
- local confCellModemPort = 1003
- local confTextColor = colors.white
- local confRedstone = {}
- confRedstone["Essence"] = {0.5,0.99,true}
- local tankData = nil
- local aeData = nil
- local cellData = nil
- local lastScreenRefresh = 0
- if(not os.loadAPI("hydraApi")) then
- error("Could not load hydraApi")
- end
- function formatPercent(fraction)
- percent = math.floor(fraction * 1000) / 10
- return string.format("%3.1f", percent) .. "%"
- end
- function formatLiquidAmount(amount)
- local postfix
- if(amount >= 1000000000) then
- amount = math.floor(amount / 100000000) / 10
- postFix = "MB"
- elseif(amount >= 1000000) then
- amount = math.floor(amount / 100000) / 10
- postFix = "kB"
- elseif(amount >= 1000) then
- amount = math.floor(amount / 100) / 10
- postFix = "B"
- else
- postFix = "mB"
- end
- return string.format("%3.1f", amount) .. postFix
- end
- function getFractionColor(fraction)
- if(fraction >= 0.9) then
- return colors.white
- elseif(fraction >= 0.5) then
- return colors.orange
- else
- return colors.red
- end
- end
- function handleMessage(modemSide, senderChannel, replyChannel, message, senderDistance)
- if(replyChannel == confTankModemPort) then
- tankData = message
- elseif(replyChannel == confAeModemPort) then
- aeData = message
- elseif(replyChannel == confCellModemPort) then
- cellData = message
- else
- print("Got message from unknown channel(" .. replyChannel .. "): ".. message)
- end
- end
- local modem = peripheral.wrap(confModemSide)
- local monitor = hydraApi.getMonitor()
- modem.open(confModemPort)
- os.startTimer(5)
- function writeTanks()
- local line = 1
- monitor.setCursorPos(1,line)
- monitor.setTextColor(confTextColor)
- monitor.write("Liquids: ")
- if(tankData == nil) then return end
- for k,tank in pairs(tankData) do
- monitor.setTextColor(confTextColor)
- line=line+1
- monitor.setCursorPos(1,line)
- monitor.write(tostring(tank["name"]))
- monitor.setCursorPos(16,line)
- monitor.write(formatLiquidAmount(tank["amount"]))
- monitor.setCursorPos(24,line)
- monitor.setTextColor(getFractionColor(tank["fraction"]))
- monitor.write(formatPercent(tank["fraction"]))
- monitor.setTextColor(confTextColor)
- monitor.setCursorPos(30,line)
- monitor.write(tank["dir"])
- end
- end
- function writeAe()
- local line = 12
- monitor.setCursorPos(1,line)
- monitor.setTextColor(confTextColor)
- monitor.write("AE status: ")
- if(aeData == nil) then return end
- monitor.setTextColor(confTextColor)
- line=line+1
- monitor.setCursorPos(1,line)
- monitor.write("Items: " .. tostring(aeData["storedItemCount"]))
- line=line+1
- monitor.setCursorPos(1,line)
- local used = tonumber(aeData["usedBytes"])
- local total = tonumber(aeData["totalBytes"])
- local fraction = used / total
- monitor.write("Bytes: " .. hydraApi.formatLargeNumber(used) .. " / " .. hydraApi.formatLargeNumber(total))
- monitor.setCursorPos(24,line)
- monitor.write(formatPercent(fraction))
- end
- function writeCells()
- local line = 16
- monitor.setCursorPos(1,line)
- monitor.setTextColor(confTextColor)
- monitor.write("Energy status: ")
- if(cellData == nil) then return end
- monitor.setTextColor(confTextColor)
- line=line+1
- monitor.setCursorPos(1,line)
- local s = hydraApi.formatEnergy(cellData["totalEnergy"]) .. " / " .. hydraApi.formatEnergy(cellData["totalMaxEnergy"])
- monitor.write(s)
- monitor.setCursorPos(24,line)
- monitor.write(formatPercent(cellData["fraction"]))
- end
- function writeMisc()
- local line = 19
- local mcTime = textutils.formatTime(os.time(), true)
- monitor.setCursorPos(1,line)
- monitor.write("Day " .. tostring(os.day()) .. " " .. mcTime)
- end
- function refreshScreen()
- if(os.clock() - lastScreenRefresh < 1) then return end
- lastScreenRefresh = os.clock()
- monitor.clear()
- monitor.setTextScale(1.5)
- writeTanks()
- writeAe()
- writeCells()
- writeMisc()
- end
- while true do
- print("Loop")
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent()
- if(event == "modem_message") then
- handleMessage(modemSide, senderChannel, replyChannel, message, senderDistance)
- elseif(event == "timer") then
- print("Tick!")
- os.startTimer(5)
- else
- print ("Got event type "..event)
- end
- refreshScreen()
- end
Advertisement
Add Comment
Please, Sign In to add comment