brandonleon
6/25/2013 - 5:04 PM

Turtle Mining Prog, Stolen from http://reddit.com/u/Mitoni

Turtle Mining Prog, Stolen from http://reddit.com/u/Mitoni

--Place Torches in slot 1, Tunnel filler in slot 2
--Creating functions

function checkbottom()
  turtle.turnLeft()
	if not turtle.detect() then
		turtle.select(2)
		turtle.place()
		turtle.turnRight()
	else
		turtle.turnRight()
	end
	turtle.turnRight()
	if not turtle.detect() then
		turtle.select(2)
		turtle.place()
		turtle.turnLeft()
	else
		turtle.turnLeft()
	end
end

function checktop()
	turtle.turnLeft()
	if not turtle.detect() then
		turtle.select(2)
		turtle.place()
		turtle.turnRight()
	else
		turtle.turnRight()
	end
	if not turtle.detectUp() then
		turtle.select(2)
		turtle.placeUp()
		turtle.turnRight()
	else
		turtle.turnRight()
	end
	if not turtle.detect() then
		turtle.select(2)
		turtle.place()
		turtle.turnLeft()
	else
		turtle.turnLeft()
	end
end

function safedig()
        if not turtle.forward() then
                repeat
                        turtle.dig()
                        sleep(0.6)
                until turtle.forward()
        end
end

--Getting the variables
local tArgs = {...}

if #tArgs[1] < 1 then
	print("Usage: branch <length> <torches>")
	return true
end

steps = tonumber(tArgs[1])
 if #tArgs[1] <= 8 and tArgs[2] == "nt" then
	torch = false
else
	torch = true
end

--Starting the dig
for x = 1, steps do
        checkbottom()
        safedig()
end
 
--Positioning the return
checkbottom()
turtle.digUp()
turtle.up()
turtle.turnRight()
turtle.turnRight()
checktop()
 
--Starting the return
for x = 1, steps do
        checktop()
        if torch and x % 8 == 0 then
                turtle.select(1)
                turtle.placeDown()
        end
        safedig()
end