Advertisement
Axow01

Untitled

Aug 12th, 2023 (edited)
1,434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.54 KB | None | 0 0
  1. local directions = {north = 1, east = 2, south = 3, west = 4}
  2. local facing = directions.north
  3. local pos = {gps.locate()}
  4. local pos_moving = pos
  5.  
  6. local action = {}
  7.  
  8. action.forward = function (times)
  9.     for i = 0, times, 1 do
  10.         turtle.forward()
  11.     end
  12.     pos = {gps.locate()}
  13.     -- if (facing == directions.north) then
  14.     --  pos[3] = pos[3] - times
  15.     -- elseif (facing == directions.south) then
  16.     --  pos[3] = pos[3] + times
  17.     -- elseif (facing == directions.east) then
  18.     --  pos[1] = pos[1] + times
  19.     -- elseif (facing == directions.west) then
  20.     --  pos[1] = pos[1] - times
  21.     -- end
  22. end
  23.  
  24. action.back = function (times)
  25.     for i = 0, times, 1 do
  26.         turtle.back()
  27.     end
  28.     pos = {gps.locate()}
  29. end
  30.  
  31. action.turn = function(times, side)
  32.     if (side == "right") then
  33.         for i = 0, times, 1 do
  34.             turtle.turnRight()
  35.         end
  36.         if (directions.north == facing) then facing = directions.east
  37.         elseif (directions.south == facing) then facing = directions.west
  38.         elseif (directions.west == facing) then facing = directions.north
  39.         elseif (directions.east == facing) then facing = directions.south end
  40.     else
  41.         for i = 0, times, 1 do
  42.             turtle.turnLeft()
  43.         end
  44.         facing = directions.west
  45.         if (directions.north == facing) then facing = directions.west
  46.         elseif (directions.south == facing) then facing = directions.east
  47.         elseif (directions.west == facing) then facing = directions.south
  48.         elseif (directions.east == facing) then facing = directions.north end
  49.     end
  50.     pos = {gps.locate()}
  51. end
  52.  
  53. action.height = function (times, side)
  54.     if (side == "up") then
  55.         for i = 0, times, 1 do
  56.             turtle.up()
  57.         end
  58.     else
  59.         for i = 0, times, 1 do
  60.             turtle.down()
  61.         end
  62.     end
  63.     pos = {gps.locate()}
  64. end
  65.  
  66.  
  67. -- north z-
  68. -- south z+
  69. -- west x+
  70. -- east x-
  71. function go_to_coords(x, y ,z)
  72.     pos = {gps.locate()}
  73.     local nx, ny, nz = pos[1] - x, pos[2] - y, pos[3] - z
  74.     if (nx < 0) then
  75.         while (facing ~= directions.west) do action.turn(1, "right") end
  76.         action.forward(nx * -1)
  77.     elseif (nx > 0) then
  78.         while (facing ~= directions.east) do action.turn(1, "left") end
  79.         action.forward(nx)
  80.     end
  81.     if (nz < 0) then
  82.         while (facing ~= directions.north) do action.turn(1, "right") end
  83.         action.forward(nz * -1)
  84.     elseif (nz > 0) then
  85.         while (facing ~= directions.south) do action.turn(1, "left") end
  86.         action.forward(nz)
  87.     end
  88.     if (ny < 0) then action.height(ny * -1, "down")
  89.     elseif (ny > 0) then action.height(ny, "up") end
  90.     print("got here\n")
  91.     while (pos[1] ~= x and pos[2] ~= y and pos[3] ~= z) do go_to_coords(x, y, z) pos = {gps.locate()} end
  92. end
  93.  
  94. go_to_coords(137, 61, 698)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement