gelatine87

reactorWiFiempfanger

Aug 2nd, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.49 KB | None | 0 0
  1. ----------------------------------------------------------
  2. -- Active Cooling Big Reactor Monitor                   --
  3. --                                                      --
  4. -- Minecraft HermitCraft FTB Infinity Episode 28        --
  5. -- https://www.youtube.com/watch?v=cIPxwZJWOiE          --
  6. --                                                      --
  7. -- YouTube Channel http://youtube.com/hypnotizd         --
  8. ----------------------------------------------------------
  9.  
  10. local mon = {}
  11. local hasMon = false
  12. local hasRMon = false
  13. local rMonName = ""
  14. local directions = {"top", "bottom", "front", "back", "left", "right"}
  15.  
  16. local function findPeripherals()
  17.   for k, v in pairs(peripheral.getNames()) do
  18.     if string.find(v, "monitor") then
  19.       hasMon = true
  20.       hasRMon = true
  21.       rMonName = v
  22.       print("INFO: Found remote "..v)
  23.       os.sleep(1)
  24.     end
  25.   end
  26. end
  27.  
  28. local function findMon()
  29.   if hasRMon then return end
  30.   for k, v in pairs(directions) do
  31.     local p = peripheral.wrap(v)
  32.     if p ~= nil then
  33.       if string.find(peripheral.getType(v), "monitor") then
  34.         mon = p
  35.         hasMon = true
  36.         return
  37.       end
  38.     end
  39.   end
  40.   print("WARNING: No monitor detected!")
  41.   os.sleep(5)
  42. end
  43.  
  44. local function monClear()
  45.   if hasMon then
  46.     if hasRMon then
  47.       peripheral.call(rMonName, "setCursorPos", 1, 1)
  48.       peripheral.call(rMonName, "clear")
  49.     else
  50.       mon.setCursorPos(1, 1)
  51.       mon.clear()
  52.     end
  53.   else
  54.     term.clear()
  55.     term.setCursorPos(1, 1)
  56.   end
  57. end
  58.  
  59. local function monWrite(x, y, text)
  60.   if hasMon then
  61.     if hasRMon then
  62.       peripheral.call(rMonName, "setCursorPos", x, y)
  63.       peripheral.call(rMonName, "write", text)
  64.     else
  65.       mon.setCursorPos(x, y)
  66.       mon.write(text)
  67.     end
  68.   else
  69.     term.setCursorPos(x, y)
  70.     term.write(text)
  71.   end
  72. end
  73.  
  74. local function init()
  75.   term.clear()
  76.   term.setCursorPos(1, 1)
  77.   findPeripherals()
  78.   findMon()
  79.   monClear()
  80. end
  81.  
  82. init()
  83.  
  84. while true do
  85.  
  86.   local rods = 0
  87.   local casingTemp = 0
  88.   local coreTemp = 0
  89.   local rodLevel = 0
  90.   local fuelReactivity = 0
  91.   local fuelConsumed = 0
  92.   local steamProduced = 0
  93.   local active = ""
  94.   local X = 0
  95.   local Y = 0
  96.   local Z = 0
  97.  
  98.   rednet.open("top")
  99.   local id, msg = rednet.receive()
  100.   local table = textutils.unserialize(msg)
  101.   -- print(table[0]) == getNumberOfControlRods
  102.   -- print(table[1]) == getCasingTemperature
  103.   -- print(table[2]) == getFuelTemperature
  104.   -- print(table[3]) == getControlRodLevel
  105.   -- print(table[4]) == getFuelReactivity
  106.   -- print(table[5]) == getFuelConsumedLastTick
  107.   -- print(table[6]) == getHotFluidProducedLastTick
  108.   -- print(table[7]) == active
  109.   -- print(table[8]) == X
  110.   -- print(table[9]) == Y
  111.   -- print(table[10]) == Z
  112.  
  113.   rods = table[0]
  114.   casingTemp = table[1]
  115.   coreTemp = table[2]
  116.   rodLevel = table[3]
  117.   fuelReactivity = table[4]
  118.   fuelConsumed = table[5]
  119.   steamProduced = table[6]
  120.   active = table[7]
  121.   X = table[8]
  122.   Y = table[9]
  123.   Z = table[10]
  124.  
  125.   monClear()
  126.   monWrite(1, 1, "   Reactor Status: "..active)
  127.   monWrite(1, 2, "     Reactor Size: "..X.."x"..Y.."x"..Z)
  128.   monWrite(1, 3, " Num Control Rods: "..rods)
  129.   monWrite(1, 4, "     Casing Temp.: "..casingTemp)
  130.   monWrite(1, 5, "       Core Temp.: "..coreTemp)
  131.   monWrite(1, 6, "Control Rod Level: "..rodLevel)
  132.   monWrite(1, 7, "  Fuel Reactivity: "..fuelReactivity)
  133.   monWrite(1, 8, "  Fuel Usage/tick: "..fuelConsumed)
  134.   monWrite(1, 9, "   Steam Produced: "..steamProduced)
  135.  
  136.   os.sleep(3)
  137. end
Add Comment
Please, Sign In to add comment