Advertisement
Guest User

Untitled

a guest
May 21st, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 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()
  59. while not turtle.forward() do
  60. turtle.dig()
  61. turtle.attack()
  62. sleep(delay)
  63. end
  64. if ORIENTATION == 0 then
  65. X = X + 1
  66. elseif ORIENTATION == 1 then
  67. Z = Z + 1
  68. elseif ORIENTATION == 2 then
  69. X = X - 1
  70. elseif ORIENTATION == 3 then
  71. Z = Z - 1
  72. end
  73. end
  74.  
  75. function orient(arg1)
  76. while arg1 ~= 0 do
  77. right()
  78. end
  79. end
  80.  
  81. function dig()
  82. while turtle.detect() do
  83. turtle.dig()
  84. sleep(delay)
  85. end
  86. end
  87.  
  88. function digUp()
  89. while turtle.detectUp() do
  90. turtle.digUp()
  91. sleep(delay)
  92. end
  93. end
  94.  
  95. function digDown()
  96. while turtle.detectDown() do
  97. turtle.digDown()
  98. sleep(delay)
  99. end
  100. end
  101.  
  102. function go(lx, ly, lz)
  103. print("going to " .. lx .. "/" .. ly .. "/" .. lz)
  104. if X < lx then
  105. orient(0)
  106. for _ = 1, (lx - X) do
  107. forward()
  108. end
  109. end
  110.  
  111. if X > lx then
  112. orient(2)
  113. for _ = 1, X - lx do
  114. forward()
  115. end
  116. end
  117.  
  118. if Y < ly then
  119. for _ = 1, ly - Y do
  120. up()
  121. end
  122. end
  123.  
  124. if Y > ly then
  125. for _ = 1, Y - ly do
  126. down()
  127. end
  128. end
  129.  
  130. if Z < lz then
  131. orient(1)
  132. for _ = 1, lz - Z do
  133. forward()
  134. end
  135. end
  136.  
  137. if Z > lz then
  138. orient(3)
  139. for _ = 1, Z - lz do
  140. forward()
  141. end
  142. end
  143. end
  144.  
  145. function deposit()
  146. for i = 2, 16 do
  147. turtle.select(i)
  148. while not turtle.drop() and turtle.getItemCount() ~= 0 do
  149. -- Waits until turtle can deposit item
  150. sleep(1)
  151. end
  152. turtle.drop()
  153. end
  154. turtle.select(1)
  155. return true
  156. end
  157.  
  158. function check()
  159. return turtle.getItemCount(15) == 0
  160. end
  161.  
  162. print("Creating a tunnel " .. height .. " x " .. width .. " " .. length .. " long!")
  163.  
  164. lx = X
  165. ly = Y
  166. lz = Z
  167. for _ = 1, length do
  168. lx = X
  169. ly = Y
  170. lz = Z
  171. for _ = 1, width do
  172. forward()
  173. for _ = 1, height do
  174. up()
  175. end
  176. down(height)
  177. if _ == 1 then
  178. right()
  179. end
  180. end
  181. go(lx, ly, lz)
  182. end
  183.  
  184. go(0, 0, 0)
  185. orient(2)
  186. deposit()
  187. orient(0)
  188. print("Finished task!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement