Advertisement
Guest User

Untitled

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