Advertisement
HarvDad

collect

Mar 15th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. -- collect
  2. -- Collects specified blocks from chests left by 'branch' and 'bwb' programs
  3. -- Written by HarvDad, March 2014
  4.  
  5. args = {...}
  6. nArgs = #args
  7. usage = "Usage: collect"
  8.  
  9. print("collect: Rev 0.1")
  10.  
  11. loop = 0;
  12. x = 0
  13. y = 0
  14. z = 0
  15. face = 0
  16. patchSlot = 2
  17. minimumFuel = 100
  18. missionMessage = "Mission complete."
  19. abort = false
  20. local currentFuelLevel = turtle.getFuelLevel()
  21.  
  22. if (nArgs == 1 and args[1]== "help") then
  23. print("Collects specified blocks from in-ground chests")
  24. print(" as left by the 'branch' and 'bwb' programs.")
  25. print("Place fuel in slot 1")
  26. print("Place at least 1 block of target material in slot 2.")
  27. print("Turtle proceeds in straight line until it hits something")
  28. print(usage)
  29. return
  30. end
  31.  
  32. if nArgs ~= 0 then
  33. print(usage)
  34. return
  35. end
  36.  
  37. function suckChest()
  38. local i
  39.  
  40. turtle.select(3)
  41. for i=3,16 do
  42. turtle.suckDown()
  43. end
  44. end
  45.  
  46. targetSlot = 2
  47.  
  48. function gatherTargetMaterial()
  49. local i
  50.  
  51. for i=3,16 do
  52. turtle.select(i)
  53. if turtle.compareTo(targetSlot) then
  54. turtle.transferTo(targetSlot)
  55. end
  56. end
  57. end
  58.  
  59. function dumpRejects()
  60. local i
  61.  
  62. turtle.select(3)
  63. for i=3,16 do
  64. turtle.select(i)
  65. if not turtle.compareTo(targetSlot) then
  66. turtle.dropDown()
  67. end
  68. end
  69. end
  70.  
  71. function home()
  72. while z > 0 do
  73. turtle.back()
  74. end
  75. end
  76.  
  77. -- Main Program
  78.  
  79. for i=1,100 do
  80. turtle.select(3)
  81. if turtle.suckDown() then
  82. turtle.dropDown()
  83. suckChest()
  84. dumpRejects()
  85. gatherTargetMaterial()
  86. end
  87. if not turtle.forward() then
  88. break
  89. end
  90. z = z+1
  91. end
  92.  
  93. home()
  94. print(missionMessage, " Current fuel level is ", turtle.getFuelLevel())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement