SHOW:
|
|
- or go back to the newest paste.
1 | local tArgs = { ... } | |
2 | if #tArgs ~= 1 then | |
3 | print( "Usage: tunnel <length>" ) | |
4 | return | |
5 | end | |
6 | ||
7 | -- Mine in a quarry pattern until we hit something we can't dig | |
8 | local length = tonumber( tArgs[1] ) | |
9 | if length < 1 then | |
10 | print( "Tunnel length must be positive" ) | |
11 | return | |
12 | end | |
13 | ||
14 | local depth = length | |
15 | local collected = 0 | |
16 | ||
17 | local function collect() | |
18 | collected = collected + 1 | |
19 | if math.fmod(collected, 25) == 0 then | |
20 | print( "Mined "..collected.." items." ) | |
21 | end | |
22 | end | |
23 | ||
24 | local function tryDig() | |
25 | while turtle.detect() do | |
26 | if turtle.dig() then | |
27 | collect() | |
28 | sleep(0.5) | |
29 | else | |
30 | return false | |
31 | end | |
32 | end | |
33 | return true | |
34 | end | |
35 | ||
36 | local function tryDigUp() | |
37 | while turtle.detectUp() do | |
38 | if turtle.digUp() then | |
39 | collect() | |
40 | sleep(0.5) | |
41 | else | |
42 | return false | |
43 | end | |
44 | end | |
45 | return true | |
46 | end | |
47 | ||
48 | local function refuel() | |
49 | local fuelLevel = turtle.getFuelLevel() | |
50 | if fuelLevel == "unlimited" or fuelLevel > 0 then | |
51 | return | |
52 | end | |
53 | ||
54 | local function tryRefuel() | |
55 | for n=1,16 do | |
56 | if turtle.getItemCount(n) > 0 then | |
57 | turtle.select(n) | |
58 | if turtle.refuel(1) then | |
59 | turtle.select(1) | |
60 | return true | |
61 | end | |
62 | end | |
63 | end | |
64 | turtle.select(1) | |
65 | return false | |
66 | end | |
67 | ||
68 | if not tryRefuel() then | |
69 | print( "Add more fuel to continue." ) | |
70 | while not tryRefuel() do | |
71 | sleep(1) | |
72 | end | |
73 | print( "Resuming Tunnel." ) | |
74 | end | |
75 | end | |
76 | ||
77 | local function tryUp() | |
78 | refuel() | |
79 | while not turtle.up() do | |
80 | if turtle.detectUp() then | |
81 | if not tryDigUp() then | |
82 | return false | |
83 | end | |
84 | elseif turtle.attackUp() then | |
85 | collect() | |
86 | else | |
87 | sleep( 0.5 ) | |
88 | end | |
89 | end | |
90 | return true | |
91 | end | |
92 | ||
93 | local function tryDown() | |
94 | refuel() | |
95 | while not turtle.down() do | |
96 | if turtle.detectDown() then | |
97 | if not tryDigDown() then | |
98 | return false | |
99 | end | |
100 | elseif turtle.attackDown() then | |
101 | collect() | |
102 | else | |
103 | sleep( 0.5 ) | |
104 | end | |
105 | end | |
106 | return true | |
107 | end | |
108 | ||
109 | local function tryForward() | |
110 | refuel() | |
111 | while not turtle.forward() do | |
112 | if turtle.detect() then | |
113 | if not tryDig() then | |
114 | return false | |
115 | end | |
116 | elseif turtle.attack() then | |
117 | collect() | |
118 | else | |
119 | sleep( 0.5 ) | |
120 | end | |
121 | end | |
122 | return true | |
123 | end | |
124 | ||
125 | print( "Tunnelling..." ) | |
126 | ||
127 | for n=1,length do | |
128 | turtle.placeDown() | |
129 | tryDigUp() | |
130 | turtle.turnLeft() | |
131 | tryDig() | |
132 | tryUp() | |
133 | tryDig() | |
134 | - | tryDig() |
134 | + | tryUp() |
135 | - | tryUp() |
135 | + | |
136 | turtle.turnRight() | |
137 | turtle.turnRight() | |
138 | tryDig() | |
139 | tryDown() | |
140 | tryDig() | |
141 | tryDown() | |
142 | - | tryDown() |
142 | + | tryDig() |
143 | - | tryDig() |
143 | + | |
144 | ||
145 | if n<length then | |
146 | tryDig() | |
147 | if not tryForward() then | |
148 | print( "Aborting Tunnel." ) | |
149 | break | |
150 | end | |
151 | else | |
152 | print( "Tunnel complete." ) | |
153 | end | |
154 | ||
155 | end | |
156 | ||
157 | ||
158 | print( "Returning to start..." ) | |
159 | ||
160 | -- Return to where we started | |
161 | turtle.turnLeft() | |
162 | turtle.turnLeft() | |
163 | tryUp() | |
164 | j = 0 | |
165 | while depth > 1 do | |
166 | if tryForward() then | |
167 | - | if turtle.forward() then |
167 | + | |
168 | j = j+1 | |
169 | if j == 5 then | |
170 | turtle.select(15) | |
171 | turtle.placeDown() | |
172 | end | |
173 | else | |
174 | turtle.dig() | |
175 | end | |
176 | end | |
177 | tryDown() | |
178 | turtle.turnRight() | |
179 | turtle.turnRight() | |
180 | ||
181 | ||
182 | print( "Tunnel complete." ) | |
183 | print( "Mined "..collected.." items total." ) |