bigtwisty

MEDisposal

Jul 6th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. local name = "ME Disposal"
  2. local version = "1.0a"
  3.  
  4. local itemListFileName = "itemlist.txt"
  5. local itemList = {}
  6.  
  7. function resetBridge()
  8. print("Unable to access ME Bridge.")
  9. print("Sending reset command to turtle.")
  10. redstone.setBundledOutput("left",1)
  11. while not colors.test(redstone.getBundledInput("left"),2) do
  12. os.sleep(1)
  13. end
  14. redstone.setBundledOutput("left",0)
  15. end
  16.  
  17. local function doScreen(str)
  18. items = peripheral.call("bottom","listItems")
  19. while items == nil do
  20. resetBridge()
  21. os.sleep(1)
  22. items = peripheral.call("bottom","listItems")
  23. end
  24. term.clear()
  25. term.setCursorPos(1,1)
  26. print(name.." - ver "..version)
  27. print("------------------------------")
  28. print("Item | Max Qty | In ME")
  29. print("------------------------------")
  30.  
  31. for i=1,#itemList do
  32. t=itemList[i]
  33. write(t[1])
  34. write(string.rep(" ",9-string.len(t[1])))
  35. write("| "..t[3])
  36. write(string.rep(" ",8-string.len(t[3])))
  37. write("| ")
  38. local found = false
  39. for id,qty in pairs(items) do
  40. if id==tonumber(t[2]) then
  41. print(qty)
  42. if qty>tonumber(t[3]) then
  43. discard = qty - tonumber(t[3])
  44. if discard > tonumber(t[4]) then
  45. discard = tonumber(t[4])
  46. end
  47. peripheral.call("bottom","retrieve",id,discard,0)
  48. end
  49. found = true
  50. end
  51. end
  52. if not found then
  53. print(0)
  54. end
  55. end
  56. print("------------------------------")
  57. print(str)
  58. end
  59.  
  60. if not fs.exists(itemListFileName) then
  61. print("File ("..itemListFileName..") does not exist.")
  62. exit()
  63. end
  64.  
  65. handle = fs.open(itemListFileName, "r")
  66. if handle == nil then
  67. print("Failed to open ("..itemListFileName..").")
  68. exit()
  69. end
  70.  
  71. str = handle.readAll()
  72. for name,id,qty,stack in string.gmatch(str,"(%w+)|(%d+)|(%d+)|(%d+)") do
  73. table.insert(itemList,{name,id,qty,stack})
  74. end
  75. handle.close()
  76.  
  77. if #itemList == 0 then
  78. print(itemListFileName.." contains no readable data.")
  79. exit()
  80. end
  81.  
  82. while true do
  83. doScreen("")
  84. os.sleep(10)
  85. end
Advertisement
Add Comment
Please, Sign In to add comment