Guest User

quick fix v2 for mekanism v10 MJRLegends Fusion Reactor Managment

a guest
May 19th, 2023
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.21 KB | None | 0 0
  1. ----------- Made BY MJRLegends (Please dont claim as your own code) -----------
  2. ------------------------- Fixed by Magnusa2007(MagBot) ------------------------
  3. version = "1.0.4"
  4.  
  5. mouseWidth = 0
  6. mouseHeight = 0
  7.  
  8. setting = false
  9. function clear(y)
  10.     monitor.setCursorPos(1,y)
  11.     monitor.clearLine()
  12. end
  13. function draw_line(x, y, length, color)
  14.     monitor.setBackgroundColor(color)
  15.     monitor.setCursorPos(x,y)
  16.     monitor.write(string.rep(" ", length))
  17. end
  18.  
  19. function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
  20.     draw_line(x, y, length, bg_color) --backgoround bar
  21.     local barSize = math.floor((minVal/maxVal) * length)
  22.     draw_line(x, y, barSize, bar_color)     --progress so far
  23. end
  24.  
  25. function draw_text(x, y, text, text_color, bg_color)
  26.     monitor.setBackgroundColor(bg_color)
  27.     monitor.setTextColor(text_color)
  28.     monitor.setCursorPos(x,y)
  29.     monitor.write(text)
  30. end
  31.  
  32. function initPeripherals()
  33.     local perList = peripheral.getNames()
  34.     for i=1,#perList,1 do
  35.         if peripheral.getType(perList[i]) == "monitor" then
  36.             monitor = peripheral.wrap(perList[i])
  37.             term.setCursorPos(1,3)
  38.             term.write("Monitor Found!")
  39.             monitor.clear()
  40.         end
  41.         if peripheral.getType(perList[i]) == "fusionReactorLogicAdapter" then
  42.             reactor = peripheral.wrap(perList[i])
  43.             term.setCursorPos(1,4)
  44.             term.write("Fusion Reactor Found!")
  45.         end
  46.         if peripheral.getType(perList[i]) == "fusionReactorLogicAdapter" then
  47.             reactor = peripheral.wrap(perList[i])
  48.             term.setCursorPos(1,4)
  49.             term.write("Fusion Reactor Found!")
  50.         end
  51.     end
  52. end
  53.  
  54. function drawTitle()
  55.     monitor.setTextColour((colours.blue))
  56.     monitor.setCursorPos(1,1)
  57.     monitor.write("MJRLegends Fusion Reactor Management")
  58.     monitor.setTextColour((colours.white))
  59.    
  60.     displayW,displayH=monitor.getSize()
  61.     monitor.setTextColour((colours.blue))
  62.     monitor.setCursorPos(0,2)
  63.     monitor.write(string.rep("-", displayW))
  64. end
  65.  
  66. function drawConsoleHeader()
  67.     term.setBackgroundColor(colors.black)
  68.     term.setTextColor(colors.blue)
  69.     term.setCursorPos(1,1)
  70.     term.write("MJRLegends Fusion Reactor Management")
  71.     term.setCursorPos(1,2)
  72.     term.write("Version: " .. version)
  73. end
  74.  
  75. function drawControlScreen()
  76.     drawConsoleHeader()
  77.     monitor.setTextScale(1)
  78.     --monitor.clear()
  79.     active = reactor.isFormed()
  80.    
  81.     -----------Title---------------------
  82.     drawTitle()
  83.     -----------Reactor Enable/Disable---------------------
  84.     monitor.setCursorPos(1,3)
  85.     monitor.write("Reactor: ")
  86.     if active then
  87.         monitor.setBackgroundColour((colours.blue))
  88.     else
  89.         monitor.setBackgroundColour((colours.grey))
  90.     end
  91.     monitor.setCursorPos(20,3)
  92.     monitor.write(" ON  ")
  93.    
  94.     if active then
  95.         monitor.setBackgroundColour((colours.grey))
  96.     else
  97.         monitor.setBackgroundColour((colours.blue))
  98.     end
  99.     monitor.setCursorPos(25,3)
  100.     monitor.write(" OFF ")
  101.     monitor.setBackgroundColour((colours.black))
  102.  
  103.     -----------Section Lines---------------------
  104.     displayW,displayH=monitor.getSize()
  105.    
  106.     monitor.setTextColour((colours.blue))
  107.     monitor.setCursorPos(0,4)
  108.     monitor.write(string.rep("-", displayW))
  109.     monitor.setTextColour((colours.white))
  110.    
  111.     monitor.setTextColour((colours.blue))
  112.     monitor.setCursorPos(0,displayH - 2)
  113.     monitor.write(string.rep("-", displayW))
  114.     monitor.setTextColour((colours.white))
  115.    
  116.     monitor.setTextColour((colours.blue))
  117.     monitor.setCursorPos(0,displayH - 0)
  118.     monitor.write(string.rep("-", displayW))
  119.     monitor.setTextColour((colours.white))
  120.    
  121.     -----------Bottom Bar Buttons---------------------
  122.     if setting then
  123.         monitor.setBackgroundColour((colours.grey))
  124.     else
  125.         monitor.setBackgroundColour((colours.blue))
  126.     end
  127.     monitor.setCursorPos(displayW - 10,displayH - 1)
  128.     monitor.write(" Settings ")
  129.     monitor.setBackgroundColour((colours.black))
  130. end
  131.  
  132. function drawDisplayScreen()
  133.     displayW,displayH=monitor.getSize()
  134.     monitor.setTextScale(1)
  135.    
  136.     -----------Casing Heat---------------------
  137.     clear(5)
  138.     draw_text(2, 5, "Casing Heat: ", colors.yellow, colors.black)
  139.     local maxVal = reactor.getMaxCasingTemperature(false)*10
  140.     local minVal = math.floor(tonumber(reactor.getCaseTemperature()))
  141.     draw_text(19, 5, minVal.." C", colors.white, colors.black)
  142.    
  143.     if minVal < 100000 then
  144.     clear(6)
  145.     progress_bar(2, 6, displayW-2, minVal, maxVal, colors.lightBlue, colors.gray)
  146.     elseif minVal < math.floor((1000000000 / 2)/2) then
  147.     progress_bar(2, 6, displayW-2, minVal, maxVal, colors.lime, colors.gray)
  148.     elseif minVal < math.floor(1000000000 / 2) then
  149.     progress_bar(2, 6, displayW-2, minVal, maxVal, colors.yellow, colors.gray)
  150.     elseif minVal >= math.floor(1000000000 / 2) then
  151.     progress_bar(2, 6, displayW-2, minVal, maxVal, colors.red, colors.gray)
  152.     end
  153.     monitor.setBackgroundColour((colours.black))
  154.    
  155.     -----------Plasma Heat---------------------
  156.     clear(8)
  157.     draw_text(2, 8, "Plasma Heat: ", colors.yellow, colors.black)
  158.     local maxVal = reactor.getMaxPlasmaTemperature(false)*10
  159.     local minVal = math.floor(tonumber(reactor.getPlasmaTemperature()))
  160.     draw_text(19, 8, minVal.." C", colors.white, colors.black)
  161.     clear(9)
  162.    
  163.     if minVal < 100000 then
  164.     progress_bar(2, 9, displayW-2, minVal, maxVal, colors.lightBlue, colors.gray)
  165.     elseif minVal < math.floor((1000000000 / 2)/2) then
  166.     progress_bar(2, 9, displayW-2, minVal, maxVal, colors.lime, colors.gray)
  167.     elseif minVal < math.floor(1000000000 / 2) then
  168.     progress_bar(2, 9, displayW-2, minVal, maxVal, colors.yellow, colors.gray)
  169.     elseif minVal >= math.floor(1000000000 / 2) then
  170.     progress_bar(2, 9, displayW-2, minVal, maxVal, colors.red, colors.gray)
  171.     end
  172.     monitor.setBackgroundColour((colours.black))
  173.    
  174.     -----------Ignition Heat---------------------
  175.     clear(11)
  176.     draw_text(2, 11, "Ignition Heat: ", colors.yellow, colors.black)
  177.     local maxVal = 100000000
  178.     local minVal = math.floor(tonumber(reactor.getIgnitionTemperature(false)))
  179.     draw_text(19, 11, minVal.." C", colors.white, colors.black)
  180.    
  181.     clear(12)
  182.     if minVal < 100000 then
  183.     progress_bar(2, 12, displayW-2, minVal, maxVal, colors.lightBlue, colors.gray)
  184.     elseif minVal < math.floor((100000000 / 2)/2) then
  185.     progress_bar(2, 12, displayW-2, minVal, maxVal, colors.lime, colors.gray)
  186.     elseif minVal < math.floor(100000000 / 2) then
  187.     progress_bar(2, 12, displayW-2, minVal, maxVal, colors.yellow, colors.gray)
  188.     elseif minVal >= math.floor(100000000 / 2) then
  189.     progress_bar(2, 12, displayW-2, minVal, maxVal, colors.red, colors.gray)
  190.     end
  191.     monitor.setBackgroundColour((colours.black))
  192.    
  193.     clear(14)
  194.     -----------Deuterium---------------------
  195.     draw_text(2, 14, "Deuterium: ", colors.yellow, colors.black)
  196.     local maxVal = 1000
  197.     local minVal = tonumber(reactor.getDeuterium().amount)
  198.     draw_text(19, 14, minVal.." mb", colors.white, colors.black)
  199.    
  200.     clear(15)
  201.     progress_bar(2, 15, displayW-2, minVal, maxVal, colors.lightGray, colors.gray)
  202.     monitor.setBackgroundColour((colours.black))
  203.    
  204.     -----------Tritium---------------------
  205.     clear(17)
  206.     draw_text(2, 17, "Tritium: ", colors.yellow, colors.black)
  207.     local maxVal = 1000
  208.     local minVal = tonumber(reactor.getTritium().amount)
  209.     draw_text(19, 17, minVal.." mb", colors.white, colors.black)
  210.    
  211.     clear(18)
  212.     progress_bar(2, 18, displayW-2, minVal, maxVal, colors.pink, colors.gray)
  213.     monitor.setBackgroundColour((colours.black))
  214.    
  215.     -----------Injection Rate---------------------
  216.     clear(20)
  217.     draw_text(2, 20, "Injection Rate: ", colors.yellow, colors.black)
  218.     draw_text(24, 20, reactor.getInjectionRate(), colors.white, colors.black)
  219.    
  220.     -----------Has Fuel---------------------
  221.     --draw_text(2, 18, "Fuel: ", colors.yellow, colors.black)
  222.     --draw_text(24, 18, reactor.hasFuel(), colors.white, colors.black)
  223.    
  224.     -----------Engery Producing---------------------
  225.     --draw_text(2, 19, "Engery Producing J/T: ", colors.yellow, colors.black)
  226.     --draw_text(24, 19, math.floor(tonumber(reactor.getProducing())) .. " J/T", colors.white, colors.black)
  227.     clear(21)
  228.     draw_text(2, 21, "Engery Producing RF/T: ", colors.yellow, colors.black)
  229.     draw_text(24, 21, math.floor(tonumber(reactor.getProductionRate()) / 2.5) .. " RF/T", colors.white, colors.black)
  230.    
  231.     -----------Can Ignite---------------------
  232.     --draw_text(2, 21, "Can Ignite: ", colors.yellow, colors.black)
  233.     --draw_text(24, 21, reactor.canIgnite(), colors.white, colors.black)
  234.    
  235. end
  236.  
  237. function drawSettingScreen()
  238.     monitor.clear()
  239.     drawTitle()
  240.     drawConsoleHeader()
  241.     drawControlScreen()
  242.     displayW,displayH=monitor.getSize()
  243.    
  244.     -------------Title-------------------
  245.     draw_text(16, 6, "Settings", colors.blue, colors.black)
  246.    
  247.     monitor.setTextColour((colours.blue))
  248.     monitor.setCursorPos(0,7)
  249.     monitor.write(string.rep("-", displayW))
  250.     monitor.setTextColour((colours.white))
  251. end
  252.  
  253. function checkClickPosition()
  254.     displayW,displayH=monitor.getSize()
  255.     --if mouseWidth > 20 and mouseWidth < 24 and mouseHeight == 3 then
  256.     --    reactor.setActive(true)
  257.     --elseif mouseWidth > 24 and mouseWidth < 28 and mouseHeight == 3 then
  258.      --   reactor.setActive(false)
  259.     if mouseWidth > (displayW - 10) and mouseWidth < displayW and mouseHeight == (displayH - 1) then
  260.         monitor.clear()
  261.         if setting then
  262.             setting = false
  263.         else
  264.             setting = true
  265.         end
  266.     end
  267.     sleep(0.5)
  268. end
  269.  
  270.  
  271. function mainMenu()
  272.     initPeripherals()
  273.     drawConsoleHeader()
  274.     if reactor == nil then
  275.         term.setCursorPos(1,4)
  276.         term.setTextColor(colors.red)
  277.         term.write("No Fusion Reactor Found!")
  278.     elseif  monitor == nil then
  279.         term.setCursorPos(1,4)
  280.         term.setTextColor(colors.red)
  281.         term.write("No Monitor Found!")
  282.     else
  283.         while true do
  284.             displayW,displayH=monitor.getSize()
  285.             if displayH == 26 and displayW == 39 then
  286.                 if tonumber(reactor.getCaseTemperature()) == nil then
  287.                     drawTitle()
  288.                 clear(3)
  289.                     draw_text(2, 3, "Fusion Reactor currently not formed!", colors.red, colors.black)
  290.                 else
  291.                     drawControlScreen()
  292.                     if setting == true then
  293.                         drawSettingScreen()
  294.                     else
  295.                         drawDisplayScreen()
  296.                     end
  297.                 end
  298.             else
  299.                 print("This program is built for a 4x4 monitor only!")
  300.                 return
  301.             end
  302.             sleep(1.0)
  303.         end
  304.     end
  305. end
  306.  
  307. function events()
  308.     while true do
  309.         event,p1,p2,p3 = os.pullEvent()
  310.         if event=="monitor_touch" then
  311.             mouseWidth = p2 -- sets mouseWidth
  312.             mouseHeight = p3 -- and mouseHeight
  313.             checkClickPosition() -- this runs our function
  314.         end
  315.     end
  316. end
  317.  
  318. parallel.waitForAny(mainMenu,events)
Advertisement
Add Comment
Please, Sign In to add comment