Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local directions = {north = 1, east = 2, south = 3, west = 4}
- local facing = directions.north
- local pos = {gps.locate()}
- local pos_moving = pos
- local action = {}
- action.forward = function (times)
- for i = 0, times, 1 do
- turtle.forward()
- end
- pos = {gps.locate()}
- -- if (facing == directions.north) then
- -- pos[3] = pos[3] - times
- -- elseif (facing == directions.south) then
- -- pos[3] = pos[3] + times
- -- elseif (facing == directions.east) then
- -- pos[1] = pos[1] + times
- -- elseif (facing == directions.west) then
- -- pos[1] = pos[1] - times
- -- end
- end
- action.back = function (times)
- for i = 0, times, 1 do
- turtle.back()
- end
- pos = {gps.locate()}
- end
- action.turn = function(times, side)
- if (side == "right") then
- for i = 0, times, 1 do
- turtle.turnRight()
- end
- if (directions.north == facing) then facing = directions.east
- elseif (directions.south == facing) then facing = directions.west
- elseif (directions.west == facing) then facing = directions.north
- elseif (directions.east == facing) then facing = directions.south end
- else
- for i = 0, times, 1 do
- turtle.turnLeft()
- end
- facing = directions.west
- if (directions.north == facing) then facing = directions.west
- elseif (directions.south == facing) then facing = directions.east
- elseif (directions.west == facing) then facing = directions.south
- elseif (directions.east == facing) then facing = directions.north end
- end
- pos = {gps.locate()}
- end
- action.height = function (times, side)
- if (side == "up") then
- for i = 0, times, 1 do
- turtle.up()
- end
- else
- for i = 0, times, 1 do
- turtle.down()
- end
- end
- pos = {gps.locate()}
- end
- -- north z-
- -- south z+
- -- west x+
- -- east x-
- function go_to_coords(x, y ,z)
- pos = {gps.locate()}
- local nx, ny, nz = pos[1] - x, pos[2] - y, pos[3] - z
- if (nx < 0) then
- while (facing ~= directions.west) do action.turn(1, "right") end
- action.forward(nx * -1)
- elseif (nx > 0) then
- while (facing ~= directions.east) do action.turn(1, "left") end
- action.forward(nx)
- end
- if (nz < 0) then
- while (facing ~= directions.north) do action.turn(1, "right") end
- action.forward(nz * -1)
- elseif (nz > 0) then
- while (facing ~= directions.south) do action.turn(1, "left") end
- action.forward(nz)
- end
- if (ny < 0) then action.height(ny * -1, "down")
- elseif (ny > 0) then action.height(ny, "up") end
- print("got here\n")
- while (pos[1] ~= x and pos[2] ~= y and pos[3] ~= z) do go_to_coords(x, y, z) pos = {gps.locate()} end
- end
- go_to_coords(137, 61, 698)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement