Guest User

goto

a guest
Apr 2nd, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | None | 0 0
  1. local tArgs = {...}
  2. local args1 = tonumber(tArgs[4])
  3. local args2 = tonumber(tArgs[5])
  4. local args3 = tonumber(tArgs[6])
  5.  
  6. local cDir = "north"
  7. local cX = tonumber(tArgs[1])
  8. local cY = tonumber(tArgs[2])
  9. local cZ = tonumber(tArgs[3])
  10. local home = {cX,cY,cZ}
  11. local blocks = "blocks"
  12.  
  13. function turnRight()
  14.   if cDir == "north" then
  15.     cDir = "east"
  16.   elseif cDir == "east" then
  17.     cDir = "south"
  18.   elseif cDir == "south" then
  19.     cDir = "west"
  20.   elseif cDir == "west" then
  21.     cDir = "north"
  22.   else
  23.     print("Error!!")
  24.   end
  25.   turtle.turnRight()
  26. end
  27.  
  28.  
  29. function turnTo(dir)
  30.   if cDir ~= dir then
  31.     repeat
  32.      turnRight()
  33.     until cDir == dir
  34.   end
  35. end
  36.  
  37. function moveForward()
  38.   if cDir == "north" then
  39.     cZ = cZ-1
  40.   elseif cDir == "east" then
  41.     cX = cX+1
  42.   elseif cDir == "south" then
  43.     cZ = cZ+1
  44.   elseif cDir == "west" then
  45.     cX = cX-1
  46.   else
  47.     print("Error!!")
  48.   end
  49.   while not turtle.forward() do
  50.     turtle.dig()
  51.   end
  52. end
  53.  
  54. function moveUp()
  55.   cY = cY+1
  56.   while not turtle.up() do
  57.     turtle.digUp()
  58.   end
  59. end
  60.  
  61. function moveDown()
  62.   cY = cY-1
  63.   while not turtle.down() do
  64.     turtle.digDown()
  65.   end
  66. end
  67.    
  68. function moveToX(x)
  69.   if cX < x then
  70.     turnTo("east")
  71.     repeat
  72.       moveForward()
  73.     until cX == x
  74.   elseif cX > x then
  75.     turnTo("west")
  76.     repeat
  77.       moveForward()
  78.     until cX == x
  79.   else
  80.     --print("already there")
  81.   end
  82. end
  83.  
  84. function moveToZ(z)
  85.   if cZ < z then
  86.     turnTo("south")
  87.     repeat
  88.       moveForward()
  89.     until cZ == z
  90.   elseif cZ > z then
  91.     turnTo("north")
  92.     repeat
  93.       moveForward()
  94.     until cZ == z
  95.   else
  96.    --print("already there")
  97.   end
  98. end    
  99.  
  100. function moveToY(y)
  101.   if cY < y then
  102.     repeat
  103.       moveUp()
  104.     until cY == y
  105.   elseif cY > y then
  106.     repeat
  107.       moveDown()
  108.     until cY == y
  109.   else
  110.    --print("already there")
  111.   end
  112. end
  113.  
  114. function goTo(x, y, z)
  115.   moveToX(x)  
  116.   moveToY(y)
  117.   moveToZ(z)
  118.   turnTo("north")
  119. end
  120.                          
  121. goTo(args1,args2,args3)
  122. --sleep(5)
  123. --goTo(home[1],home[2],home[3])
Advertisement
Add Comment
Please, Sign In to add comment