gghf

goTo

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