Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local t = { ... }
- local direction = 0
- if #t < 2 then
- local programName = shell.getRunningProgram()
- print("Usage: "..fs.getName(programName).." <length> <width>")
- return
- end
- length = tonumber(t[1])
- depth = tonumber(t[2])
- hits = 0
- length = length - 1
- print("Digging...")
- local function refuel()
- if turtle.getFuelLevel() < 50 then
- turtle.select(1)
- turtle.refuel(1)
- end
- end
- local function unload()
- for n = 1,14 do
- turtle.select(n)
- turtle.drop()
- end
- end
- local function tunnel()
- refuel()
- attacks = 0
- for a = 1,length do
- while not turtle.forward() do
- if turtle.detect() then
- turtle.dig()
- else
- turtle.attack()
- attacks = attacks + 1
- end
- end
- while turtle.detectUp() or turtle.detectDown() do
- if turtle.detectUp() then
- turtle.digUp()
- else
- turtle.digDown()
- end
- end
- end
- return attacks
- end
- local function turnTowards()
- turtle.turnRight()
- while not turtle.forward() do
- turtle.dig()
- end
- turtle.digUp()
- turtle.digDown()
- turtle.turnRight()
- end
- local function turnAway()
- turtle.turnLeft()
- while not turtle.forward() do
- turtle.dig()
- end
- turtle.digUp()
- turtle.digDown()
- turtle.turnLeft()
- end
- turtle.digUp()
- turtle.digDown()
- hits = tunnel() + hits
- for d = 1,(depth-1) do
- if direction == 0 then
- turnTowards()
- direction = 1
- else
- turnAway()
- direction = 0
- end
- hits = tunnel() + hits
- end
- if direction == 0 then
- turtle.turnRight()
- turtle.turnRight()
- for q = 1,length do
- turtle.forward()
- end
- end
- turtle.turnRight()
- for j = 1,(depth-1) do
- turtle.forward()
- end
- turtle.turnLeft()
- unload()
- turtle.turnRight()
- turtle.turnRight()
- print("Done digging")
- if hits > 0 then
- print("I attacked "..hits.." times.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement