jseely

miningTurtle

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