SHOW:
|
|
- or go back to the newest paste.
| 1 | - | -- tunnelbuilder <distance> |
| 1 | + | -- bridge <distance> |
| 2 | -- needs building material in the first slot (eg. cobblestone) | |
| 3 | -- more building material can be supplied in other slots too if needed | |
| 4 | - | -- turtle will build the top row (with ceiling) first, then turn around, drop below and build the floor |
| 4 | + | |
| 5 | - | -- tunnel height will be 2 +1 ceiling +1 floor |
| 5 | + | |
| 6 | local args = { ... }
| |
| 7 | local distance = 0 | |
| 8 | if #args ~= 1 then | |
| 9 | print("Usage: bridge<distance>")
| |
| 10 | error() | |
| 11 | - | print("Usage: tunnelbuilder <distance>")
|
| 11 | + | |
| 12 | distance = args[1] | |
| 13 | if turtle.getFuelLevel() < 1*distance then | |
| 14 | print("Not enough fuel to build the specified distance")
| |
| 15 | - | if turtle.getFuelLevel() < 2*distance then |
| 15 | + | |
| 16 | end | |
| 17 | -- --------------------------------------------------------------------- | |
| 18 | function reorderWalls() | |
| 19 | for i = 1,16 do | |
| 20 | if i~=WALL_SLOT then | |
| 21 | turtle.select(i) | |
| 22 | -- os.sleep(0.1) | |
| 23 | if turtle.compareTo(WALL_SLOT) and (turtle.getItemCount(i)>0) then | |
| 24 | - | os.sleep(0.1) |
| 24 | + | |
| 25 | -- os.sleep(0.01) | |
| 26 | end | |
| 27 | end | |
| 28 | end | |
| 29 | end | |
| 30 | turtle.select(WALL_SLOT) | |
| 31 | end | |
| 32 | ||
| 33 | function suckAll() | |
| 34 | local i = 1 | |
| 35 | while i <= 16 and (i==WALL_SLOT or turtle.getItemSpace(i)==0) do | |
| 36 | i = i + 1 | |
| 37 | - | while i < 17 and (i==WALL_SLOT or turtle.getItemSpace(i)==0) do |
| 37 | + | |
| 38 | if i <= 16 then | |
| 39 | turtle.select(i) | |
| 40 | - | turtle.select(i) |
| 40 | + | turtle.suck() |
| 41 | - | turtle.suck() |
| 41 | + | turtle.suckUp() |
| 42 | - | turtle.suckUp() |
| 42 | + | turtle.suckDown() |
| 43 | - | turtle.suckDown() |
| 43 | + | reorderWalls() |
| 44 | - | reorderWalls() |
| 44 | + | |
| 45 | turtle.select(WALL_SLOT) | |
| 46 | end | |
| 47 | ||
| 48 | function wall() | |
| 49 | turtle.select(WALL_SLOT) | |
| 50 | while turtle.detect() and not turtle.compare() do | |
| 51 | turtle.dig() | |
| 52 | - | suckAll() |
| 52 | + | -- suckAll() |
| 53 | end | |
| 54 | turtle.select(WALL_SLOT) | |
| 55 | if not turtle.compare() then | |
| 56 | - | turtle.place() |
| 56 | + | while not turtle.place() do |
| 57 | turtle.dig() | |
| 58 | end | |
| 59 | - | function wallUp() |
| 59 | + | |
| 60 | end | |
| 61 | - | while turtle.detectUp() and not turtle.compareUp() do |
| 61 | + | |
| 62 | turtle.select(WALL_SLOT) | |
| 63 | - | suckAll() |
| 63 | + | |
| 64 | turtle.digDown() | |
| 65 | -- suckAll() | |
| 66 | - | if not turtle.compareUp() then |
| 66 | + | |
| 67 | - | turtle.placeUp() |
| 67 | + | |
| 68 | if not turtle.compareDown() then | |
| 69 | while not turtle.placeDown() do | |
| 70 | turtle.digDown() | |
| 71 | end | |
| 72 | end | |
| 73 | end | |
| 74 | - | suckAll() |
| 74 | + | |
| 75 | -- --------------------------------------------------------------------- | |
| 76 | local stepsSinceReorder = 21 | |
| 77 | ||
| 78 | - | turtle.placeDown() |
| 78 | + | |
| 79 | if stepsSinceReorder>20 then | |
| 80 | reorderWalls() | |
| 81 | stepsSinceReorder = 0 | |
| 82 | turtle.select(WALL_SLOT) | |
| 83 | - | reorderWalls() |
| 83 | + | if turtle.getItemCount() < 3 then |
| 84 | print("not enough building blocks")
| |
| 85 | error() | |
| 86 | end | |
| 87 | end | |
| 88 | while not turtle.forward() do | |
| 89 | turtle.dig() | |
| 90 | -- suckAll() | |
| 91 | end | |
| 92 | wallDown() | |
| 93 | while turtle.detectUp() do | |
| 94 | turtle.digUp() | |
| 95 | - | wallUp() |
| 95 | + | -- suckAll() |
| 96 | end | |
| 97 | turtle.turnLeft() | |
| 98 | - | -- turn around and drop |
| 98 | + | |
| 99 | - | turtle.turnRight() |
| 99 | + | |
| 100 | - | turtle.turnRight() |
| 100 | + | |
| 101 | - | while not turtle.down() do |
| 101 | + | |
| 102 | - | turtle.digDown() |
| 102 | + | |
| 103 | - | suckAll() |
| 103 | + | stepsSinceReorder = stepsSinceReorder+1 |
| 104 | end | |
| 105 | print("bridge built") |