Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ####################################### --
- -- # InductionMatrix Monitoring Software # --
- -- # Written by TrueVirusTV # --
- -- # Minecraft Version: 1.16.5 # --
- -- # Script-Version: 1.3 # --
- -- ####################################### --
- -- Scale 0.5: 3x2
- -- Scale 1: 5x3
- -- Scale 1.5:
- -- # CHANGELOG:
- -- # # v1.3:
- -- # - Fixed the charging bug
- -- # # v1.2:
- -- # - Added Peta to the Downscaling function
- -- # # v1.1:
- -- # - Adding Colors to some text (Status, Input, Output)
- -- ## INITIATE NAMES ## --
- -- # DEFINE NAMES ("monitor" and "inductionPort")
- local mon
- local matrix
- local rawPower
- local rawPowerMax
- local rawInput
- local rawOutput
- local rawPercentage
- local formed
- local cells
- local providers
- local powerFE
- local powerMaxFE
- local inputFE
- local outputFE
- local percentage
- local powerTillFull
- local balance
- local avgAr = {}
- local monX, monY
- local curX, curY
- -- ############################# --
- -- # START OF FUNCTION SECTION # --
- -- ############################# --
- -- # Getting all values
- function getValues()
- rawPower = matrix.getEnergy()
- rawPowerMax = matrix.getMaxEnergy()
- formed = matrix.isFormed()
- powerTillFull = matrix.getMaxEnergy() - matrix.getEnergy()
- if formed == true then
- rawPercentage = matrix.getEnergyFilledPercentage()
- cells = matrix.getInstalledCells()
- providers = matrix.getInstalledProviders()
- rawInput = matrix.getLastInput()
- rawOutput = matrix.getLastOutput()
- else
- rawPercentage = 0
- cells = 0
- providers = 0
- rawInput = 0
- rawOutput = 0
- end
- end
- -- # Calculation raw energydata to FE
- function calcToFE()
- powerFE = (rawPower / 10)*4
- powerMaxFE = (rawPowerMax / 10)*4
- percentage = rawPercentage*100
- inputFE = (rawInput / 10)*4
- outputFE = (rawOutput / 10)*4
- end
- -- # Drawing Interface
- function drawBoxes()
- monX, monY = mon.getSize()
- scale = mon.getTextScale()
- --if scale == 0.5 and monX < 100
- mon.setBackgroundColor(colors.black)
- mon.clear()
- -- # Left Box
- paintutils.drawBox(2,2,((monX/4)*3)-1,monY-1, colors.blue)
- --# Right Box
- paintutils.drawBox(((monX/4)*3)+1, 2, monX-1, monY-1, colors.blue)
- end
- -- # Drawing Energybar
- function drawBar()
- monX, monY = mon.getSize()
- local redStartX
- local redStartY
- local redEndX
- local redEndY
- local greenStartX
- local greenStartY
- local greenEndX
- local greenEndY
- -- # Calculate Red Bar
- redStartX = ((monX/4)*3)+3
- redStartY = 4
- redEndX = monX-3
- redEndY = monY-5
- -- # Bar Background (RED)
- paintutils.drawFilledBox(redStartX, redStartY, redEndX, redEndY, colors.red)
- local barHeight = redEndY-3
- local linePerPercent = 100 / barHeight
- local rawLineCount = percentage / linePerPercent
- local lineCount = math.floor(rawLineCount)
- -- # Energy Bar (GREEN)
- if lineCount ~= 0 then
- if percentage == 100 then
- paintutils.drawFilledBox(redStartX, (redEndY-lineCount), redEndX, redEndY, colors.green)
- else
- paintutils.drawFilledBox(redStartX, (redEndY-lineCount)+1, redEndX, redEndY, colors.green)
- end
- end
- mon.setCursorPos(((monX/4)*3)+3, monY-3)
- pertemp = string.format("%02.02f",percentage)
- mon.setBackgroundColor(colors.black)
- mon.write(pertemp.." %")
- end
- -- # Down-Scaling the loooong energynumbers
- function energy_calc(val)
- local pre = ''
- local suf = ''
- if val < 0 then
- pre = '-'
- val = -val
- end
- if val > 1000 then
- suf = 'k'
- val = val / 1000
- end
- if val > 1000 then
- suf = 'M'
- val = val / 1000
- end
- if val > 1000 then
- suf = 'G'
- val = val / 1000
- end
- if val > 1000 then
- suf = 'T'
- val = val / 1000
- end
- if val > 1000 then
- suf = 'P'
- val = val / 1000
- end
- return string.format('%s%0.2f %sFE', pre, val, suf)
- end
- -- # Calculation the time left
- function time(secs)
- secs = math.floor(secs)
- -- Days
- local weeks = math.floor(secs / 604800)
- secs = secs - (604800 * weeks)
- -- Days
- local days = math.floor(secs / 86400)
- secs = secs - (86400 * days)
- -- Hours
- local hours = math.floor(secs / 3600)
- secs = secs - (3600 * hours)
- -- Minutes
- local mins = math.floor(secs / 60)
- secs = secs - (60 * mins)
- -- If we have more than 72h worth of storage, switch to week, day, hour format
- if weeks > 0 then
- return string.format('%dwk %dd %dh', weeks, days, hours)
- elseif days >= 3 then
- return string.format('%dd %dh', days, hours)
- end
- -- Formatting to have trailing zeros on H:MM:SS
- return string.format('%d:%02d:%02d', hours, mins, secs)
- end
- -- ############################## --
- -- # ENDING OF FUNCTION SECTION # --
- -- ############################## --
- -- # Check of peripheral "monitor"
- if nil == peripheral.find("monitor") then
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.orange)
- print("")
- print("Trying to find monitor...")
- print("")
- local counter = 0
- -- # Start loop of monitor check
- while nil == peripheral.find("monitor") do
- if counter==10 then
- term.setTextColor(colors.red)
- print("No monitor could be found. Make sure a monitor is directly, or via a modem connected. The modem should be red if connected!")
- print("Continue search...")
- print("")
- end
- counter = counter+1
- os.sleep(1)
- end
- term.setTextColor(colors.lime)
- print("Monitor has been found! Connecting...")
- term.setTextColor(colors.white)
- os.sleep(2)
- mon = peripheral.find("monitor")
- else
- mon = peripheral.find("monitor")
- end
- -- # Check of peripheral "inductionPort"
- if nil == peripheral.find("inductionPort") then
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.orange)
- print("")
- print("Trying to find Induction Port...")
- print("")
- local counter = 0
- -- # Start loop of inductionPort check
- while nil == peripheral.find("inductionPort") do
- if counter==10 then
- term.setTextColor(colors.red)
- print("No Induction Port could be found. Make sure a Port is directly, or via a modem connected. The modem should be red if connected!")
- print("Continue search...")
- print("")
- end
- counter = counter+1
- os.sleep(1)
- end
- term.setTextColor(colors.lime)
- print("Induction Port has been found! Connecting...")
- os.sleep(2)
- matrix = peripheral.find("inductionPort")
- else
- matrix = peripheral.find("inductionPort")
- end
- -- ##################### --
- -- # INITIALISE SCREEN # --
- -- # STARTING LOOP # --
- -- ##################### --
- balance = matrix.getEnergy()
- while true do
- local status, err = pcall(function ()
- --local termEvent = os.pullEventRaw("terminate")
- term.redirect(mon)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- -- #
- -- # ONLY WHILE WIP
- mon.setTextScale(1)
- -- #
- monX, monY = mon.getSize()
- -- # Recheck of peripheral "monitor"
- if nil == peripheral.find("monitor") then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.orange)
- print("")
- print("Error trying to find monitor!")
- print("")
- local counter = 0
- -- # Start loop of monitor check
- while nil == peripheral.find("monitor") do
- if counter==10 then
- term.setTextColor(colors.red)
- print("No monitor could be found. Make sure a monitor is directly, or via a modem connected. The modem should be red if connected!")
- print("Continue search...")
- print("")
- end
- counter = counter+1
- os.sleep(1)
- end
- term.setTextColor(colors.lime)
- print("Monitor has been found! Connecting...")
- term.setTextColor(colors.white)
- os.sleep(2)
- mon = peripheral.find("monitor")
- else
- mon = peripheral.find("monitor")
- end
- -- # Recheck of peripheral "inductionPort"
- if nil == peripheral.find("inductionPort") then
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.orange)
- print("")
- print("Error trying to find Induction Port!")
- print("")
- local counter = 0
- -- # Start loop of inductionPort check
- while nil == peripheral.find("inductionPort") do
- if counter==10 then
- term.setTextColor(colors.red)
- print("No Induction Port could be found. Make sure a Port is directly, or via a modem connected. The modem should be red if connected!")
- print("Continue search...")
- print("")
- end
- counter = counter+1
- os.sleep(1)
- end
- term.setTextColor(colors.lime)
- print("Induction Port has been found! Connecting...")
- os.sleep(2)
- matrix = peripheral.find("inductionPort")
- else
- matrix = peripheral.find("inductionPort")
- end
- getValues()
- calcToFE()
- --setMonitorSize()
- drawBoxes()
- drawBar()
- mon.setBackgroundColor(colors.black)
- monX, monY = mon.getSize()
- -- # SET TITLE OF SCREEN
- local title = ' Induction Matrix '
- local len = string.len(title)
- mon.setCursorPos(((monX-1)-(monX/4)-len+2)/2, 2)
- mon.write(title)
- --#####################################################################
- -- # START OF STATS
- mon.setCursorPos(4,4)
- mon.write("Status: ")
- if formed == true then
- mon.setTextColor(colors.lime)
- mon.write("Online")
- else
- mon.setTextColor(colors.red)
- mon.write("Offline")
- end
- mon.setTextColor(colors.white)
- curX, curY = mon.getCursorPos()
- mon.setCursorPos(4,curY+1)
- if formed == true then
- mon.write("Cells: "..cells.." | Providers: "..providers)
- else
- mon.write("Cells: n/a | Providers: n/a")
- end
- curX, curY = mon.getCursorPos()
- mon.setCursorPos(4,curY+1)
- mon.write("")
- curX, curY = mon.getCursorPos()
- mon.setCursorPos(4,curY+1)
- mon.write("Current: "..energy_calc(powerFE).." / "..energy_calc(powerMaxFE))
- curX, curY = mon.getCursorPos()
- mon.setCursorPos(4,curY+1)
- mon.write("")
- curX, curY = mon.getCursorPos()
- mon.setCursorPos(4,curY+1)
- mon.setTextColor(colors.lime)
- mon.write("Input : "..energy_calc(inputFE).."/t")
- curX, curY = mon.getCursorPos()
- mon.setCursorPos(4,curY+1)
- mon.write(" "..energy_calc(inputFE*20).."/s")
- curX, curY = mon.getCursorPos()
- mon.setCursorPos(4,curY+1)
- mon.write("")
- curX, curY = mon.getCursorPos()
- mon.setCursorPos(4,curY+1)
- mon.setTextColor(colors.red)
- mon.write("Output : "..energy_calc(outputFE).."/t")
- curX, curY = mon.getCursorPos()
- mon.setCursorPos(4,curY+1)
- mon.write(" "..energy_calc(outputFE*20).."/s")
- mon.setTextColor(colors.white)
- curX, curY = mon.getCursorPos()
- mon.setCursorPos(4,curY+1)
- mon.write("")
- curX, curY = mon.getCursorPos()
- -- # Calculating balance
- local balanceChangePerTick = inputFE - outputFE
- local balanceChange = balanceChangePerTick*20
- mon.setCursorPos(4,curY+1)
- mon.write("Change: "..energy_calc(balanceChange).."/s")
- curX, curY = mon.getCursorPos()
- if table.getn(avgAr) >= 20 then
- table.remove(avgAr,1)
- table.insert(avgAr,balanceChange)
- else
- table.insert(avgAr,balanceChange)
- end
- local avg = 0
- for i=1,#avgAr do
- avg = avg + avgAr[i]
- end
- if balanceChange > 0 then
- -- # Matrix is charging
- local seconds = powerTillFull / (avg/20)
- mon.setCursorPos(4,curY+1)
- mon.write("Charging: "..time(seconds))
- elseif balanceChange < 0 then
- -- # Matrix is discharging
- local seconds = powerFE / -(avg/20)
- mon.setCursorPos(4,curY+1)
- mon.write("Depleting: "..time(seconds))
- else
- -- # No Balance
- mon.setCursorPos(4,curY+1)
- mon.write("No Change. Idle.")
- end
- end)
- if not status then
- --if event == "terminate" then
- -- os.pullEvent()
- -- end
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(2,2)
- term.setTextColor(colors.red)
- term.write("Errors where detected during runtime.")
- term.setCursorPos(2,3)
- term.write("Trying to continue...")
- term.setCursorPos(2,4)
- term.write("-------------------------------------")
- term.setCursorPos(2,5)
- term.write(err)
- os.sleep(5)
- end
- os.sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement