Advertisement
SryNotToxic

Untitled

Sep 25th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.85 KB | None | 0 0
  1. -- Configuration
  2. local refuelLevel = 20 -- Minimum fuel level before refueling
  3. local fuelSlot = 16 -- Slot where fuel (coal) is stored
  4. local tunnelLength = 10 -- Length of the tunnel
  5. local startYLevel = 70 -- Starting Y level
  6. local targetYLevel = 12 -- Target Y level (Y=12)
  7.  
  8. -- Movement tracking (stack-based approach)
  9. local movementLog = {} -- Stack to store movements for backtracking
  10. local minedOres = {} -- List to track mined ore coordinates to prevent infinite loops
  11. local currentY = startYLevel -- Track Y level manually
  12.  
  13. -- List of valuables (all ores) to detect in Minecraft 1.7.10
  14. local valuables = {
  15. "minecraft:iron_ore",
  16. "minecraft:coal_ore",
  17. "minecraft:gold_ore",
  18. "minecraft:diamond_ore",
  19. "minecraft:redstone_ore",
  20. "minecraft:emerald_ore",
  21. "minecraft:lapis_ore",
  22. "minecraft:quartz_ore"
  23. }
  24.  
  25. -- Function to refuel the turtle
  26. function refuel()
  27. if turtle.getFuelLevel() < refuelLevel then
  28. turtle.select(fuelSlot)
  29. if turtle.refuel(1) then
  30. print("Turtle refueled.")
  31. else
  32. print("No fuel available!")
  33. end
  34. end
  35. end
  36.  
  37. -- Function to move forward with tracking
  38. function moveForward()
  39. turtle.dig() -- Dig if there's a block in front
  40. turtle.forward()
  41. table.insert(movementLog, "forward") -- Track movement
  42. end
  43.  
  44. -- Function to move down with tracking, stops at Y=12
  45. function moveDown()
  46. if currentY > targetYLevel then
  47. turtle.digDown() -- Dig if there's a block below
  48. turtle.down() -- Move down
  49. currentY = currentY - 1 -- Update Y level manually
  50. table.insert(movementLog, "down") -- Track movement
  51. else
  52. print("Reached target Y-level: " .. targetYLevel)
  53. end
  54. end
  55.  
  56. -- Function to move up with tracking
  57. function moveUp()
  58. turtle.up()
  59. currentY = currentY + 1 -- Update Y level manually
  60. table.insert(movementLog, "up") -- Track movement
  61. end
  62.  
  63. -- Function to move back with tracking
  64. function moveBackward()
  65. turtle.back()
  66. table.insert(movementLog, "backward") -- Track movement
  67. end
  68.  
  69. -- Function to move left or right with tracking
  70. function turnAndMove(direction)
  71. if direction == "left" then
  72. turtle.turnLeft()
  73. moveForward()
  74. turtle.turnRight()
  75. elseif direction == "right" then
  76. turtle.turnRight()
  77. moveForward()
  78. turtle.turnLeft()
  79. end
  80. end
  81.  
  82. -- Function to check if a block is valuable
  83. function isValuable(blockName)
  84. for _, valuable in ipairs(valuables) do
  85. if blockName == valuable then
  86. return true
  87. end
  88. end
  89. return false
  90. end
  91.  
  92. -- Function to track mined ore locations to prevent looping
  93. function isAlreadyMined(x, y, z)
  94. local key = x .. "," .. y .. "," .. z
  95. return minedOres[key] ~= nil
  96. end
  97.  
  98. function markOreMined(x, y, z)
  99. local key = x .. "," .. y .. "," .. z
  100. minedOres[key] = true
  101. end
  102.  
  103. -- Recursive function to mine an entire vein of ore
  104. function mineVein()
  105. local directions = { "forward", "up", "down", "left", "right", "back" }
  106.  
  107. -- Recursively mine all connected ore blocks
  108. for _, direction in ipairs(directions) do
  109. local success, block
  110. if direction == "forward" then
  111. success, block = turtle.inspect()
  112. elseif direction == "up" then
  113. success, block = turtle.inspectUp()
  114. elseif direction == "down" then
  115. success, block = turtle.inspectDown()
  116. elseif direction == "left" then
  117. turtle.turnLeft()
  118. success, block = turtle.inspect()
  119. turtle.turnRight()
  120. elseif direction == "right" then
  121. turtle.turnRight()
  122. success, block = turtle.inspect()
  123. turtle.turnLeft()
  124. elseif direction == "back" then
  125. turtle.turnRight()
  126. turtle.turnRight()
  127. success, block = turtle.inspect()
  128. turtle.turnRight()
  129. turtle.turnRight()
  130. end
  131.  
  132. if success and isValuable(block.name) then
  133. -- Mark this ore as mined
  134. local x, y, z = gps.locate() -- Assumes GPS is available, or simulate coordinate tracking manually
  135. if not isAlreadyMined(x, y, z) then
  136. markOreMined(x, y, z)
  137.  
  138. -- Move toward the ore and mine it
  139. if direction == "forward" then
  140. moveForward()
  141. elseif direction == "up" then
  142. moveUp()
  143. elseif direction == "down" then
  144. moveDown()
  145. elseif direction == "left" then
  146. turnAndMove("left")
  147. elseif direction == "right" then
  148. turnAndMove("right")
  149. elseif direction == "back" then
  150. moveBackward()
  151. end
  152.  
  153. -- Recursively continue mining the connected vein
  154. mineVein()
  155.  
  156. -- After mining the vein, return to the original position
  157. if direction == "forward" then
  158. moveBackward()
  159. elseif direction == "up" then
  160. moveDown()
  161. elseif direction == "down" then
  162. moveUp()
  163. elseif direction == "left" then
  164. turnAndMove("right") -- Reverse left movement
  165. elseif direction == "right" then
  166. turnAndMove("left") -- Reverse right movement
  167. elseif direction == "back" then
  168. moveForward()
  169. end
  170. end
  171. end
  172. end
  173. end
  174.  
  175. -- Function to check for and mine entire ore veins around the turtle
  176. function checkAndMineVein()
  177. local success, block = turtle.inspect()
  178. if success and isValuable(block.name) then
  179. print("Ore detected, mining the entire vein...")
  180. moveForward()
  181. mineVein() -- Mine the entire vein
  182. moveBackward() -- Return to tunnel
  183. end
  184.  
  185. -- Also check left, right, up, and down for veins
  186. turtle.turnLeft()
  187. success, block = turtle.inspect()
  188. if success and isValuable(block.name) then
  189. print("Ore detected on the left, mining the entire vein...")
  190. moveForward()
  191. mineVein()
  192. moveBackward()
  193. end
  194. turtle.turnRight() -- Return to original direction
  195.  
  196. turtle.turnRight()
  197. success, block = turtle.inspect()
  198. if success and isValuable(block.name) then
  199. print("Ore detected on the right, mining the entire vein...")
  200. moveForward()
  201. mineVein()
  202. moveBackward()
  203. end
  204. turtle.turnLeft() -- Return to original direction
  205.  
  206. -- Check above and below
  207. success, block = turtle.inspectUp()
  208. if success and isValuable(block.name) then
  209. print("Ore detected above, mining the entire vein...")
  210. moveUp()
  211. mineVein()
  212. moveDown()
  213. end
  214.  
  215. success, block = turtle.inspectDown()
  216. if success and isValuable(block.name) then
  217. print("Ore detected below, mining the entire vein...")
  218. moveDown()
  219. mineVein()
  220. moveUp()
  221. end
  222. end
  223.  
  224. -- Function to dig a tunnel and look for entire veins of ores
  225. function digTunnel(length)
  226. print("Digging tunnel...")
  227. for i = 1, length do
  228. checkAndMineVein() -- Check and mine any veins nearby before moving
  229. moveForward() -- Move forward and track the movement
  230. turtle.digUp() -- Clear the block above
  231. refuel() -- Refuel as needed
  232. end
  233. end
  234.  
  235. -- Function to dig down from Y=70 to Y=12
  236. function digDownToY()
  237. print("Digging down from Y=" .. startYLevel .. " to Y=" .. targetYLevel .. "...")
  238. while currentY > targetYLevel do
  239. moveDown()
  240. refuel() -- Refuel as needed
  241. end
  242. print("Reached Y=12!")
  243. end
  244.  
  245. -- Function to backtrack to the starting point
  246. function backtrack()
  247. print("Backtracking...")
  248. while #movementLog > 0 do
  249. local lastMove = table.remove(movementLog) -- Get the last movement
  250.  
  251. -- Reverse the last movement
  252. if lastMove == "forward" then
  253. turtle.back()
  254. elseif lastMove == "down" then
  255. turtle.up() -- Go back up
  256. currentY = currentY + 1 -- Track Y level correctly
  257. elseif lastMove == "up" then
  258. turtle.down() -- Go back down
  259. currentY = currentY - 1 -- Track Y level correctly
  260. elseif lastMove == "backward" then
  261. turtle.forward() -- Move forward to undo a back movement
  262. end
  263. end
  264. print("Returned to starting point at Y=70!")
  265. end
  266.  
  267. -- Main Program
  268. refuel() -- Initial refuel
  269.  
  270. -- Step 1: Dig down from Y=70 to Y=12, and track the depth
  271. digDownToY()
  272.  
  273. -- Step 2: Dig a 10-block tunnel and mine entire veins of ore
  274. digTunnel(tunnelLength)
  275.  
  276. -- Step 3: Return to the starting point at Y=70
  277. backtrack()
  278.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement