Advertisement
Guest User

Untitled

a guest
May 21st, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. ---
  2. --- Created by deathsgun.
  3. --- DateTime: 2019-05-21 15:01
  4. ---
  5.  
  6. local length, height, width = ...
  7. local delay = 0.25
  8.  
  9. if length == nil or height == nil or width == nil then
  10. print("Usage: miner <length> <height> <width>")
  11. return false
  12. end
  13.  
  14. X = 0;
  15. Y = 0;
  16. Z = 0;
  17. ORIENTATION = 0;
  18.  
  19. function left()
  20. turtle.turnLeft()
  21. if ORIENTATION == 0 then
  22. ORIENTATION = 3
  23. else
  24. ORIENTATION = ORIENTATION - 1
  25. end
  26. end
  27.  
  28. function right()
  29. turtle.turnRight()
  30. if ORIENTATION == 3 then
  31. ORIENTATION = 0
  32. else
  33. ORIENTATION = ORIENTATION + 1
  34. end
  35. end
  36.  
  37. function up()
  38. while not turtle.up() do
  39. digUp()
  40. sleep(delay)
  41. end
  42. Y = Y + 1
  43. end
  44.  
  45. function down(q)
  46. if q == nil then
  47. q = 1
  48. end
  49. for _ = 1, q do
  50. while not turtle.down() do
  51. digDown()
  52. sleep(delay)
  53. end
  54. end
  55. Y = Y - q
  56. end
  57.  
  58. function forward(q)
  59. if q == nil then
  60. q = 1
  61. end
  62. for _ = 1, q do
  63. while not turtle.forward() do
  64. turtle.dig()
  65. turtle.attack()
  66. sleep(delay)
  67. end
  68. end
  69. if ORIENTATION == 0 then
  70. X = X + q
  71. elseif ORIENTATION == 1 then
  72. Z = Z + q
  73. elseif ORIENTATION == 2 then
  74. X = X - q
  75. elseif ORIENTATION == 3 then
  76. Z = Z - q
  77. end
  78. end
  79.  
  80. function orient(arg1)
  81. while arg1 ~= 0 do
  82. right()
  83. end
  84. end
  85.  
  86. function dig()
  87. while turtle.detect() do
  88. turtle.dig()
  89. sleep(delay)
  90. end
  91. end
  92.  
  93. function digUp()
  94. while turtle.detectUp() do
  95. turtle.digUp()
  96. sleep(delay)
  97. end
  98. end
  99.  
  100. function digDown()
  101. while turtle.detectDown() do
  102. turtle.digDown()
  103. sleep(delay)
  104. end
  105. end
  106.  
  107. function go(lx, ly, lz)
  108. print("going to " .. lx .. "/" .. ly .. "/" .. lz)
  109. if X < lx then
  110. orient(0)
  111. for _ = 1, (lx - X) do
  112. forward()
  113. end
  114. end
  115.  
  116. if X > lx then
  117. orient(2)
  118. for _ = 1, X - lx do
  119. forward()
  120. end
  121. end
  122.  
  123. if Y < ly then
  124. for _ = 1, ly - Y do
  125. up()
  126. end
  127. end
  128.  
  129. if Y > ly then
  130. for _ = 1, Y - ly do
  131. down()
  132. end
  133. end
  134.  
  135. if Z < lz then
  136. orient(1)
  137. for _ = 1, lz - Z do
  138. forward()
  139. end
  140. end
  141.  
  142. if Z > lz then
  143. orient(3)
  144. for _ = 1, Z - lz do
  145. forward()
  146. end
  147. end
  148. end
  149.  
  150. function deposit()
  151. for i = 2, 16 do
  152. turtle.select(i)
  153. while not turtle.drop() and turtle.getItemCount() ~= 0 do
  154. -- Waits until turtle can deposit item
  155. sleep(1)
  156. end
  157. turtle.drop()
  158. end
  159. turtle.select(1)
  160. return true
  161. end
  162.  
  163. function check()
  164. return turtle.getItemCount(15) == 0
  165. end
  166.  
  167. print("Creating a tunnel " .. height .. " x " .. width .. " " .. length .. " long!")
  168.  
  169. lx = X
  170. ly = Y
  171. lz = Z
  172. for _ = 1, length do
  173. lx = X
  174. ly = Y
  175. lz = Z
  176. for _ = 1, width do
  177. forward()
  178. for _ = 1, height do
  179. up()
  180. end
  181. down(height)
  182. if _ == 1 then
  183. right()
  184. elseif _ <= width then
  185. left()
  186. forward(width)
  187. end
  188. end
  189. go(lx, ly, lz)
  190. end
  191.  
  192. go(0, 0, 0)
  193. orient(2)
  194. deposit()
  195. orient(0)
  196. print("Finished task!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement