Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Terminal
- term.clear()
- term.setCursorPos(1,1)
- -- Monitor preparation
- local monitor = peripheral.find("monitor")
- if monitor then
- monitor.setBackgroundColour(colors.gray)
- monitor.clear()
- monitor.setCursorPos(1,1)
- end
- -- Functions
- -- Print text serialised
- local function printText(text)
- print(textutils.serialise(text))
- end
- -- Convert Joules to RF(Redstone Flux)
- local function convertToRF(amntEnergy)
- return math.floor(amntEnergy / 2.5)
- end
- -- Find suffix and convert value
- local function suffixFinder(val)
- val = val + 1 -- bugProof
- local suffix
- local energy = 1 -- bugProof
- if val < 1000 then
- suffix = ''
- elseif val < 1000000 then
- energy = val / 1000
- suffix = 'k'
- elseif val < 1000000000 then
- energy = val / 1000000
- suffix = 'M'
- elseif val < 1000000000000 then
- energy = val / 1000000000
- suffix = 'G'
- else
- energy = val / 1000000000000
- suffix = 'T'
- end
- return suffix, energy
- end
- -- Round a number to a specific number of decimal places
- local function roundToDecimal(number, decimalPlaces)
- local powerOf10 = 10 ^ decimalPlaces
- return math.floor(number * powerOf10 + 0.5) / powerOf10
- end
- -- Input X amount of blank spaces
- local function blankSpaces(num1)
- local spaces = ""
- for i = 1, num1 do
- spaces = spaces .. " "
- end
- return spaces
- end
- --[[ Monitor draw region
- local function drawRegion(posX, posY, color)
- local xx, xy = posX[1], posX[2]
- local yx, yy = posY[1], posY[2]
- for i = 1, yx - xx + 1, 1 do
- monitor.setCursorPos(xx, xy)
- monitor.setBackgroundColour(color)
- monitor.write(blankSpaces(yy - xy))
- end
- monitor.setBackgroundColour(colors.gray)
- end]]
- -- Monitor draw region
- --[[
- - pos1 Top-left coordinates
- - pos2 Bottom-right corner coordinates
- - monitorColor Color you want to draw with
- - monitor Monitor you want to draw to
- ]]
- local function drawRegion(pos1, pos2, monitorColor, monitor)
- local x1, y1 = pos1[1], pos1[2] -- Top-left corner coordinates
- local x2, y2 = pos2[1], pos2[2] -- Bottom-right corner coordinates
- local numSpaces = y2 - y1 + 1 -- Calculate the number of blank spaces to write
- if monitor then
- printText("Monitor is working")
- printText("Color: " .. monitorColor)
- printText("Drawing region at x1:" .. x1 .. " x2:"..x2.." y1:"..y1.." y2:"..y2)
- printText("Drawed region is "..numSpaces.. " pixels long")
- end
- monitor.setBackgroundColour(monitorColor) -- Set the color for the draw
- -- Loop through each line of the region
- for y = y1, y2 do
- -- Loop through each column of the region
- for x = x1, x2 do
- monitor.setCursorPos(x,y)
- monitor.write(" ")
- end
- end
- -- Reset the background color to the default
- monitor.setBackgroundColour(colors.gray)
- end
- -- Variable declaration
- local inductionPort
- local test = true
- local pos1
- local pos2
- -- Check for induction port in every side
- for _, side in pairs(peripheral.getNames()) do
- if "inductionPort" == peripheral.getType(side) then
- printText(peripheral.getType(side))
- inductionPort = peripheral.wrap(side)
- end
- end
- -- Get current + max energy
- local currentEnergySuffix, currentEnergy = suffixFinder(convertToRF(inductionPort.getEnergy()))
- currentEnergy = roundToDecimal(currentEnergy, 2)
- local maxEnergySuffix, maxEnergy = suffixFinder(convertToRF(inductionPort.getMaxEnergy()))
- maxEnergy = roundToDecimal(maxEnergy, 1)
- -- Get input + output + difference
- local inputSuffix, energyInput = suffixFinder(convertToRF(inductionPort.getLastInput()))
- energyInput = roundToDecimal(energyInput, 0)
- local outputSuffix, energyOutput = suffixFinder(convertToRF(inductionPort.getLastOutput()))
- energyOutput = roundToDecimal(energyOutput, 0)
- local ioDiff = energyInput - energyOutput
- -- Monitor presentation
- -- Title
- monitor.setCursorPos(1,1)
- monitor.write("INDUCTION BATTERY")
- monitor.setCursorPos(1,2)
- monitor.write("-----------------")
- -- Stored energy
- monitor.setCursorPos(1,3)
- monitor.write("Energy")
- monitor.setCursorPos(10,3)
- monitor.write(":")
- monitor.setCursorPos(11,3)
- monitor.write(currentEnergy ..currentEnergySuffix .."RF / " .. maxEnergy ..maxEnergySuffix .."RF")
- -- Input
- monitor.setCursorPos(1,4)
- monitor.write("Input")
- monitor.setCursorPos(10,4)
- monitor.write(":")
- monitor.setCursorPos(11,4)
- monitor.write(energyInput .. inputSuffix .. "RF")
- -- Output
- monitor.setCursorPos(1,5)
- monitor.write("Output")
- monitor.setCursorPos(10,5)
- monitor.write(":")
- monitor.setCursorPos(11,5)
- monitor.write(energyOutput .. outputSuffix .. "RF")
- -- Draw a progress bar
- -- Draw the initial bar
- local monitorColor = colors.black
- pos1 = {1, 18}
- pos2 = {29, 19}
- drawRegion(pos1, pos2, monitorColor, monitor)
- -- Draw the actual bar
- monitorColor = colors.red
- local progressBar = roundToDecimal(inductionPort.getEnergyFilledPercentage() * 28 + 1, 1)
- pos1 = {1, 18}
- pos2 = {progressBar, 19}
- drawRegion(pos1, pos2, monitorColor, monitor)
- if test then
- -- Test and printing
- printText("Testing print:")
- printText("color is " .. monitorColor)
- printText(inductionPort.getEnergyFilledPercentage())
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement