print("Welcome to AutoMiner v0.01")
print("Please input the level you wish to mine at.")
target_level = read()
target_level = tonumber(target_level)
current_slot = 1
depth = 0
xpos, ypos, zpos = gps.locate(5)
while true
	do
	if turtle.getFuelLevel () == 0
		then
		if turtle.getItemCount(16) == 0
			then
			rednet.open("right")
			rednet.send(3, "Trapped, please send assistance.")
			break
			end
		end
	if turtle.getItemCount(current_slot) == 64
		then
		if current_slot == 16
			then
			print("Full haul. Returning to surface.")
			break
			end
		current_slot = current_slot + 1
		turtle.select(current_slot)
		end
	if ypos > target_level
		then
		turtle.down()
		ypos = ypos - 1
		end
	if ypos == target_level
		then
		turtle.forward()
		if turtle.detect()
			then
			turtle.dig()
			turtle.forward()
			turtle.digUp()
			turtle.up()
			turtle.turnLeft()
			turtle.dig()
			turtle.turnRight()
			turtle.turnRight()
			turtle.dig()
			turtle.turnLeft()
			turtle.down()
			turtle.turnLeft()
			turtle.dig()
			turtle.turnRight()
			turtle.turnRight()
			turtle.dig()
			turtle.turnLeft()
			depth = depth + 1
			end
		end
	end
		
turtle.turnRight()
turtle.turnRight()
delta_depth = 0
while delta_depth < depth
	do
	turtle.forward()
	end

delta_height = 0
while delta_height < target_level
	do
	turtle.up()
	end