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