facing = 0 function checkFuel() fuel = turtle.getFuelLevel() if fuel < 10 then turtle.refuel(1) end end function moveForward(num) for i = 0, num do turtle.forward() end end function moveUp(num) for i = 0, num do turtle.up() end end function moveDown(num) for i = 0, num do turtle.down() end end function checkDirection() x, y, z = gps.locate() turtle.forward() comX, comY, comZ = gps.locate() turle.back() if x ~= comX then if x > comX then facing = 3 else facing = 1 end end if z ~= comZ then if z > comZ then facing = 2 else facing = 0 end end end function moveX(num) if num < 0 then turn = facing - 3 if turn == -2 then turtle.turnLeft() turtle.turnLeft() elseif turn == -1 then turle.turnRight() elseif turn == -3 then turtle.turnLeft() end moveForward(math.abs(num)) else turn = facing - 1 if turn == 2 then turtle.turnLeft() turtle.turnLeft() elseif turn == -1 then turle.turnRight() elseif turn == 1 then turtle.turnLeft() end moveForward(math.abs(num)) end end function moveY(num) if num < 0 then moveUp(math.abs(num)) else moveDown(math.abs(num)) end end function moveZ(num) if num < 0 then turn = facing - 0 if turn == 2 then turtle.turnLeft() turtle.turnLeft() elseif turn == 3 then turle.turnRight() elseif turn == 1 then turtle.turnLeft() end moveForward(math.abs(num)) else turn = facing - 2 if turn == -2 then turtle.turnLeft() turtle.turnLeft() elseif turn == -1 then turle.turnRight() elseif turn == 1 then turtle.turnLeft() end moveForward(math.abs(num)) end end function goto(toX, toY, toZ) x, y, z = gps.locate() comX = toX - x comY = toY - y comZ = toZ - z checkDirection() moveY(comY) if comX > comZ then moveX(comX) else moveZ(comZ) end end