Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local glass = peripheral.wrap('bottom')
- local power = peripheral.wrap('left')
- local text = "POWER: 0.00%"
- local c = 0
- function addBox()
- glass.addBox(1,1,textLength(text),10,0xFFFFFF,0.2)
- end
- function draw()
- print(c)
- c = c + 1
- glass.clear()
- addBox()
- local powerUsed = power.getEnergyStored()
- local powerMax = power.getMaxEnergyStored()
- local powerPercentage = ( ( powerUsed / powerMax ) * 100 )
- text = round(powerPercentage, 2) .. '%'
- glass.addText(5,2,"POWER: " .. text, 0xFF0000)
- glass.sync()
- end
- function start()
- drawLoop = os.startTimer(1)
- while true do
- checkEvent()
- sleep(0.1)
- end
- end
- function checkEvent()
- event,action,user,uuid,message = os.pullEvent()
- if event == "glasses_chat_command" then
- if ( message:len() > 0 ) then
- if ( message == 'shutdown' ) then
- setReactorState(true)
- elseif ( message == 'start' ) then
- setReactorState(false)
- end
- end
- elseif event == "timer" then
- -- Alarm
- if ( drawLoop and action == drawLoop ) then
- draw()
- drawLoop = os.startTimer(1)
- elseif ( alarmTimer and action == alarmTimer ) then
- redstone.setOutput('top', false)
- end
- end
- end
- function setReactorState(state)
- redstone.setOutput('back', state)
- redstone.setOutput('top', state)
- alarmTimer = os.startTimer(5)
- end
- function textLength(str)
- return ( (str:len() + 1) * 11 ) + 3
- end
- function ReadableNumber(num, places)
- local ret
- local placeValue = ("%%.%df"):format(places or 0)
- if not num then
- return 0
- elseif num >= 1000000000000 then
- ret = placeValue:format(num / 1000000000000) .. "T" -- trillion
- elseif num >= 1000000000 then
- ret = placeValue:format(num / 1000000000) .. "B" -- billion
- elseif num >= 1000000 then
- ret = placeValue:format(num / 1000000) .. "M" -- million
- elseif num >= 1000 then
- ret = placeValue:format(num / 1000) .. "K" -- thousand
- else
- ret = num -- hundreds
- end
- return ret
- end
- function round(num, numDecimalPlaces)
- local mult = 10^(numDecimalPlaces or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment