Advertisement
Guest User

Untitled

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