Advertisement
HarvDad

bore

Oct 2nd, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. length = 0
  2. materialSlot = 1
  3. allOut = false
  4.  
  5. function forward()
  6. for i=1,20 do
  7. if turtle.detect() then
  8. turtle.dig()
  9. else
  10. break
  11. end
  12. end
  13.  
  14. for i=1,20 do
  15. if not turtle.forward() then
  16. turtle.dig()
  17. sleep(2)
  18. else
  19. break
  20. end
  21. end
  22. end
  23.  
  24. function up()
  25. digUp()
  26. turtle.up()
  27. end
  28.  
  29. function down()
  30. digDown()
  31. turtle.down()
  32. end
  33.  
  34. function digUp()
  35. for i=1,20 do
  36. if turtle.detectUp() then
  37. turtle.digUp()
  38. else
  39. break
  40. end
  41. end
  42. end
  43.  
  44. function digDown()
  45. if turtle.detectDown() then
  46. turtle.digDown()
  47. end
  48. end
  49.  
  50. function ensureMaterial()
  51. if allOut then
  52. return false
  53. end
  54.  
  55. if turtle.getItemCount(materialSlot) < 3 then
  56. organizeMaterial()
  57. end
  58. if turtle.getItemCount(materialSlot) < 3 then
  59. print("No more material")
  60. allOut = true
  61. return false
  62. end
  63. return true
  64. end
  65.  
  66. function organizeMaterial()
  67. local i
  68. materialCount = turtle.getItemCount(materialSlot)
  69.  
  70. if materialCount < 3 then
  71. -- print("Attempting to refill slot ", materialSlot)
  72. for i=2,16 do
  73. turtle.select(i)
  74. if turtle.compareTo(materialSlot) then
  75. turtle.transferTo(materialSlot)
  76. end
  77. end
  78. end
  79. turtle.select(materialSlot)
  80. end
  81.  
  82. function bore(len)
  83. for i=1,len do
  84. forward()
  85. digUp()
  86. digDown()
  87. end
  88. end
  89.  
  90. function boreUpper(len)
  91. for i=1,len do
  92. forward()
  93. digUp()
  94. digDown()
  95. placeBlockUp()
  96. end
  97. end
  98.  
  99. function boreLower(len)
  100. for i=1,len do
  101. digDown()
  102. placeBlockDown()
  103. forward()
  104. end
  105. end
  106.  
  107. function placeBlock()
  108. if ensureMaterial() then
  109. turtle.select(materialSlot)
  110. turtle.place()
  111. end
  112. end
  113.  
  114. function placeBlockUp()
  115. if ensureMaterial() then
  116. turtle.select(materialSlot)
  117. turtle.placeUp()
  118. end
  119. end
  120.  
  121. function placeBlockDown()
  122. if ensureMaterial() then
  123. turtle.select(materialSlot)
  124. turtle.placeDown()
  125. end
  126. end
  127.  
  128.  
  129. function sideWall()
  130. for i=1,length do
  131. placeBlockUp()
  132. placeBlockDown()
  133. turtle.back()
  134. placeBlock()
  135. end
  136. end
  137.  
  138. args = {...}
  139. nArgs = #args
  140.  
  141. if nArgs ~= 1 then
  142. print("Usage: bore <length>")
  143. return
  144. end
  145.  
  146. length = tonumber(args[1])
  147. if length == nil then
  148. print("\"", args[1], "\" is not a valid length") return
  149. end
  150.  
  151. digUp()
  152. turtle.up()
  153. bore(length) -- Right-hand wall
  154. sideWall()
  155.  
  156. turtle.turnLeft()
  157. forward()
  158. turtle.turnRight()
  159. up()
  160. boreUpper(length)
  161.  
  162. turtle.turnLeft()
  163. turtle.turnLeft()
  164. down()
  165. down()
  166. boreLower(length)
  167.  
  168. turtle.turnRight()
  169. forward()
  170. turtle.turnRight()
  171. forward()
  172. boreLower(length)
  173.  
  174. turtle.turnLeft()
  175. turtle.turnLeft()
  176. up()
  177. up()
  178. boreUpper(length)
  179.  
  180. forward()
  181. turtle.turnRight()
  182. forward()
  183. turtle.turnRight()
  184. boreUpper(length)
  185.  
  186. turtle.turnLeft()
  187. turtle.turnLeft()
  188. down()
  189. down()
  190. boreLower(length)
  191.  
  192. turtle.turnRight()
  193. forward()
  194. turtle.turnRight()
  195. up()
  196. bore(length)
  197. sideWall()
  198.  
  199. --[[
  200. forward()
  201. turtle.turnLeft()
  202. bore(length)
  203. sideWall()
  204. --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement