Advertisement
M2key1

sdf

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