Guest User

Untitled

a guest
Mar 11th, 2015
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.46 KB | None | 0 0
  1. function goto( gx, gy, gz )
  2.     if gx == nil or gy == nil or gz == nil then
  3.         return
  4.     end
  5.     --defining x, y, z, f position
  6.     cx, cy, cz = gps.locate( 2, false )
  7.     if cf == nil then
  8.         turtle.dig()
  9.         repeat until turtle.forward()
  10.         local fx, fy, fz = gps.locate( 2, false )
  11.         if cz < fz then
  12.             cf = 0
  13.         elseif cx > fx then
  14.             cf = 1
  15.         elseif cz > fz then
  16.             cf = 2
  17.         elseif cx < fx then
  18.             cf = 3
  19.         end
  20.         repeat until turtle.back()
  21.     end
  22.  
  23.     while cx ~= gx or cz ~= gz do
  24.         if cf == 0 then
  25.             if cx < gx then
  26.                 turtle.turnLeft()
  27.                 cf = 3
  28.             elseif cx > gx or cz > gz then
  29.                 turtle.turnRight()
  30.                 cf = 1
  31.             end
  32.         elseif cf == 1 and cx <= gx then
  33.             if cz > gz or cx ~= gx then
  34.                 turtle.turnRight()
  35.                 cf = 2
  36.             elseif cz < gz then
  37.                 turtle.turnLeft()
  38.                 cf = 0
  39.             end
  40.         elseif cf == 2 then
  41.             if cx > gx then
  42.                 turtle.turnLeft()
  43.                 cf = 1
  44.             elseif cx < gx or cz < gz then
  45.                 turtle.turnRight()
  46.                 cf = 3
  47.             end
  48.         elseif cf == 3 and cx >= gx then
  49.             if cz < gz or cx ~= gx then
  50.                 turtle.turnRight()
  51.                 cf = 0
  52.             elseif cz > gz then
  53.                 turtle.turnLeft()
  54.                 cf = 2
  55.             end
  56.         end
  57.         if cf == 1 or cf == 3 then
  58.             while cx ~= gx or not turtle.detectDown() do
  59.                 if turtle.down() then
  60.                     cy = cy - 1
  61.                 elseif cx ~= gx then
  62.                     while not turtle.forward() do
  63.                         while not turtle.up() do
  64.                             while not turtle.back() do
  65.                                 while not turtle.down() do
  66.                                     return
  67.                                 end
  68.                                 cy = cy - 1
  69.                             end
  70.                             if cf == 1 then
  71.                                 cx = cx + 1
  72.                             else
  73.                                 cx = cx - 1
  74.                             end
  75.                         end
  76.                         cy = cy+1
  77.                     end
  78.                     if cf == 1 then
  79.                         cx = cx - 1
  80.                     else
  81.                         cx = cx + 1
  82.                     end
  83.                 end
  84.             end
  85.         elseif cx == gx then
  86.             while cz ~= gz or not turtle.detectDown() do
  87.                 if turtle.down() then
  88.                     cy = cy - 1
  89.                 elseif cz ~= gz then
  90.                     while not turtle.forward() do
  91.                         while not turtle.up() do
  92.                             while not turtle.back() do
  93.                                 while not turtle.down() do
  94.                                     return
  95.                                 end
  96.                                 cy = cy - 1
  97.                             end
  98.                             if cf == 0 then
  99.                                 cz = cz - 1
  100.                             else
  101.                                 cz = cz + 1
  102.                             end
  103.                         end
  104.                         cy = cy + 1
  105.                     end
  106.                     if cf == 0 then
  107.                         cz = cz + 1
  108.                     else
  109.                         cz = cz - 1
  110.                     end
  111.                 end
  112.             end
  113.         end
  114.     end
  115.  
  116.     while cy ~= gy do
  117.         if cy < gy then
  118.             turtle.digUp()
  119.             if turtle.up() then
  120.                 cy = cy + 1
  121.             end
  122.         else
  123.             turtle.digDown()
  124.             if turtle.down() then
  125.                 cy = cy - 1
  126.             end
  127.         end
  128.     end
  129. end
Advertisement
Add Comment
Please, Sign In to add comment