SHOW:
|
|
- or go back to the newest paste.
1 | local tArgs = { ... } | |
2 | if #tArgs ~= 3 then | |
3 | print( "Usage: <program> <far> <dump> <depth>" ) | |
4 | return | |
5 | end | |
6 | ||
7 | -- Mine in a one-wide pattern until we hit something we can't dig | |
8 | local size = tonumber( tArgs[1] ) | |
9 | local gDump = tonumber( tArgs[2] ) | |
10 | local tStop = tonumber( tArgs[3] ) | |
11 | if size < 1 then | |
12 | print( "Excavate outward must be positive" ) | |
13 | return | |
14 | end | |
15 | if tStop < 1 then | |
16 | tStop = 255 | |
17 | end | |
18 | if gDump < 1 then | |
19 | gDump = 1 | |
20 | end | |
21 | ||
22 | local xDir = 0 | |
23 | local yDir = 1 | |
24 | local myX = 0 | |
25 | local myY = 0 | |
26 | local myZ = 0 | |
27 | local depth = 0 | |
28 | local collected = 0 | |
29 | local aDump = 0 | |
30 | local cPos = 0 | |
31 | local reseal = false | |
32 | local done = false | |
33 | local lastDepth = 0 | |
34 | local bedrock = false | |
35 | local fcDown = 0 | |
36 | local fcPush = 0 | |
37 | ||
38 | local function findFuel() | |
39 | if turtle.getFuelLevel() < 1 then | |
40 | for i = 1, 16 do -- loop through the slots | |
41 | turtle.select(i) -- change to the slot | |
42 | if turtle.refuel(0) then -- if it's valid fuel | |
43 | local halfStack = math.ceil(turtle.getItemCount(i)/2) -- work out half of the amount of fuel in the slot | |
44 | turtle.refuel(halfStack) -- consume half the stack as fuel | |
45 | return true | |
46 | end | |
47 | - | local function proxyDown() |
47 | + | |
48 | - | if not turtle.down() then |
48 | + | |
49 | - | print ("Move down failed. Checking fuel...") |
49 | + | return true |
50 | - | if not findFuel() then |
50 | + | |
51 | - | print ("Out of fuel!") |
51 | + | |
52 | end | |
53 | ||
54 | - | if not turtle.down() then |
54 | + | |
55 | - | print ("Something in the way! Bedrock?") |
55 | + | |
56 | - | return false |
56 | + | |
57 | - | end |
57 | + | |
58 | end | |
59 | while turtle.back() == false do | |
60 | - | return true |
60 | + | |
61 | end | |
62 | turtle.turnLeft() | |
63 | - | local function proxyForward() |
63 | + | |
64 | turtle.select(1) | |
65 | - | print ("Move forward failed. Checking fuel...") |
65 | + | |
66 | - | if not findFuel() then |
66 | + | |
67 | - | print ("Out of fuel!") |
67 | + | |
68 | turtle.select(3) | |
69 | turtle.drop() | |
70 | - | if not turtle.forward() then |
70 | + | |
71 | - | print ("Something in front!") |
71 | + | |
72 | - | return false |
72 | + | |
73 | - | end |
73 | + | |
74 | turtle.select(6) | |
75 | turtle.drop() | |
76 | - | return true |
76 | + | |
77 | turtle.drop() | |
78 | turtle.select(8) | |
79 | - | local function proxyUp() |
79 | + | |
80 | - | if not turtle.up() then |
80 | + | |
81 | - | print ("Move forward failed. Checking fuel...") |
81 | + | |
82 | - | if not findFuel() then |
82 | + | |
83 | - | print ("Out of fuel!") |
83 | + | |
84 | sleep(0.8) | |
85 | end | |
86 | - | if not turtle.up() then |
86 | + | |
87 | - | print ("Something in front!") |
87 | + | |
88 | - | return false |
88 | + | |
89 | turtle.turnLeft() | |
90 | turtle.turnLeft() | |
91 | end | |
92 | - | return true |
92 | + | |
93 | local function collect() | |
94 | -- print( "Collect Called" ) | |
95 | collected = collected + 1 | |
96 | if math.fmod(collected, 25) == 0 then | |
97 | print( "Mined "..collected.." blocks." ) | |
98 | end | |
99 | ||
100 | for n=1,9 do | |
101 | if turtle.getItemCount(n) == 0 then | |
102 | return true | |
103 | end | |
104 | end | |
105 | ||
106 | print( "No empty slots left." ) | |
107 | print (" Going Home to Dump. ") | |
108 | lastDepth = depth | |
109 | goHome() | |
110 | return false | |
111 | end | |
112 | ||
113 | local function digFront() | |
114 | if turtle.dig() then | |
115 | collect() | |
116 | return true | |
117 | else | |
118 | return false | |
119 | end | |
120 | end | |
121 | ||
122 | local function digDown() | |
123 | if turtle.digDown() then | |
124 | collect() | |
125 | return true | |
126 | end | |
127 | return false | |
128 | end | |
129 | ||
130 | local function digUp() | |
131 | if turtle.digUp() then | |
132 | collect() | |
133 | return true | |
134 | end | |
135 | return false | |
136 | end | |
137 | ||
138 | local function moveForward() | |
139 | if not findFuel() then | |
140 | return false | |
141 | end | |
142 | if not turtle.forward() then | |
143 | if not digFront() then | |
144 | return false | |
145 | end | |
146 | else | |
147 | myX = myX + xDir | |
148 | myY = myY + yDir | |
149 | return true | |
150 | end | |
151 | return false | |
152 | end | |
153 | - | local function tryPush() |
153 | + | |
154 | - | if not proxyForward() then |
154 | + | local function faceLeft() |
155 | - | if turtle.dig() then |
155 | + | yd = yDir |
156 | - | collect() |
156 | + | xd = xDir |
157 | - | else |
157 | + | -- 0,1 -> -1,0 |
158 | - | fcPush = fcPush + 1 |
158 | + | -- -1,0 -> 0,-1 |
159 | - | -- give sand a chance to fall |
159 | + | -- 0,-1 -> 1,0 |
160 | - | sleep(0.8) |
160 | + | -- 1,0 -> 0,1 |
161 | - | if turtle.dig() then |
161 | + | |
162 | - | collect() |
162 | + | -- 0,1 -> -1 |
163 | - | else |
163 | + | -- -1,0 -> 0 |
164 | - | fcPush = fcPush + 1 |
164 | + | -- 0,-1 -> 1 |
165 | - | return false |
165 | + | -- 1,0 -> 0 |
166 | - | end |
166 | + | |
167 | - | end |
167 | + | -- 0,1 -> 0 |
168 | -- -1,0 -> -1 | |
169 | - | cPos = cPos + 1 |
169 | + | -- 0,-1 -> 0 |
170 | -- 1,0 -> 1 | |
171 | - | return true |
171 | + | xDir = -1*yd |
172 | yDir = xd | |
173 | turtle.turnLeft() | |
174 | - | local function tryDown() |
174 | + | |
175 | - | -- print (" Down Called ") |
175 | + | |
176 | - | if not proxyDown() then |
176 | + | local function faceRight() |
177 | - | print (" Can't move down, trying dig... ") |
177 | + | yd = yDir |
178 | - | if turtle.digDown() then |
178 | + | xd = xDir |
179 | - | collect() |
179 | + | -- 0,1 -> 1,0 |
180 | - | else |
180 | + | -- 1,0 -> 0,-1 |
181 | - | fcDown = fcDown + 1 |
181 | + | -- 0,-1 -> -1,0 |
182 | -- -1,0 -> 0,1 | |
183 | - | if not proxyDown() then |
183 | + | |
184 | - | fcDown = fcDown + 1 |
184 | + | -- 0,1 -> 1 |
185 | - | print ("Move down failed.") |
185 | + | -- 1,0 -> 0 |
186 | -- 0,-1 -> -1 | |
187 | - | depth = depth + 1 |
187 | + | -- -1,0 -> 0 |
188 | ||
189 | -- 0,1 -> 0 | |
190 | -- 1,0 -> -1 | |
191 | -- 0,-1 -> 0 | |
192 | - | print (" I moved down. ") |
192 | + | -- -1,0 -> 1 |
193 | - | return true |
193 | + | |
194 | xDir = yd | |
195 | yDir = -1 * xd | |
196 | turtle.turnRight() | |
197 | end | |
198 | ||
199 | ||
200 | local function goHome() | |
201 | print( " Coming Home... From Depth: "..depth ) | |
202 | while depth > 0 do | |
203 | if proxyUp() == true then | |
204 | print ( "Updiddy: "..depth ) | |
205 | depth = depth - 1 | |
206 | else | |
207 | turtle.digUp() | |
208 | print ( "Up is blocked, panicing." ) | |
209 | end | |
210 | ||
211 | end | |
212 | ||
213 | while cPos > 0 do | |
214 | if turtle.back() == false then | |
215 | print ( "Back is blocked, panicing." ) | |
216 | turtle.turnLeft() | |
217 | turtle.turnLeft() | |
218 | turtle.dig() | |
219 | turtle.turnLeft() | |
220 | turtle.turnLeft() | |
221 | else | |
222 | cPos = cPos - 1 | |
223 | end | |
224 | end | |
225 | print ( "Now Home, failed: "..(fcDown+fcPush).." times." ) | |
226 | ||
227 | dump() | |
228 | ||
229 | if done == false then | |
230 | print ( " Going back to work. " ) | |
231 | while depth < lastDepth do | |
232 | if tryDown() == true then | |
233 | -- D | |
234 | end | |
235 | end | |
236 | - | local function goOut() |
236 | + | |
237 | - | while cPos < size do |
237 | + | |
238 | - | if tryPush() == false then |
238 | + | |
239 | ||
240 | - | -- print( "Not Moving " ) |
240 | + | |
241 | if not turtle.digDown() then | |
242 | - | -- print( "Moving" ) |
242 | + | |
243 | return false | |
244 | else | |
245 | depth = depth + 1 | |
246 | print ( " Layer: "..depth ) | |
247 | end | |
248 | - | local function comeBack() |
248 | + | |
249 | ||
250 | - | if turtle.back() == true then |
250 | + | local function digLocal() |
251 | digDown() | |
252 | digUp() | |
253 | digFront() | |
254 | end | |
255 | ||
256 | local function digLine() | |
257 | while (myY < size) do | |
258 | - | -- print ( "Move your ass" ) |
258 | + | digLocal() |
259 | moveForward() | |
260 | - | -- print (cPos) |
260 | + | |
261 | digUp() | |
262 | while (myY > 0) do | |
263 | digDown() | |
264 | moveBack() | |
265 | - | if tryDown() == false then |
265 | + | |
266 | end | |
267 | ||
268 | local function newLine() | |
269 | - | -- depth = depth + 1 |
269 | + | faceRight() |
270 | digFront() | |
271 | moveForward() | |
272 | faceLeft() | |
273 | end | |
274 | - | local fcTotal = 0 |
274 | + | |
275 | local function digall() | |
276 | while (~done == true) do | |
277 | - | while (done ~= true) do |
277 | + | while (myX < size) do |
278 | - | fcTotal = fcPush + fcDown |
278 | + | digLine() |
279 | - | print ("Fails: "..fcPush.." : "..fcDown) |
279 | + | faceRight() |
280 | - | if fcTotal > 2 then |
280 | + | digFront() |
281 | - | done = true |
281 | + | moveForward() |
282 | faceLeft() | |
283 | - | if (depth > tStop) then |
283 | + | |
284 | - | done = true |
284 | + | digLine() |
285 | digDown() | |
286 | - | goOut() |
286 | + | moveDown() |
287 | - | comeBack() |
287 | + | digDown() |
288 | - | if digDown() == false then |
288 | + | moveDown() |
289 | - | done = true |
289 | + | while (myX > 0) do |
290 | digLine() | |
291 | faceLeft() | |
292 | digFront() | |
293 | moveForward() | |
294 | faceRight() | |
295 | end | |
296 | digLine() | |
297 | digDown() | |
298 | moveDown() | |
299 | digDown() | |
300 | moveDown() | |
301 | end | |
302 | print (" Done, Coming Home Last Time ") | |
303 | done = true | |
304 | goHome() | |
305 | end | |
306 | ||
307 | digall() |