Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Strip Mining Turtle Program for ComputerCraft
- -- Configuration
- local MINING_DEPTH = 50 -- Number of blocks to mine in one direction
- local STRIP_WIDTH = 3 -- Width of the mining strip
- local FUEL_SLOT = 16 -- Slot dedicated for fuel
- -- Helper functions
- local function refuel()
- turtle.select(FUEL_SLOT)
- if turtle.getFuelLevel() < MINING_DEPTH * 2 then
- turtle.refuel()
- end
- end
- local function forward()
- while not turtle.forward() do
- if turtle.detect() then
- turtle.dig()
- elseif turtle.attack() then
- -- Handle mobs if necessary
- else
- sleep(0.5)
- end
- end
- end
- local function digLayer(depth)
- for _ = 1, depth do
- for _ = 1, STRIP_WIDTH - 1 do
- forward()
- turtle.digUp()
- turtle.digDown()
- end
- -- Turn around at the end of the strip
- if depth % 2 == 0 then
- turtle.turnLeft()
- forward()
- turtle.turnLeft()
- else
- turtle.turnRight()
- forward()
- turtle.turnRight()
- end
- end
- end
- local function returnToStart()
- -- Return to starting position
- for _ = 1, MINING_DEPTH do
- if not turtle.back() then
- turtle.turnLeft()
- turtle.turnLeft()
- forward()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- end
- end
- local function emptyInventory()
- for slot = 1, 16 do
- if slot ~= FUEL_SLOT then
- turtle.select(slot)
- turtle.drop()
- end
- end
- end
- -- Main program
- local function mineStrip()
- refuel()
- for strip = 1, MINING_DEPTH / STRIP_WIDTH do
- digLayer(STRIP_WIDTH)
- -- Return to base after finishing the strip
- returnToStart()
- emptyInventory()
- end
- end
- mineStrip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement