Advertisement
Guest User

Untitled

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