Advertisement
SryNotToxic

Untitled

Sep 25th, 2024
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 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 (assumed Y=70)
  6. local targetYLevel = 12 -- Target Y level to stop at (Y=12)
  7. local diggingDepth = startYLevel - targetYLevel -- Depth to dig down (58 blocks)
  8.  
  9. -- Movement tracking (stack-based approach)
  10. local movementLog = {} -- Stack to store movements for backtracking
  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 check if a block is valuable
  70. function isValuable(blockName)
  71. for _, valuable in ipairs(valuables) do
  72. if blockName == valuable then
  73. return true
  74. end
  75. end
  76. return false
  77. end
  78.  
  79. -- Function to check and mine valuables around the turtle
  80. function checkAndMineValuables()
  81. -- Helper function to inspect and mine a block in the current direction
  82. local function inspectAndMine()
  83. local success, block = turtle.inspect()
  84. if success and isValuable(block.name) then
  85. print("Valuable ore detected in front, mining...")
  86. moveForward()
  87. turtle.digUp() -- Clean up above the ore
  88. turtle.digDown() -- Clean below the ore
  89. moveBackward() -- Go back to tunnel
  90. end
  91. end
  92.  
  93. -- Check all four directions around the turtle (left, right, back, and forward)
  94. inspectAndMine() -- Check front first
  95.  
  96. -- Turn and check left
  97. turtle.turnLeft()
  98. inspectAndMine()
  99. turtle.turnRight() -- Return to original direction
  100.  
  101. -- Turn and check right
  102. turtle.turnRight()
  103. inspectAndMine()
  104. turtle.turnLeft() -- Return to original direction
  105.  
  106. -- Check above
  107. local successUp, blockUp = turtle.inspectUp()
  108. if successUp and isValuable(blockUp.name) then
  109. print("Valuable ore detected above, mining...")
  110. turtle.digUp()
  111. end
  112.  
  113. -- Check below
  114. local successDown, blockDown = turtle.inspectDown()
  115. if successDown and isValuable(blockDown.name) then
  116. print("Valuable ore detected below, mining...")
  117. turtle.digDown()
  118. end
  119. end
  120.  
  121. -- Function to dig a tunnel and look for valuables
  122. function digTunnel(length)
  123. print("Digging tunnel...")
  124. for i = 1, length do
  125. checkAndMineValuables() -- Check for valuables nearby before moving
  126. moveForward() -- Move forward and track the movement
  127. turtle.digUp() -- Clear the block above
  128. refuel() -- Refuel as needed
  129. end
  130. end
  131.  
  132. -- Function to dig down from Y=70 to Y=12
  133. function digDownToY()
  134. print("Digging down from Y=" .. startYLevel .. " to Y=" .. targetYLevel .. "...")
  135. while currentY > targetYLevel do
  136. moveDown()
  137. refuel() -- Refuel as needed
  138. end
  139. print("Reached Y=12!")
  140. end
  141.  
  142. -- Function to backtrack to the starting point
  143. function backtrack()
  144. print("Backtracking...")
  145. while #movementLog > 0 do
  146. local lastMove = table.remove(movementLog) -- Get the last movement
  147.  
  148. -- Reverse the last movement
  149. if lastMove == "forward" then
  150. turtle.back()
  151. elseif lastMove == "down" then
  152. turtle.up() -- Go back up
  153. currentY = currentY + 1 -- Track Y level correctly
  154. elseif lastMove == "up" then
  155. turtle.down() -- Go back down
  156. currentY = currentY - 1 -- Track Y level correctly
  157. elseif lastMove == "backward" then
  158. turtle.forward() -- Move forward to undo a back movement
  159. end
  160. end
  161. print("Returned to starting point at Y=70!")
  162. end
  163.  
  164. -- Main Program
  165. refuel() -- Initial refuel
  166.  
  167. -- Step 1: Dig down from Y=70 to Y=12, and track the depth
  168. digDownToY()
  169.  
  170. -- Step 2: Dig a 10-block tunnel and look for valuables
  171. digTunnel(tunnelLength)
  172.  
  173. -- Step 3: Return to the starting point at Y=70
  174. backtrack()
  175.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement