bigtwisty

BatteryManager

Apr 17th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. --name BatteryManager
  2. --version 1.0a
  3. local version = "1.0a"
  4.  
  5. local side = {}
  6. side.batbox = 0
  7. side.chest = 4
  8. side.output = 1
  9. local batteryId = {}
  10. batteryId.full = 38041
  11. batteryId.empty = 5272
  12.  
  13. local inventory = {}
  14. inventory.batbox = "Empty"
  15. inventory.chest = false
  16. inventory.chestFull = 0
  17. inventory.chestEmpty = 0
  18. inventory.output = "Not found..."
  19.  
  20. local function output(str)
  21. term.clear()
  22. term.setCursorPos(1,1)
  23. print(string.format("BattMgr (v%s)",version))
  24. print("By BigTwisty")
  25. print(str)
  26. end
  27.  
  28. local sorter = peripheral.wrap("back")
  29.  
  30. local monitor = peripheral.wrap("bottom")
  31. term.redirect(monitor)
  32. monitor.setTextScale(0.5)
  33.  
  34. while true do
  35. inventory.batbox = "Not Found..."
  36. x = sorter.list(side.batbox)
  37. if x ~= nil then
  38. inventory.batbox = "Empty"
  39. for id,qty in pairs(x) do
  40. if id == batteryId.full then
  41. inventory.batbox = "Full"
  42. else
  43. inventory.batbox = "Charging"
  44. end
  45. end
  46. end
  47.  
  48. inventory.chestFull = 0
  49. inventory.chestEmpty = 0
  50. inventory.chestOther = 0
  51.  
  52. x = sorter.list(side.chest)
  53. if x == nil then
  54. inventory.chest = false
  55. else
  56. inventory.chest = true
  57. for id,qty in pairs(x) do
  58. if id == batteryId.full then
  59. inventory.chestFull = inventory.chestFull + qty
  60. elseif id == batteryId.empty then
  61. inventory.chestEmpty = inventory.chestEmpty + qty
  62. end
  63. end
  64. end
  65.  
  66. x = sorter.list(side.output)
  67. if x == nil then
  68. inventory.output = "Not found..."
  69. else
  70. inventory.output = "Ready"
  71. for id,qty in pairs(x) do
  72. if id == batteryId.full then
  73. inventory.output = "Full"
  74. end
  75. end
  76. end
  77.  
  78. output(string.format("\n-- Status:\nBatbox: %s\nOutput: %s",
  79. inventory.batbox,
  80. inventory.output))
  81. write(string.format("-- Inventory:\nCharged: %d\nEmpty: %d\n",
  82. inventory.chestFull,
  83. inventory.chestEmpty))
  84.  
  85. if (inventory.batbox == "Full") and (inventory.output == "Ready") then
  86. sorter.extract(side.batbox, batteryId.full, side.output, 1)
  87. elseif inventory.batbox == "Empty" then
  88. sorter.extract(side.chest, batteryId.empty, side.batbox, 1)
  89. end
  90.  
  91. os.sleep(0.3)
  92.  
  93. end
Advertisement
Add Comment
Please, Sign In to add comment