jseely

miningTurtle

Nov 15th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. local lastCleared = "back"
  2.  
  3. function clearCube(X, Y, Z, vertDir, horDir)
  4. vertDir = vertDir or "down"
  5. horDir = horDir or "right"
  6. turtle.select(16)
  7. for y = 1, Y, 1 do
  8. for x = 1, X, 1 do
  9. for z = 1, Z - 1, 1 do
  10. forward()
  11. invFull()
  12. end
  13. turn(horDir)
  14. if not (x == X) then
  15. forward()
  16. end
  17. turn(horDir)
  18. if not (x == X) then
  19. horDir = swapRowDir(horDir)
  20. end
  21. end
  22. if vertDir == "up" then
  23. up()
  24. elseif vertDir == "down" then
  25. down()
  26. end
  27. invFull()
  28. end
  29. end
  30.  
  31. function invFull(placeChestDir, excludeSlots)
  32. placeChestDir = placeChestDir or lastCleared
  33. excludeSlots = excludeSlots or 1
  34. if turtle.getItemCount(16 - excludeSlots) > 0 then
  35. if placeChestDir == "back" then
  36. turn("right", 2)
  37. dropAll("front", 1, 16 - excludeSlots)
  38. turn("right", 2)
  39. elseif placeChestDir == "top" then
  40. dropAll("top", 1, 16 - excludeSlots)
  41. elseif placeChestDir == "bottom" then
  42. dropAll("bottom", 1, 16 - excludeSlots)
  43. elseif placeChestDir == "front" then
  44. dropAll("front", 1, 16 - excludeSlots)
  45. elseif placeChestDir == "right" then
  46. turn("right")
  47. dropAll("front", 1, 16 - excludeSlots)
  48. turn("left")
  49. elseif placeChestDir == "left" then
  50. turn("left")
  51. dropAll("front", 1, 16 - excludeSlots)
  52. turn("right")
  53. end
  54. end
  55. end
  56.  
  57. function dropAll(dir, startSlot, endSlot)
  58. dir = dir or "front"
  59. startSlot = startSlot or 1
  60. endSlot = endSlot or 16
  61.  
  62. turtle.select(16)
  63. if dir == "front" then
  64. turtle.place()
  65. elseif dir == "top" then
  66. turtle.placeUp()
  67. elseif dir == "bottom" then
  68. turtle.placeDown()
  69. end
  70.  
  71. for i = startSlot, endSlot, 1 do
  72. local drop = true
  73. turtle.select(i)
  74. for j = endSlot + 1, 16, 1 do
  75. if turtle.compareTo(j) then
  76. drop = false
  77. break
  78. end
  79. end
  80. if drop then
  81. if dir == "front" then
  82. turtle.drop()
  83. elseif dir == "top" then
  84. turtle.dropUp()
  85. elseif dir == "bottom" then
  86. turtle.dropDown()
  87. end
  88. end
  89. end
  90.  
  91. turtle.select(16)
  92. if dir == "front" then
  93. turtle.dig()
  94. elseif dir == "top" then
  95. turtle.digUp()
  96. elseif dir == "bottom" then
  97. turtle.digDown()
  98. end
  99. end
  100.  
  101. function dig()
  102. while turtle.detect() do
  103. turtle.dig()
  104. end
  105. end
  106.  
  107. function digUp()
  108. while turtle.detectUp() do
  109. turtle.digUp()
  110. end
  111. end
  112.  
  113. function digDown()
  114. while turtle.detectDown() do
  115. turtle.digDown()
  116. end
  117. end
  118.  
  119. function forward(times)
  120. times = times or 1
  121. for i = 1, times, 1 do
  122. local done = false
  123. while not done do
  124. dig()
  125. done = turtle.forward()
  126. end
  127. end
  128. lastCleared = "back"
  129. end
  130.  
  131. function up(times)
  132. times = times or 1
  133. for i = 1, times, 1 do
  134. done = false
  135. while not done do
  136. digUp()
  137. done = turtle.up()
  138. end
  139. end
  140. lastCleared = "bottom"
  141. end
  142.  
  143. function down(times)
  144. times = times or 1
  145. for i = 1, times, 1 do
  146. done = false
  147. while not done do
  148. digDown()
  149. done = turtle.down()
  150. end
  151. end
  152. lastCleared = "top"
  153. end
Advertisement
Add Comment
Please, Sign In to add comment