Advertisement
TheProgrammer

Minecraft - BigReactors TEST1

May 28th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.64 KB | None | 0 0
  1. local MONITOR_NAME = "front"
  2. local REACTOR_NAME = "back"
  3. local monitor = peripheral.wrap(MONITOR_NAME)
  4. local reactor = peripheral.wrap(REACTOR_NAME)
  5. local DMST = "monitor"
  6. local mClick = DMST.."_click"
  7. local mTouch = DMST.."_touch"
  8. local mResize = DMST.."_resize"
  9. local MONITOR_COLORTABLE = {colors.lightBlue, colors.green, colors.red, colors.lightGray, colors.gray, colors.white}
  10. --lightblue = cryotheum, green = ender, red = redstone, lightgray = air, gray = casing, white = rod
  11. --local REACTOR_BLOCKTYPES = {"cryotheum", "ender", "redstone", "air", "casing", "rod"}
  12. local rSizeX,rSizeY,rSizeZ = 0
  13. local lastEnergyLevel = 0
  14. local lastCheck = os.clock()
  15.  
  16. local c = "casing"
  17. local e = "ender"
  18. local r = "rod"
  19. local ROW1  = {c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c}
  20. local ROW2  = {c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c}
  21. local ROW3  = {c,c,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,c,c}
  22. local ROW4  = {c,c,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,c,c}
  23. local ROW5  = {c,c,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,c,c}
  24. local ROW6  = {c,c,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,c,c}
  25. local ROW7  = {c,c,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,c,c}
  26. local ROW8  = {c,c,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,c,c}
  27. local ROW9  = {c,c,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,c,c}
  28. local ROW10 = {c,c,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,c,c}
  29. local ROW11 = {c,c,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,c,c}
  30. local ROW12 = {c,c,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,c,c}
  31. local ROW13 = {c,c,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,c,c}
  32. local ROW14 = {c,c,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,c,c}
  33. local ROW15 = {c,c,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,c,c}
  34. local ROW16 = {c,c,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,c,c}
  35. local ROW17 = {c,c,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,c,c}
  36. local ROW18 = {c,c,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,c,c}
  37. local ROW19 = {c,c,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,c,c}
  38. local ROW20 = {c,c,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,c,c}
  39. local ROW21 = {c,c,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,c,c}
  40. local ROW22 = {c,c,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,r,r,e,e,c,c}
  41. local ROW23 = {c,c,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,c,c}
  42. local ROW24 = {c,c,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,c,c}
  43. local ROW25 = {c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c}
  44. local ROW26 = {c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c}
  45. local PIX = {ROW1,ROW2,ROW3,ROW4,ROW5,ROW6,ROW7,ROW8,ROW9,ROW10,ROW11,ROW12,ROW13,ROW14,ROW15,ROW16,ROW17,ROW18,ROW19,ROW20,ROW21,ROW22,ROW23,ROW24,ROW25,ROW26}
  46. local MODE_BOX_X,MODE_BOX_Y,MODE_BOX_WIDTH,MODE_BOX_HEIGHT = 1,27,24,3
  47. local INFO_BOX_X,INFO_BOX_Y,INFO_BOX_WIDTH,INFO_BOX_HEIGHT = 5,27,24,3
  48. local STOP_BOX_X,STOP_BOX_Y,STOP_BOX_WIDTH,STOP_BOX_HEIGHT = 24,27,24,3
  49. local currentScreen = ""
  50. local AUTO = true
  51.  
  52. function init()
  53.     monitor.setBackgroundColor(colors.black)
  54.     monitor.setTextColor(colors.red)
  55.     monitor.clear()
  56.     monitor.setBackgroundColor(colors.black)
  57.     monitor.setTextColor(colors.red)
  58. end
  59.  
  60. function check()
  61.     --TODO?
  62. end
  63.  
  64. function getTemperature()
  65.     --local temp = reactor.getTemperature()
  66.     --local tempString = temp..""
  67.     --if(string.len(tostring(temp))>3)then
  68.     --  tempString = math.floor(temp/1000).."K "
  69.     --end
  70.     return reactor.getTemperature().."°C"
  71. end
  72.  
  73. function getEnergyLevel()
  74.     return reactor.getEnergyStored().."RF"
  75. end
  76.  
  77. function getEnergyUsage()
  78.     local currentEnergyLevel = reactor.getEnergyStored()
  79.     local currentEnergyUsage = currentEnergyLevel - lastEnergyLevel
  80.     local currentTimeDiff = os.clock()-lastCheck
  81.     currentEnergyUsage = currentEnergyUsage / currentTimeDiff
  82.     lastEnergyLevel = currentEnergyLevel
  83.     lastCheck = os.clock()
  84.     return currentEnergyUsage.." RF/s"
  85. end
  86.  
  87. function getReactorState()
  88.     return reactor.getActive()
  89. end
  90.  
  91. function trimEnergy(l)
  92.     --TODO?
  93. end
  94.  
  95. function handleReactor()
  96.     while true do
  97.         if AUTO then
  98.             if (reactor.getEnergyStored()>=8000000) then
  99.                 reactor.setActive(false)
  100.             else
  101.                 reactor.setActive(true)
  102.             end
  103.         end
  104.         os.sleep(2)
  105.     end
  106. end
  107.  
  108. function showReactor()
  109.     for i=1,26,1 do
  110.         for j=1,26,1 do
  111.             local entry = PIX[i][j]
  112.             if entry==c then
  113.                 monitor.setBackgroundColor(MONITOR_COLORTABLE[5])
  114.                 monitor.setCursorPos(i,j)
  115.                 monitor.write(" ")
  116.             elseif entry==e then
  117.                 monitor.setBackgroundColor(MONITOR_COLORTABLE[2])
  118.                 monitor.setCursorPos(i,j)
  119.                 monitor.write(" ")
  120.             elseif entry==r then
  121.                 monitor.setBackgroundColor(MONITOR_COLORTABLE[6])
  122.                 monitor.setCursorPos(i,j)
  123.                 monitor.write(" ")
  124.             end
  125.         end
  126.     end
  127. end
  128.  
  129. function fuckMyLife(j)
  130.     monitor.setBackgroundColor(colors.lightGray)   
  131.     if j==4 then
  132.         monitor.setBackgroundColor(colors.black)
  133.     elseif j==8 then
  134.         monitor.setBackgroundColor(colors.black)
  135.     elseif j>=12 then
  136.         if j<=23 then
  137.             monitor.setBackgroundColor(colors.black)
  138.         end
  139.     end
  140. end
  141.  
  142. function showSelection()
  143.     for j=1,26,1 do
  144.         for i=27,50,1 do
  145.             monitor.setTextColor(colors.red)
  146.             --fuckMyLife(j)
  147.             monitor.setCursorPos(i,j)
  148.             if j==2 then
  149.                 monitor.write("MODE")
  150.                 i = i+string.len("MODE")
  151.                 for i=i,26,1 do
  152.                     monitor.write(" ")
  153.                 end
  154.             elseif i==6 then
  155.                 monitor.write("INFO")
  156.                 i = i+string.len("INFO")
  157.                 for i=i,26,1 do
  158.                     monitor.write(" ")
  159.                 end
  160.             elseif j==25 then
  161.                 monitor.write("STOP")
  162.                 i = i+string.len("STOP")
  163.                 for i=i,26,1 do
  164.                     monitor.write(" ")
  165.                 end
  166.             else                           
  167.                 monitor.write(" ")
  168.             end
  169.         end
  170.     end
  171.     currentScreen = "selection"
  172. end
  173.  
  174. function stop()
  175.     os.shutdown()
  176. end
  177.  
  178. function showModes()
  179.     for j=1,26,1 do
  180.         for i=27,50,1 do
  181.             fuckMyLife(j)
  182.             monitor.setCursorPos(i,j)
  183.             if j==2 then
  184.                 monitor.write("AUTO")
  185.                 i = i+string.len("AUTO")
  186.                 for i=i,26,1 do
  187.                     monitor.write(" ")
  188.                 end
  189.             elseif j==6 then
  190.                 monitor.write("MANU")
  191.                 i = i+string.len("MANU")
  192.                 for i=i,26,1 do
  193.                     monitor.write(" ")
  194.                 end
  195.             elseif j==25 then
  196.                 monitor.write("BACK")
  197.                 i = i+string.len("BACK")
  198.                 for i=i,26,1 do
  199.                     monitor.write(" ")
  200.                 end
  201.             else                           
  202.                 monitor.write(" ")
  203.             end
  204.         end
  205.     end
  206.     currentScreen = "mode"
  207. end
  208.  
  209. function showInfo()
  210.    
  211. end
  212.  
  213. function inFirstBox()
  214.     if posX>=MODE_BOX_X then
  215.         if posX<=MODE_BOX_X+MODE_BOX_HEIGHT-1 then
  216.             if posY>=MODE_BOX_Y then
  217.                 if posY<=MODE_BOX_Y+MODE_BOX_WIDTH-1 then
  218.                     return true
  219.                 end
  220.             end
  221.         end
  222.     end
  223.     return false
  224. end
  225.  
  226. function inSecondBox()
  227.     if posX>=INFO_BOX_X then
  228.         if posX<=INFO_BOX_X+INFO_BOX_HEIGHT-1 then
  229.             if posY>=INFO_BOX_Y then
  230.                 if posY<=INFO_BOX_Y+INFO_BOX_WIDTH-1 then
  231.                     return true
  232.                 end
  233.             end
  234.         end
  235.     end
  236.     return false
  237. end
  238.  
  239. function inLastBox()
  240.     if posX>=STOP_BOX_X then
  241.         if posX<=STOP_BOX_X+STOP_BOX_HEIGHT-1 then
  242.             if posY>=STOP_BOX_Y then
  243.                 if posY<=STOP_BOX_Y+STOP_BOX_WIDTH-1 then
  244.                     return true
  245.                 end
  246.             end
  247.         end
  248.     end
  249.     return false
  250. end
  251.  
  252. function XlistenForEvent()
  253.     local event,button,posX,posY = os.pullEvent()
  254.     if event==mTouch then
  255.         if currentScreen=="selection" then
  256.             if inFirstBox() then
  257.                 showModes()
  258.             elseif inSecondBox() then
  259.                 showInfo()
  260.             elseif inLastBox() then
  261.                 stop()
  262.             end
  263.         elseif currentScreen=="mode" then
  264.             if inFirstBox() then
  265.                 AUTO = true
  266.             elseif inSecondBox() then
  267.                 AUTO = false
  268.             elseif inLastBox() then
  269.                 showSelection()
  270.             end        
  271.         elseif currentScreen=="info" then
  272.                
  273.         end
  274.     end
  275. end
  276.  
  277.  
  278.  
  279. init()
  280. print("Successfully initialized!")
  281. showReactor()
  282. print("Reactor shown")
  283. showSelection()
  284. print("Selection shown")
  285. monitor.setCursorPos(1,5)
  286. monitor.write("X")
  287. while true do
  288.     parallel.waitForAll(handleReactor,XlistenForEvent)
  289.     os.sleep(.1)
  290. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement