Advertisement
Guest User

test

a guest
Nov 26th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.70 KB | None | 0 0
  1. local cells = peripheral.getNames()
  2. local totalEnergyStored = 0
  3. local maxCapacity = 0
  4. local totalEnergyCells = 0
  5. local lowEnergyCells = 0
  6. local highEnergyCells = 0
  7.  
  8. function reset()
  9.   totalEnergyStored = 0
  10.   maxCapacity = 0
  11.   totalEnergyCells = 0
  12.   lowEnergyCells = 0
  13.   highEnergyCells = 0
  14. end
  15.  
  16. function comma(v)
  17.   local s = string.format("%d", math.floor(v))
  18.   local pos = string.len(s) % 3
  19.   if pos == 0 then pos = 3 end
  20.   return string.sub(s, 1, pos)
  21.   .. string.gsub(string.sub(s, pos + 1), "(...)", ",%1")
  22. end
  23.  
  24. function readEnergyCells()
  25.   for i,j in ipairs(cells) do
  26.     if peripheral.getType(j) == "cofh_thermalexpansion_energycell" then
  27.       energyStored = peripheral.call(j, "getEnergyStored", "unknown")
  28.       energyMax = peripheral.call(j, "getMaxEnergyStored", "unknown")
  29.       if energyStored < 10000000 then
  30.         lowEnergyCells = lowEnergyCells + 1
  31.       elseif energyStored > 40000000 then
  32.         highEnergyCells = highEnergyCells + 1
  33.       end
  34.       totalEnergyCells = totalEnergyCells + 1
  35.       totalEnergyStored = totalEnergyStored + energyStored
  36.       maxCapacity = maxCapacity + energyMax
  37.     end
  38.   end
  39. end
  40.  
  41. function chargeEnergyCells()
  42.  
  43. end
  44.  
  45. function printEnergyCells()
  46.   print("Total Number of Enery Cells: "..totalEnergyCells)
  47.   print("Low Energy Cells: "..lowEnergyCells)
  48.   print("Total Energy Stored: "..comma(totalEnergyStored))
  49.   print("Maximum Capacity: "..comma(maxCapacity))
  50. end
  51.  
  52. while true do
  53.   readEnergyCells()
  54.   printEnergyCells()
  55.   if lowEnergyCells >= totalEnergyCells - 1 then
  56.     redstone.setOutput("back", true)
  57.   elseif highEnergyCells == totalEnergyCells then
  58.     redstone.setOutput("back", false)
  59.   end
  60.   reset()
  61.   sleep(1)
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement