Advertisement
ItsNoah

goTo

Apr 22nd, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. local depth = 0
  4. local xPos,zPos = 0,0
  5. local xDir,zDir = 0,1
  6.  
  7. local goTo
  8.  
  9. local function turnLeft()
  10.     turtle.turnLeft()
  11.     xDir, zDir = -zDir, xDir
  12. end
  13.  
  14. local function turnRight()
  15.     turtle.turnRight()
  16.     xDir, zDir = zDir, -xDir
  17. end
  18.  
  19. function goTo( x, y, z, xd, zd )
  20.     while depth > y do
  21.         if turtle.up() then
  22.             depth = depth - 1
  23.         else
  24.             turtle.digUp()
  25.         end
  26.     end
  27.  
  28.     if xPos > x then
  29.         while xDir ~= -1 do
  30.             turnLeft()
  31.         end
  32.         while xPos > x do
  33.             if turtle.forward() then
  34.                 xPos = xPos - 1
  35.             else
  36.                 turtle.dig()
  37.             end
  38.         end
  39.     elseif xPos < x then
  40.         while xDir ~= 1 do
  41.             turnLeft()
  42.         end
  43.         while xPos < x do
  44.             if turtle.forward() then
  45.                 xPos = xPos + 1
  46.             else
  47.                 turtle.dig()
  48.             end
  49.         end
  50.     end
  51.    
  52.     if zPos > z then
  53.         while zDir ~= -1 do
  54.             turnLeft()
  55.         end
  56.         while zPos > z do
  57.             if turtle.forward() then
  58.                 zPos = zPos - 1
  59.             else
  60.                 turtle.dig()
  61.             end
  62.         end
  63.     elseif zPos < z then
  64.         while zDir ~= 1 do
  65.             turnLeft()
  66.         end
  67.         while zPos < z do
  68.             if turtle.forward() then
  69.                 zPos = zPos + 1
  70.             else
  71.                 turtle.dig()
  72.             end
  73.         end
  74.     end
  75.    
  76.     while depth < y do
  77.         if turtle.down() then
  78.             depth = depth + 1
  79.         else
  80.             turtle.digDown()
  81.         end
  82.     end
  83.    
  84.     if zd ~= xd then
  85.         while zDir ~= zd or xDir ~= xd do
  86.             turnLeft()
  87.         end
  88.     end
  89. end
  90.  
  91. -- start --
  92. goTo(tonumber(tArgs[1]), tonumber(tArgs[2]), tonumber(tArgs[3]), tonumber(tArgs[4]), tonumber(tArgs[5]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement