Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local statusChannelID = 5
- local controlChannelID = 7
- local reactorActivateP = 5
- -- Find Modem
- local modem = peripheral.find("modem", function(n, o) return o.isWireless() end)
- if modem ~= nil then
- modem.open(controlChannelID)
- end
- -- Find Reactor
- local reactor = peripheral.find("BigReactors-Reactor")
- if reactor == nil then
- error("Could not bind to reactor. Is one attached?")
- end
- -- Find Tesseract side
- local tessSide = nil
- for sideId, side in ipairs(redstone.getSides()) do
- if peripheral.getType(side) == "tile_thermalexpansion_ender_tesseract_name" then
- tessSide = side
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- print("BigReactor Monitor...")
- print()
- if tessSide ~= nil then
- print("Tesseract is present")
- else
- print("Tesseract is absent")
- end
- print("Reactor Output: Enabled")
- print("Reactor Status: Inactive")
- print("Reactor Buffer: ")
- print("Reactor Fuel: ")
- print("Reactor Generation: ")
- print()
- print("Press 'q' to quit.")
- print()
- if tessSide ~= nil then rs.setOutput(tessSide, false) end
- local reactorEnabled = true
- reactor.setActive(false)
- local rActive = reactor.getActive()
- local pollTimer = os.startTimer(0)
- local status = {}
- while true do
- local event, p1, p2, p3, p4 = os.pullEvent()
- if event == "key" then
- if p1 == 16 then -- 'q'
- term.setCursorPos(1, 6)
- return
- end
- elseif event == "modem_message" and p2 == controlChannelID then
- local message = p4
- if message == "enabled" then
- reactorEnabled = true
- term.setCursorPos(1,4)
- term.write("Reactor output: Enabled ")
- if tessSide ~= nil then rs.setOutput(tessSide, true) end
- elseif message == "disabled" then
- reactorEnabled = false
- term.setCursorPos(1,4)
- term.write("Reactor output: Disabled")
- if tessSide ~= nil then rs.setOutput(tessSide, false) end
- end
- elseif event == "timer" and p1 == pollTimer then
- local rEnergyP = (reactor.getEnergyStored() / 10000000) * 100
- if rActive == false and rEnergyP <= reactorActivateP then
- reactor.setActive(true)
- end
- if rActive == true and rEnergyP >= 95 and reactorEnabled == false then
- reactor.setActive(false)
- end
- rActive = reactor.getActive()
- if rActive == true then
- status["Reactor Status"] = "Active"
- else
- status["Reactor Status"] = "Inactive"
- end
- term.setCursorPos(1,5)
- term.write("Reactor Status: " .. status["Reactor Status"] .. " ")
- status["Reactor Buffer"] = math.floor(rEnergyP) .. "%"
- term.setCursorPos(1,6)
- term.write("Reactor Buffer: " .. status["Reactor Buffer"] .. " ")
- status["Reactor Fuel"] = math.floor((reactor.getFuelAmount() / reactor.getFuelAmountMax()) * 100) .. "%"
- term.setCursorPos(1,7)
- term.write("Reactor Fuel: " .. status["Reactor Fuel"] .. " ")
- status["Reactor Generation"] = math.floor(reactor.getEnergyProducedLastTick()) .. " RF/t"
- term.setCursorPos(1,8)
- term.write("Reactor Generation: " .. status["Reactor Generation"] .. " ")
- modem.transmit(statusChannelID, 0, textutils.serialize(status))
- pollTimer = os.startTimer(5)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement