SHOW:
|
|
- or go back to the newest paste.
1 | - | -- Defaults |
1 | + | -- Defaults |
2 | - | local flags = { |
2 | + | local flags = { |
3 | - | ["placing"] = false, |
3 | + | ["placing"] = false, |
4 | - | ["placingDown"] = false, |
4 | + | ["placingDown"] = false, |
5 | - | ["placingUp"] = false, |
5 | + | ["placingUp"] = false, |
6 | - | ["placingLeft"] = false, |
6 | + | ["placingLeft"] = false, |
7 | - | ["placingRight"] = false, |
7 | + | ["placingRight"] = false, |
8 | - | ["placingBack"] = false, |
8 | + | ["placingBack"] = false, |
9 | - | ["digging"] = false, |
9 | + | ["digging"] = false, |
10 | - | ["diggingUp"] = false, |
10 | + | ["diggingUp"] = false, |
11 | - | ["diggingDown"] = false, |
11 | + | ["diggingDown"] = false, |
12 | - | ["diggingLeft"] = false, |
12 | + | ["diggingLeft"] = false, |
13 | - | ["diggingRight"] = false, |
13 | + | ["diggingRight"] = false, |
14 | - | ["attacking"] = true, |
14 | + | ["attacking"] = true, |
15 | - | } |
15 | + | } |
16 | - | |
16 | + | |
17 | - | local fuelList = { |
17 | + | local fuelList = { |
18 | - | "minecraft:coal", |
18 | + | "minecraft:coal", |
19 | - | "minecraft:planks", |
19 | + | "minecraft:planks", |
20 | - | "minecraft:log", |
20 | + | "minecraft:log", |
21 | - | "minecraft:stick", |
21 | + | "minecraft:stick", |
22 | - | "minecraft:coal_block", |
22 | + | "minecraft:coal_block", |
23 | - | } |
23 | + | } |
24 | - | |
24 | + | |
25 | - | function contains(table, element) |
25 | + | function contains(table, element) |
26 | - | for _,v in ipairs(table) do |
26 | + | for _,v in ipairs(table) do |
27 | - | if v == element then |
27 | + | if v == element then |
28 | - | return true |
28 | + | return true |
29 | - | end |
29 | + | end |
30 | - | end |
30 | + | end |
31 | - | return false |
31 | + | return false |
32 | end | |
33 | - | |
33 | + | |
34 | - | function selectFromList(list) |
34 | + | function selectFromList(list) |
35 | - | local selected = turtle.getItemDetail() |
35 | + | local selected = turtle.getItemDetail() |
36 | - | if selected and contains(list, selected.name) then |
36 | + | if selected and contains(list, selected.name) then |
37 | - | -- Already selected |
37 | + | -- Already selected |
38 | - | return true |
38 | + | return true |
39 | - | end |
39 | + | end |
40 | - | |
40 | + | |
41 | - | for slot=16,1,-1 do |
41 | + | for slot=16,1,-1 do |
42 | - | local data = turtle.getItemDetail(slot) |
42 | + | local data = turtle.getItemDetail(slot) |
43 | - | |
43 | + | |
44 | - | if data then |
44 | + | if data then |
45 | - | if contains(list, data.name) then |
45 | + | if contains(list, data.name) then |
46 | - | turtle.select(slot) |
46 | + | turtle.select(slot) |
47 | - | return true |
47 | + | return true |
48 | - | end |
48 | + | end |
49 | - | end |
49 | + | end |
50 | - | end |
50 | + | end |
51 | - | return false |
51 | + | return false |
52 | end | |
53 | - | |
53 | + | |
54 | - | function refuelIfLow(val, amt) |
54 | + | function refuelIfLow(val, amt) |
55 | - | val = val or 5 |
55 | + | val = val or 5 |
56 | - | amt = amt or 1 |
56 | + | amt = amt or 1 |
57 | - | if turtle.getFuelLevel() < val then |
57 | + | if turtle.getFuelLevel() < val then |
58 | - | if selectFromList(fuelList) then |
58 | + | if selectFromList(fuelList) then |
59 | - | turtle.refuel(amt) |
59 | + | turtle.refuel(amt) |
60 | - | end |
60 | + | end |
61 | - | end |
61 | + | end |
62 | end | |
63 | - | |
63 | + | |
64 | - | function select(slot) |
64 | + | function select(slot) |
65 | - | turtle.select(slot) |
65 | + | turtle.select(slot) |
66 | end | |
67 | - | |
67 | + | |
68 | - | function togglePlace() |
68 | + | function togglePlace() |
69 | - | flags["placing"] = not flags["placing"] |
69 | + | flags["placing"] = not flags["placing"] |
70 | end | |
71 | - | |
71 | + | |
72 | - | function togglePlaceDown() |
72 | + | function togglePlaceDown() |
73 | - | flags["placingDown"] = not flags["placingDown"] |
73 | + | flags["placingDown"] = not flags["placingDown"] |
74 | end | |
75 | - | |
75 | + | |
76 | - | function togglePlaceUp() |
76 | + | function togglePlaceUp() |
77 | - | flags["placingUp"] = not flags["placingUp"] |
77 | + | flags["placingUp"] = not flags["placingUp"] |
78 | end | |
79 | - | |
79 | + | |
80 | - | function togglePlaceLeft() |
80 | + | function togglePlaceLeft() |
81 | - | flags["placingLeft"] = not flags["placingLeft"] |
81 | + | flags["placingLeft"] = not flags["placingLeft"] |
82 | end | |
83 | - | |
83 | + | |
84 | - | function togglePlaceRight() |
84 | + | function togglePlaceRight() |
85 | - | flags["placingRight"] = not flags["placingRight"] |
85 | + | flags["placingRight"] = not flags["placingRight"] |
86 | end | |
87 | - | |
87 | + | |
88 | - | function togglePlaceBack() |
88 | + | function togglePlaceBack() |
89 | - | flags["placingBack"] = not flags["placingBack"] |
89 | + | flags["placingBack"] = not flags["placingBack"] |
90 | end | |
91 | - | |
91 | + | |
92 | - | function toggleDig() |
92 | + | function toggleDig() |
93 | - | flags["digging"] = not flags["digging"] |
93 | + | flags["digging"] = not flags["digging"] |
94 | end | |
95 | - | |
95 | + | |
96 | - | function toggleDigUp() |
96 | + | function toggleDigUp() |
97 | - | flags["diggingUp"] = not flags["diggingUp"] |
97 | + | flags["diggingUp"] = not flags["diggingUp"] |
98 | end | |
99 | - | |
99 | + | |
100 | - | function toggleDigDown() |
100 | + | function toggleDigDown() |
101 | - | flags["diggingDown"] = not flags["diggingDown"] |
101 | + | flags["diggingDown"] = not flags["diggingDown"] |
102 | end | |
103 | - | |
103 | + | |
104 | - | function toggleDigLeft() |
104 | + | function toggleDigLeft() |
105 | - | flags["diggingLeft"] = not flags["diggingLeft"] |
105 | + | flags["diggingLeft"] = not flags["diggingLeft"] |
106 | end | |
107 | - | |
107 | + | |
108 | - | function toggleDigRight() |
108 | + | function toggleDigRight() |
109 | - | flags["diggingRight"] = not flags["diggingRight"] |
109 | + | flags["diggingRight"] = not flags["diggingRight"] |
110 | end | |
111 | - | |
111 | + | |
112 | - | function toggleAttack() |
112 | + | function toggleAttack() |
113 | - | flags["attacking"] = not flags["attacking"] |
113 | + | flags["attacking"] = not flags["attacking"] |
114 | end | |
115 | - | |
115 | + | |
116 | - | function turnRight(turns) |
116 | + | function turnRight(turns) |
117 | - | turns = turns or 1 |
117 | + | turns = turns or 1 |
118 | - | for i=1,turns do |
118 | + | for i=1,turns do |
119 | - | turtle.turnRight() |
119 | + | turtle.turnRight() |
120 | - | end |
120 | + | end |
121 | end | |
122 | - | |
122 | + | |
123 | - | function turnLeft(turns) |
123 | + | function turnLeft(turns) |
124 | - | turns = turns or 1 |
124 | + | turns = turns or 1 |
125 | - | for i=1,turns do |
125 | + | for i=1,turns do |
126 | - | turtle.turnLeft() |
126 | + | turtle.turnLeft() |
127 | - | end |
127 | + | end |
128 | end | |
129 | - | |
129 | + | |
130 | - | function move(func, blocks) |
130 | + | function move(func, blocks) |
131 | - | blocks = blocks or 1 |
131 | + | blocks = blocks or 1 |
132 | - | local digFunc |
132 | + | local digFunc |
133 | - | if func == "f" then |
133 | + | if func == "f" then |
134 | - | func = turtle.forward |
134 | + | func = turtle.forward |
135 | - | digFunc = turtle.dig |
135 | + | digFunc = turtle.dig |
136 | - | elseif func == "u" then |
136 | + | elseif func == "u" then |
137 | - | func = turtle.up |
137 | + | func = turtle.up |
138 | - | digFunc = turtle.digUp |
138 | + | digFunc = turtle.digUp |
139 | - | elseif func == "d" then |
139 | + | elseif func == "d" then |
140 | - | func = turtle.down |
140 | + | func = turtle.down |
141 | - | digFunc = turtle.digDown |
141 | + | digFunc = turtle.digDown |
142 | - | elseif func == "b" then |
142 | + | elseif func == "b" then |
143 | - | func = turtle.back |
143 | + | func = turtle.back |
144 | - | digFunc = turtle.dig |
144 | + | digFunc = turtle.dig |
145 | - | end |
145 | + | end |
146 | - | |
146 | + | |
147 | - | for block=1,blocks do |
147 | + | for block=1,blocks do |
148 | - | if flags["placing"] and not turtle.detect() then |
148 | + | if flags["placing"] and not turtle.detect() then |
149 | - | turtle.place() |
149 | + | turtle.place() |
150 | - | end |
150 | + | end |
151 | - | |
151 | + | |
152 | - | if flags["placingDown"] and not turtle.detectDown() then |
152 | + | if flags["placingDown"] and not turtle.detectDown() then |
153 | - | turtle.placeDown() |
153 | + | turtle.placeDown() |
154 | - | end |
154 | + | end |
155 | - | |
155 | + | |
156 | - | if flags["placingUp"] and not turtle.detectUp() then |
156 | + | if flags["placingUp"] and not turtle.detectUp() then |
157 | - | turtle.placeUp() |
157 | + | turtle.placeUp() |
158 | - | end |
158 | + | end |
159 | - | |
159 | + | |
160 | - | if flags["placingLeft"] then |
160 | + | if flags["placingLeft"] then |
161 | - | turnLeft() |
161 | + | turnLeft() |
162 | - | turtle.place() |
162 | + | turtle.place() |
163 | - | turnRight() |
163 | + | turnRight() |
164 | - | end |
164 | + | end |
165 | - | |
165 | + | |
166 | - | if flags["placingRight"] then |
166 | + | if flags["placingRight"] then |
167 | - | turnRight() |
167 | + | turnRight() |
168 | - | turtle.place() |
168 | + | turtle.place() |
169 | - | turnLeft() |
169 | + | turnLeft() |
170 | - | end |
170 | + | end |
171 | - | |
171 | + | |
172 | - | if flags["placingBack"] then |
172 | + | if flags["placingBack"] then |
173 | - | if math.random(2) == 1 then |
173 | + | if math.random(2) == 1 then |
174 | - | turnRight(2) |
174 | + | turnRight(2) |
175 | - | else |
175 | + | else |
176 | - | turnLeft(2) |
176 | + | turnLeft(2) |
177 | - | end |
177 | + | end |
178 | - | turtle.place() |
178 | + | turtle.place() |
179 | - | if math.random(2) == 1 then |
179 | + | if math.random(2) == 1 then |
180 | - | turnRight(2) |
180 | + | turnRight(2) |
181 | - | else |
181 | + | else |
182 | - | turnLeft(2) |
182 | + | turnLeft(2) |
183 | - | end |
183 | + | end |
184 | - | end |
184 | + | end |
185 | - | |
185 | + | |
186 | - | local dug, digError |
186 | + | local dug, digError |
187 | - | if flags["digging"] then |
187 | + | if flags["digging"] then |
188 | - | dug, digError = turtle.dig() |
188 | + | dug, digError = turtle.dig() |
189 | - | if not dug and flags["attacking"] then |
189 | + | if not dug and flags["attacking"] then |
190 | - | repeat until not turtle.attack() |
190 | + | repeat until not turtle.attack() |
191 | - | end |
191 | + | end |
192 | - | end |
192 | + | end |
193 | - | |
193 | + | |
194 | - | if flags["diggingUp"] then |
194 | + | if flags["diggingUp"] then |
195 | - | turtle.digUp() |
195 | + | turtle.digUp() |
196 | - | end |
196 | + | end |
197 | - | |
197 | + | |
198 | - | if flags["diggingDown"] then |
198 | + | if flags["diggingDown"] then |
199 | - | turtle.digDown() |
199 | + | turtle.digDown() |
200 | - | end |
200 | + | end |
201 | - | |
201 | + | |
202 | - | if flags["diggingLeft"] then |
202 | + | if flags["diggingLeft"] then |
203 | - | turnLeft() |
203 | + | turnLeft() |
204 | - | dug, digError = turtle.dig() |
204 | + | dug, digError = turtle.dig() |
205 | - | if not dug and flags["attacking"] then |
205 | + | if not dug and flags["attacking"] then |
206 | - | repeat until not turtle.attack() |
206 | + | repeat until not turtle.attack() |
207 | - | end |
207 | + | end |
208 | - | turnRight() |
208 | + | turnRight() |
209 | - | end |
209 | + | end |
210 | - | |
210 | + | |
211 | - | if flags["diggingRight"] then |
211 | + | if flags["diggingRight"] then |
212 | - | turnRight() |
212 | + | turnRight() |
213 | - | dug, digError = turtle.dig() |
213 | + | dug, digError = turtle.dig() |
214 | - | if not dug and flags["attacking"] then |
214 | + | if not dug and flags["attacking"] then |
215 | - | repeat until not turtle.attack() |
215 | + | repeat until not turtle.attack() |
216 | - | end |
216 | + | end |
217 | - | turnLeft() |
217 | + | turnLeft() |
218 | - | end |
218 | + | end |
219 | - | |
219 | + | |
220 | - | refuelIfLow() |
220 | + | refuelIfLow() |
221 | - | local moved = func() |
221 | + | local moved = func() |
222 | - | if not moved then |
222 | + | if not moved then |
223 | - | repeat |
223 | + | repeat |
224 | - | local dug,err |
224 | + | local dug,err |
225 | - | if flags["digging"] then |
225 | + | if flags["digging"] then |
226 | - | dug,err = digFunc() |
226 | + | dug,err = digFunc() |
227 | - | end |
227 | + | end |
228 | - | |
228 | + | |
229 | - | if flags["attacking"] and not dug then |
229 | + | if flags["attacking"] and not dug then |
230 | - | if not turtle.attack() then |
230 | + | if not turtle.attack() then |
231 | - | print("I think I hit bedrock, skipping to next command...") |
231 | + | print("I think I hit bedrock, skipping to next command...") |
232 | - | return false |
232 | + | return false |
233 | - | end |
233 | + | end |
234 | - | end |
234 | + | end |
235 | - | until func() |
235 | + | until func() |
236 | - | end |
236 | + | end |
237 | - | end |
237 | + | end |
238 | - | |
238 | + | |
239 | - | return true |
239 | + | return true |
240 | end | |
241 | - | |
241 | + | |
242 | - | function forward(blocks) |
242 | + | function forward(blocks) |
243 | - | return move("f", blocks) |
243 | + | return move("f", blocks) |
244 | end | |
245 | - | |
245 | + | |
246 | - | function right(blocks) |
246 | + | function right(blocks) |
247 | - | turnRight() |
247 | + | turnRight() |
248 | - | local result = move("f", blocks) |
248 | + | local result = move("f", blocks) |
249 | - | turnLeft() |
249 | + | turnLeft() |
250 | - | return result |
250 | + | return result |
251 | end | |
252 | - | |
252 | + | |
253 | - | function left(blocks) |
253 | + | function left(blocks) |
254 | - | turnLeft() |
254 | + | turnLeft() |
255 | - | local result = move("f", blocks) |
255 | + | local result = move("f", blocks) |
256 | - | turnRight() |
256 | + | turnRight() |
257 | - | return result |
257 | + | return result |
258 | end | |
259 | - | |
259 | + | |
260 | - | function back(blocks) |
260 | + | function back(blocks) |
261 | - | if flags["attacking"] or flags["digging"] then |
261 | + | if flags["attacking"] or flags["digging"] then |
262 | - | if math.random(2) == 1 then |
262 | + | if math.random(2) == 1 then |
263 | - | turnRight(2) |
263 | + | turnRight(2) |
264 | - | else |
264 | + | else |
265 | - | turnLeft(2) |
265 | + | turnLeft(2) |
266 | - | end |
266 | + | end |
267 | - | end |
267 | + | end |
268 | - | local result = move((flags["attacking"] or flags["digging"]) and "f" or "b", blocks) |
268 | + | local result = move((flags["attacking"] or flags["digging"]) and "f" or "b", blocks) |
269 | - | if flags["attacking"] or flags["digging"] then |
269 | + | if flags["attacking"] or flags["digging"] then |
270 | - | if math.random(2) == 1 then |
270 | + | if math.random(2) == 1 then |
271 | - | turnRight(2) |
271 | + | turnRight(2) |
272 | - | else |
272 | + | else |
273 | - | turnLeft(2) |
273 | + | turnLeft(2) |
274 | - | end |
274 | + | end |
275 | - | end |
275 | + | end |
276 | - | return result |
276 | + | return result |
277 | end | |
278 | - | |
278 | + | |
279 | - | function up(blocks) |
279 | + | function up(blocks) |
280 | - | return move("u", blocks) |
280 | + | return move("u", blocks) |
281 | end | |
282 | - | |
282 | + | |
283 | - | function down(blocks) |
283 | + | function down(blocks) |
284 | - | return move("d", blocks) |
284 | + | return move("d", blocks) |
285 | end | |
286 | - | |
286 | + | |
287 | - | function place() |
287 | + | function place() |
288 | - | return turtle.place() |
288 | + | return turtle.place() |
289 | end | |
290 | - | |
290 | + | |
291 | - | function placeDown() |
291 | + | function placeDown() |
292 | - | return turtle.placeDown() |
292 | + | return turtle.placeDown() |
293 | end | |
294 | - | |
294 | + | |
295 | - | function placeUp() |
295 | + | function placeUp() |
296 | - | return turtle.placeUp() |
296 | + | return turtle.placeUp() |
297 | end | |
298 | - | |
298 | + | |
299 | - | function placeBack() |
299 | + | function placeBack() |
300 | - | if math.random(2) == 1 then |
300 | + | if math.random(2) == 1 then |
301 | - | turnRight(2) |
301 | + | turnRight(2) |
302 | - | else |
302 | + | else |
303 | - | turnLeft(2) |
303 | + | turnLeft(2) |
304 | - | end |
304 | + | end |
305 | - | local result = turtle.place() |
305 | + | local result = turtle.place() |
306 | - | if math.random(2) == 1 then |
306 | + | if math.random(2) == 1 then |
307 | - | turnRight(2) |
307 | + | turnRight(2) |
308 | - | else |
308 | + | else |
309 | - | turnLeft(2) |
309 | + | turnLeft(2) |
310 | - | end |
310 | + | end |
311 | - | return result |
311 | + | return result |
312 | end | |
313 | - | |
313 | + | |
314 | - | function placeLeft() |
314 | + | function placeLeft() |
315 | - | turnLeft() |
315 | + | turnLeft() |
316 | - | local result = turtle.place() |
316 | + | local result = turtle.place() |
317 | - | turnRight() |
317 | + | turnRight() |
318 | - | return result |
318 | + | return result |
319 | end | |
320 | - | |
320 | + | |
321 | - | function placeRight() |
321 | + | function placeRight() |
322 | - | turnRight() |
322 | + | turnRight() |
323 | - | local result = turtle.place() |
323 | + | local result = turtle.place() |
324 | - | turnLeft() |
324 | + | turnLeft() |
325 | - | return result |
325 | + | return result |
326 | end | |
327 | - | |
327 | + | |
328 | - | function dig() |
328 | + | function dig() |
329 | - | return turtle.dig() |
329 | + | return turtle.dig() |
330 | end | |
331 | - | |
331 | + | |
332 | - | function digUp() |
332 | + | function digUp() |
333 | - | return turtle.digUp() |
333 | + | return turtle.digUp() |
334 | end | |
335 | - | |
335 | + | |
336 | - | function digDown() |
336 | + | function digDown() |
337 | - | return turtle.digDown() |
337 | + | return turtle.digDown() |
338 | end | |
339 | - | |
339 | + | |
340 | - | function digRight() |
340 | + | function digRight() |
341 | - | turnRight() |
341 | + | turnRight() |
342 | - | local result = turtle.dig() |
342 | + | local result = turtle.dig() |
343 | - | turnLeft() |
343 | + | turnLeft() |
344 | - | return result |
344 | + | return result |
345 | end | |
346 | - | |
346 | + | |
347 | - | function digLeft() |
347 | + | function digLeft() |
348 | - | turnLeft() |
348 | + | turnLeft() |
349 | - | local result = turtle.dig() |
349 | + | local result = turtle.dig() |
350 | - | turnRight() |
350 | + | turnRight() |
351 | - | return result |
351 | + | return result |
352 | end | |
353 | - | |
353 | + | |
354 | - | function digBack() |
354 | + | function digBack() |
355 | - | if math.random(2) == 1 then |
355 | + | if math.random(2) == 1 then |
356 | - | turnRight(2) |
356 | + | turnRight(2) |
357 | - | else |
357 | + | else |
358 | - | turnLeft(2) |
358 | + | turnLeft(2) |
359 | - | end |
359 | + | end |
360 | - | local result = turtle.dig() |
360 | + | local result = turtle.dig() |
361 | - | if math.random(2) == 1 then |
361 | + | if math.random(2) == 1 then |
362 | - | turnRight(2) |
362 | + | turnRight(2) |
363 | - | else |
363 | + | else |
364 | - | turnLeft(2) |
364 | + | turnLeft(2) |
365 | - | end |
365 | + | end |
366 | - | return result |
366 | + | return result |
367 | end | |
368 | - | |
368 | + | |
369 | - | local commands = { |
369 | + | local commands = { |
370 | - | ["f"] = forward, ["fd"] = forward, ["forward"] = forward, |
370 | + | ["f"] = forward, ["fd"] = forward, ["forward"] = forward, |
371 | - | ["r"] = right, ["right"] = right, |
371 | + | ["r"] = right, ["right"] = right, |
372 | - | ["l"] = left, ["left"] = left, |
372 | + | ["l"] = left, ["left"] = left, |
373 | - | ["b"] = back, ["back"] = back, |
373 | + | ["b"] = back, ["back"] = back, |
374 | - | ["u"] = up, ["up"] = up, |
374 | + | ["u"] = up, ["up"] = up, |
375 | - | ["d"] = down, ["down"] = down, |
375 | + | ["d"] = down, ["down"] = down, |
376 | - | ["tr"] = turnRight, ["rt"] = turnRight, ["turnright"] = turnRight, |
376 | + | ["tr"] = turnRight, ["rt"] = turnRight, ["turnright"] = turnRight, |
377 | - | ["tl"] = turnLeft, ["lt"] = turnLeft, ["turnleft"] = turnLeft, |
377 | + | ["tl"] = turnLeft, ["lt"] = turnLeft, ["turnleft"] = turnLeft, |
378 | - | ["s"] = select, ["sl"] = select, ["sel"] = select, ["select"] = select, |
378 | + | ["s"] = select, ["sl"] = select, ["sel"] = select, ["select"] = select, |
379 | - | ["p"] = place, ["place"] = place, |
379 | + | ["p"] = place, ["place"] = place, |
380 | - | ["tp"] = togglePlace, ["toggleplace"] = togglePlace, |
380 | + | ["tp"] = togglePlace, ["toggleplace"] = togglePlace, |
381 | - | ["pd"] = placeDown, ["placedown"] = placeDown, |
381 | + | ["pd"] = placeDown, ["placedown"] = placeDown, |
382 | - | ["tpd"] = togglePlaceDown, ["toggleplacedown"] = togglePlaceDown, |
382 | + | ["tpd"] = togglePlaceDown, ["toggleplacedown"] = togglePlaceDown, |
383 | - | ["pu"] = placeUp, ["placeup"] = placeUp, |
383 | + | ["pu"] = placeUp, ["placeup"] = placeUp, |
384 | - | ["tpu"] = togglePlaceUp, ["toggleplaceup"] = togglePlaceUp, |
384 | + | ["tpu"] = togglePlaceUp, ["toggleplaceup"] = togglePlaceUp, |
385 | - | ["pl"] = placeLeft, ["placeleft"] = placeLeft, |
385 | + | ["pl"] = placeLeft, ["placeleft"] = placeLeft, |
386 | - | ["tpl"] = togglePlaceLeft, ["toggleplaceleft"] = togglePlaceLeft, |
386 | + | ["tpl"] = togglePlaceLeft, ["toggleplaceleft"] = togglePlaceLeft, |
387 | - | ["pr"] = placeRight, ["placeright"] = placeRight, |
387 | + | ["pr"] = placeRight, ["placeright"] = placeRight, |
388 | - | ["tpr"] = togglePlaceRight, ["toggleplaceright"] = togglePlaceRight, |
388 | + | ["tpr"] = togglePlaceRight, ["toggleplaceright"] = togglePlaceRight, |
389 | - | ["pb"] = placeBack, ["placeback"] = placeBack, |
389 | + | ["pb"] = placeBack, ["placeback"] = placeBack, |
390 | - | ["tpb"] = togglePlaceBack, ["tpb"] = togglePlaceBack, |
390 | + | ["tpb"] = togglePlaceBack, ["tpb"] = togglePlaceBack, |
391 | - | ["dig"] = dig, |
391 | + | ["dig"] = dig, |
392 | - | ["td"] = toggleDig, ["tdig"] = toggleDig, ["toggledig"] = toggleDig, |
392 | + | ["td"] = toggleDig, ["tdig"] = toggleDig, ["toggledig"] = toggleDig, |
393 | - | ["du"] = digUp, ["digup"] = digUp, |
393 | + | ["du"] = digUp, ["digup"] = digUp, |
394 | - | ["tdu"] = toggleDigUp, ["tdigup"] = toggleDigUp, ["toggledigup"] = toggleDigUp, |
394 | + | ["tdu"] = toggleDigUp, ["tdigup"] = toggleDigUp, ["toggledigup"] = toggleDigUp, |
395 | - | ["dd"] = digDown, ["digdown"] = digDown, |
395 | + | ["dd"] = digDown, ["digdown"] = digDown, |
396 | - | ["tdd"] = toggleDigDown, ["tdigdown"] = toggleDigDown, ["toggledigdown"] = toggleDigDown, |
396 | + | ["tdd"] = toggleDigDown, ["tdigdown"] = toggleDigDown, ["toggledigdown"] = toggleDigDown, |
397 | - | ["dr"] = digRight, ["digright"] = digRight, |
397 | + | ["dr"] = digRight, ["digright"] = digRight, |
398 | - | ["tdr"] = toggleDigRight, ["tdigright"] = toggleDigRight, ["toggledigright"] = toggleDigRight, |
398 | + | ["tdr"] = toggleDigRight, ["tdigright"] = toggleDigRight, ["toggledigright"] = toggleDigRight, |
399 | - | ["dl"] = digLeft, ["digleft"] = digLeft, |
399 | + | ["dl"] = digLeft, ["digleft"] = digLeft, |
400 | - | ["tdl"] = toggleDigLeft, ["tdigleft"] = toggleDigLeft, ["toggledigleft"] = toggleDigLeft, |
400 | + | ["tdl"] = toggleDigLeft, ["tdigleft"] = toggleDigLeft, ["toggledigleft"] = toggleDigLeft, |
401 | - | ["db"] = digBack, ["digback"] = digBack, |
401 | + | ["db"] = digBack, ["digback"] = digBack, |
402 | - | ["ta"] = toggleAttack, ["toggleattack"] = toggleAttack, |
402 | + | ["ta"] = toggleAttack, ["toggleattack"] = toggleAttack, |
403 | - | } |
403 | + | } |
404 | - | |
404 | + | |
405 | - | function shift(t) |
405 | + | function shift(t) |
406 | - | return table.remove(t, 1) |
406 | + | return table.remove(t, 1) |
407 | end | |
408 | - | |
408 | + | |
409 | - | local queue = {} |
409 | + | local queue = {} |
410 | - | |
410 | + | |
411 | - | function join(t, s) |
411 | + | function join(t, s) |
412 | - | local result = "" |
412 | + | local result = "" |
413 | - | for i,v in ipairs(t) do |
413 | + | for i,v in ipairs(t) do |
414 | - | result = result .. v |
414 | + | result = result .. v |
415 | - | if i ~= #t then |
415 | + | if i ~= #t then |
416 | - | result = result .. s |
416 | + | result = result .. s |
417 | - | end |
417 | + | end |
418 | - | end |
418 | + | end |
419 | - | |
419 | + | |
420 | - | return result |
420 | + | return result |
421 | end | |
422 | - | |
422 | + | |
423 | - | function trim(s) |
423 | + | function trim(s) |
424 | - | return (s:gsub("^%s*(.-)%s*$", "%1")) |
424 | + | return (s:gsub("^%s*(.-)%s*$", "%1")) |
425 | end | |
426 | - | |
426 | + | |
427 | - | function capture(s) |
427 | + | function capture(s) |
428 | - | local p = "(%b()) (%d%d?)" |
428 | + | local p = "(%b()) (%d%d?)" |
429 | - | local _,_,group,times = s:find(p) |
429 | + | local _,_,group,times = s:find(p) |
430 | - | |
430 | + | |
431 | - | if not group then |
431 | + | if not group then |
432 | - | return false |
432 | + | return false |
433 | - | end |
433 | + | end |
434 | - | |
434 | + | |
435 | - | local times = tonumber(times) |
435 | + | local times = tonumber(times) |
436 | - | local result = trim( |
436 | + | local result = trim( |
437 | - | s:gsub(p, (group:sub(2, -2) .. " "):rep(times)) |
437 | + | s:gsub(p, (group:sub(2, -2) .. " "):rep(times)) |
438 | - | ) |
438 | + | ) |
439 | - | |
439 | + | |
440 | - | return result |
440 | + | return result |
441 | end | |
442 | - | |
442 | + | |
443 | - | function parse(s) |
443 | + | function parse(s) |
444 | - | local result = s |
444 | + | local result = s |
445 | - | repeat |
445 | + | repeat |
446 | - | result = capture(s) or result |
446 | + | result = capture(s) or result |
447 | - | until not capture(result) |
447 | + | until not capture(result) |
448 | - | |
448 | + | |
449 | - | return result |
449 | + | return result |
450 | end | |
451 | - | |
451 | + | |
452 | - | function validate(name) |
452 | + | function validate(name) |
453 | - | return name and (commands[name] or shell.resolveProgram(name)) |
453 | + | return name and (commands[name] or shell.resolveProgram(name)) |
454 | end | |
455 | - | |
455 | + | |
456 | - | local args = {...} |
456 | + | local args = {...} |
457 | - | local joinedArgs = join(args, " ") |
457 | + | local joinedArgs = join(args, " ") |
458 | - | local unpackedArgs = {} |
458 | + | local unpackedArgs = {} |
459 | - | for word in parse(joinedArgs):gmatch("%S+") do table.insert(unpackedArgs, word) end |
459 | + | for word in parse(joinedArgs):gmatch("%S+") do table.insert(unpackedArgs, word) end |
460 | - | |
460 | + | |
461 | - | while #unpackedArgs ~= 0 do |
461 | + | while #unpackedArgs ~= 0 do |
462 | - | local name = shift(unpackedArgs) |
462 | + | local name = shift(unpackedArgs) |
463 | - | if not validate(name) then |
463 | + | if not validate(name) then |
464 | - | print(name .. " is not a valid program") |
464 | + | print(name .. " is not a valid program") |
465 | - | return |
465 | + | return |
466 | - | end |
466 | + | end |
467 | - | local arg = tonumber(unpackedArgs[1]) |
467 | + | local arg = tonumber(unpackedArgs[1]) |
468 | - | if arg ~= nil then |
468 | + | if arg ~= nil then |
469 | - | shift(unpackedArgs) |
469 | + | shift(unpackedArgs) |
470 | - | end |
470 | + | end |
471 | - | table.insert(queue, { ["name"] = name, ["arg"] = arg }) |
471 | + | table.insert(queue, { ["name"] = name, ["arg"] = arg }) |
472 | end | |
473 | - | |
473 | + | |
474 | - | for i,v in ipairs(queue) do |
474 | + | for i,v in ipairs(queue) do |
475 | - | local name, arg = v.name:lower(), v.arg |
475 | + | local name, arg = v.name:lower(), v.arg |
476 | - | local cmd = commands[name] |
476 | + | local cmd = commands[name] |
477 | - | |
477 | + | |
478 | - | if cmd then |
478 | + | if cmd then |
479 | - | cmd(arg) |
479 | + | cmd(arg) |
480 | - | elseif name then |
480 | + | elseif name then |
481 | - | local resolved = shell.resolveProgram(name) |
481 | + | local resolved = shell.resolveProgram(name) |
482 | - | if resolved then |
482 | + | if resolved then |
483 | - | shell.run(resolved, arg) |
483 | + | shell.run(resolved, arg) |
484 | - | else |
484 | + | else |
485 | - | end |
485 | + | end |
486 | - | end |
486 | + | end |
487 | end |