Advertisement
CaptainSpaceCat

Follower

May 22nd, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. rednet.open("right")
  2.  
  3. function left()
  4.   turtle.turnLeft()
  5.   fDir = fDir - 1
  6.   if fDir < 0 then fDir = 3 end
  7. end
  8.  
  9. function up()
  10.   turtle.up()
  11.   yPos = yPos + 1
  12. end
  13.  
  14. function down()
  15.   turtle.down()
  16.   yPos = yPos - 1
  17. end
  18.  
  19. function forward()
  20.   turtle.forward()
  21.   if fDir == 0 then zPos = zPos + 1 end
  22.   if fDir == 2 then zPos = zPos - 1 end
  23.   if fDir == 1 then xPos = xPos - 1 end
  24.   if fDir == 3 then xPos = xPos + 1 end
  25. end
  26.  
  27. fDir = nil
  28. xPos = nil
  29. yPos = nil
  30. zPos = nil
  31. function initDir()
  32.   xPos, yPos, zPos = gps.locate()
  33.   if not xPos or not yPos or not zPos then
  34.     print("ERROR: GPS API REQUIRED")
  35.     os.exit(goTo)
  36.   end
  37.   turtle.forward()
  38.   xPos2, yPos2, zPos2 = gps.locate()
  39.   turtle.back()
  40.   if xPos ~= xPos2 then
  41.     if xPos > xPos2 then
  42.       fDir = 1
  43.     else
  44.       fDir = 3
  45.     end
  46.   else
  47.     if zPos > zPos2 then
  48.       fDir = 2
  49.     else
  50.       fDir = 0
  51.     end
  52.   end
  53. end
  54.  
  55. initDir()
  56. while true do
  57.   id = nil
  58.   id, location = rednet.receive(.01)
  59.   if id then
  60.     xDest = location[1]
  61.     yDest = location[2]
  62.     zDest = location[3]
  63.   end
  64.   if xDest < xPos then
  65.     while fDir ~= 1 do
  66.       left()
  67.     end
  68.     turtle.dig()
  69.     forward()
  70.   elseif xDest > xPos then
  71.     while fDir ~= 3 do
  72.       left()
  73.     end
  74.     turtle.dig()
  75.     forward()
  76.   elseif zDest < zPos then
  77.     while fDir ~= 2 do
  78.       left()
  79.     end
  80.     turtle.dig()
  81.     forward()
  82.   elseif zDest > zPos then
  83.     while fDir ~= 0 do
  84.       left()
  85.     end
  86.     turtle.dig()
  87.     forward()
  88.   elseif yDest < yPos then
  89.     turtle.digDown()
  90.     down()
  91.   elseif yDest > yPos then
  92.     turtle.digUp()
  93.     up()
  94.   end
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement