Advertisement
Guest User

Untitled

a guest
May 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. local dn = 15
  2. local length, walk = ...
  3. local delay = 0.25
  4. if length == nil then
  5. print("No length argument was given")
  6. return false -- Closes Program
  7. end
  8.  
  9. if walk == 'true' then
  10. walk = true
  11. else
  12. walk = false
  13. end
  14.  
  15. X = 0
  16. Y = 0
  17. Z = 0
  18. O = 0
  19.  
  20. function left(q)
  21. if q == nil then q = 1 end
  22. for i=1,q do
  23. turtle.turnLeft()
  24. if O == 0 then
  25. O = 3
  26. else
  27. O = O - 1
  28. end
  29. end
  30. return true
  31. end
  32.  
  33. function right(q)
  34. if q == nil then q = 1 end
  35. for i=1,q do
  36. turtle.turnRight()
  37. if O == 3 then
  38. O = 0
  39. else
  40. O = O + 1
  41. end
  42. end
  43. return true
  44. end
  45.  
  46. function up(q)
  47. if q == nil then q = 1 end
  48. for i=1,q do
  49. while not turtle.up() do
  50. digUp()
  51. turtle.up()
  52. sleep(delay)
  53. end
  54. Y = Y + 1
  55. end
  56. return true
  57. end
  58.  
  59. function down(q)
  60. if q == nil then q = 1 end
  61. for i=1,q do
  62. while not turtle.down() do
  63. digDown()
  64. turtle.attackDown()
  65. sleep(delay)
  66. end
  67. Y = Y - 1
  68. end
  69. return true
  70. end
  71.  
  72. function forward(q)
  73. if q == nil then q = 1 end
  74. for i=1,q do
  75. while not turtle.forward() do
  76. turtle.dig()
  77. turtle.attack()
  78. sleep(delay)
  79. end
  80. if O == 0 then
  81. X = X + 1
  82. elseif O == 1 then
  83. Z = Z + 1
  84. elseif O == 2 then
  85. X = X - 1
  86. elseif O == 3 then
  87. Z = Z - 1
  88. end
  89. end
  90. return true
  91. end
  92.  
  93. function back()
  94. right()
  95. right()
  96. forward()
  97. left()
  98. left()
  99. return true
  100. end
  101.  
  102. function orient(arg1)
  103. while arg1 ~= O do
  104. right()
  105. end
  106. return true
  107. end
  108.  
  109. function dig()
  110. while turtle.detect() do
  111. turtle.dig()
  112. sleep(delay)
  113. end
  114. return true
  115. end
  116.  
  117. function digUp()
  118. while turtle.detectUp() do
  119. turtle.digUp()
  120. sleep(delay)
  121. end
  122. return true
  123. end
  124.  
  125. function digDown()
  126. while turtle.detectDown() do
  127. turtle.digDown()
  128. sleep(delay)
  129. end
  130. return true
  131. end
  132.  
  133. function go(lx,ly,lz)
  134. if X < lx then
  135. orient(0)
  136. for i=1,(lx-X) do
  137. forward()
  138. end
  139. end
  140.  
  141. if X > lx then
  142. orient(2)
  143. for i=1,X-lx do
  144. forward()
  145. end
  146. end
  147.  
  148. if Y < ly then
  149. for i=1,ly-Y do
  150. up()
  151. end
  152. end
  153.  
  154. if Y > ly then
  155. for i=1,Y-ly do
  156. down()
  157. end
  158. end
  159.  
  160. if Z < lz then
  161. orient(1)
  162. for i=1,lz-Z do
  163. forward()
  164. end
  165. end
  166.  
  167. if Z > lz then
  168. orient(3)
  169. for i=1,Z-lz do
  170. forward()
  171. end
  172. end
  173. end
  174.  
  175. function deposit()
  176. for i=1,16 do
  177. turtle.select(i)
  178. while turtle.drop() == false and turtle.getItemCount() ~= 0 do -- Waits until turtle can deposit item
  179. sleep(1)
  180. end
  181. turtle.drop()
  182. end
  183. turtle.select(1)
  184. return true
  185. end
  186.  
  187. function mine()
  188. dig()
  189. forward()
  190. digUp()
  191. digDown()
  192. up()
  193. left()
  194. dig()
  195. right(2)
  196. dig()
  197. down()
  198. dig()
  199. left(2)
  200. dig()
  201. down()
  202. dig()
  203. right(2)
  204. dig()
  205. left()
  206. up()
  207. end
  208.  
  209. function check()
  210. if turtle.getItemCount(15) == 0 then -- Checks second last slot. I'd like to leave 2 slots empty just to be safe
  211. return false
  212. else
  213. return true
  214. end
  215. end
  216.  
  217. function notify(include)
  218. if X % dn == 0 and X ~= 0 then
  219. print("The turtle has traveled "..X.."/"..length+include.." blocks so far")
  220. end
  221. return true
  222. end
  223.  
  224. local dni = 0
  225.  
  226. for i=1,length do
  227. mine()
  228. notify(dni) -- Notifies Distance
  229. if check() then -- Checks if turtle should deposit items
  230. local lx,ly,lz = X,Y,Z
  231. go(0,0,0)
  232. orient(2) -- Faces Chest
  233. deposit()
  234. orient(0)
  235. go(lx,ly,lz)
  236. end
  237. end
  238.  
  239. go(0,0,0)
  240. orient(2) -- Faces Chest
  241. deposit()
  242. orient(0)
  243. print("Finished!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement