Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --sender
- local main = function()
- local modems = {peripheral.find("modem")}
- local modem
- for k,v in pairs(modems) do
- if v.isWireless() then
- modem = v
- end
- end
- if not modem then
- error("no modem!",0)
- end
- if not fs.exists("reactor.data") then
- fs.open("reactor.data","w").close()
- end
- if not fs.exists("buttonH.lua") then
- shell.run("pastebin get LTDZZZEJ buttonH.lua")
- end
- local b = require("buttonH").terminal
- local file = fs.open("reactor.data","r")
- local lenRead = function(maxlen,bcol)
- local str = ""
- local xs, ys = term.getCursorPos()
- while true do
- local e = {os.pullEvent()}
- if e[1] == "char" and #str < maxlen then
- str = str..e[2]
- elseif e[1] == "key" and e[2] == keys.backspace and #str >= 1 then
- str = str:match("(.*).$")
- elseif e[1] == "key" and e[2] == keys.enter then
- return str
- end
- term.setCursorPos(xs, ys)
- local obc = term.getBackgroundColor()
- term.setBackgroundColor(bcol)
- term.write((" "):rep(maxlen))
- term.setBackgroundColor(obc)
- term.setCursorPos(xs, ys)
- term.write(str)
- end
- end
- local datas = {}
- if file.readAll() == "" then
- file.close()
- local ID
- local name
- local identifier = math.random(1,100000000)
- local rin,rout = peripheral.find("bigreactors:tileentityreactoraccessport")
- if not rin then error("no reactor input!",0) end
- if not rout then error("no reactor output!",0) end
- local reactorM = peripheral.find("BigReactors-Reactor")
- if not reactorM then error("no reactor!",0) end
- local rin,rout = peripheral.getName(rin),peripheral.getName(rout)
- local reactorM = peripheral.getName(reactorM)
- local chest
- local getData = function()
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- term.setCursorPos(24,5)
- term.write("SETUP")
- b.frame(13,11,28,5,"gray","black",false)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.black)
- term.setCursorPos(13,9)
- print(("\143"):rep(27))
- term.setCursorPos(13,12)
- print(("\143"):rep(27))
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.blue)
- term.setCursorPos(13,7)
- print("Pocket pc ID (number)")
- term.setCursorPos(13,10)
- print("Reactor Name (text)")
- term.setCursorPos(13,13)
- print("Chest Type (ex: mc:chest)")
- term.setCursorPos(13,8)
- term.setBackgroundColor(colors.gray)
- ID = lenRead(27,colors.black)
- term.setCursorPos(13,11)
- name = lenRead(27,colors.black)
- term.setCursorPos(13,14)
- chest = peripheral.find(lenRead(27,colors.black))
- if not chest then return "chestERR" end
- chest = peripheral.getName(chest)
- end
- while getData() do
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.red)
- term.clear()
- b.frame(10,10,34,4,"black","gray")
- term.setCursorPos(18,10)
- term.setBackgroundColor(colors.lightGray)
- term.write("Not a valid chest")
- sleep(2)
- end
- while true do
- local click = b.timetouch(0)
- if b.boxButton(1,click,17,18,"red","black","discard",1,1) then
- while getData() do
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.red)
- term.clear()
- b.frame(10,10,34,4,"black","gray")
- term.setCursorPos(18,10)
- term.setBackgroundColor(colors.lightGray)
- term.write("Not a valid chest")
- sleep(2)
- end
- end
- if b.boxButton(1,click,27,18,"green","black","confirm",1,1) then
- datas = {
- metadata = {
- stamp = "POCKETn@P#C3Y5XnNTj79gyj__GD=Zg92&Mn,e#2wE,Nyuc2sS/D>V>Hg_)3C*Q_%b*N5E",
- sendID = ID,
- reply = os.getComputerID(),
- identifier = identifier,
- name = name,
- save = false
- },
- reactor = {
- state = false,
- rods = 0,
- input = rin,
- output = rout,
- chest = chest,
- self = reactorM,
- isSteam = false,
- energyData = {
- perT = 0,
- perSec = 0,
- perMin = 0,
- stored = 0,
- maxstored = 0
- },
- tempInfo = {
- coreTemp = 0,
- caseTemp = 0,
- tempDiff = 0
- },
- fuelInfo = {
- fuel = 0,
- waste = 0,
- fuelUsePerT = 0,
- reactivity = 0
- },
- peripherals = {
- list = {}
- }
- },
- chestEvents = {
- items = {},
- push = false,
- toInput = false,
- fromInput = false,
- toOutput = false,
- slot = 0
- }
- }
- local file = fs.open("reactor.data","w")
- file.write(textutils.serialize(datas))
- file.close()
- break
- end
- end
- else
- file.close()
- end
- local file = fs.open("reactor.data","r")
- local default = textutils.unserialise(file.readAll())
- local current = default
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.blue)
- term.clear()
- term.setCursorPos(19,5)
- term.write("pocket running")
- b.frame(8,10,38,4,"black","gray")
- term.setBackgroundColor(colors.black)
- term.setCursorPos(8,7)
- term.write("STATUS")
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.gray)
- rednet.open(peripheral.getName(modem))
- local writes = function(state,tcol,bcol)
- local obc = term.getBackgroundColor()
- local otc = term.getTextColor()
- term.setCursorPos(9,10)
- term.setTextColor(tcol or otc)
- term.setBackgroundColor(bcol or obc)
- term.write(state)
- term.setTextColor(otc)
- term.setBackgroundColor(obc)
- end
- local gdt
- local tempData
- while true do
- local click = b.timetouch(0.1)
- term.setBackgroundColor(colors.blue)
- b.switch(1,1,click,17,18,"red","green","black","PAUSE",1,1)
- if b.boxButton(1,click,25,18,"red","black","restart config",1,1) then
- fs.open("reactor.data","w").close()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- break
- end
- term.setCursorPos(11,10)
- if not b.switch("db",1) then
- gdt = function()
- while true do
- rednet.send(tonumber(default.metadata.sendID),current,"POCKETn@P#C3Y5XnNTj79gyj__GD=Zg92&Mn,e#2wE,Nyuc2sS/D>V>Hg_)3C*Q_%b*N5E")
- local _,recdata = rednet.receive("POCKETn@P#C3Y5XnNTj79gyj__GD=Zg92&Mn,e#2wE,Nyuc2sS/D>V>Hg_)3C*Q_%b*N5E",1)
- if not recdata then
- writes("TIMED OUT. trying again... ",colors.white,colors.red)
- sleep(1)
- else
- writes(" WORKING ",colors.white,colors.green)
- return recdata
- end
- end
- end
- current = gdt()
- if current.metadata.save then
- writes("saving new received config")
- current.metadata.save = false
- local file = fs.open("reactor.data","w")
- file.write(textutils.serialize(current))
- file.close()
- sleep(1)
- end
- local reactor = peripheral.wrap(current.reactor.self)
- local rin = peripheral.wrap(current.reactor.input)
- local rout = peripheral.wrap(current.reactor.output)
- local chest = peripheral.wrap(current.reactor.chest)
- local updatedata = {}
- parallel.waitForAll(
- function() updatedata.energyPerT = reactor.getEnergyProducedLastTick() end,
- function() updatedata.stored = reactor.getEnergyStored() end,
- function() updatedata.storedMax = reactor.getEnergyCapacity() end,
- function() updatedata.coreTemp = reactor.getFuelTemperature() end,
- function() updatedata.caseTemp = reactor.getCasingTemperature() end,
- function() updatedata.fuel = reactor.getFuelAmount() end,
- function() updatedata.waste = reactor.getWasteAmount() end,
- function() updatedata.fuelUsePerT = reactor.getWasteAmount() end,
- function() updatedata.reactivity = reactor.getFuelReactivity() end,
- function() updatedata.items = chest.list() end
- )
- updatedata.energyPerS = updatedata.energyPerT*20
- updatedata.energyPerMin = updatedata.energyPerS*6
- updatedata.tempDiff = updatedata.coreTemp - updatedata.caseTemp
- current.reactor.energyData.perT = updatedata.energyPerT
- current.reactor.energyData.perSec = updatedata.energyPerSec
- current.reactor.energyData.perMin = updatedata.energyPerMin
- current.reactor.energyData.stored = updatedata.stored
- current.reactor.energyData.maxstored = updatedata.storedMax
- current.reactor.tempInfo.coreTemp = updatedata.coreTemp
- current.reactor.tempInfo.caseTemp = updatedata.caseTemp
- current.reactor.tempInfo.tempDiff = updatedata.tempDiff
- current.reactor.fuelInfo.fuel = updatedata.fuel
- current.reactor.fuelInfo.waste = updatedata.waste
- current.reactor.fuelInfo.fuelUsePerT = updatedata.fuelUsePerT
- current.reactor.fuelInfo.reactivity = updatedata.reactivity
- current.chestEvents.items = updatedata.items
- reactor.setAllControlRodLevels(current.reactor.rods)
- reactor.setActive(current.reactor.state or false)
- else
- term.setBackgroundColor(colors.blue)
- b.frame(8,10,38,4,"black","gray")
- term.setBackgroundColor(colors.black)
- term.setCursorPos(8,7)
- term.write("STATUS")
- writes("Paused...",colors.black,colors.yellow)
- end
- end
- end
- local ok, err = pcall(main)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- if not ok then
- print("pocket crashed. reason:\n"..err)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement