MinoCraft72

Botania Mana Generator V2

Apr 30th, 2023
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | Gaming | 0 0
  1. -- Configs:
  2.  
  3.     pool_numb = 5
  4.     mana_min = 75
  5.     rs_side = "top"
  6.     monitor = "monitor_8"
  7.  
  8.  
  9.  
  10. -- Init Variables:
  11.  
  12.     pool_list = { }
  13.     have_monitor = false
  14.  
  15. -- Functions:
  16.  
  17. function wrapPeriph()
  18.  wrap_list = peripheral.getNames()
  19.   for _,w in pairs(wrap_list) do
  20.     if string.find(w, "manaPool") ~= nil then
  21.      wrap_name = string.sub(w,5,string.len(w))
  22.      wrap_side = w
  23.      wrap = peripheral.wrap(wrap_side)
  24.      pool_list[wrap_name] = wrap
  25.      wrap_info = string.format("%s connected to %s",wrap_name,wrap_side)
  26.      sleep(1)
  27.     elseif string.find(w,"monitor") ~= nil then
  28.      wrap_side = w
  29.      mon = peripheral.wrap(wrap_side)
  30.      wrap_info = string.format("[mon] connected to %s - %s;%s",wrap_side,mon_x,mon_y)
  31.      have_monitor = true
  32.      mon.clear()
  33.      mon_x, mon_y = mon.getSize()
  34.     else
  35.      wrap_name = w
  36.      wrap_info = string.format("%s not connected to Network",wrap_name)
  37.     end
  38.    print(wrap_info)
  39.   end
  40. end
  41.  
  42. function drawMana()
  43.   dx = mon_x
  44.   dy_max = mon_y-3
  45.   dy = math.floor((pp_t*dy_max)/100)
  46.   for d = dy_max,dy,-1 do
  47.    mon.setCursorPos(2,d)
  48.    mon.clearLine()
  49.    mon.setBackgroundColor(colors.lightBlue)
  50.    mon.write("        ")
  51.    --mon.setCursorPos(5,d+1)
  52.    mon.setBackgroundColor(colors.black)  
  53.    --last_y = d
  54.   end
  55.  --mon.setCursorPos(5,last_y+1)
  56.  --mon.clearLine()
  57.  --mon.setBackgroundColor(colors.lightBlue)
  58.  --mon.setTextColor(colors.black)
  59.  --mon.write(pp_t.."%")
  60.  --mon.setBackgroundColor(colors.black)
  61. end
  62.  
  63. function writeMana(ys,data)
  64.  mon.setCursorPos(2,ys)
  65.  mon.clearLine()
  66.  mon.setTextColor(colors.white)
  67.  mon.write(data)
  68. end
  69.  
  70. -- Init Main Loop:
  71.  
  72. wrapPeriph()
  73. signal = false
  74.  
  75.  
  76.  
  77. -- Main Loop:
  78.  
  79. term.clear()
  80. sleep(2)
  81. term.clear()
  82.  
  83. while true do
  84.  sleep(0.5)
  85.  term.setCursorPos(1,3)
  86.  pl_t = 0
  87.  pm_t = 0
  88.  pn_t = 0
  89.  pp_t = 0
  90.  pb_t = false
  91.  ys = 4
  92.   for k,v in pairs(pool_list) do
  93.    p_name = k
  94.    p = pool_list[p_name]
  95.    pl = p["getMana"]()
  96.    pm = p["getMaxMana"]()
  97.    pn = p["getManaNeeded"]()
  98.    pb = p["isFull"]()
  99.    pp = math.floor((pl*100)/pm)
  100.    pl_t = pl_t+pl
  101.    pm_t = pm_t+pm
  102.    pn_t = pn_t+pn
  103.    str = string.format("%s: %s/%s [%s] - %s (%s)",p_name,pl,pm,pp,pn,pb)
  104.    term.clearLine()
  105.    print(str)
  106.     if have_monitor then
  107.      writeMana(ys,str)
  108.      ys = ys+1
  109.      last_ys = ys+1
  110.     end
  111.    sleep(0.5)
  112.     if not pb then
  113.      pb_t = false
  114.     else
  115.      pb_t = true
  116.     end
  117.   end
  118.  pp_t = math.floor((pl_t*100)/pm_t)
  119.  x,y = term.getCursorPos()
  120.  term.setCursorPos(1,y+1)
  121.  str_t = string.format("Total: %s/%s [%s] - %s (%s)",pl_t,pm_t,pp_t,pn_t,pb_t)
  122.  writeMana(last_ys,str_t)
  123.  print(str_t)
  124. --  if have_monitor then
  125. --   mon.setBackgroundColor(colors.black)
  126. --   drawMana()
  127. --  end
  128.   if pp_t <= mana_min then
  129.    signal = true
  130.   elseif pp_t == 100 then
  131.    signal = false
  132.   end
  133.  rs.setOutput(rs_side,signal)
  134. end
  135.  
Advertisement
Add Comment
Please, Sign In to add comment