DerReuter

Untitled

Sep 17th, 2019
181
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.    /---------------------------------\
  3.    | The Big Reactors Status Display |
  4.    | Version 1.5                     |
  5.    | By Jac0b                        |
  6.    | Published under the MIT license |
  7.    \---------------------------------
  8. ]]
  9.  
  10. -- =============
  11. -- Configuration
  12. -- =============
  13.  
  14. -- This is the side on which your reactor is connected
  15. local reactor_side = "BigReactors-Reactor_0"
  16. -- This is the side on which your monitor is connected
  17. local monitor_side = "right"
  18.  
  19. -- Maximum amount of energy in buffer before the reactor is shut down
  20. local max_buffer = 9000000
  21. -- Minimum amount of energy needed to start the reactor
  22. local min_buffer = 5000000
  23.  
  24. -- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  25. -- !!! DO NOT EDIT ANYTHING BEYOND THIS POINT UNLESS YOU KNOW, WHAT TO DO !!!
  26. -- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  27.  
  28. -- If the reactor is not connected, exit the program
  29. if not peripheral.isPresent(reactor_side) then
  30.   print("Please check, that the reactor is connected to the same side as in your config!")
  31.   return
  32. end
  33. -- If the monitor is not connected, exit
  34. if not peripheral.isPresent(monitor_side) then
  35.   print("Please check, that the monitor is connected to the same side as in your config!")
  36.   return
  37. end
  38.  
  39. -- Wrap the peripherals
  40. local r = peripheral.wrap(reactor_side)
  41. while not r.getConnected() do sleep(10) end
  42. local m = peripheral.wrap(monitor_side)
  43.  
  44. print("The program is now running on the monitor!")
  45.  
  46. -- BEGIN FUNCTIONS PART
  47. function clear()
  48.   m.clear()
  49.   m.setTextColor(colors.white)
  50.   m.setBackgroundColor(colors.black)
  51.   m.setCursorPos(1, 1)
  52. end
  53.  
  54. function resetColors()
  55.   m.setTextColor(colors.white)
  56.   m.setBackgroundColor(colors.black)
  57. end
  58.  
  59. function newLine()
  60.   local x, y = m.getCursorPos()
  61.   m.setCursorPos(1, y+1)
  62. end
  63.  
  64. function drawUI()
  65.   m.write("/---------------------------\\")
  66.  
  67.   for x = 2, 11, 1 do
  68.     m.setCursorPos(1, x)
  69.         m.write("|")
  70.         m.setCursorPos(29, x)
  71.         m.write("|")
  72.   end
  73.  
  74.   m.setCursorPos(2, 3)
  75.   m.write("---------------------------")
  76.  
  77.   m.setCursorPos(2, 5)
  78.   m.write("---------------------------")
  79.   m.setCursorPos(2, 8)
  80.   m.write("---------------------------")
  81.  
  82.   m.setCursorPos(1, 12)
  83.   m.write("\\---------------------------/")
  84. end
  85.  
  86. -- END FUNCTIONS PART
  87.  
  88. -- Repeat forever
  89. while true do
  90.   -- Clear the terminal
  91.   clear()
  92.   -- Draw the basic UI layout
  93.   drawUI()
  94.  
  95.   -- Reactor status
  96.   active = r.getActive()    
  97.   m.setCursorPos(3, 2)
  98.  
  99.   m.write("Status: ")
  100.   if active then
  101.     m.setTextColor(colors.green)
  102.     m.write("Active")
  103.   else
  104.     m.setTextColor(colors.red)
  105.     m.write("Inactive")
  106.   end
  107.   -- End reactor status
  108.  
  109.   -- Buffer Status
  110.   resetColors()  
  111.   m.setCursorPos(3, 4)  
  112.   energy = r.getEnergyStored()
  113.  
  114.   -- If the buffer is above the max_buffer value, shut the reactor down
  115.   if energy >= max_buffer then
  116.     r.setActive(false)
  117.   end
  118.    -- If the energy is below the min_buffer value, turn it back on
  119.   if energy <= min_buffer then
  120.     r.setActive(true)
  121.   end
  122.  
  123.   -- Print out the buffer value
  124.   m.setTextColor(colors.white)
  125.   m.write("Buffer: ")
  126.   m.setTextColor(colors.yellow)
  127.   m.write(energy)
  128.   -- END buffer Status
  129.  
  130.   -- Temperatures
  131.   m.setCursorPos(3, 6)
  132.   m.setTextColor(colors.white)
  133.   m.write("Fuel:")
  134.   m.setCursorPos(15, 6)
  135.   m.write("| Case:")
  136.   m.setCursorPos(15, 7)
  137.   m.write("|")
  138.  
  139.   local fuelTemp = math.floor(r.getFuelTemperature())
  140.   local caseTemp = math.floor(r.getCasingTemperature())
  141.  
  142.   m.setCursorPos(3, 7)
  143.   m.setTextColor(colors.cyan)
  144.   m.write(fuelTemp .. " C")
  145.   m.setCursorPos(17, 7)
  146.   m.write(caseTemp .. " C")
  147.   -- END temperatures
  148.  
  149.   -- Waste and fuel status
  150.   local waste = math.floor(r.getWasteAmount())
  151.   local fuel = math.floor(r.getFuelAmount())
  152.  
  153.   m.setTextColor(colors.white)
  154.   m.setCursorPos(3, 9)
  155.   m.write("Fuel:")
  156.   m.setCursorPos(15, 9)
  157.   m.write("| Waste:")
  158.   m.setCursorPos(3, 10)
  159.   m.setTextColor(colors.yellow)
  160.   m.write(fuel)
  161.   m.setTextColor(colors.white)
  162.   m.setCursorPos(15, 10)
  163.   m.write("|")
  164.   m.setCursorPos(17, 10)
  165.   m.setTextColor(colors.red)
  166.   m.write(waste)
  167.   -- END Waste and Fuel Status
  168.  
  169.   -- Sleep for a 1/4 of a second (decreases CPU load significantly)...
  170.   sleep(1)
  171. end
RAW Paste Data