unli

udig

Jul 21st, 2012
1,124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. -- change mx for width, my for length and mz for height, the turtle will dig down and to the right
  2. mx = 100
  3. my = 100
  4. mz = 18
  5. -- Don't change anything bellow this line
  6.  
  7. x = 1
  8. y = 1
  9. z = 1
  10.  
  11. cx = 1
  12. cy = 1
  13. cz = 1
  14.  
  15. posx = 1
  16. posy = 1
  17.  
  18. function f()
  19. if turtle.forward() == false then
  20. repeat
  21. turtle.dig()
  22. sleep(0.25)
  23. until turtle.forward() == true
  24. end
  25. end
  26.  
  27. function savepos()
  28. local f1=io.open("posx", "w")
  29. local f2=io.open("posy", "w")
  30. f1:write(cx)
  31. f2:write(cy)
  32. f1:close()
  33. f2:close()
  34. return true
  35. end
  36.  
  37. function loadpos()
  38. local f1 = io.open("posx", "r")
  39. local f2 = io.open("posy", "r")
  40. posx = tonumber(f1:read())
  41. posy = tonumber(f2:read())
  42. f1:close()
  43. f2:close()
  44. end
  45.  
  46. function d()
  47. if turtle.down() == false then
  48. repeat
  49. turtle.digDown()
  50. sleep(0.25)
  51. until turtle.down() == true
  52. end
  53. end
  54.  
  55. function u()
  56. if turtle.up() == false then
  57. repeat
  58. turtle.digUp()
  59. sleep(0.25)
  60. until turtle.up() == true
  61. end
  62. end
  63.  
  64. function check()
  65. for i = 1,15 do
  66. if turtle.getItemCount(i) == 0 then
  67. return true
  68. end
  69. end
  70. end
  71.  
  72. function dropall()
  73. for dropSlot = 1,16 do
  74. turtle.select(dropSlot)
  75. turtle.drop()
  76. end
  77. turtle.select(1)
  78. turtle.turnRight()
  79. turtle.turnRight()
  80. end
  81.  
  82. function down()
  83. while cz < mz do
  84. d()
  85. cz = cz+1
  86. end
  87. end
  88.  
  89. function up()
  90. while cz > z do
  91. u()
  92. cz = cz-1
  93. end
  94. end
  95.  
  96. function bdig()
  97. if cz == z and cx == x then
  98. goback()
  99. dropall()
  100. else
  101. up()
  102. goback()
  103. dropall()
  104. end
  105. end
  106.  
  107. function refuel()
  108.  
  109. end
  110.  
  111. function goback()
  112. print("y - ",posy)
  113. print("x - ",posx)
  114. turtle.turnLeft()
  115. while cx > x do
  116. f()
  117. cx = cx - 1
  118. end
  119. turtle.turnLeft()
  120. while cy > y do
  121. f()
  122. cy = cy - 1
  123. end
  124. end
  125.  
  126. function udig()
  127. while check() and cy < my do
  128. f()
  129. turtle.digUp()
  130. down()
  131. up()
  132. cy = cy+1
  133. savepos()
  134. end
  135. bdig()
  136. end
  137.  
  138. while true do
  139. loadpos()
  140. if posx == x and posy ~= my then
  141. while cy < posy do
  142. f()
  143. cy = cy + 1
  144. end
  145. udig()
  146. elseif posx < mx and posy == my then
  147. turtle.turnRight()
  148. while cx < posx + 1 do
  149. turtle.digUp()
  150. f()
  151. cx = cx + 1
  152. end
  153. turtle.turnLeft()
  154. udig()
  155. elseif posx < mx and posy ~= my then
  156. turtle.turnRight()
  157. while cx < posx do
  158. turtle.digUp()
  159. f()
  160. cx = cx + 1
  161. end
  162. turtle.turnLeft()
  163. while cy < posy do
  164. turtle.digUp()
  165. f()
  166. cy = cy + 1
  167. end
  168. udig()
  169. elseif posy == my and posx == mx then
  170. print("Complete")
  171. break
  172. end
  173. end
Advertisement
Add Comment
Please, Sign In to add comment