Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap("back")
- local reactorSetup = "XFFX.XFFXCXXC.CXXCXCCX.XCCXFXXF.FXXFFXXF.FXXFXCCX.XCCX"
- local reactorData = {}
- local totalEU = 0
- local FUEL = "reactorUraniumDual"
- local VENT = "reactorVentGold"
- local SPREAD = "reactorVentSpread"
- local DEPLETED = "reactorUraniumDualdepleted"
- local toggle = 0
- local alarm = false;
- function getSetupItem(i)
- return string.sub(reactorSetup,i,i)
- end
- function printMon(mon,text)
- mon.write(text)
- local x,y = mon.getCursorPos()
- mon.setCursorPos(1,y+1)
- end
- function setTextColor(mon,color)
- if not mon then mon = term end
- if mon.isColor() then mon.setTextColor(color) end
- end
- function setBackgroundColor(mon,color)
- if not mon then mon = term end
- if mon.isColor() then mon.setBackgroundColor(color) end
- end
- function controlReactor(reactorName)
- local r = peripheral.wrap(reactorName)
- local i
- local missingVents = false
- for i=1,r.getInventorySize() do
- local data = r.getStackInSlot(i)
- if data then
- if data.name == FUEL then
- --ok
- elseif data.name == VENT then
- --ok
- elseif data.name == SPREAD then
- --ok
- elseif data.name == DEPLETED then
- --eject item downward
- r.pushItem("DOWN",i);
- end
- end
- end
- for i=1,r.getInventorySize() do
- local data = r.getStackInSlot(i)
- if not data then
- --check what should go here
- --pull that thing into here
- if getSetupItem(i) == "F" then
- --pull item in from above into that position
- r.pullItemIntoSlot("UP",2,1,i)
- elseif getSetupItem(i) == "X" then
- --There should be a vent here but there isn't!
- missingVents = true
- end
- end
- end
- local data = {}
- data["name"] = reactorName
- data["missingVents"] = missingVents and "true" or "false"
- data["energy"] = r.getEUOutput() * 5
- data["heat"] = r.getHeat()
- data["maxHeat"] = r.getMaxHeat()
- data["active"] = r.isActive() and "true" or "false"
- if data.heat > 0 then
- alarm = true
- end
- reactorData[reactorName] = data
- totalEU = totalEU + data.energy
- end
- function render(mon)
- if not mon then
- mon = term
- end
- if mon.setTextScale then
- mon.setTextScale(0.5)
- end
- local w,h = mon.getSize()
- setTextColor(mon,colors.white)
- mon.clear()
- mon.setCursorPos(1,1)
- for name,data in pairs(reactorData) do
- printMon(mon,"Name: "..name)
- printMon(mon,"EU/t: "..data.energy)
- printMon(mon,"Heat: "..data.heat.."/"..data.maxHeat)
- printMon(mon,"Active: "..data.active)
- printMon(mon,"Missing vents? "..data.missingVents)
- printMon(mon,"")
- end
- setTextColor(mon,colors.red)
- mon.setCursorPos(1,h)
- mon.write("Total EU/t: "..totalEU.." ("..(totalEU*4).." RF/t)")
- setTextColor(mon,colors.green)
- mon.setCursorPos(w-9,1)
- local i
- for i = 1,10 do
- mon.write(math.floor(math.random()*10))
- end
- end
- function update()
- totalEU = 0
- reactorData = {}
- alarm = false
- local names = modem.getNamesRemote()
- for i=1,#names do
- if modem.getTypeRemote(names[i]) == "nuclear_reactor" then
- controlReactor(names[i])
- end
- end
- for i=1,#names do
- if modem.getTypeRemote(names[i]) == "monitor" then
- render(peripheral.wrap(names[i]))
- end
- end
- end
- while true do
- update()
- render()
- toggle = (toggle + 1) % 8
- redstone.setOutput("bottom",toggle < 4)
- redstone.setOutput("top",alarm)
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment