Advertisement
Guest User

Untitled

a guest
Jun 24th, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local bridge = peripheral.wrap("bottom")
  2. local net = peripheral.wrap("right")
  3.  
  4. bridge.sync()
  5.  
  6. bridge.clear()
  7.  
  8. local width = 100
  9.  
  10. local storageUnits = {
  11.    {
  12.          ["id"] = "tile_thermalexpansion_cell_resonant_name_0",
  13.          ["name"] = "Main"
  14.    },
  15.    
  16.  
  17. }
  18.  
  19. local offset = 0
  20. for key, storageUnit in pairs(storageUnits) do
  21.   if net.getTypeRemote(storageUnit["id"]) == "tile_thermalexpansion_cell_resonant_name_0" then
  22.    pxOffset = offset * 20
  23.    storageUnit["label"] = bridge.addText(4, 4 + pxOffset, storageUnit["name"], 0xffffff)
  24.    storageUnit["bar"] = bridge.addBox(4, 14 + pxOffset, 0, 5, 0xCC0000, 0.9)
  25.    storageUnit["bar"].setZ(2)
  26.    storageUnit["bg"] = bridge.addBox(4, 14 + pxOffset, width, 5, 0x000000, 0.5)
  27.    storageUnit["num"] = bridge.addText(4, 24 + pxOffset, "0/0", 0xffffff)
  28.    storageUnit["percent"] = bridge.addText(0 + bridge.getStringWidth(storageUnit["name"]), 4 + pxOffset, "##%", 0xffffff)
  29.    offset = offset + 2
  30.   end
  31. end
  32.  
  33. while true do
  34.   for i=#storageUnits,1,-1 do
  35.         storageUnit = storageUnits[i]
  36.         if net.isPresentRemote(storageUnit["id"]) then
  37.           if net.getTypeRemote(storageUnit["id"]) == "tile_thermalexpansion_cell_resonant_name_0" then
  38.             t = peripheral.wrap(storageUnit["id"])
  39.             capacity = t.getMaxEnergyStored("")
  40.             amount = t.getEnergyStored("")
  41.             storageUnit["bar"].setWidth(width / capacity * amount)
  42.             perc = math.floor(amount/capacity * 100)
  43.             tCap = tostring(capacity)
  44.             tAmt = tostring(amount)
  45.             tPerc = tostring(perc)
  46.             storageUnit["num"].setText(tAmt.."/"..tCap)
  47.             storageUnit["percent"].setText(tPerc.."%")
  48.           elseif net.getTypeRemote(storageUnit["id"]) == "harvester" or net.getTypeRemote(storageUnit["id"]) == "planter" then
  49.             t = peripheral.wrap(storageUnit["id"])
  50.                 running = t.isActive()
  51.                   if running == true then
  52.                     storageUnit["run"].setText("Running")
  53.               storageUnit["run"].setColor(0x33cc33)
  54.               --storageUnit["label"].setText(storageUnit["name"]..": Running")
  55.    
  56.                   else
  57.                     storageUnit["run"].setText("Not Running")
  58.               storageUnit["run"].setColor(0xff0000)
  59.                     --storageUnit["label"].setText(storageUnit["name"]..": Not Running")
  60.             end
  61.             end
  62.         else
  63.          if net.getTypeRemote(storageUnit["id"]) == "tile_thermalexpansion_cell_resonant_name_0" then
  64.               storageUnit["bar"].delete()
  65.           storageUnit["bg"].delete()
  66.           storageUnit["label"].delete()
  67.           storageUnit["num"].delete()
  68.           storageUnit["percent"].delte()
  69.               table.remove(storageUnits, i)
  70.          
  71.               storageUnit["label"].delete()
  72.               storageUnit["run"].delete()
  73.               table.remove(storageUnits, i)
  74.              end
  75.         end
  76.   end
  77.   sleep(0.5)
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement