local homeX, homeY, homeZ -- Coordinates of turtle home station homeX = 420 homeY = 65 homeZ = -104 local direction local timeout = 5 -- The timeout of the gps local safeHeight = 35 --The height that is safe to dig at function go(dist, dig) dig = (dig == true) dist = dist or 1 if(dist <= 0) then return end for i = 1, dist do while(not turtle.forward()) do turtle.attack() if(turtle.detect()) then if(dig) then turtle.dig() else local x,y,z = gps.locate(timeout, true) if(safeHeight= 0 and dir <= 3) then local turns = (dir-direction)%4 if (turns == 1 or turns == -3) then turnRight() elseif(turns == 2) then turnRight() turnRight() elseif(turns == -1 or turns == 3) then turnLeft() elseif(turns == -2) then turnLeft() turnLeft() end end if(dir ~= direction) then print((dir-direction)%4) print("Problem in turnTo()") end end function goHome() local x,y,z = gps.locate(5, false) -- if(y > safeHeight) then -- goDown(y-safeHeight) --end direction = getDirection(y<=safeHeight) print("Got direction: "..direction) if(x>homeX) then turnTo(0) elseif(xhomeZ) then turnTo(1) elseif(zhomeY) then goDown(y-homeY) elseif(y