SHOW:
|
|
- or go back to the newest paste.
1 | --[[function saveVarsToConsole(name) | |
2 | local h = fs.open(name,'w') | |
3 | local env = getfenv() | |
4 | for i,v in pairs(env) do | |
5 | if i then | |
6 | h.write(i) | |
7 | if v then | |
8 | --h.write("("..tostring(type(v))..")") | |
9 | h.write(': ') | |
10 | h.writeLine(v) | |
11 | end | |
12 | end | |
13 | end | |
14 | h.close() | |
15 | end]] | |
16 | ||
17 | function openRednet() | |
18 | for _,v in ipairs(peripheral.getNames()) do | |
19 | if peripheral.getType(v)=="modem" then | |
20 | rednet.open(v) | |
21 | end | |
22 | end | |
23 | end | |
24 | ||
25 | function checkIfRefill() | |
26 | local _,inFront = turtle.inspect() | |
27 | local _,below = turtle.inspectDown() | |
28 | local mem = turtle.getSelectedSlot() | |
29 | turtle.select(16) | |
30 | local check = turtle.getItemDetail() | |
31 | if check and check.name ~= "EnderStorage:enderChest" then | |
32 | if not turtle.dropDown() then | |
33 | if not turtle.drop() then | |
34 | turtle.dropUp() | |
35 | end | |
36 | end | |
37 | end | |
38 | if inFront or below then | |
39 | if inFront.name == "EnderStorage:enderChest" then | |
40 | turtle.select(enderchest1) | |
41 | turtle.dig() | |
42 | end | |
43 | if below.name == "EnderStorage:enderChest" then | |
44 | turtle.select(enderchest2) | |
45 | turtle.digDown() | |
46 | end | |
47 | end | |
48 | turtle.select(mem) | |
49 | end | |
50 | ||
51 | function calibrateDir() | |
52 | - | if gpsi then |
52 | + | --if gpsi then |
53 | local dir | |
54 | local h,k,l = gps.locate() | |
55 | while not turtle.forward() do | |
56 | turtle.dig() | |
57 | end | |
58 | local h2,k2,l2 = gps.locate() | |
59 | turtle.back() | |
60 | if h2>h then | |
61 | dir = "east" | |
62 | elseif h2<h then | |
63 | dir = "west" | |
64 | elseif l2>l then | |
65 | dir = "south" | |
66 | elseif l2<l then | |
67 | dir = "north" | |
68 | end | |
69 | return dir | |
70 | --end | |
71 | end | |
72 | ||
73 | function recalibratePos() | |
74 | local h,k,l = gps.locate() | |
75 | local ytemp,xtemp,ztemp = h - Hoff, k - Koff, l - Loff | |
76 | ||
77 | if origDir == "south" then | |
78 | xnew = 0 + xtemp | |
79 | ynew = ytemp | |
80 | znew = 0 + ztemp | |
81 | elseif origDir == "north" then | |
82 | xnew = 0 - xtemp | |
83 | ynew = ytemp | |
84 | znew = 0 - ztemp | |
85 | elseif origDir == "east" then | |
86 | xnew = 0 - ztemp | |
87 | ynew = ytemp | |
88 | znew = 0 + xtemp | |
89 | elseif origDir == "west" then | |
90 | xnew = 0 + ztemp | |
91 | ynew = ytemp | |
92 | znew = 0 - xtemp | |
93 | end | |
94 | ||
95 | widthPos,heightPos,lengthPos = xnew,ynew,znew | |
96 | end | |
97 | ||
98 | function recalibrateFace() | |
99 | if origDir ~= "south" then | |
100 | if origDir == "north" then | |
101 | update("right") | |
102 | update("right") | |
103 | elseif origDir == "east" then | |
104 | update("right") | |
105 | elseif origDir == "west" then | |
106 | update("left") | |
107 | end | |
108 | end | |
109 | end | |
110 | ||
111 | function resynchronize() | |
112 | recalibratePos() | |
113 | face = calibrateDir() | |
114 | recalibrateFace() | |
115 | recordPos(heightPos,widthPos,lengthPos,face) | |
116 | end | |
117 | ||
118 | function saveVarsToFile() | |
119 | local h = fs.open("currentVars",'w') | |
120 | local env = getfenv() | |
121 | for i,v in pairs(env) do | |
122 | if type(v) == "string" then | |
123 | h.write(tostring(i)) | |
124 | h.write(" = ") | |
125 | h.write([["]]..tostring(v)..[["]]) | |
126 | elseif type(v) == "table" then | |
127 | h.write(i) | |
128 | h.write(" = ") | |
129 | h.write(textutils.serialize(v)) | |
130 | end | |
131 | end | |
132 | h.close() | |
133 | end | |
134 | ||
135 | function loadVars() | |
136 | local h = fs.open("currentVars",'r') | |
137 | end | |
138 | ||
139 | function recordPos(heightPos,widthPos,lengthPos,face) | |
140 | local h = fs.open("position","w") | |
141 | h.writeLine("heightPos = "..tostring(heightPos)) | |
142 | h.writeLine("widthPos = "..tostring(widthPos)) | |
143 | h.writeLine("lengthPos = "..tostring(lengthPos)) | |
144 | h.writeLine("face = ".."\""..tostring(face).."\"") | |
145 | h.close() | |
146 | end | |
147 | ||
148 | function recordObj(x,y,z) | |
149 | local h = fs.open("objective",'w') | |
150 | h.writeLine("x = "..tostring(x)) | |
151 | h.writeLine("y = "..tostring(y)) | |
152 | h.writeLine("z = "..tostring(z)) | |
153 | h.close() | |
154 | end | |
155 | ||
156 | block_id = {} | |
157 | block_id[0] = "Air" | |
158 | block_id[1] = "Stone" | |
159 | block_id[2] = "Grass" | |
160 | block_id[3] = "Dirt" | |
161 | block_id[4] = "Cobblestone" | |
162 | block_id[5] = "Wooden Plank" | |
163 | block_id[6] = "Sapling" | |
164 | block_id[7] = "Bedrock" | |
165 | block_id[8] = "Water" | |
166 | block_id[9] = "Stationary water" | |
167 | block_id[10] = "Lava" | |
168 | block_id[11] = "Stationary lava" | |
169 | block_id[12] = "Sand" | |
170 | block_id[13] = "Gravel" | |
171 | block_id[14] = "Gold Ore" | |
172 | block_id[15] = "Iron (Ore)" | |
173 | block_id[16] = "Coal Ore" | |
174 | block_id[17] = "Log" | |
175 | block_id[18] = "Leaves" | |
176 | block_id[19] = "Sponge" | |
177 | block_id[20] = "Glass" | |
178 | block_id[21] = "Lapis Lazuli (Ore)" | |
179 | block_id[22] = "Lapis Lazuli (Block)" | |
180 | block_id[23] = "Dispenser" | |
181 | block_id[24] = "Sandstone" | |
182 | block_id[25] = "Note Block Tile entity" | |
183 | block_id[26] = "Bed" | |
184 | block_id[27] = "Powered Rail " | |
185 | block_id[28] = "Detector Rail " | |
186 | block_id[29] = "Sticky Piston" | |
187 | block_id[30] = "Cobweb" | |
188 | block_id[31] = "Tall Grass" | |
189 | block_id[32] = "Dead Bush" | |
190 | block_id[33] = "Piston" | |
191 | block_id[34] = "Piston Extension" | |
192 | block_id[35] = "Wool" | |
193 | block_id[36] = "Block moved by Piston" | |
194 | block_id[37] = "Dandelionandelion" | |
195 | block_id[38] = "Rose" | |
196 | block_id[39] = "Brown Mushroom" | |
197 | block_id[40] = "Red Mushroom" | |
198 | block_id[41] = "Block of Gold" | |
199 | block_id[42] = "Block of Iron" | |
200 | block_id[43] = "Double Slabs" | |
201 | block_id[44] = "Slabs" | |
202 | block_id[45] = "Brick Block" | |
203 | block_id[46] = "TNT" | |
204 | block_id[47] = "Bookshelf" | |
205 | block_id[48] = "Moss Stone" | |
206 | block_id[49] = "Obsidian" | |
207 | block_id[50] = "Torch" | |
208 | block_id[51] = "Fire" | |
209 | block_id[52] = "Monster Spawner" | |
210 | block_id[53] = "Wooden Stairs" | |
211 | block_id[54] = "Chest" | |
212 | block_id[55] = "Redstone (Wire)" | |
213 | block_id[56] = "Diamond (Ore)" | |
214 | block_id[57] = "Block of Diamond" | |
215 | block_id[58] = "Crafting Table" | |
216 | block_id[59] = "Seeds" | |
217 | block_id[60] = "Farland" | |
218 | block_id[61] = "Furnace" | |
219 | block_id[62] = "Burning Furnace" | |
220 | block_id[63] = "Sign Post" | |
221 | block_id[64] = "Wooden Door" | |
222 | block_id[65] = "Ladders" | |
223 | block_id[66] = "Rails" | |
224 | block_id[67] = "Cobblestone Stairs" | |
225 | block_id[68] = "Wall Sign" | |
226 | block_id[69] = "Lever" | |
227 | block_id[70] = "Stone Pressure Plate" | |
228 | block_id[71] = "Iron Door" | |
229 | block_id[72] = "Wooden Pressure Plates" | |
230 | block_id[73] = "Redstone Ore" | |
231 | block_id[74] = "Glowing Redstone Ore" | |
232 | block_id[75] = "Redstone Torch" | |
233 | block_id[76] = "Redstone Torch" | |
234 | block_id[77] = "Stone Button " | |
235 | block_id[78] = "Snow" | |
236 | block_id[79] = "Ice" | |
237 | block_id[80] = "Snow Block" | |
238 | block_id[81] = "Cactus" | |
239 | block_id[82] = "Clay (Block)" | |
240 | block_id[83] = "Sugar Cane" | |
241 | block_id[84] = "Jukebox" | |
242 | block_id[85] = "Fence" | |
243 | block_id[86] = "Pumpkin" | |
244 | block_id[87] = "Netherrack" | |
245 | block_id[88] = "Soul Sand" | |
246 | block_id[89] = "Glowstone" | |
247 | block_id[90] = "Portal" | |
248 | block_id[91] = "Jack-O-Lantern" | |
249 | block_id[92] = "Cake Block" | |
250 | block_id[93] = "Redstone Repeater" | |
251 | block_id[94] = "Redstone Repeater" | |
252 | block_id[95] = "Locked Chest" | |
253 | block_id[96] = "Trapdoors" | |
254 | block_id[97] = "Hidden Silverfish" | |
255 | block_id[98] = "Stone Brick" | |
256 | block_id[99] = "Huge brown and red mushroom" | |
257 | block_id[100] = "Huge brown and red mushroom" | |
258 | block_id[101] = "Iron Bars" | |
259 | block_id[102] = "Glass Pane" | |
260 | block_id[103] = "Melon" | |
261 | block_id[104] = "Pumpkin Stem" | |
262 | block_id[105] = "Melon Stem" | |
263 | block_id[106] = "Vines" | |
264 | block_id[107] = "Fence Gate" | |
265 | block_id[108] = "Brick Stairs" | |
266 | block_id[109] = "Stone Brick Stairs" | |
267 | block_id[110] = "Mycelium" | |
268 | block_id[111] = "Lily Pad" | |
269 | block_id[112] = "Nether Brick" | |
270 | block_id[113] = "Nether Brick Fence" | |
271 | block_id[114] = "Nether Brick Stairs" | |
272 | block_id[115] = "Nether Wart" | |
273 | block_id[116] = "Enchantment Table" | |
274 | block_id[117] = "Brewing Stand" | |
275 | block_id[118] = "Cauldron" | |
276 | block_id[119] = "End Portal" | |
277 | block_id[120] = "End Portal Frame" | |
278 | block_id[121] = "End Stone " | |
279 | block_id[256] = "Iron Ingotron Shovel" | |
280 | block_id[257] = "Iron Pickaxe" | |
281 | block_id[258] = "Iron Axe" | |
282 | block_id[259] = "Flint and Steel" | |
283 | block_id[260] = "Red Apple" | |
284 | block_id[261] = "Bow" | |
285 | block_id[262] = "Arrow" | |
286 | block_id[263] = "Coal" | |
287 | ||
288 | woolColors = {} | |
289 | woolColors[0] = "White" | |
290 | woolColors[1] = "Orange" | |
291 | woolColors[2] = "Magenta" | |
292 | woolColors[3] = "Light Blue" | |
293 | woolColors[4] = "Yellow" | |
294 | woolColors[5] = "Lime" | |
295 | woolColors[6] = "Pink" | |
296 | woolColors[7] = "Gray" | |
297 | woolColors[8] = "Light Gray" | |
298 | woolColors[9] = "Cyan" | |
299 | woolColors[10] = "Purple" | |
300 | woolColors[11] = "Blue" | |
301 | woolColors[12] = "Brown" | |
302 | woolColors[13] = "Green" | |
303 | woolColors[14] = "Red" | |
304 | woolColors[15] = "Black" | |
305 | ||
306 | --[[Navigation Functions]]-- | |
307 | ||
308 | function goto(heightGoal,widthGoal,lengthGoal) | |
309 | shell.run("position") | |
310 | if turtle.getFuelLevel() < 200 then | |
311 | refill() | |
312 | end | |
313 | if heightGoal > heightPos then | |
314 | while heightGoal > heightPos do | |
315 | up() | |
316 | end | |
317 | elseif heightGoal < heightPos then | |
318 | while heightGoal < heightPos do | |
319 | down() | |
320 | end | |
321 | end | |
322 | if widthGoal > widthPos then | |
323 | turn("east") | |
324 | while widthGoal > widthPos do | |
325 | forward() | |
326 | end | |
327 | elseif widthGoal < widthPos then | |
328 | turn("west") | |
329 | while widthGoal < widthPos do | |
330 | forward() | |
331 | end | |
332 | end | |
333 | if lengthGoal > lengthPos then | |
334 | turn("south") | |
335 | while lengthGoal > lengthPos do | |
336 | forward() | |
337 | end | |
338 | elseif lengthGoal < lengthPos then | |
339 | turn("north") | |
340 | while lengthGoal < lengthPos do | |
341 | forward() | |
342 | end | |
343 | end | |
344 | end | |
345 | ||
346 | function update(dir) | |
347 | if dir == "forward" then | |
348 | if face == "north" then | |
349 | lengthPos = lengthPos - 1 | |
350 | elseif face == "south" then | |
351 | lengthPos = lengthPos + 1 | |
352 | elseif face == "west" then | |
353 | widthPos = widthPos - 1 | |
354 | elseif face == "east" then | |
355 | widthPos = widthPos + 1 | |
356 | end | |
357 | elseif dir == "backward" then | |
358 | if face == "north" then | |
359 | lengthPos = lengthPos + 1 | |
360 | elseif face == "south" then | |
361 | lengthPos = lengthPos - 1 | |
362 | elseif face == "west" then | |
363 | widthPos = widthPos + 1 | |
364 | elseif face == "east" then | |
365 | widthPos = widthPos - 1 | |
366 | end | |
367 | elseif dir == "up" then | |
368 | heightPos = heightPos + 1 | |
369 | elseif dir == "down" then | |
370 | heightPos = heightPos - 1 | |
371 | elseif dir == "right" then | |
372 | if face == "north" then | |
373 | face = "east" | |
374 | elseif face == "east" then | |
375 | face = "south" | |
376 | elseif face == "south" then | |
377 | face = "west" | |
378 | elseif face == "west" then | |
379 | face = "north" | |
380 | end | |
381 | elseif dir == "left" then | |
382 | if face == "north" then | |
383 | face = "west" | |
384 | elseif face == "west" then | |
385 | face = "south" | |
386 | elseif face == "south" then | |
387 | face = "east" | |
388 | elseif face == "east" then | |
389 | face = "north" | |
390 | end | |
391 | end | |
392 | recordPos(heightPos,widthPos,lengthPos,face) | |
393 | end | |
394 | ||
395 | --[[Refill Functions]]-- | |
396 | ||
397 | function scanInv() | |
398 | local invList = {} | |
399 | for i = 1,16 do | |
400 | turtle.select(i) | |
401 | local item = turtle.getItemDetail() | |
402 | if item then | |
403 | invList[i] = {} | |
404 | invList[i][item.name] = item.damage | |
405 | end | |
406 | end | |
407 | return invList | |
408 | end | |
409 | ||
410 | function ParseInv() | |
411 | turtle.select(16) | |
412 | turtle.dropUp() | |
413 | while turtle.suck() do | |
414 | local item = turtle.getItemDetail() | |
415 | for i =1,16 do | |
416 | if invList[i][item.name] then | |
417 | if invList[i][item.name] == item.damage then | |
418 | turtle.transferTo(i) | |
419 | break | |
420 | end | |
421 | end | |
422 | if item.name == "minecraft:lava_bucket" or item.name == "minecraft:coal" then | |
423 | turtle.refuel(64) | |
424 | end | |
425 | end | |
426 | turtle.dropUp() | |
427 | end | |
428 | end | |
429 | ||
430 | function refill() | |
431 | local mem = turtle.getSelectedSlot() | |
432 | chester("set") | |
433 | ParseInv() | |
434 | chester("gather") | |
435 | turtle.select(mem) | |
436 | end | |
437 | ||
438 | function chester(action) | |
439 | --action = 'set' or 'gather' | |
440 | if action == "set" then | |
441 | turtle.select(tonumber(enderchest1)) | |
442 | turtle.place() | |
443 | turtle.select(tonumber(enderchest2)) | |
444 | turtle.placeUp() | |
445 | elseif action == "gather" then | |
446 | if tonumber(chestOrder) == 1 then | |
447 | turtle.select(tonumber(enderchest1)) | |
448 | turtle.digUp() | |
449 | turtle.select(tonumber(enderchest2)) | |
450 | turtle.dig() | |
451 | chestOrder = 2 | |
452 | elseif tonumber(chestOrder) == 2 then | |
453 | turtle.select(tonumber(enderchest1)) | |
454 | turtle.dig() | |
455 | turtle.select(tonumber(enderchest2)) | |
456 | turtle.digUp() | |
457 | chestOrder = 1 | |
458 | end | |
459 | end | |
460 | end | |
461 | ||
462 | function getBlockName(id, blockData) | |
463 | blockData = blockData or nil | |
464 | if(block_id[id] == nil) then | |
465 | return "ID: "..tostring(id)..", Data: "..tostring(blockData) | |
466 | else | |
467 | if(blockData) then | |
468 | if(id == 35) then | |
469 | str = woolColors[blockData] .. " " .. block_id[id] | |
470 | return str | |
471 | end | |
472 | end | |
473 | return block_id[id] | |
474 | end | |
475 | end | |
476 | ||
477 | function getBlockId(x,y,z) | |
478 | return blocks[y + z*width + x*length*width + 1] | |
479 | end | |
480 | ||
481 | function getData(x,y,z) | |
482 | return data[y + z*width + x*length*width + 1] | |
483 | end | |
484 | ||
485 | function readbytes(handle, n) | |
486 | for i=1,n do | |
487 | handle.read() | |
488 | end | |
489 | end | |
490 | ||
491 | function readname(handle) | |
492 | n1 = handle.read() | |
493 | n2 = handle.read() | |
494 | ||
495 | if(n1 == nil or n2 == nil) then | |
496 | return "" | |
497 | end | |
498 | ||
499 | n = n1*256 + n2 | |
500 | ||
501 | str = "" | |
502 | for i=1,n do | |
503 | c = handle.read() | |
504 | if c == nil then | |
505 | return | |
506 | end | |
507 | str = str .. string.char(c) | |
508 | end | |
509 | return str | |
510 | end | |
511 | ||
512 | function parse(a, handle, containsName) | |
513 | containsName = containsName or true | |
514 | if a==0 then | |
515 | return | |
516 | end | |
517 | if containsName then | |
518 | name = readname(handle) | |
519 | end | |
520 | ||
521 | if a==1 then | |
522 | readbytes(handle,1) | |
523 | elseif a==2 then | |
524 | i1 = handle.read() | |
525 | i2 = handle.read() | |
526 | i = i1*256 + i2 | |
527 | if(name=="Height") then | |
528 | height = i | |
529 | elseif (name=="Length") then | |
530 | length = i | |
531 | elseif (name=="Width") then | |
532 | width = i | |
533 | end | |
534 | elseif a==3 then | |
535 | readbytes(handle,4) | |
536 | elseif a==4 then | |
537 | readbytes(handle,8) | |
538 | elseif a==5 then | |
539 | readbytes(handle,4) | |
540 | elseif a==6 then | |
541 | readbytes(handle,8) | |
542 | elseif a==7 then | |
543 | i1 = handle.read() | |
544 | i2 = handle.read() | |
545 | i3 = handle.read() | |
546 | i4 = handle.read() | |
547 | i = i1*256*256*256 + i2*256*256 + i3*256 + i4 | |
548 | if name == "Blocks" then | |
549 | for i=1,i do | |
550 | table.insert(blocks, handle.read()) | |
551 | end | |
552 | elseif name == "Data" then | |
553 | for i=1,i do | |
554 | table.insert(data, handle.read()) | |
555 | end | |
556 | else | |
557 | readbytes(handle,i) | |
558 | end | |
559 | elseif a==8 then | |
560 | i1 = handle.read() | |
561 | i2 = handle.read() | |
562 | i = i1*256 + i2 | |
563 | readbytes(handle,i) | |
564 | elseif a==9 then | |
565 | --readbytes(handle,5) | |
566 | type = handle.read() | |
567 | i1 = handle.read() | |
568 | i2 = handle.read() | |
569 | i3 = handle.read() | |
570 | i4 = handle.read() | |
571 | i = i1*256*256*256 + i2*256*256 + i3*256 + i4 | |
572 | for j=1,i do | |
573 | parse(handle.read(), handle, false) | |
574 | end | |
575 | end | |
576 | end | |
577 | ||
578 | --[[Movement Functions]]-- | |
579 | ||
580 | function forward() | |
581 | update("forward") | |
582 | while not turtle.forward() do | |
583 | turtle.dig() | |
584 | end | |
585 | end | |
586 | ||
587 | function up() | |
588 | update("up") | |
589 | while not turtle.up() do | |
590 | turtle.digUp() | |
591 | end | |
592 | end | |
593 | ||
594 | function down() | |
595 | update("down") | |
596 | while not turtle.down() do | |
597 | turtle.digDown() | |
598 | end | |
599 | end | |
600 | ||
601 | function right() | |
602 | update("right") | |
603 | turtle.turnRight() | |
604 | end | |
605 | ||
606 | function left() | |
607 | update("left") | |
608 | turtle.turnLeft() | |
609 | end | |
610 | ||
611 | function turn(dir) | |
612 | if face == "north" then | |
613 | if dir == "east" then | |
614 | while face ~= dir do | |
615 | right() | |
616 | end | |
617 | else | |
618 | while face ~= dir do | |
619 | left() | |
620 | end | |
621 | end | |
622 | elseif face == "east" then | |
623 | if dir == "south" then | |
624 | while face ~= dir do | |
625 | right() | |
626 | end | |
627 | else | |
628 | while face ~= dir do | |
629 | left() | |
630 | end | |
631 | end | |
632 | elseif face == "south" then | |
633 | if dir == "west" then | |
634 | while face ~= dir do | |
635 | right() | |
636 | end | |
637 | else | |
638 | while face ~= dir do | |
639 | left() | |
640 | end | |
641 | end | |
642 | elseif face == "west" then | |
643 | if dir == "north" then | |
644 | while face ~= dir do | |
645 | right() | |
646 | end | |
647 | else | |
648 | while face ~= dir do | |
649 | left() | |
650 | end | |
651 | end | |
652 | end | |
653 | end | |
654 | ||
655 | function place() | |
656 | while not turtle.placeDown() do | |
657 | turtle.digDown() | |
658 | end | |
659 | return true | |
660 | end | |
661 | ||
662 | --[[Working Functions]]-- | |
663 | ||
664 | function setup() | |
665 | a = 0 | |
666 | while (a ~= nil) do | |
667 | a = handle.read() | |
668 | parse(a, handle) | |
669 | end | |
670 | ||
671 | write("length: " .. length) | |
672 | write(" width: " .. width) | |
673 | write(" height: " .. height .. "\n") | |
674 | ||
675 | uniqueblocks={} | |
676 | for i,v in ipairs(blocks) do | |
677 | found = false | |
678 | for j,w in ipairs(uniqueblocks) do | |
679 | -- for now, data is only accounted for when the block is wool | |
680 | if (w.blockID==v and (w.data==data[i] or w.blockID ~= 35)) then | |
681 | found = true | |
682 | w.amount = w.amount + 1 | |
683 | break | |
684 | end | |
685 | end | |
686 | ||
687 | if found==false then | |
688 | uniqueblocks[#uniqueblocks+1] = {} | |
689 | uniqueblocks[#uniqueblocks].blockID = v | |
690 | uniqueblocks[#uniqueblocks].data = data[i] | |
691 | uniqueblocks[#uniqueblocks].amount = 1 | |
692 | end | |
693 | end | |
694 | ||
695 | print("number of block types: " .. #uniqueblocks) | |
696 | for i,v in ipairs(uniqueblocks) do | |
697 | if (i%9)==0 then | |
698 | read() | |
699 | end | |
700 | print(" -" .. getBlockName(v.blockID, v.data) .. ": " .. v.amount) | |
701 | end | |
702 | ||
703 | read() | |
704 | ||
705 | print("Give the numbers of all slots containing the specified block type:") | |
706 | ||
707 | slots={} | |
708 | for i,block in ipairs(uniqueblocks) do | |
709 | blockData = block.data | |
710 | print(" -in which slots is " .. getBlockName(block.blockID, blockData) .. "?") | |
711 | if not slots[block.blockID] then | |
712 | slots[block.blockID] = {} | |
713 | end | |
714 | slots[block.blockID][blockData] = {} | |
715 | write(" ") | |
716 | str = read() | |
717 | for i = 1, #str do | |
718 | local c = str:sub(i,i) | |
719 | n = tonumber(c) | |
720 | if(n) then | |
721 | if(n>0 and n<10) then | |
722 | table.insert(slots[block.blockID][blockData], n) | |
723 | end | |
724 | end | |
725 | end | |
726 | end | |
727 | invList = scanInv() | |
728 | end | |
729 | ||
730 | function run() | |
731 | print("Press key to start building...") | |
732 | read() | |
733 | --invList = scanInv() | |
734 | ||
735 | up() | |
736 | n = 1 | |
737 | turtle.select(n) | |
738 | ||
739 | for x=1,height do | |
740 | for y=1,width do | |
741 | for z=1,length do | |
742 | blockID = getBlockId(x-1,y-1,z-1) | |
743 | blockData = getData(x-1,y-1,z-1) | |
744 | forward() | |
745 | turtle.digDown() | |
746 | slot_lst = slots[blockID][blockData] | |
747 | if(slot_lst ~= nil) then | |
748 | if(#slot_lst > 0) then | |
749 | local found=false | |
750 | for i,v in ipairs(slot_lst) do | |
751 | if(turtle.getItemCount(v) > 0) then | |
752 | found=true | |
753 | turtle.select(v) | |
754 | break | |
755 | end | |
756 | end | |
757 | if not found then | |
758 | print("Not enough " .. getBlockName(blockID, blockData) .. ". Please refill...") | |
759 | refill() | |
760 | end | |
761 | while turtle.getItemCount() == 0 do | |
762 | refill() | |
763 | end | |
764 | if turtle.getFuelLevel() < 200 then | |
765 | refill() | |
766 | end | |
767 | end | |
768 | end | |
769 | end | |
770 | left() | |
771 | forward() | |
772 | left() | |
773 | for i=1,length do | |
774 | forward() | |
775 | end | |
776 | right() | |
777 | right() | |
778 | end | |
779 | right() | |
780 | for i=1,width do | |
781 | forward() | |
782 | end | |
783 | left() | |
784 | up() | |
785 | end | |
786 | ||
787 | for i=1,height+1 do | |
788 | down() | |
789 | end | |
790 | end | |
791 | ||
792 | function findNextBlock(x,y,z) | |
793 | blockID = getBlockId(x,y,z) | |
794 | blockData = getData(x,y,z) | |
795 | if blockID then | |
796 | slot_lst = slots[blockID][blockData] | |
797 | if(slot_lst ~= nil) then | |
798 | if(#slot_lst > 0) then | |
799 | local found=false | |
800 | for i,v in ipairs(slot_lst) do | |
801 | if(turtle.getItemCount(v) > 0) then | |
802 | found=true | |
803 | turtle.select(v) | |
804 | break | |
805 | end | |
806 | end | |
807 | if not found then | |
808 | print("Not enough " .. getBlockName(blockID, blockData) .. ". Please refill...") | |
809 | refill() | |
810 | end | |
811 | while turtle.getItemCount() == 0 do | |
812 | refill() | |
813 | end | |
814 | local doubleCheck = turtle.getItemDetail() | |
815 | if doubleCheck.name ~= "EnderStorage:enderChest" then | |
816 | place() | |
817 | else | |
818 | findNextBlock(x,y,z) | |
819 | end | |
820 | end | |
821 | if turtle.getFuelLevel() < 200 then | |
822 | refill() | |
823 | end | |
824 | end | |
825 | end | |
826 | end | |
827 | ||
828 | function oldIterate() | |
829 | --x,y,z = height,width,length | |
830 | if z < length then | |
831 | z = z + 1 | |
832 | elseif z == length then | |
833 | z = 0 | |
834 | if y < width then | |
835 | y = y + 1 | |
836 | elseif y == width then | |
837 | y = 0 | |
838 | if x < height then | |
839 | x = x + 1 | |
840 | elseif x == height then | |
841 | x = 'max' | |
842 | y = 'max' | |
843 | z = 'max' | |
844 | end | |
845 | end | |
846 | end | |
847 | recordObj(x,y,z) | |
848 | end | |
849 | ||
850 | function check() | |
851 | if x%2==0 then | |
852 | evenx = true | |
853 | if y%2==0 then | |
854 | eveny = true | |
855 | else | |
856 | eveny = false | |
857 | end | |
858 | else | |
859 | evenx = false | |
860 | if y%2==0 then | |
861 | eveny = false | |
862 | else | |
863 | eveny = true | |
864 | end | |
865 | end | |
866 | end | |
867 | ||
868 | function iterate() | |
869 | check() | |
870 | if z == length and eveny then | |
871 | Yiterate() | |
872 | elseif z==length and (not eveny) then | |
873 | z = z - 1 | |
874 | elseif z == 0 and eveny then | |
875 | z = z + 1 | |
876 | elseif z == 0 and (not eveny) then | |
877 | Yiterate() | |
878 | elseif z < length then | |
879 | if eveny then | |
880 | z = z + 1 | |
881 | else | |
882 | z = z - 1 | |
883 | end | |
884 | end | |
885 | end | |
886 | ||
887 | function Yiterate() | |
888 | if evenx then | |
889 | if y < width then | |
890 | y = y + 1 | |
891 | elseif y == width then | |
892 | if x < height then | |
893 | x = x + 1 | |
894 | end | |
895 | end | |
896 | else | |
897 | if y == 0 then | |
898 | if x < height then | |
899 | x = x + 1 | |
900 | end | |
901 | else | |
902 | y=y-1 | |
903 | end | |
904 | end | |
905 | end | |
906 | ||
907 | function checkIfAir() | |
908 | while true do | |
909 | iterate() | |
910 | blockID2 = getBlockId(x,y,z) | |
911 | blockData2 = getData(x,y,z) | |
912 | slot_2nd = slots[blockID2][blockData2] | |
913 | if slot_2nd then | |
914 | if #slot_2nd > 0 then | |
915 | recordObj(x,y,z) | |
916 | break | |
917 | end | |
918 | end | |
919 | end | |
920 | end | |
921 | ||
922 | function autorun() | |
923 | --get the current coords | |
924 | --get the iterater/goal block location | |
925 | while true do | |
926 | shell.run("position") | |
927 | shell.run("objective") | |
928 | goto(x,y,z) | |
929 | findNextBlock(x,y,z) | |
930 | checkIfAir() | |
931 | end | |
932 | end |