Advertisement
LoganRusinek

Untitled

Mar 28th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. local mineHeight = 0;
  2. local run = true;
  3. local currentRotation = 0
  4. local currentYPosition = 0
  5. local currentZPosition = 0
  6.  
  7. local oldYPosition = 0
  8. local oldZPosition = 0
  9. local oldRotation = 0
  10.  
  11.  
  12.  
  13. function turnLeft()
  14. currentRotation = currentRotation - 1;
  15. turtle.turnLeft()
  16. end
  17.  
  18.  
  19. function turnRight()
  20. currentRotation = currentRotation + 1;
  21. turtle.turnRight()
  22. end
  23.  
  24.  
  25. function dig()
  26. print("Digging! " .. " Y: " .. currentYPosition .. " Z: " .. currentZPosition .. " Rotation: " .. currentRotation)
  27. if turtle.getItemCount(16) == 0 then
  28. turtle.dig()
  29. else
  30. returnToHome()
  31. deposit()
  32. returnToOldPosition()
  33. end
  34. end
  35.  
  36.  
  37. function digUp()
  38. if turtle.getItemCount(16) == 0 then
  39. turtle.digUp()
  40. else
  41. returnToHome()
  42. deposit()
  43. returnToOldPosition()
  44. end
  45. end
  46.  
  47.  
  48. function digDown()
  49. if turtle.getItemCount(16) == 0 then
  50. turtle.digDown()
  51. else
  52. returnToHome()
  53. deposit()
  54. returnToOldPosition()
  55. end
  56. end
  57.  
  58.  
  59. function oddLevelDig()
  60. dig()
  61. turnRight()
  62. dig()
  63. turnRight()
  64. dig()
  65. end
  66.  
  67.  
  68. function evenLevelDig()
  69. dig()
  70. turnLeft()
  71. dig()
  72. turnLeft()
  73. dig()
  74. end
  75.  
  76.  
  77. function turnStraight()
  78. print("Turning straight")
  79. if currentRotation > 0 then
  80. repeat
  81. turnLeft()
  82. until currentRotation == 0
  83. else
  84. repeat
  85. turnRight()
  86. until currentRotation == 0
  87. end
  88. end
  89.  
  90.  
  91. function turnBackwards()
  92. print("Turning backwards")
  93. if currentRotation > 0 then
  94. repeat
  95. turnRight()
  96. until currentRotation == 2
  97. else
  98. repeat
  99. turnLeft()
  100. until currentRotation == -2
  101. end
  102. end
  103.  
  104.  
  105. function returnToHome()
  106. turnBackwards()
  107.  
  108. for i = 1, currentZPosition do
  109. turtle.forward()
  110. end
  111.  
  112. for i = 1, currentYPosition do
  113. turtle.down()
  114. end
  115. end
  116.  
  117.  
  118. function deposit()
  119. for i = 1, 16 do
  120. turtle.select(i)
  121. turtle.drop()
  122. end
  123. turtle.select(1)
  124. end
  125.  
  126.  
  127. function returnToOldPosition()
  128. turnStraight()
  129.  
  130. for i = 1, currentZPosition do
  131. turtle.forward()
  132. end
  133.  
  134. for i = 1, currentYPosition do
  135. turtle.up()
  136. end
  137. end
  138.  
  139.  
  140.  
  141. write("Mine Height: ")
  142. mineHeight = tonumber(read());
  143.  
  144. turtle.select(1)
  145. turtle.refuel()
  146.  
  147.  
  148.  
  149. while run do
  150. turnLeft()
  151.  
  152. for i = 1, mineHeight do
  153. print("Starting to mine at height: " .. i)
  154.  
  155. if i % 2 == 1 then
  156. oddLevelDig()
  157. else
  158. evenLevelDig()
  159. end
  160.  
  161. if i ~= mineHeight then
  162. digUp()
  163. turtle.up()
  164. currentYPosition = currentYPosition + 1
  165. end
  166. end
  167.  
  168. turnStraight()
  169. turtle.forward()
  170. currentZPosition = currentZPosition + 1
  171. turnLeft()
  172.  
  173. for i = mineHeight, 1, -1 do
  174. print("Starting to mine at height: " .. i)
  175.  
  176. if i % 2 == 1 then
  177. oddLevelDig()
  178. else
  179. evenLevelDig()
  180. end
  181.  
  182. if i ~= 1 then
  183. digDown()
  184. turtle.down()
  185. currentYPosition = currentYPosition - 1
  186. end
  187.  
  188. end
  189.  
  190. turnStraight()
  191. turtle.forward()
  192. currentZPosition = currentZPosition + 1
  193. end
  194.  
  195. --loadstring(http.get("https://pastebin.com/raw/f6CQKKwP").readAll())()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement