Advertisement
Plazter

IC2 Reactor WITH mfsu

Sep 10th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.92 KB | None | 0 0
  1. component = require("component")
  2. term = require("term")
  3. gpu = component.gpu
  4. event = require("event")
  5. sides = require("sides")
  6. mfsu = component.ic2_te_mfsu
  7. redstone = component.proxy(component.get("687c5bc1-1a41-4930-9a1c-a7d1af612a5b"))
  8. reactor = component.proxy(component.get("e4b738c2-b758-495f-899e-39e6114ff2b3"))
  9.  
  10. colors = { black = 0x000000, white = 0xf8f8ff, blue = 0x0000ff, lightGray = 0xd9d9d9, red = 0xff0000,
  11. purple = 0x9b30ff, carrot = 0xffa500, magenta = 0xcd00cd, lightBlue = 0x87cefa, yellow = 0xffff00,
  12. lime = 0x32cd32, pink = 0xffc0cb, gray = 0x696969, brown = 0x8b4500, green = 0x006400, cyan = 0x008b8b,
  13. olive = 0x6b8e23, gold = 0x8b6914, orangered = 0xdb4e02, diamond = 0x0fa7c7,crimson = 0xaf002a,fuchsia = 0xfd3f92,
  14. folly = 0xff004f, frenchBlue = 0x0072bb, lilac = 0x86608e, flax = 0xeedc82, darkGray = 0x563c5c,
  15. englishGreen = 0x1b4d3e, eggplant = 0x614051, deepPink  = 0xff1493, ruby = 0x843f5b, orange = 0xf5c71a,
  16. lemon = 0xffd300, darkBlue = 0x002e63, bitterLime = 0xbfff00 }
  17. ------------------------------------------------------------------------------------------------------------------
  18.                                                  --[[ VARIABLES ]]--
  19. ------------------------------------------------------------------------------------------------------------------
  20. Border_bg = colors.diamond
  21. Default_bg = colors.gray
  22. text_col = colors.blue
  23. status_col = colors.black
  24. barBack = colors.black
  25. barFill = colors.white
  26. header = colors.orange
  27. Side = sides.east
  28. -----------------------------------------------------------------------------------------------------------------
  29.                                                  --[[ FUNCTIONS ]]--
  30. ------------------------------------------------------------------------------------------------------------------
  31. function guiBorders(x,y,len,height,str) -- BORDER FUNC FOR GUI
  32.   gpu.setBackground(Border_bg)
  33.   gpu.fill(x,y,len,height,str)
  34.   gpu.setBackground(Default_bg)
  35. end
  36.  
  37. function GUI() -- SETS THE GUI LAYOUT (GRAPHICAL USER INTERFACE)
  38.   gpu.setBackground(Default_bg)
  39.   term.clear()
  40.   w,  h = gpu.getResolution()
  41.   guiBorders(1,1,w,1," ")
  42.   guiBorders(1,5,w,1," ")
  43.     for i = 1,h do
  44.       guiBorders(1,i,1,1," ")
  45.       guiBorders(w,i,1,1," ")
  46.     end
  47.     for i = 5,h do
  48.       guiBorders(7,i,1,5," ")
  49.     end
  50.   for i = 5,h do
  51.     guiBorders(w-6, i,1,5," ")
  52.   end
  53.   guiBorders(1,h,w,1," ")
  54.   gpu.setForeground(header)
  55.   Center(3,"--[[ Nuclear Reactor Control ]]--")
  56. end
  57.  
  58. function key()
  59.  -- KEYS --
  60.   gpu.set(25, 14, "lol")
  61.   gpu.setBackground(colors.red)
  62.   gpu.fill(16,14,8,3," ")
  63.  
  64.   gpu.setBackground(Default_bg)
  65. end
  66.  
  67. function drawBarPos(xOff,yOff,w,h,percentage,text)
  68.   barLen = math.floor(percentage*(h-2) +0.5)
  69.   gpu.setForeground(barBack)
  70.   gpu.fill(xOff,yOff,w,h,"█")
  71.   gpu.setForeground(barFill)
  72.   gpu.fill(xOff+1,yOff+1,w-2,h-2,"█")
  73.  
  74.   if percentage >= 0.75 then
  75.     gpu.setForeground(colors.green)
  76.   elseif percentage >= 0.5 then
  77.     gpu.setForeground(colors.yellow)
  78.   elseif percentage >= 0.25 then
  79.     gpu.setForeground(colors.orange)
  80.   elseif percentage >= 0 then
  81.     gpu.setForeground(colors.red)
  82.   end
  83.  
  84.   gpu.fill(xOff+1,(yOff+h-1)-barLen,w-2,barLen,"█")
  85.  
  86.   gpu.setForeground(colors.white)
  87.   gpu.set(xOff,h+6,"%"..math.floor(percentage*100).." ")
  88.   gpu.set(xOff, h+7, text)
  89. end
  90.  
  91. function drawBarNeg(xOff,yOff,w,h,percentage, text)
  92.   barLen = math.floor(percentage*(h-2) +0.5)
  93.   gpu.setForeground(barBack)
  94.   gpu.fill(xOff,yOff,w,h,"█")
  95.   gpu.setForeground(barFill)
  96.   gpu.fill(xOff+1,yOff+1,w-2,h-2,"█")
  97.  
  98.   if percentage >= 0.75 then
  99.     gpu.setForeground(colors.red)
  100.   elseif percentage >= 0.5 then
  101.     gpu.setForeground(colors.orange)
  102.   elseif percentage >= 0.25 then
  103.     gpu.setForeground(colors.yellow)
  104.   elseif percentage >= 0 then
  105.     gpu.setForeground(colors.green)
  106.   end
  107.  
  108.   gpu.fill(xOff+1,(yOff+h-1)-barLen,w-2,barLen,"█")
  109.  
  110.   gpu.setForeground(colors.white)
  111.   gpu.set(xOff+1,h+6,"%"..math.floor(percentage*100).." ")
  112.   gpu.set(xOff, h+7, text)
  113. end
  114.  
  115. function Center(y, text)
  116.   w, h = gpu.getResolution()
  117.   term.setCursor((w-string.len(text))/2+1, y)
  118.   term.write(text)
  119. end
  120.  
  121. function InfoUpdate(y, text) -- Text for function UPDATE
  122.   w, h = gpu.getResolution()
  123.       place = (w-string.len(text))-7
  124.     gpu.set(place, y, text)
  125. end
  126.  
  127. function Display()
  128. w, h = gpu.getResolution()
  129.   gpu.set(9,6,"Reactor Status:")
  130.   InfoUpdate(6,"   "..tostring(stat))
  131.   gpu.set(9,8, "Heat: ")
  132.   InfoUpdate(8, tostring(heat).." C")
  133.   gpu.set(9,10, "EU/T: ")
  134.   InfoUpdate(10, "   "..tostring(out))
  135.   gpu.set(9,12, "Stored EU: ")
  136.   InfoUpdate(12,"    ".. math.floor(stored).."/"..math.floor(mfsu.getCapacity()))
  137. end
  138.  
  139. function addButton(x, y, col,text)
  140.   leng = string.len(text)
  141.   gpu.setBackground(col)
  142.   gpu.fill(x, y, (leng + 2), 3," ")
  143.   gpu.setForeground(status_col)
  144.   gpu.set(x+1, y+1, text)
  145.   gpu.setBackground(Default_bg)
  146. end
  147.  
  148. function fail()
  149.   if heatPerc*100 >= 20 then
  150.     redstone.setOutput(Side, 0)
  151.   end
  152. end
  153.  
  154.  
  155. gpu.setResolution(60,20)
  156. GUI()
  157. --key()
  158. addButton(19,16, colors.red,"Offline")
  159. addButton(34,16, colors.lime,"Online")
  160.  
  161. function getP()
  162.     if x~= nil and y ~= nil then
  163.       if x >= 19 and x<=25 and y >= 16 and y <= 18 then
  164.         redstone.setOutput(Side, 0)
  165.       elseif x >= 34 and x <= 42 and y >= 16 and y <= 18 then
  166.         redstone.setOutput(Side, 15)
  167.       end
  168.     end
  169. end
  170.  
  171. while true do
  172.   -- Update
  173.   if reactor.producesEnergy() then
  174.     stat = "Active"
  175.   else
  176.     stat = "Offline"
  177.   end
  178.   --Updates
  179.   stored = mfsu.getEnergy()
  180.   heat = reactor.getHeat()
  181.   out = reactor.getReactorEUOutput()
  182.   EOut = reactor. getReactorEnergyOutput()
  183.   -- Percs
  184.   heatPerc = reactor.getHeat() / reactor.getMaxHeat()
  185.   mfsuPerc = mfsu.getEnergy() / mfsu.getCapacity()
  186.   -- Bars
  187.   drawBarNeg(2,6,5,12, heatPerc, "Heat")
  188.   drawBarPos(55,6,5,12, mfsuPerc,"Mfsu")
  189.   -- Functions
  190.   Display()
  191.   fail()
  192.   _,_,x,y = event.pull(1, "touch")
  193.   getP()
  194. --os.sleep(.2)
  195. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement