Advertisement
Guest User

PowerReserve

a guest
Nov 21st, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.88 KB | None | 0 0
  1. local upper = 0.90
  2. local lower = 0.10
  3.  
  4. isError=0
  5.  
  6. function detectDevice(DeviceName)
  7. DeviceSide="none"
  8. for k,v in pairs(redstone.getSides()) do
  9.   if peripheral.getType(v)==DeviceName then
  10.       DeviceSide = v
  11.       break
  12.   end
  13. end
  14.   return(DeviceSide)
  15. end
  16.  
  17. cell="none"
  18. monitor="none"
  19. local peripheralList = peripheral.getNames()
  20.  
  21. CellSide=detectDevice("cofh_thermalexpansion_energycell")
  22.  
  23. if CellSide=="none" then
  24.   cell=peripheral.wrap(CellSide)
  25.   print ("TE Energy Cell on the " .. CellSide .. " connected.")
  26.   else
  27.     CellSide=detectDevice("title_enderio_blockcapacitor_name")
  28.     if CellSide=="none" then
  29.       cell=peripheral.wrap(CellSide)
  30.       print ("EnderIO Capacitor Bank on the " .. CellSide .. " connected.")
  31.     else
  32.         for Index = 1, #peripheralList do
  33.           if string.find(peripheralList[Index], "cofh_thermalexpansion_energycell") then
  34.             cell=peripheral.wrap(peripheralList[Index])
  35.             print ("TE Energy Cell on wired modem: " ..peripheralList[Index].." connected.")
  36.           elseif string.find(peripheralList[Index], "tile_enderio_blockcapacitorbank_name") then
  37.             cell=peripheral.wrap(peripheral[Index])
  38.             print ("EnderIO Capacitor Bank on wired modem: "..peripheralList[Index].." connected.")
  39.           end
  40.         end
  41.         if cell == "none" then
  42.           print("No Energy storage found. Halting Program!")
  43.           return
  44.         end
  45.     end
  46. end
  47.  
  48. MonitorSide=detectDevice("monitor")
  49.  
  50. if MonitorSide~="none" then
  51.   monitor=peripheral.wrap(MonitorSide)
  52.   print ("Monitor found on the " .. MonitorSide .. " connected.")
  53.   else
  54.     for Index = 1, #peripheralList do
  55.       if string.find(peripheralList[Index], "monitor") then
  56.         monitor=peripheral.wrap(peripheralList[Index])
  57.         print ("Monitor found on the wired modem: "..peripheralList[Index].." connected.")
  58.       end
  59.     end
  60.     if monitor == "none" then
  61.       print ("Warning! - Monitor not found! Program is continuing!")
  62.    end
  63. end
  64.  
  65. redstone.setOutput("back", false)
  66.  
  67. if monitor ~= "none" then
  68.   monitor.clear()
  69.   monitor.setBackgroundColour((colours.grey))
  70.   monitor.setCursorPos(1,4)
  71.   monitor.write(" ON ")
  72.   monitor.setBackgroundColour((colours.green))
  73.   monitor.setCursorPos(5,4)
  74.   monitor.write(" OFF ")
  75.   monitor.setBackgroundColour((colours.black))
  76. end
  77.  
  78. while true do
  79.   eNow = cell.getEnergyStored("unknown")
  80.   eMax = cell.getMaxEnergyStored("unknown")
  81.  
  82.   fill = (eNow / eMax)
  83.  
  84. if monitor ~= "none" then
  85.   if eMax >= 10000000 then
  86.   monitor.setCursorPos(11,2)
  87.   monitor.write("Storage:")
  88.   monitor.setCursorPos(11,3)
  89.   monitor.write(math.ceil(eNow/1000).."kRF")
  90.   monitor.setCursorPos(11,4)
  91.   monitor.write("Of:")
  92.   monitor.setCursorPos(11,5)
  93.   monitor.write(math.ceil(eMax/1000).."kRF")
  94.   else
  95.   monitor.setCursorPos(11,2)
  96.   monitor.write("Storage:")
  97.   monitor.setCursorPos(11,3)
  98.   monitor.write(math.ceil(eNow))
  99.   monitor.setCursorPos(11,4)
  100.   monitor.write("Of:")
  101.   monitor.setCursorPos(11,5)
  102.   monitor.write(math.ceil(eMax))
  103.   end
  104.  
  105.   monitor.setSursorPos(1,2)
  106.   monitor.write("Engines:")
  107. end
  108.  
  109.   if fill > upper then
  110.     redstone.setOutput("back", false)
  111.  
  112.     if monitor ~= "none" then
  113.       monitor.setBackgroundColour((colours.grey))
  114.       monitor.setCursorPos(1,4)
  115.       monitor.write(" ON ")
  116.       monitor.setBackgroundColour((colours.green))
  117.       monitor.setCursorPos(5,4)
  118.       monitor.write(" OFF ")
  119.       monitor.setBackgroundColour((colours.black))
  120.     end
  121.  
  122.   elseif fill < lower then
  123.     redstone.setOutput("back", true)
  124.    
  125.     if monitor ~= "none" then
  126.       monitor.setBackgroundColour((colours.green))
  127.       monitor.setCursorPos(1,4)
  128.       monitor.write(" ON ")
  129.       monitor.setBackgroundColour((colours.grey))
  130.       monitor.setCursorPos(5,4)
  131.       monitor.write(" OFF ")
  132.       monitor.setBackgroundColour((colours.black))
  133.     end
  134.    
  135.   end
  136.  
  137.   sleep(1)
  138.  
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement