SHOW:
|
|
- or go back to the newest paste.
| 1 | local tArgs = {...}
| |
| 2 | local face = 0 | |
| 3 | local r = 1 | |
| 4 | - | local tturned = 0 |
| 4 | + | |
| 5 | local cx,cy,cz = gps.locate(2,false) | |
| 6 | if #tArgs ~= 3 then | |
| 7 | - | if #tArgs ~= 3 and #tArgs ~= 4 then |
| 7 | + | |
| 8 | --print("goto <x> <y> <z>")
| |
| 9 | - | --print("goto <x> <y> <z> (<Heading>)")
|
| 9 | + | |
| 10 | local gx = tonumber(tArgs[1]) | |
| 11 | local gy = tonumber(tArgs[2]) | |
| 12 | local gz = tonumber(tArgs[3]) | |
| 13 | local x | |
| 14 | - | local enddirlet = tArgs[4] |
| 14 | + | |
| 15 | local z | |
| 16 | function PL() | |
| 17 | --print("Going to:")
| |
| 18 | --write(gx) write(" ") write(gy) write(" ") print(gz)
| |
| 19 | - | if enddirlet == "n" or enddirlet == "north" then |
| 19 | + | |
| 20 | - | enddir = 4 |
| 20 | + | |
| 21 | if face == 5 then | |
| 22 | - | if enddirlet == "s" or enddirlet == "south" then |
| 22 | + | |
| 23 | - | enddir = 2 |
| 23 | + | elseif face == 0 then |
| 24 | face = 4 | |
| 25 | - | if enddirlet == "e" or enddirlet == "east" then |
| 25 | + | |
| 26 | - | enddir = 1 |
| 26 | + | |
| 27 | function get_Face() | |
| 28 | - | if enddirlet == "w" or enddirlet == "west" then |
| 28 | + | |
| 29 | - | enddir = 3 |
| 29 | + | |
| 30 | --turtle.digUp() | |
| 31 | end | |
| 32 | - | function tturnup() |
| 32 | + | |
| 33 | - | tturned = tturned + 1 |
| 33 | + | |
| 34 | - | if tturned > 10 then |
| 34 | + | |
| 35 | - | os.reboot() |
| 35 | + | |
| 36 | face = 1 | |
| 37 | end | |
| 38 | if nx < cx then | |
| 39 | face = 3 | |
| 40 | end | |
| 41 | if nz > cz then | |
| 42 | face = 2 | |
| 43 | end | |
| 44 | - | if face >= 5 then |
| 44 | + | |
| 45 | face = 4 | |
| 46 | - | elseif face <= 0 then |
| 46 | + | |
| 47 | end | |
| 48 | function calc() | |
| 49 | x = nx - gx | |
| 50 | y = ny - gy | |
| 51 | z = nz - gz | |
| 52 | end | |
| 53 | function setDir(dir) | |
| 54 | while dir ~= face do | |
| 55 | turtle.turnLeft() | |
| 56 | face = face - 1 | |
| 57 | c_face() | |
| 58 | end | |
| 59 | end | |
| 60 | function f() | |
| 61 | while not turtle.forward() do | |
| 62 | if not turtle.up() then | |
| 63 | --turtle.digUp() | |
| 64 | end | |
| 65 | y = y + 1 | |
| 66 | end | |
| 67 | end | |
| 68 | function go() | |
| 69 | if x < 0 then | |
| 70 | setDir(1) | |
| 71 | while x ~= 0 do | |
| 72 | f() | |
| 73 | x = x + 1 | |
| 74 | end | |
| 75 | end | |
| 76 | if x > 0 then | |
| 77 | setDir(3) | |
| 78 | while x ~= 0 do | |
| 79 | - | if face >= dir then |
| 79 | + | |
| 80 | - | turtle.turnLeft() |
| 80 | + | |
| 81 | - | face = face - 1 |
| 81 | + | |
| 82 | - | tturnup() |
| 82 | + | |
| 83 | - | end |
| 83 | + | |
| 84 | - | if face < dir then |
| 84 | + | |
| 85 | - | turtle.turnRight() |
| 85 | + | |
| 86 | - | face = face + 1 |
| 86 | + | |
| 87 | - | tturnup() |
| 87 | + | |
| 88 | - | end |
| 88 | + | |
| 89 | end | |
| 90 | if z > 0 then | |
| 91 | setDir(4) | |
| 92 | while z ~= 0 do | |
| 93 | f() | |
| 94 | - | tturned = 0 |
| 94 | + | |
| 95 | end | |
| 96 | end | |
| 97 | while y < 0 do | |
| 98 | if turtle.up() ~= true then | |
| 99 | --turtle.digUp() | |
| 100 | end | |
| 101 | y = y + 1 | |
| 102 | - | tturned = 0 |
| 102 | + | |
| 103 | while y > 0 do | |
| 104 | if turtle.down() ~= true then | |
| 105 | --turtle.digDown() | |
| 106 | end | |
| 107 | y = y - 1 | |
| 108 | end | |
| 109 | end | |
| 110 | ||
| 111 | ||
| 112 | ||
| 113 | tonumber(gx) | |
| 114 | tonumber(gy) | |
| 115 | tonumber(gz) | |
| 116 | PL() | |
| 117 | get_Face() | |
| 118 | calc() | |
| 119 | go() | |
| 120 | ||
| 121 | end | |
| 122 |