AliquotMesozoic

KISS Navigation API (Uncompressed)

Jul 7th, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. turtle.rot, turtle.x, turtle.y, turtle.z = 0,0,0,0
  2. local forward=turtle.forward; turtle.forward=function() while not forward() do end end
  3. turtle.turnTo = function(rot) --KISS: Keep It Simple, Stupid
  4.     local diff = turtle.rot>rot and turtle.rot-rot or rot-turtle.rot
  5.     if (diff==0) then return true end
  6.     if (diff==2) then turtle.turnRight() turtle.turnRight() end
  7.     if (diff==1) then if (turtle.rot>rot) then turtle.turnLeft() else turtle.turnRight() end end
  8.     if (diff==3) then if (turtle.rot>rot) then turtle.turnRight() else turtle.turnLeft() end end
  9.     turtle.rot = rot
  10. end
  11. turtle.goto = function(x,y,z)
  12.     local tX, tZ = (x>turtle.x and 1 or 3), (z>turtle.z and 0 or 2)
  13.     local dX, dY, dZ = (x>turtle.x and 1 or -1),(y>turtle.y and 1 or -1),(z>turtle.z and 1 or -1)
  14.     while (turtle.x~=x) do turtle.turnTo(tX) turtle.forward() turtle.x=turtle.x+dX end
  15.     while (turtle.z~=z) do turtle.turnTo(tZ) turtle.forward() turtle.z=turtle.z+dZ end
  16.     while (turtle.y~=y) do if (dY==1) then turtle.up() else turtle.down() end turtle.y=turtle.y+dY end
  17. end
Advertisement
Add Comment
Please, Sign In to add comment