SHOW:
|
|
- or go back to the newest paste.
1 | -- branch | |
2 | -- Creates a 1x1x3 tunnel of the length specified by the user | |
3 | -- then mines 3 blocks to the right and tunnels back | |
4 | -- Torches, if supplied, will be placed on the right-hand wall at 8 block intervals | |
5 | -- Written by HarvDad, March 2014 | |
6 | ||
7 | args = {...} | |
8 | nArgs = #args | |
9 | ||
10 | - | print("branch: Rev 1.3") |
10 | + | print("branch: Rev 1.0") |
11 | ||
12 | loop = 0; | |
13 | x = 0 | |
14 | y = 0 | |
15 | z = 0 | |
16 | face = 0 | |
17 | minimumFuel = 100 | |
18 | missionMessage = "Mission complete." | |
19 | abort = false | |
20 | local currentFuelLevel = turtle.getFuelLevel() | |
21 | ||
22 | if nArgs == 0 or (nArgs == 1 and args[1]== "help") then | |
23 | print("Creates a 2x2 tunnel with sealed sides.") | |
24 | print("Place fuel in slot 1") | |
25 | print("Place patch material (like cobblestone) in slot 2.") | |
26 | print("If torches are desired, place torches in slot 16.") | |
27 | print("Usage: branch <length>") | |
28 | return | |
29 | end | |
30 | ||
31 | if nArgs ~= 1 then | |
32 | print("Usage: branch <length>") | |
33 | return | |
34 | end | |
35 | ||
36 | length = tonumber(args[1]) | |
37 | if length == nil then | |
38 | print("\"", args[1], "\" is not a valid length") | |
39 | return | |
40 | end | |
41 | if length < 1 then | |
42 | print("length must be a positive number greater than zero") | |
43 | end | |
44 | ||
45 | targetArea = length | |
46 | areaCovered = 1; | |
47 | ||
48 | ||
49 | function left() | |
50 | if face == 0 then face = 1 turtle.turnLeft() return end | |
51 | if face == 1 then face = 2 turtle.turnLeft() return end | |
52 | if face == 2 then face = 3 turtle.turnLeft() return end | |
53 | if face == 3 then face = 0 turtle.turnLeft() return end | |
54 | print("function left\(\): Bad face value: ", face) | |
55 | end | |
56 | ||
57 | function right() | |
58 | if face == 0 then face = 3 turtle.turnRight() return end | |
59 | if face == 1 then face = 0 turtle.turnRight() return end | |
60 | if face == 2 then face = 1 turtle.turnRight() return end | |
61 | if face == 3 then face = 2 turtle.turnRight() return end | |
62 | print("function right\(\): Bad face value: ", face) | |
63 | end | |
64 | ||
65 | function up() | |
66 | success = false | |
67 | ||
68 | repeat | |
69 | while turtle.detectUp() do -- This loop added in case of falling sand or whatever | |
70 | turtle.digUp() | |
71 | end | |
72 | success = turtle.up() | |
73 | until success | |
74 | y = y+1 | |
75 | end | |
76 | ||
77 | function rise(nBlocks) | |
78 | local i | |
79 | for i=1,nBlocks do | |
80 | up() | |
81 | end | |
82 | end | |
83 | ||
84 | function descend(nBlocks) | |
85 | local i | |
86 | for i=1,nBlocks do | |
87 | down() | |
88 | end | |
89 | end | |
90 | ||
91 | function down() | |
92 | if turtle.detectDown() then | |
93 | turtle.digDown() | |
94 | end | |
95 | turtle.down() | |
96 | y = y-1 | |
97 | end | |
98 | ||
99 | ||
100 | function forward() | |
101 | while turtle.detect() do -- This loop added in case of falling sand or whatever | |
102 | turtle.dig() | |
103 | end | |
104 | for i=1,10 do | |
105 | if turtle.forward() then | |
106 | break | |
107 | end | |
108 | turtle.attack() | |
109 | sleep(2) | |
110 | end | |
111 | if face == 0 then z = z+1 return end | |
112 | if face == 1 then x = x-1 return end | |
113 | if face == 2 then z = z-1 return end | |
114 | if face == 3 then x = x+1 return end | |
115 | end | |
116 | ||
117 | function patch() | |
118 | turtle.select(2) | |
119 | turtle.place() | |
120 | end | |
121 | ||
122 | function patchUp() | |
123 | turtle.select(2) | |
124 | turtle.placeUp() | |
125 | end | |
126 | ||
127 | function patchDown() | |
128 | turtle.select(2) | |
129 | turtle.placeDown() | |
130 | end | |
131 | ||
132 | addTorch = true | |
133 | - | torchSpacing = 8 |
133 | + | torchSpacing = 3 |
134 | - | torchSpot = 6 |
134 | + | torchSpot = 7 |
135 | ||
136 | function mineForward() | |
137 | forward() | |
138 | ||
139 | while turtle.detectUp() do -- This loop added in case of falling sand or whatever | |
140 | turtle.digUp() | |
141 | - | -- turtle.suckUp() |
141 | + | turtle.suckUp() |
142 | end | |
143 | ||
144 | if turtle.detectDown() then | |
145 | turtle.digDown() | |
146 | - | -- turtle.suckDown() |
146 | + | turtle.suckDown() |
147 | end | |
148 | ||
149 | if addTorch then | |
150 | if (torchSpot % torchSpacing) == 0 then | |
151 | left() | |
152 | left() | |
153 | turtle.select(16) | |
154 | turtle.place() | |
155 | right() | |
156 | right() | |
157 | end | |
158 | end | |
159 | torchSpot = torchSpot + 1 | |
160 | end | |
161 | ||
162 | function setFace(f) | |
163 | if f == 0 then | |
164 | if face == 0 then return end | |
165 | if face == 1 then right() return end | |
166 | if face == 2 then right() right() return end | |
167 | if face == 3 then left() return end | |
168 | end | |
169 | ||
170 | if f == 1 then | |
171 | if face == 0 then left() return end | |
172 | if face == 1 then return end | |
173 | if face == 2 then right() return end | |
174 | if face == 3 then right() right() return end | |
175 | end | |
176 | ||
177 | if f == 2 then | |
178 | if face == 0 then left() left() return end | |
179 | if face == 1 then left() return end | |
180 | if face == 2 then return end | |
181 | if face == 3 then right() return end | |
182 | end | |
183 | ||
184 | if f == 3 then | |
185 | if face == 0 then right() return end | |
186 | if face == 1 then left() left() return end | |
187 | if face == 2 then left() return end | |
188 | if face == 3 then return end | |
189 | end | |
190 | end | |
191 | ||
192 | function checkFuel() | |
193 | if currentFuelLevel == "unlimited" then | |
194 | return true | |
195 | end | |
196 | ||
197 | if currentFuelLevel < minimumFuel then | |
198 | if not turtle.refuel(200) then | |
199 | areaCovered = targetArea | |
200 | missionMessage = "Mission aborted due to low fuel." | |
201 | abort = true | |
202 | return false | |
203 | end | |
204 | end | |
205 | return true | |
206 | end | |
207 | ||
208 | function home(targetY) | |
209 | -- print("home:face ", face, ", x = ", x, ", z = ", z) | |
210 | if x < 0 then | |
211 | setFace(3) | |
212 | while x < 0 do | |
213 | forward() | |
214 | end | |
215 | else | |
216 | if x > 0 then | |
217 | setFace(1) | |
218 | while x > 0 do | |
219 | forward() | |
220 | end | |
221 | end | |
222 | end | |
223 | ||
224 | if z < 0 then | |
225 | setFace(0) | |
226 | while z < 0 do | |
227 | forward() | |
228 | end | |
229 | else | |
230 | if z > 0 then | |
231 | setFace(2) | |
232 | while z > 0 do | |
233 | forward() | |
234 | end | |
235 | end | |
236 | end | |
237 | end | |
238 | ||
239 | function dump() | |
240 | for i=2,14 do | |
241 | turtle.select(i) | |
242 | turtle.dropDown() | |
243 | end | |
244 | end | |
245 | ||
246 | function branchLoop() | |
247 | - | torchSpot = 6 |
247 | + | torchSpot = 7 |
248 | local i | |
249 | ||
250 | for i=1,length do | |
251 | mineForward() | |
252 | end | |
253 | ||
254 | right() | |
255 | ||
256 | for i=1,3 do | |
257 | mineForward() | |
258 | end | |
259 | ||
260 | right() | |
261 | ||
262 | for i=1,length do | |
263 | mineForward() | |
264 | end | |
265 | ||
266 | setFace(0) | |
267 | down() | |
268 | ||
269 | if turtle.detectDown() then | |
270 | turtle.select(15) | |
271 | if not turtle.compareDown() then | |
272 | turtle.digDown() | |
273 | - | -- turtle.suckDown() |
273 | + | turtle.suckDown() |
274 | turtle.placeDown() | |
275 | end | |
276 | end | |
277 | if turtle.compareDown() then | |
278 | dump() | |
279 | end | |
280 | end | |
281 | ||
282 | -- MAIN PROGRAM | |
283 | ||
284 | turtle.select(1) | |
285 | ||
286 | print("Current Fuel Level: ", currentFuelLevel) | |
287 | ||
288 | if currentFuelLevel ~= "unlimited" then | |
289 | if currentFuelLevel < minimumFuel then | |
290 | if not turtle.refuel() then | |
291 | print("No fuel") | |
292 | return | |
293 | end | |
294 | end | |
295 | end | |
296 | ||
297 | for loop=1,5 do | |
298 | addTorch = false | |
299 | ||
300 | rise(1) | |
301 | for i=1,5 do | |
302 | mineForward() | |
303 | end | |
304 | turtle.back() | |
305 | turtle.back() | |
306 | left() | |
307 | addTorch = true | |
308 | branchLoop() | |
309 | end | |
310 | ||
311 | ||
312 | print(missionMessage, " Current fuel level is ", turtle.getFuelLevel()) |