Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Configuration
- local refuelLevel = 20 -- Minimum fuel level before refueling
- local fuelSlot = 16 -- Slot where fuel (coal) is stored
- local tunnelLength = 10 -- Length of the tunnel
- local startYLevel = 70 -- Starting Y level
- local targetYLevel = 12 -- Target Y level (Y=12)
- -- Movement tracking (stack-based approach)
- local movementLog = {} -- Stack to store movements for backtracking
- local minedOres = {} -- List to track mined ore coordinates to prevent infinite loops
- local currentY = startYLevel -- Track Y level manually
- -- List of valuables (all ores) to detect in Minecraft 1.7.10
- local valuables = {
- "minecraft:iron_ore",
- "minecraft:coal_ore",
- "minecraft:gold_ore",
- "minecraft:diamond_ore",
- "minecraft:redstone_ore",
- "minecraft:emerald_ore",
- "minecraft:lapis_ore",
- "minecraft:quartz_ore"
- }
- -- Function to refuel the turtle
- function refuel()
- if turtle.getFuelLevel() < refuelLevel then
- turtle.select(fuelSlot)
- if turtle.refuel(1) then
- print("Turtle refueled.")
- else
- print("No fuel available!")
- end
- end
- end
- -- Function to move forward with tracking
- function moveForward()
- turtle.dig() -- Dig if there's a block in front
- turtle.forward()
- table.insert(movementLog, "forward") -- Track movement
- end
- -- Function to move down with tracking, stops at Y=12
- function moveDown()
- if currentY > targetYLevel then
- turtle.digDown() -- Dig if there's a block below
- turtle.down() -- Move down
- currentY = currentY - 1 -- Update Y level manually
- table.insert(movementLog, "down") -- Track movement
- else
- print("Reached target Y-level: " .. targetYLevel)
- end
- end
- -- Function to move up with tracking
- function moveUp()
- turtle.up()
- currentY = currentY + 1 -- Update Y level manually
- table.insert(movementLog, "up") -- Track movement
- end
- -- Function to move back with tracking
- function moveBackward()
- turtle.back()
- table.insert(movementLog, "backward") -- Track movement
- end
- -- Function to move left or right with tracking
- function turnAndMove(direction)
- if direction == "left" then
- turtle.turnLeft()
- moveForward()
- turtle.turnRight()
- elseif direction == "right" then
- turtle.turnRight()
- moveForward()
- turtle.turnLeft()
- end
- end
- -- Function to check if a block is valuable
- function isValuable(blockName)
- for _, valuable in ipairs(valuables) do
- if blockName == valuable then
- return true
- end
- end
- return false
- end
- -- Function to track mined ore locations to prevent looping
- function isAlreadyMined(x, y, z)
- local key = x .. "," .. y .. "," .. z
- return minedOres[key] ~= nil
- end
- function markOreMined(x, y, z)
- local key = x .. "," .. y .. "," .. z
- minedOres[key] = true
- end
- -- Recursive function to mine an entire vein of ore
- function mineVein()
- local directions = { "forward", "up", "down", "left", "right", "back" }
- -- Recursively mine all connected ore blocks
- for _, direction in ipairs(directions) do
- local success, block
- if direction == "forward" then
- success, block = turtle.inspect()
- elseif direction == "up" then
- success, block = turtle.inspectUp()
- elseif direction == "down" then
- success, block = turtle.inspectDown()
- elseif direction == "left" then
- turtle.turnLeft()
- success, block = turtle.inspect()
- turtle.turnRight()
- elseif direction == "right" then
- turtle.turnRight()
- success, block = turtle.inspect()
- turtle.turnLeft()
- elseif direction == "back" then
- turtle.turnRight()
- turtle.turnRight()
- success, block = turtle.inspect()
- turtle.turnRight()
- turtle.turnRight()
- end
- if success and isValuable(block.name) then
- -- Mark this ore as mined
- local x, y, z = gps.locate() -- Assumes GPS is available, or simulate coordinate tracking manually
- if not isAlreadyMined(x, y, z) then
- markOreMined(x, y, z)
- -- Move toward the ore and mine it
- if direction == "forward" then
- moveForward()
- elseif direction == "up" then
- moveUp()
- elseif direction == "down" then
- moveDown()
- elseif direction == "left" then
- turnAndMove("left")
- elseif direction == "right" then
- turnAndMove("right")
- elseif direction == "back" then
- moveBackward()
- end
- -- Recursively continue mining the connected vein
- mineVein()
- -- After mining the vein, return to the original position
- if direction == "forward" then
- moveBackward()
- elseif direction == "up" then
- moveDown()
- elseif direction == "down" then
- moveUp()
- elseif direction == "left" then
- turnAndMove("right") -- Reverse left movement
- elseif direction == "right" then
- turnAndMove("left") -- Reverse right movement
- elseif direction == "back" then
- moveForward()
- end
- end
- end
- end
- end
- -- Function to check for and mine entire ore veins around the turtle
- function checkAndMineVein()
- local success, block = turtle.inspect()
- if success and isValuable(block.name) then
- print("Ore detected, mining the entire vein...")
- moveForward()
- mineVein() -- Mine the entire vein
- moveBackward() -- Return to tunnel
- end
- -- Also check left, right, up, and down for veins
- turtle.turnLeft()
- success, block = turtle.inspect()
- if success and isValuable(block.name) then
- print("Ore detected on the left, mining the entire vein...")
- moveForward()
- mineVein()
- moveBackward()
- end
- turtle.turnRight() -- Return to original direction
- turtle.turnRight()
- success, block = turtle.inspect()
- if success and isValuable(block.name) then
- print("Ore detected on the right, mining the entire vein...")
- moveForward()
- mineVein()
- moveBackward()
- end
- turtle.turnLeft() -- Return to original direction
- -- Check above and below
- success, block = turtle.inspectUp()
- if success and isValuable(block.name) then
- print("Ore detected above, mining the entire vein...")
- moveUp()
- mineVein()
- moveDown()
- end
- success, block = turtle.inspectDown()
- if success and isValuable(block.name) then
- print("Ore detected below, mining the entire vein...")
- moveDown()
- mineVein()
- moveUp()
- end
- end
- -- Function to dig a tunnel and look for entire veins of ores
- function digTunnel(length)
- print("Digging tunnel...")
- for i = 1, length do
- checkAndMineVein() -- Check and mine any veins nearby before moving
- moveForward() -- Move forward and track the movement
- turtle.digUp() -- Clear the block above
- refuel() -- Refuel as needed
- end
- end
- -- Function to dig down from Y=70 to Y=12
- function digDownToY()
- print("Digging down from Y=" .. startYLevel .. " to Y=" .. targetYLevel .. "...")
- while currentY > targetYLevel do
- moveDown()
- refuel() -- Refuel as needed
- end
- print("Reached Y=12!")
- end
- -- Function to backtrack to the starting point
- function backtrack()
- print("Backtracking...")
- while #movementLog > 0 do
- local lastMove = table.remove(movementLog) -- Get the last movement
- -- Reverse the last movement
- if lastMove == "forward" then
- turtle.back()
- elseif lastMove == "down" then
- turtle.up() -- Go back up
- currentY = currentY + 1 -- Track Y level correctly
- elseif lastMove == "up" then
- turtle.down() -- Go back down
- currentY = currentY - 1 -- Track Y level correctly
- elseif lastMove == "backward" then
- turtle.forward() -- Move forward to undo a back movement
- end
- end
- print("Returned to starting point at Y=70!")
- end
- -- Main Program
- refuel() -- Initial refuel
- -- Step 1: Dig down from Y=70 to Y=12, and track the depth
- digDownToY()
- -- Step 2: Dig a 10-block tunnel and mine entire veins of ore
- digTunnel(tunnelLength)
- -- Step 3: Return to the starting point at Y=70
- backtrack()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement