bldng1

FusionReactor

Jun 11th, 2024 (edited)
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.86 KB | None | 0 0
  1. function periphalsearch(pname)
  2.    local names = peripheral.getNames()
  3.    local i, name
  4.    for i, name in pairs(names) do
  5.       if peripheral.getType(name) == pname then
  6.          return peripheral.wrap(name)
  7.       end
  8.    end
  9.    return nil
  10. end
  11. monitor=periphalsearch("monitor")
  12. if not monitor then
  13.     monitor=term
  14. end
  15.    
  16. function clear()
  17.    monitor.clear()
  18. end
  19. function getSize()
  20.     return monitor.getSize()
  21. end
  22. function draw_text(x, y, text, text_color, bg_color)
  23.    monitor.setBackgroundColor(bg_color)
  24.    monitor.setTextColor(text_color)
  25.    monitor.setCursorPos(x,y)
  26.    monitor.write(text)
  27.  end
  28. function draw_line(x, y, length, color)
  29.    draw_text(x,y,string.rep(" ", length),color,color)
  30. end
  31. function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
  32.    draw_line(x, y, length, bg_color) --backgoround bar
  33.    local barSize = math.floor((minVal/maxVal) * length)
  34.    draw_line(x, y, barSize, bar_color) --progress so far
  35. end
  36.  function button(x, y, length, text, txt_color, bg_color)
  37.    draw_line(x, y, length, bg_color)
  38.    draw_text((x+2), y, text, txt_color, bg_color)
  39.    if clicked and mx>=x-1 and mx<=x+length+1 and my>=y-1 and my<=y+1 then
  40.       return true
  41.    end
  42.    return false
  43.  end
  44.  
  45. function round(num,s)
  46.    return math.floor((num*(10^s))+0.5)/(10^s)
  47. end
  48. clicked=false
  49. mx=0
  50. my=0
  51. function handletouch()
  52.    clicked=false
  53.    mx=0
  54.    my=0
  55.    local event, button, x, y = os.pullEvent("monitor_touch")
  56.    clicked=true
  57.    mx=x
  58.    my=y
  59. end
  60. updatetime=1
  61. function timeout()
  62.    sleep(updatetime)
  63. end
  64. function unit(amount)
  65.    if amount > 1000000 then
  66.       return round(amount/1000000,1).."M"
  67.    elseif amount > 1000 then
  68.       return round(amount/1000,1).."K"
  69.    else
  70.       return amount
  71.    end
  72. end
  73. reactor=periphalsearch("fusionReactorLogicAdapter")
  74. function update()
  75.    draw_text(3,2,"Reactor Control",colors.yellow,colors.black)
  76.    tanks=(redstone.getAnalogInput("front")/15)
  77.    tanks=math.min(tanks,reactor.getTritium().amount/1000)
  78.    tanks=math.min(tanks,reactor.getDeuterium().amount/1000)
  79.    inj=reactor.getInjectionRate()
  80.    draw_text(3,3,"Tanks",colors.white,colors.black)
  81.    progress_bar(3,4,20,tanks*100,100,colors.green, colors.white)
  82.    draw_text(3,5,"Injection Rate",colors.white,colors.black)
  83.    draw_text(3,6,inj,colors.white,colors.black)
  84.    draw_text(3,7,"Generating",colors.white,colors.black)
  85.    draw_text(3,8,unit(reactor.getPassiveGeneration(false)/2500).."RF/T",colors.white,colors.black)
  86.    if tanks>0.7 then
  87.       draw_text(3,9,"Injecting DT Fuel",colors.red,colors.black)
  88.       redstone.setAnalogOutput("top",15)
  89.       updatetime=0.05
  90.    else
  91.       draw_text(3,9,"Tank Level too low not injecting",colors.white,colors.black)
  92.       redstone.setAnalogOutput("top",0)
  93.       updatetime=1
  94.    end
  95. end
  96. clear()
  97. while true do
  98.    parallel.waitForAny(timeout,handletouch)
  99.    update()
  100. end
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
Advertisement
Add Comment
Please, Sign In to add comment