Advertisement
taoshi

In-game monitoring for flux network and AE2 power used and crafting Cpus.

Jun 12th, 2024 (edited)
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | None | 0 0
  1. --need border.lua library for work
  2. local keyboard=require('keyboard')
  3. local gpu=require('component').gpu
  4. local term=require('term')
  5. local event=require'event'
  6. local border=require('border')
  7. local c={
  8. green=0x00e000,
  9. light_gray=0x909090,
  10. gray=0x303030,
  11. red=0xe00000,
  12. purple=0xa000a0,
  13. black=0x0
  14. }
  15. local rx,ry=gpu.getResolution()
  16. gpu.setResolution (80,18)
  17.  
  18. function fl()
  19. local y_pos=2
  20. local flux_net = border.getDevice('flux')
  21.  
  22. local half=gpu.getResolution()/2
  23.  
  24.  if #flux_net > 0 then
  25.   local name='--FLUX NETWORKS--'
  26.   border.put(name,half-#name/2,y_pos,c.black,c.light_gray)
  27.   y_pos=y_pos+3
  28.     for f in pairs(flux_net) do
  29.       local name=flux_net[f].getNetworkInfo().name
  30.       local energy=flux_net[f].getEnergyInfo()
  31.       local input=" IN: "..border.energyTier(energy.energyInput).." "
  32.       local output=" OUT: "..border.energyTier(energy.energyOutput).." "
  33.       local x=half-(#name+#input+#output+2)/2
  34.  
  35.       border.put(name,x,y_pos,c.green,c.gray) x=x+#name+2
  36.       border.put (input,x,y_pos,c.green,c.gray) x=x+#input+2
  37.       border.put(output,x,y_pos,c.green,c.gray)--gpu.set(x,2,output)
  38.       y_pos=y_pos+3
  39.     end
  40.  end
  41.  
  42.  local me=border.getDevice('me_')
  43.  if #me > 0 then
  44.   me=me[1]
  45.   local power=' ME use: ' .. border.energyTier(me.getAvgPowerUsage()) .. ' '
  46.   local stored=' ME power stored: ' .. border.energyTier(me.getStoredPower()) .. ' '
  47.   stored=string.sub(stored,1,#stored-5)
  48.   local xl=half-#power/2-#stored/2
  49.   border.put(power,xl,y_pos,c.green,c.gray)
  50.   border.put(stored,xl+#power+2,y_pos,c.green,c.gray)
  51.   y_pos=y_pos+3
  52.  
  53.   name='--ME CPUS--'
  54.   border.put(name,half-#name/2,y_pos,c.black,c.light_gray)
  55.   y_pos=y_pos+3
  56.  
  57.   local cpus=me.getCpus()
  58.   local width=half/2-1 --сколько ЦПУ уместится в ряд минус края
  59.   local state=c.gray
  60.    
  61.   local cpuX = 0
  62.   for f in pairs(cpus) do
  63.     if cpuX == 0 then
  64.       if #cpus - f + 1 > width then-- за раз не влезет
  65.        cpuX = 1
  66.       else cpuX = width / 2 - (#cpus-f+1)/2 --неполный ряд
  67.       end
  68.     end
  69.    
  70.     state = cpus[f].busy and c.gray or c.green
  71.     border.put('  ',cpuX*4+2,y_pos,nil,state)
  72.     cpuX = cpuX + 1
  73.     if cpuX == width - 1 then
  74.       cpuX = 0 y_pos = y_pos + 3
  75.     end
  76.   end
  77.  
  78.   y_pos=y_pos+3
  79.  end
  80.  
  81. return true
  82. end
  83.  
  84. local monitoringID=event.timer(0.1,fl,math.huge)
  85. term.clear()
  86. while true do --absolutely nothing
  87.   event.pull(1)
  88.   if keyboard.isKeyDown(keyboard.keys.delete) then  
  89.     event.cancel(monitoringID)
  90.     monitoringID=nil
  91.     gpu.setResolution(rx,ry)
  92.     term.clear()
  93.     break
  94.   end
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement