Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local glasses = peripheral.wrap("openperipheral_bridge_0")
- local lastPower = 0
- local bounds = {
- low = 0.1,
- high = 0.9,
- }
- local cells = {
- peripheral.wrap("powered_tile_0"),
- peripheral.wrap("powered_tile_1"),
- peripheral.wrap("powered_tile_2"),
- peripheral.wrap("powered_tile_3"),
- peripheral.wrap("powered_tile_4"),
- peripheral.wrap("powered_tile_5"),
- peripheral.wrap("powered_tile_6"),
- peripheral.wrap("powered_tile_7"),
- peripheral.wrap("powered_tile_8"),
- peripheral.wrap("powered_tile_9"),
- }
- local tesseracts = {
- peripheral.wrap("powered_tile_10"),
- }
- function setGenerationEnabled(bool)
- for _,tesseract in ipairs(tesseracts) do
- if bool == true then
- tesseract.setRedstoneControl("low")
- else
- tesseract.setRedstoneControl("high")
- end
- end
- end
- function getGenerationEnabled()
- return tesseracts[1].getRedstoneControl() == "low"
- end
- function getPowerStored()
- local stored = 0
- for _,cell in ipairs(cells) do
- stored = stored + cell.getEnergyStored()
- end
- return stored
- end
- function getMaxPowerStored()
- local max = 0
- for _,cell in ipairs(cells) do
- max = max + cell.getMaxEnergyStored()
- end
- return max
- end
- function getMinPowerStored()
- local min = 1e309
- local minxMax
- for _,cell in ipairs(cells) do
- local stored = cell.getEnergyStored()
- if stored < min then
- min = stored
- minMax = cell.getMaxEnergyStored()
- end
- end
- return min / minxMax
- end
- function handleGeneration()
- local power = getPowerStored()
- lastPower = power
- local maxPower = getMaxPowerStored()
- local filled = getMinPowerStored()
- if filled < bounds.low then
- setGenerationEnabled(true)
- elseif filled > bounds.high then
- setGenerationEnabled(false)
- end
- end
- function handleDisplay()
- local power = getPowerStored()
- local maxPower = getMaxPowerStored()
- local filled = power / maxPower
- glasses.clear()
- local g = filled * 255
- local r = 255 - g
- local color = tonumber("0x" .. num2hex(r) .. num2hex(g) .. "00")
- glasses.addBox(700,0,250,100,0xAAAAAA,0.2)
- glasses.addBox(710,10,230,80,0xBBBBBB,0.2)
- glasses.addBox(710,10,230 * filled,80,color,0.2)
- glasses.addText(715,15,math.floor(power / 1e6) .." / " .. math.floor(maxPower / 1e6) .." MRF", 0xFFFFFF)
- glasses.addText(715,25,( math.floor(power - lastPower) / 20 ) .." RF / tick", 0xFFFFFF)
- glasses.addText(715,35,"Generating: ", 0xFFFFFF)
- local color = 0xff0000
- local generating = getGenerationEnabled()
- if generating then
- color = 0x00ff00
- end
- glasses.addText(715,45,tostring( generating ), color)
- glasses.sync()
- end
- function num2hex(num)
- local hexstr = '0123456789abcdef'
- local s = ''
- while num > 0 do
- local mod = math.fmod(num, 16)
- s = string.sub(hexstr, mod+1, mod+1) .. s
- num = math.floor(num / 16)
- end
- if s == '' then s = '0' end
- return s
- end
- while true do
- handleDisplay()
- handleGeneration()
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement