SHOW:
|
|
- or go back to the newest paste.
| 1 | - | function setHeading(heading,newHeading) |
| 1 | + | |
| 2 | - | if(heading ~= 'N' and heading ~= 'n' and heading ~= 'E' and heading ~= 'e' and heading ~= 'S' and heading ~= 's' and heading ~= 'W' and heading ~= 'w') then |
| 2 | + | |
| 3 | - | if(turtle.getFuelLevel() < 2) then |
| 3 | + | |
| 4 | - | error("Insufficient fuel")
|
| 4 | + | |
| 5 | - | end |
| 5 | + | |
| 6 | - | local start = vector.new(gps.locate()) |
| 6 | + | |
| 7 | - | while(turtle.detect()) do |
| 7 | + | |
| 8 | - | turtle.dig() |
| 8 | + | |
| 9 | - | end |
| 9 | + | |
| 10 | - | turtle.forward() |
| 10 | + | |
| 11 | - | local current = vector.new(gps.locate()) |
| 11 | + | |
| 12 | - | turtle.back() |
| 12 | + | |
| 13 | - | if(start.z - current.z > 0) then |
| 13 | + | |
| 14 | - | heading = 'N' |
| 14 | + | |
| 15 | - | elseif (start.z - current.z < 0) then |
| 15 | + | |
| 16 | - | heading = 'S' |
| 16 | + | |
| 17 | - | end |
| 17 | + | |
| 18 | - | if(start.x - current.x > 0) then |
| 18 | + | |
| 19 | - | heading = 'W' |
| 19 | + | |
| 20 | - | elseif (start.x - current.x < 0) then |
| 20 | + | |
| 21 | - | heading = 'E' |
| 21 | + | |
| 22 | - | end |
| 22 | + | |
| 23 | - | end |
| 23 | + | |
| 24 | ||
| 25 | - | if(heading ~= newHeading) then |
| 25 | + | |
| 26 | - | if(newHeading == 'N' or newHeading == 'n') then |
| 26 | + | |
| 27 | - | if(heading == 'S' or heading == 's') then |
| 27 | + | print (getHeading()) |