Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. function modrefuel()
  2. for i = 1, 16 do
  3. turtle.select(i)
  4. if turtle.refuel(0) then
  5. print("Slot "..i.." is valid fuel.")
  6. turtle.refuel()
  7. end
  8. end
  9. turtle.select(1)
  10. end
  11.  
  12. function digLine(length)
  13. local backCheck = false
  14. local forwardCheck = false
  15. for i = 2, length do
  16. while (forwardCheck == false) do
  17. turtle.dig()
  18. forwardCheck = turtle.forward()
  19. end
  20. forwardCheck = false
  21. end
  22. for i = 2, length do
  23. while (backCheck == false) do
  24. backCheck = turtle.back()
  25. end
  26. backCheck = false
  27. end
  28. end
  29.  
  30. function digSquare(width, height)
  31. local upCheck = false
  32. local downCheck = false
  33. digLine(width)
  34. for i = 2, height do
  35. while (upCheck == false) do
  36. turtle.digUp()
  37. upCheck = turtle.up()
  38. end
  39. upCheck = false
  40. digLine(width)
  41. end
  42. for i = 2, height do
  43. while (downCheck == false) do
  44. turtle.digDown()
  45. downCheck = turtle.down()
  46. end
  47. downCheck = false
  48. end
  49. end
  50.  
  51. function digCube(depth, width, height)
  52. local forwardCheck = false
  53. for i = 1, depth do
  54. while (forwardCheck == false) do
  55. print("Digging forward!")
  56. turtle.dig()
  57. forwardCheck = turtle.forward()
  58. end
  59. forwardCheck = false
  60. turtle.turnRight()
  61. digSquare(width, height)
  62. turtle.turnLeft()
  63. end
  64. for i = 1, depth do
  65. while (backCheck == false) do
  66. backCheck = turtle.back()
  67. end
  68. backCheck = false
  69. end
  70. end
  71.  
  72. function mine(depth, height, width, chestX, chestY, chestZ)
  73. local backCheck = false
  74. local downCheck = false
  75. local forwardCheck = false
  76. local upCheck = false
  77. for i = 1, depth do
  78. print("Digging forward!")
  79. turtle.dig()
  80. while (forwardCheck == false) do
  81. turtle.dig()
  82. forwardCheck = turtle.forward()
  83. end
  84. forwardCheck = false
  85. turtle.turnRight()
  86. for i = 1, width do
  87. turtle.dig()
  88. while (forwardCheck == false) do
  89. turtle.dig()
  90. forwardCheck = turtle.forward()
  91. end
  92. forwardCheck = false
  93. end
  94. for i = 1, width do
  95. while (backCheck == false) do
  96. backCheck = turtle.back()
  97. end
  98. backCheck = false
  99. end
  100. turtle.turnLeft()
  101. for i = 1, height do
  102. print("Digging up!")
  103. turtle.digUp()
  104. while (upCheck == false) do
  105. turtle.digUp()
  106. upCheck = turtle.up()
  107. end
  108. upCheck = false
  109. print("Turning right!")
  110. turtle.turnRight()
  111. for i = 1, width do
  112. print("Digging wide, right!")
  113. turtle.dig()
  114. while (forwardCheck == false) do
  115. turtle.dig()
  116. forwardCheck = turtle.forward()
  117. end
  118. forwardCheck = false
  119. end
  120. for i = 1, width do
  121. print("Heading back!")
  122. while (backCheck == false) do
  123. backCheck = turtle.back()
  124. end
  125. backCheck = false
  126. end
  127. print("Turning left!")
  128. turtle.turnLeft()
  129. end
  130. for i = 1, height do
  131. print("Heading down!")
  132. while (downCheck == false) do
  133. turtle.digDown()
  134. downCheck = turtle.down()
  135. end
  136. downCheck = false
  137. end
  138. print("Checking for fuel...")
  139. modrefuel()
  140. print("Checking inventory full...")
  141. fullCheck(chestX, chestY, chestZ)
  142. end
  143. end
  144.  
  145. function dropOff(chestX, chestY, chestZ)
  146. local chestCheck = false
  147.  
  148. print("Inventory full, dropping off!")
  149. local turtleX, turtleY, turtleZ = gps.locate()
  150. if (turtleX == nil) or (turtleY == nil) or (turtleZ == nil) then
  151. print("GPS not functioning or out of range")
  152. end
  153. print("I am at (" ..turtleX.. ", " ..turtleY.. ", " ..turtleZ.. ")")
  154. shell.run("goto", chestX, chestZ, chestY)
  155. for i = 1, 16 do
  156. turtle.select(i)
  157. while (chestCheck == false) do
  158. chestCheck = turtle.dropDown()
  159. if (chestCheck == false) then
  160. print("Chest is full!")
  161. sleep(10)
  162. end
  163. end
  164. chestCheck = false
  165. end
  166. turtle.select(1)
  167. shell.run("goto", turtleX, turtleZ, turtleY)
  168. end
  169.  
  170. function fullCheck(chestX, chestY, chestZ)
  171. if turtle.getItemCount(16) > 0 then
  172. dropOff(chestX, chestY, chestZ)
  173. end
  174. end
  175.  
  176. local chestCheck
  177. local chestX
  178. local chestY
  179. local chestZ
  180. local turtleX
  181. local turtleY
  182. local turtleZ
  183. local digDepth
  184. local digHeight
  185. local digWidth
  186.  
  187. print("Input chest coordinates\n")
  188. print("X: ")
  189. chestX = io.read()
  190. print("\nZ: ")
  191. chestZ = io.read()
  192. print("\nY: ")
  193. chestY = io.read()
  194. print(chestX, chestY, chestZ)
  195. print("Input digging dimensions\n")
  196. print("Depth: ")
  197. digDepth = io.read()
  198. print("\nHeight: ")
  199. digHeight = io.read()
  200. print("\nWidth: ")
  201. digWidth = io.read()
  202. print(digDepth, digHeight, digWidth)
  203. print("Running mining protocol")
  204. digCube(tonumber(digDepth), tonumber(digWidth), tonumber(digHeight))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement