· 4 years ago · Jan 13, 2021, 11:18 PM
1version = 20210106.1516
2--[[
3 **********Toolkit v2**********
4 https://pastebin.com/UFvjc1bw
5 Last edited: see version YYYYMMDD.HHMM
6 if NOT online:
7 Make sure you create a folder 'lib' and place menu.lua and clsTurtle.lua into it
8 else
9 lib folder will be created and files obtained automatically!
10 end
11]]
12
13args = {...} -- eg "farm", "tree"
14
15local menu, T
16
17function checkFuelNeeded(quantity)
18 local fuelNeeded = quantity - turtle.getFuelLevel() -- eg 600
19 if fuelNeeded > 0 then
20 T:checkInventoryForItem({"minecraft:lava_bucket", "minecraft:coal", "minecraft:planks"}, {1, math.ceil(fuelNeeded / 60), math.ceil(fuelNeeded / 15)}) -- 0 if not present
21 end
22end
23
24function checkLabel()
25 if os.getComputerLabel() == nil then
26 os.setComputerLabel("toolkit")
27 print("Computer label set to "..os.getComputerLabel())
28 end
29end
30
31function checkLibs(libDir, filename)
32 local fileExists = false
33 if fs.exists(libDir) then
34 if not fs.isDir(libDir) then
35 fs.move(libDir, libDir.."Renamed")
36 fs.makeDir(libDir)
37 end
38 else
39 fs.makeDir(libDir)
40 end
41 if fs.exists(fs.combine(libDir, filename)) or fs.exists(fs.combine(libDir, filename..".lua")) then
42 fileExists = true
43 end
44 return fileExists
45end
46
47function clearArea(width, length, useDirt)
48 if useDirt == nil then
49 useDirt = true
50 end
51 local evenWidth = false
52 local evenHeight = false
53 local loopWidth
54 -- go(path, useTorch, torchInterval, leaveExisting)
55 if width % 2 == 0 then
56 evenWidth = true
57 loopWidth = width / 2
58 else
59 loopWidth = math.ceil(width / 2)
60 end
61 if length % 2 == 0 then
62 evenHeight = true
63 end
64 -- clear an area between 2 x 4 and 32 x 32
65 -- if width is even no, then complete the up/down run
66 -- if width odd no then finish at top of up run and reverse
67 -- should be on flat ground, check voids below, harvest trees
68 for x = 1, loopWidth do
69 -- Clear first column (up)
70 for y = 1, length do
71 if useDirt then
72 if not turtle.detectDown() then
73 T:place("minecraft:dirt", -1, "down", true)
74 else --if not water, dirt, grass , stone then replace with dirt
75 blockType, blockModifier = T:getBlockType("down")
76 if blockType ~= "" then
77 if blockType ~= "minecraft:dirt" and blockType ~= "minecraft:grass_block" then
78 turtle.digDown()
79 T:place("minecraft:dirt", -1, "down", true)
80 end
81 end
82 end
83 end
84 blockType, blockModifier = T:getBlockType("forward")
85 if blockType ~= "" then
86 if string.find(blockType, "log") ~= nil then -- tree in front, so harvest it
87 T:harvestTree() --automatically moves forward 1 block
88 if y == length then -- move back 1 if already at max length
89 T:back(1)
90 end
91 else
92 if y < length then
93 T:go("F1+1", false,0,false)
94 end
95 end
96 else
97 if y < length then
98 T:go("F1+1", false,0,false)
99 end
100 end
101 end
102 -- clear second column (down)
103 if x < loopWidth or (x == loopWidth and evenWidth) then -- go down if on width 2,4,6,8 etc
104 T:go("R1F1+1R1", false,0,false)
105 for y = 1, length do
106 if useDirt then
107 if not turtle.detectDown() then
108 T:place("minecraft:dirt", -1, "down", true)
109 else
110 blockType, blockModifier = T:getBlockType("down")
111 if blockType ~= "" then
112 if blockType ~= "minecraft:dirt" and blockType ~= "minecraft:grass_block" then
113 turtle.digDown()
114 T:place("minecraft:dirt", -1, "down", true)
115 end
116 end
117 end
118 end
119 blockType, blockModifier = T:getBlockType("forward")
120 if blockType ~= "" then
121 if string.find(blockType, "log") ~= nil then -- tree in front, so harvest it
122 T:harvestTree()
123 if y == length then
124 T:back(1)
125 end
126 else
127 if y < length then
128 T:go("F1+1", false,0,false)
129 end
130 end
131 else
132 if y < length then
133 T:go("F1+1", false,0,false)
134 end
135 end
136 end
137 if x < loopWidth then
138 T:go("L1F1+1L1", false,0,false)
139 else
140 T:turnRight(1)
141 T:forward(width - 1)
142 T:turnRight(1)
143 end
144 else -- equals width but is 1,3,5,7 etc
145 T:turnLeft(2) --turn round 180
146 T:forward(length - 1)
147 T:turnRight(1)
148 T:forward(width - 1)
149 T:turnRight(1)
150 end
151 end
152end
153
154function clearBuilding(width, length, height, direction, withCeiling, withFloor)
155 -- direction = Bottom->Top (0), Top->bottom(1)
156 if (direction == 0 and withFloor) or (direction == 1 and withCeiling) then
157 --clear floor/ceiling
158 clearRectangle(width, length)
159 else --perimeter only
160 clearPerimeterWall(width, length, 1)
161 end
162 if direction == 0 then -- bottom to top
163 T:up(1)
164 else
165 T:down(1)
166 end
167 clearPerimeterWall(width, length, height - 2, direction) -- if height set to 0, will auto find top
168 if direction == 0 and withCeiling then
169 --clear ceiling
170 T:up(1)
171 clearRectangle(width, length)
172 elseif direction == 1 and withFloor then
173 --clear floor
174 T:down(1)
175 clearRectangle(width, length)
176 else --perimeter only
177 clearPerimeterWall(width, length, 1)
178 end
179 if direction == 0 then -- bottom to top
180 T:down(height - 1)
181 else
182 T:up(height - 1)
183 end
184end
185
186function clearMonumentLayer(width, length, size)
187 local extend = true
188 if size == 0 then
189 extend = false
190 end
191 -- send turtle down until it hits bottom
192 -- then clear rectangle of given size
193 -- start above water, usually on cobble scaffold above monument
194 if T:detect("down") then -- in case not over wall
195 T:forward(1)
196 end
197 height = 1
198 -- go down until solid block detected
199 while clearVegetation("down") do
200 T:down(1)
201 height = height + 1
202 end
203 T:down(1)
204 height = height + 1
205 clearRectangle(width, length, extend)
206 T:up(height - 1)
207end
208
209function clearSeaweed(width, length)
210 -- move over water
211 T:clear()
212 print("Checking water length")
213 while not clearVegetation("down") do
214 T:forward(1)
215 end
216 local odd = false
217 local calcLength = 0
218 while clearVegetation("down") do
219 T:forward(1)
220 calcLength = calcLength + 1
221 end
222 -- now check on correct side: wall to the right
223 print("Checking position")
224 T:go("R2F1R1F1") -- over ? wall
225 if clearVegetation("down") then -- over water, so return to start on correct side
226 T:go("R2F1R1F"..calcLength - 1 .."R2")
227 else
228 T:go("R2F1R1") -- over water
229 end
230 if calcLength % 2 == 1 then
231 odd = true
232 end
233 local forward = true
234 --print("calcLength:"..calcLength.. " odd:"..tostring(odd))
235 for w = 1, width do
236 for l = 1, calcLength, 2 do -- 1,3,5,7 etc length 3 runs 1, 5 runs 2 etc
237 local depth = 0
238 if l == 1 or (l % 2 == 1 and l == calcLength) then
239 if forward then
240 T:turnLeft(1)
241 else
242 T:turnRight(1)
243 end
244 else
245 T:turnLeft(2)
246 end
247 -- go down destroying vegetation until on floor, checking in front at same time
248 while clearVegetation("down") do
249 clearVegetation("forward")
250 T:down()
251 depth = depth + 1
252 end
253 -- if slab at bottom, cover with solid block
254 if string.find(T:getBlockType("down"), "slab") then
255 T:up(1)
256 T:place("minecraft:sand", "down")
257 depth = depth + 1
258 end
259 if l == 1 or (l % 2 == 1 and l == calcLength) then
260 if forward then
261 T:turnRight(1)
262 else
263 T:turnLeft(1)
264 end
265 else
266 T:turnLeft(2)
267 end
268 for d = depth, 1, -1 do
269 clearVegetation("forward")
270 T:up(1)
271 end
272 -- first corner complete, back at surface above water
273 if l < calcLength then
274 T:forward(2)
275 end
276 end
277 if forward then
278 T:go("L1F1L1")
279 else
280 T:go("R1F1R1")
281 end
282 forward = not forward
283 if not clearVegetation("down") then -- reached far wall
284 break
285 end
286 end
287end
288
289function clearSolid(width, length, height, direction)
290 -- direction = Bottom->Top (0), Top->bottom(1)
291 if direction == nil then
292 direction = 0
293 end
294 if height <= 0 then --move up until no more solid
295 local totalItemCount = 0
296 repeat
297 totalItemCount = T:getTotalItemCount()
298 clearRectangle(width, length)
299 if direction == 0 then
300 T:up(1)
301 else
302 T:down(1)
303 end
304 height = height + 1
305 until T:getTotalItemCount() == totalItemCount -- nothing collected or full inventory
306 else
307 for i = 1, height do
308 clearRectangle(width, length)
309 if direction == 0 then
310 T:up(1)
311 else
312 T:down(1)
313 end
314 end
315 end
316 if direction == 0 then
317 T:down(height)
318 else
319 T:up(height)
320 end
321end
322
323function clearPerimeterWall(width, length, height, direction)
324 -- go(path, useTorch, torchInterval, leaveExisting)
325 -- if height <= 0 then stop when nothing above
326 if direction == nil then
327 direction = 0
328 end
329 --if height > 0 then
330 for i = 1, height do
331 T:go("F"..tostring(length - 1)..
332 "R1F"..tostring(width - 1)..
333 "R1F"..tostring(length - 1)..
334 "R1F"..tostring(width - 1)..
335 "R1", false, 0, false)
336 if direction == 0 then
337 if i < height then
338 T:up(1)
339 end
340 else
341 if i < height then
342 T:down(1)
343 end
344 end
345 end
346 --[[else -- 0 set as height
347 local go = true
348 repeat
349 T:go("F"..tostring(length - 1)..
350 "R1F"..tostring(width - 1)..
351 "R1F"..tostring(length - 1)..
352 "R1F"..tostring(width - 1)..
353 "R1", false, 0, false)
354 if direction == 0 then
355 if turtle.detectUp() then
356 T:up(1)
357 else
358 go = false
359 end
360 else
361 if turtle.detectDown() then
362 T:down(1)
363 else
364 go = false
365 end
366 end
367 until not go
368 end]]
369end
370
371function clearRectangle(width, length, extend)
372 if extend == nil then --remove blocks above and below
373 extend = false
374 end
375 -- could be 1 wide x xx length (trench) up and return
376 -- could be 2+ x 2+
377 -- even no of runs return after last run
378 -- odd no of runs forward, back, forward, reverse and return
379 local directReturn = true
380 if width % 2 == 1 then
381 directReturn = false
382 end
383 if width == 1 then -- trench ahead
384 if extend then
385 for l = 1, length - 1 do
386 T:go("x0x2F1x0x2")
387 end
388 T:go("R2")
389 for l = 1, length - 1 do
390 T:go("x0x2F1x0x2")
391 end
392 T:go("R2")
393 else
394 T:go("F"..length - 1 .."R2F"..length - 1 .."R2", false, 0, false)
395 end
396 else
397 if directReturn then -- width = 2,4,6,8 etc
398 for i = 1, width, 2 do -- i = 1,3,5,7 etc
399 if extend then
400 for l = 1, length - 1 do
401 T:go("x0x2F1", false, 0, false)
402 end
403 T:go("x0x2R1F1x0x2R1x0x2")
404 for l = 1, length - 1 do
405 T:go("F1x0x2", false, 0, false)
406 end
407 if i < width - 2 then -- eg width = 8, i compares with 6: 1, 3, 5, 7
408 T:go("L1F1x0x2L1", false, 0, false)
409 end
410 else
411 T:go("F"..length - 1 .."R1F1R1F"..length - 1, false, 0, false)
412 if i < width - 2 then -- eg width = 8, i compares with 6: 1, 3, 5, 7
413 T:go("L1F1L1", false, 0, false)
414 end
415 end
416 end
417 if extend then
418 T:go("R1")
419 for w = 1, width - 1 do
420 T:go("F1", false, 0, false)
421 end
422 T:go("R1")
423 else
424 T:go("R1F"..width - 1 .."R1", false, 0, false)
425 end
426 else -- width = 3, 5, 7, 9 eg width 7
427 if extend then
428 for i = 1, width - 1, 2 do -- i = 1,3,5
429 for l = 1, length -1 do
430 T:go("x0x2F1", false, 0, false)
431 end
432 T:go("R1x0x2F1R1x0x2", false, 0, false)
433 for l = 1, length -1 do
434 T:go("x0x2F1", false, 0, false)
435 end
436 T:go("L1x0x2F1L1")
437 end
438 -- one more run then return
439 for l = 1, length -1 do
440 T:go("x0x2F1", false, 0, false)
441 end
442 T:go("R2")
443 for l = 1, length -1 do
444 T:go("x0x2F1", false, 0, false)
445 end
446 T:go("R1")
447 for w = 1, width -1 do
448 T:go("x0x2F1", false, 0, false)
449 end
450 T:go("R1")
451 else
452 for i = 1, width - 1, 2 do -- i = 1,3,5
453 T:go("F"..length - 1 .."R1F1R1F"..length - 1 .."L1F1L1", false, 0, false)
454 end
455 -- one more run then return
456 T:go("F"..length - 1 .."R2F"..length - 1 .."R1F"..width - 1 .."R1", false, 0, false)
457 end
458 end
459 end
460end
461
462function clearSandWall(length)
463 --dig down while on top of sand/soul_sand
464 local height = 0
465 T:clear()
466 print("Checking sand length")
467 local search = 0
468 local blockType = T:getBlockType("down")
469 while blockType ~= "minecraft:sand" and blockType ~= "minecraft:soul_sand" do --move forward until sand detected or 3 moves
470 T:forward(1)
471 search = search + 1
472 blockType = T:getBlockType("down")
473 if search > 3 then
474 break
475 end
476 end
477 if search <= 3 then
478 local calcLength = 0
479 blockType = T:getBlockType("down")
480 while blockType == "minecraft:sand" or blockType == "minecraft:soul_sand" do
481 T:forward(1)
482 calcLength = calcLength + 1
483 blockType = T:getBlockType("down")
484 end
485 T:go("R2F1") -- over sand
486 blockType = T:getBlockType("down")
487 while blockType == "minecraft:sand" or blockType == "minecraft:soul_sand" do
488 T:down(1)
489 height = height + 1
490 blockType = T:getBlockType("down")
491 end
492 -- repeat length times
493 for i = 1, calcLength do
494 --if sand in front, dig
495 while turtle.detect() do
496 blockType = T:getBlockType("forward")
497 if blockType == "minecraft:sand" or blockType == "minecraft:soul_sand" then
498 T:dig("forward")
499 else --solid block, not sand so move up
500 T:up(1)
501 height = height - 1
502 end
503 end
504 --move forward
505 if i < calcLength then
506 T:forward(1)
507 blockType = T:getBlockType("down")
508 while blockType == "minecraft:sand" or blockType == "minecraft:soul_sand" do
509 T:down(1)
510 height = height + 1
511 blockType = T:getBlockType("down")
512 end
513 end
514 end
515 -- go up, but reverse if block above
516 for i = 1, height do
517 if not turtle.detectUp() then
518 T:up(1)
519 else
520 T:back(1)
521 end
522 end
523 T:go("R2")
524 end
525end
526
527function clearSandCube(width, length)
528 --go down to bottom of sand
529 while T:getBlockType("down") == "minecraft:sand" do
530 T:down(1)
531 end
532 clearBuilding(width, length, 0, false)
533end
534
535function clearWall(width, length, height)
536 local evenHeight = false
537 local atStart = true
538 local drop = height - 2
539 -- go(path, useTorch, torchInterval, leaveExisting)
540 if height % 2 == 0 then
541 evenHeight = true
542 end
543
544 -- dig along and up for specified length
545 if evenHeight then --2, 4 , 6 etc
546 for h = 2, height, 2 do
547 for i = 1, length - 1 do
548 T:go("x0F1", false, 0, false)
549 end
550 if h < height then
551 T:go("R2U2", false, 0, false)
552 end
553 atStart = not atStart
554 end
555 else
556 drop = height - 1
557 for h = 1, height, 2 do
558 if h == height then
559 T:go("F"..tostring(length - 1), false, 0, false)
560 else
561 for i = 1, length - 1 do
562 T:go("x0F1", false, 0, false)
563 end
564 end
565 atStart = not atStart
566 if h < height then
567 T:go("R2U2", false, 0, false)
568 end
569 end
570 end
571 if evenHeight then
572 T:go("x0", false, 0, false)
573 end
574 T:go("R2D"..drop, false, 0, false)
575 if not atStart then
576 T:go("F"..tostring(length - 1).."R2", false, 0, false)
577 end
578end
579
580function clearVegetation(direction)
581 local isAirWaterLava = true
582 -- blockType, blockModifier, data
583 local blockType, blockModifier = T:getBlockType(direction)
584 if blockType ~= "" then --not air
585 if T:isVegetation(blockType) then
586 T:dig(direction)
587 elseif string.find(blockType, "water") == nil and string.find(blockType, "lava") == nil then
588 -- NOT water or lava
589 isAirWaterLava = false -- solid block
590 end
591 end
592
593 return isAirWaterLava --clears any grass or sea plants, returns true if air or water
594end
595
596function createAutoTreeFarm()
597 lib = {}
598
599 function lib.fillWaterBuckets()
600 T:place("minecraft:bucket", -1, "down", false)
601 sleep(0.5)
602 T:place("minecraft:bucket", -1, "down", false)
603 end
604
605 createWaterSource(1)
606 -- clsTurtle.go(path, useTorch, torchInterval, leaveExisting)
607 -- place chest and hopper
608 T:go("x0F1x0F1x0F1x0F1R1")
609 for i = 1, 4 do
610 T:go("D1R1C1R1C1R1C1R1")
611 end
612 T:up(1)
613 T:place("minecraft:chest", -1, "down", false)
614 T:go("F1x0D1F1x0R2", false, 0, true)
615 T:place("minecraft:hopper", -1, "forward", false)
616 -- dig trench and ensure base is solid
617 T:go("U1R2X7U1", false, 0, true)
618 T:place("minecraft:water_bucket", -1, "down", false) -- collection stream
619 T:go("F1X7U1", false, 0, true)
620 T:place("minecraft:water_bucket", -1, "down", false) -- upper collection stream
621 T:go("U1F1R1C2F1R1C2") --now on corner
622 for i = 1, 14 do --place cobble
623 T:go("F1C2", false, 0, false)
624 end
625 T:go("F4R1F2C2R2C1R2")
626 for i = 1, 8 do --place cobble
627 T:go("F1C2", false, 0, false)
628 end
629 T:turnRight(1)
630 for i = 1, 18 do --place cobble
631 T:go("F1C2", false, 0, false)
632 end
633 T:turnRight(1)
634 for i = 1, 8 do --place cobble
635 T:go("F1C2", false, 0, false)
636 end
637 T:go("R1F1R1D1") -- ready to clear ground inside cobble wall
638 for i = 1, 17 do
639 T:go("C2F1C2F1C2F1C2F1C2F1C2F1C2F1C2", false, 0, true)
640 if i < 17 then
641 if i % 2 == 1 then -- odd no
642 T:go("L1F1L1")
643 else
644 T:go("R1F1R1")
645 end
646 end
647 end
648 T:go("U1R2F10R2") -- over pond
649 lib.fillWaterBuckets()
650 for i = 0, 16, 2 do
651 T:go("F10R1")
652 if i > 0 then
653 T:go("F"..i)
654 end
655 T:place("minecraft:water_bucket", -1, "down", false)
656 T:go("F1R2")
657 if i < 16 then
658 T:place("minecraft:water_bucket", -1, "down", false)
659 end
660 T:go("F"..i + 1 .."L1")
661 T:go("F10R2")
662 lib.fillWaterBuckets()
663 end
664 -- place dirt/torch/sapling
665 T:go("F1U1R1F1L1")
666 for i = 1, 7 do
667 T:go("F6R1F1L1")
668 for j = 1, 3 do
669 T:place("minecraft:dirt", -1, "forward", false)
670 T:up(1)
671 T:place("sapling", -1, "forward", false)
672 T:down(1)
673 turtle.back()
674 T:place("minecraft:torch", -1, "forward", false)
675 turtle.back()
676 end
677 if i < 7 then
678 T:go("R1F1L1")
679 end
680 end
681 T:go("L1F12")
682 T:place("minecraft:chest", -1, "up", false)
683 T:go("R1F1L1")
684 T:place("minecraft:chest", -1, "up", false)
685 T:go("F1U1R1F1R1F1L1")
686 T:clear()
687 print("Auto TreeFarm completed")
688 print("\nDO NOT PLACE ANY TORCHES OR OTHER")
689 print("BLOCKS ON THE COBBLE PERIMETER!")
690 print("\nUse option 5 Manage Auto Tree farm")
691 print("to setup monitoring\n\nEnter to continue")
692 read()
693end
694
695function createBridge(numBlocks)
696 for i = 1, numBlocks do
697 T:go("m1", false, 0, true)
698 end
699 T:go("R1F1R1", false, 0, true)
700 for i = 1, numBlocks do
701 T:go("m1", false, 0, true)
702 end
703end
704
705function createCanal(side, length, height, effect)
706 -- go(path, useTorch, torchInterval, leaveExisting)
707 -- effect 0 or 1: 1 = delete source blocks
708 -- if height = 0 then already at correct height on canal floor
709 -- check block below, block to left and block above, move forward tunnelling
710 -- if entering water then move up, onto canal wall and continue pathway
711 -- if 55 and tunnelling then flood canal
712 -- else height = 1 then above water and on path across
713 -- move forward, checking for water below
714 -- if water finishes, move into canal, drop down and continue tunnelling
715 local lib = {}
716
717 function lib.side(side, length, maxLength, height, effect)
718 local turnA = "R"
719 local turnB = "L"
720 local isWater = false
721 local isSource = false
722 local onWater = false
723 local numBlocks = 0
724 local doContinue = true
725 if side == 56 then -- right
726 turnA = "L"
727 turnB = "R"
728 end
729 -- if starting on wall, probably already on water
730 if height == 1 then -- if on wall, move to floor, turn to face opposite canal wall
731 T:forward(1)
732 isWater, isSource = T:isWater("down")
733 if isSource then --on river/ocean so just construct walkway
734 onWater = true
735 numBlocks = createPath(length - 1, true)
736 if numBlocks < maxLength then -- continue with canal
737 T:go(turnA.."1F1D1"..turnA.."1")
738 else
739 doContinue = false
740 end
741 else
742 T:go(turnA.."1F1D1")
743 end
744 else -- on canal floor, but could be open water
745 isWater, isSource = T:isWater("forward")
746 if isSource then -- water source ahead. Assume on open water
747 T:go(turnB.."1U1F1"..turnA.."1")
748 onWater = true
749 numBlocks = createPath(length - 1, true)
750 if numBlocks < maxLength then -- continue with canal
751 T:go(turnA.."1F1D1"..turnA.."1")
752 else
753 doContinue = false
754 end
755 else
756 T:go(turnA.."1")
757 end
758 end
759 if not onWater then
760 if turtle.detect() then --block to side, check is not turtle
761 if not redstone.getInput("front") then
762 --if T:getBlockType("forward"):find("turtle") == nil then --not a turtle
763 T:dig("forward") --automatically avoids turtle
764 end
765 end
766 T:go(turnA.."1")
767 -- facing canal start wall
768 if turtle.detect() then -- solid block behind: at start of canal
769 T:go(turnB.."2C2F1"..turnB.."1C1"..turnB.."1C2x0", false, 0, true) --move forward and check base/side, face start
770 T:place("minecraft:water_bucket", -1, "forward")
771 else -- air or water behind
772 -- check if water already present behind. if not create source
773 isWater, isSource = T:isWater("forward")
774 if not isSource then
775 T:place("minecraft:water_bucket", -1, "forward")
776 end
777 end
778 end
779 -- could be over water, just need walls
780 --print("Loop starting. Enter")
781 --read()
782 local blockType, modifier
783 local torch = 0
784 local sourceCount = 0
785 --loop from here. Facing backwards over existing canal/start
786 while doContinue and numBlocks < maxLength do
787 isWater, isSource = T:isWater("forward")
788 while not isSource do
789 sleep(10)
790 print("waiting for water...")
791 isWater, isSource = T:isWater("forward")
792 end
793 T:place("minecraft:bucket", -1, "forward") -- take water from source
794 -- move forward check canal wall for block, below for block
795 --T:go(turnA.."2F1C2"..turnB.."1C1", false, 0, true) -- face canal wall, repair if req
796 T:go(turnA.."2F1C2", false, 0, true) --move forward, close floor
797 isWater, isSource = T:isWater("forward")
798 --print("Source in front: "..tostring(isSource).." Enter")
799 --read()
800 if isSource then --now on open water. move up and continue
801 sourceCount = sourceCount + 1
802 if sourceCount > 3 then
803 sourceCount = 0
804 T:go(turnB.."1U1F1"..turnA.."1")
805 numBlocks = createPath(length - 1, true)
806 if numBlocks < maxLength then -- continue with canal
807 T:go(turnA.."1F1D1"..turnA.."1x1"..turnA.."2") --return to canal bottom, break any block behind
808 else
809 doContinue = false
810 end
811 end
812 end
813 T:go(turnB.."1C1", false, 0, true) -- face canal wall, repair if req
814 --print("facing wall. Enter")
815 --read()
816 T:go("U1x1") --go up and remove any block
817 torch = torch + 1
818 numBlocks = numBlocks + 1
819 if turtle.detectUp() then -- block above
820 T:go("U1x1")
821 if torch == 8 then
822 torch = 0
823 T:place("minecraft:torch", -1, "forward")
824 end
825 T:down(1)
826 end
827 if torch == 8 then
828 torch = 0
829 T:place("minecraft:torch", -1, "forward")
830 end
831 T:down(1) -- on canal floor facing wall
832 T:go(turnB.."1", false, 0, true)
833 -- place water behind if some water is present
834 isWater, isSource = T:isWater("forward")
835 if not isWater then --no flowing water behind so deploy both sources
836 T:forward(1)
837 T:place("minecraft:water_bucket", -1, "forward")
838 turtle.back()
839 end
840 T:place("minecraft:water_bucket", -1, "forward")
841 -- check opposite canal wall
842 T:go(turnB.."1")
843 if turtle.detect() then --block to side, check is not turtle
844 if not redstone.getInput("front") then
845 --if T:getBlockType("forward"):find("turtle") == nil then --not a turtle
846 T:dig("forward")
847 end
848 end
849 T:go(turnA.."1")
850 end
851 end
852
853 function lib.leftSideLegacy(side, length, maxLength, height, effect)
854 local doContinue = true
855 local numBlocks = 0
856 local doTunnel = false
857 local requestTunnel = false
858 local blockType, modifier
859 while doContinue and numBlocks < maxLength do
860 if height == 0 then -- canal floor
861 blockType, modifier = T:getBlockType("down")
862 if blockType == "" or blockType == "minecraft:lava" then -- air or lava below, so place block
863 T:place("minecraft:cobblestone", -1, "down", false)
864 end
865 -- place side block
866 T:go("L1C1R1", false , 0, true)
867 -- check above
868 blockType, modifier = T:getBlockType("up")
869 --if blockType == "minecraft:log" or blockType == "minecraft:log2" then
870 if blockType ~= "" then
871 if string.find(blockType, "log") ~= nil then
872 T:harvestTree(false, false, "up")
873 elseif blockType == "minecraft:lava" or blockType == "minecraft:water" then
874 T:up(1)
875 T:place("minecraft:cobblestone", -1, "up", false)
876 T:down(1)
877 else --solid block or air above
878 if blockType ~= "" then
879 T:dig("up")
880 end
881 end
882 end
883 -- check if block in front is water source
884 blockType, modifier = T:getBlockType("forward")
885 --if block:find("water") ~= nil then
886 if blockType == "minecraft:water" and modifier == 0 then -- source block in front could be lake/ocean
887 -- move up, to left and continue as height = 1
888 T:go("U1L1F1R1", false, 0, true)
889 height = 1
890 else
891 T:forward(1, true)
892 numBlocks = numBlocks + 1
893 end
894 else -- height = 1, on canal wall
895 numBlocks = numBlocks + createPath(0, true)
896 -- if path finished, then move back to canal floor and continue tunnelling
897 T:go("R1F1D1L1", false, 0, true)
898 height = 0
899 end
900 end
901 end
902
903 function lib.rightSideLegacy(side, length, maxLength, height, effect)
904 -- assume left side already under construction
905 local doContinue = true
906 local numBlocks = 0
907 local doTunnel = false
908 local requestTunnel = false
909 local blockType, modifier
910 local poolCreated = false
911 while doContinue and numBlocks < maxLength do
912 if height == 0 then-- canal floor
913 -- create first infinity pool
914 if not poolCreated then
915 T:up(1)
916 T:place("minecraft:water_bucket", -1, "down", false)
917 T:go("L1F1R1", false, 0, true)
918 T:place("minecraft:water_bucket", -1, "down", false)
919 T:forward(1)
920 T:place("minecraft:water_bucket", -1, "down", false)
921 T:back(1)
922 -- refill buckets
923 for j = 1, 3 do
924 T:place("minecraft:bucket", -1, "down", false)
925 sleep(0,5)
926 end
927 T:go("R1F1L1F2", false , 0, true)
928 T:down(1)
929 poolCreated = true
930 end
931 blockType, modifier = T:getBlockType("down")
932 if blockType == "" or blockType == "minecraft:lava"
933 or blockType == "minecraft:water" or blockType == "minecraft:flowing_water" then -- air, water or lava below, so place block
934 T:place("minecraft:cobblestone", -1, "down", false)
935 end
936 -- place side block
937 T:go("R1C1L1", false , 0, true)
938 T:up(1)
939 blockType, modifier = T:getBlockType("up")
940 if blockType == "minecraft:log" or blockType == "minecraft:log2" then
941 T:harvestTree(false, false, "up")
942 elseif blockType == "minecraft:lava" or blockType == "minecraft:water" then
943 T:place("minecraft:cobblestone", -1, "up", false)
944 end
945 T:place("minecraft:water_bucket", -1, "down", false)
946 for j = 1, 2 do
947 T:forward(1)
948 blockType, modifier = T:getBlockType("up")
949 --if blockType == "minecraft:log" or blockType == "minecraft:log2" then
950 if blockType ~= "" then
951 if string.find(blockType, "log") ~= nil then
952 T:harvestTree(false, false, "up")
953 elseif blockType == "minecraft:lava" or blockType == "minecraft:water" then
954 T:place("minecraft:cobblestone", -1, "up", false)
955 end
956 end
957 -- at ceiling level
958 T:go("D1R1C1L1", false, 0, true)
959 blockType, modifier = T:getBlockType("down")
960 if blockType == "" or blockType == "minecraft:lava"
961 or blockType == "minecraft:water" or blockType == "minecraft:flowing_water" then -- air, water or lava below, so place block
962 T:place("minecraft:cobblestone", -1, "down", false)
963 end
964 -- check if block in front is water source
965 blockType, modifier = T:getBlockType("forward")
966 T:up(1)
967 T:place("minecraft:water_bucket", -1, "down", false)
968 if blockType == "minecraft:water" and modifier == 0 then -- source block in front could be lake/ocean
969 -- move to right and continue as height = 1
970 T:go("R1F1L1", false, 0, true)
971 height = 1
972 break
973 end
974 end
975 if height == 0 then
976 T:back(2)
977 for j = 1, 3 do
978 T:place("minecraft:bucket", -1, "down", false)
979 sleep(0,5)
980 end
981 T:go("F3D1", false, 0, true)
982 end
983 else -- height = 1: on wall
984 numBlocks = numBlocks + createPath(0, true)
985 -- if path finished, then move back to canal floor and continue tunnelling
986 T:go("L1F1L1F1", false, 0, true) -- facing backwards, collect water
987 for j = 1, 3 do
988 T:place("minecraft:bucket", -1, "down", false)
989 sleep(0,5)
990 end
991 T:go("R2F1D1", false, 0, true) --canal floor
992 height = 0
993 end
994 end
995 end
996
997 -- side = 55/56: left/right side
998 -- size = 0-1024 0 = continuous
999 -- height = 0/1 0 = floor, 1 = wall
1000 -- T:place(blockType, damageNo, direction, leaveExisting)
1001 -- T:go(path, useTorch, torchInterval, leaveExisting)
1002 -- T:harvestTree(extend, craftChest, direction)
1003 -- start with forward run:
1004
1005 local maxLength = 1024
1006 if length ~= 0 then
1007 maxLength = length
1008 end
1009 if effect == nil then
1010 effect = 1 -- old versions, water source is deleted by turtle
1011 end
1012 -- turn on redstone on all sides
1013 redstone.setOutput("left", true)
1014 redstone.setOutput("back", true)
1015 redstone.setOutput("right", true)
1016 redstone.setOutput("front", true)
1017 if side == 55 then -- left side
1018 if effect == 0 then -- new version
1019 lib.side(side, length, maxLength, height, effect)
1020 --lib.leftSide(side, size, length, maxLength)
1021 else
1022 lib.leftSideLegacy(side, length, maxLength, height, effect)
1023 end
1024 else -- right side (56)
1025 if effect == 0 then -- new version
1026 --lib.rightSide(side, size, length, maxLength)
1027 lib.side(side, length, maxLength, height, effect)
1028 else
1029 lib.rightSideLegacy(side, length, maxLength, height, effect)
1030 end
1031 end
1032end
1033
1034function createCoridoor(length)
1035 if length == 0 then
1036 length = 2048
1037 end
1038 -- pause every 64 blocks
1039 local numSteps = 0
1040 local total = 0
1041 for steps = 1, length do
1042 if numSteps >= 64 then
1043 -- request permission to continue
1044 T:clear()
1045 print("Coridoor length: "..total.." blocks")
1046 print("Do you want to continue? (y/n)")
1047 response = read()
1048 if response:lower() ~= "y" then
1049 break
1050 end
1051 numSteps = 0
1052 end
1053 --go(path, useTorch, torchInterval, leaveExisting)
1054 T:go("F1x0C2", false, 0, true)
1055 numSteps = numSteps + 1
1056 total = total + 1
1057 end
1058end
1059
1060function createEnderTower()
1061
1062 local lib = {}
1063
1064 function lib.getEmptySlots()
1065 local empty = 0
1066 for i = 1, 16 do
1067 if turtle.getItemCount(i) == 0 then
1068 empty = empty + 1
1069 end
1070 end
1071 return empty
1072 end
1073
1074 function lib.getStone(direction, stacks)
1075 local suck = turtle.suck
1076 if direction == "down" then
1077 suck = turtle.suckDown
1078 end
1079 T:sortInventory()
1080 local slot = T:getFirstEmptySlot() --find spare slot
1081 turtle.select(1)
1082 if stacks == 0 then
1083 while suck() do end
1084 else
1085 for i = 1, stacks do -- get 6 stacks of stone from chest
1086 suck()
1087 end
1088 end
1089 return T:getSlotContains(slot) -- use this as default building block
1090 end
1091
1092 function lib.stackBuckets()
1093 local data = {}
1094 local bucketSlot = 0
1095 local emptySlots = 0
1096 local water = 0
1097 for i = 1, 16 do
1098 -- find first empty bucket
1099 if turtle.getItemCount(i) > 0 then
1100 data = turtle.getItemDetail(i)
1101 if data.name == "minecraft:bucket" then
1102 if bucketSlot == 0 then
1103 bucketSlot = i
1104 else
1105 turtle.select(i)
1106 turtle.transferTo(bucketSlot)
1107 end
1108 elseif data.name == "minecraft:water_bucket" then
1109 water = water + 1
1110 end
1111 else
1112 emptySlots = emptySlots + 1
1113 end
1114 end
1115 return emptySlots, water
1116 end
1117
1118 function lib.countWaterBuckets()
1119 local data = {}
1120 local buckets = 0
1121 for i = 1, 16 do
1122 data = turtle.getItemDetail(i)
1123 if data.name == "minecraft:water_bucket" then
1124 buckets = buckets + 1
1125 end
1126 end
1127 return buckets
1128 end
1129
1130 function lib.baseRun(preferredBlock, count, turn)
1131 for i = 1, count do
1132 T:go("C2F1", false, 0, false, preferredBlock)
1133 end
1134 T:go("C2"..turn, false, 0, false, preferredBlock)
1135 end
1136
1137 function lib.outsideRun(preferredBlock)
1138 T:place("fence", -1, "down", false)
1139 T:forward(1)
1140 T:place(preferredBlock, -1, "down", false)
1141 T:forward(1)
1142 T:place(preferredBlock, -1, "down", false)
1143 T:forward(2)
1144 T:place(preferredBlock, -1, "down", false)
1145 end
1146
1147 function lib.signRun(preferredBlock ,message)
1148 T:place(preferredBlock, -1, "down", false)
1149 T:forward(4)
1150 T:place(preferredBlock, -1, "down", false)
1151 turtle.back()
1152 turtle.back()
1153 T:down(1)
1154 T:place("sign", -1, "forward", false, message)
1155 T:go("U1F2")
1156 end
1157
1158 function lib.goToWater(height)
1159 local built = 0 -- measures completed lift height
1160 while turtle.down() do -- takes turtle to bottom of water source
1161 height = height + 1
1162 if turtle.detect() then
1163 built = built + 1
1164 end
1165 end
1166 T:up(1) -- above watersource assuming it is 1-1.5 blocks deep
1167 height = height - 1
1168 -- built = built - 1 not required as next block is water source: not detected
1169 return built, height
1170 end
1171
1172 function lib.fillBuckets(toBuild)
1173 local emptySlots, water = lib.stackBuckets() -- gets no of empty slots + no of water buckets
1174 if water < toBuild then -- no of water buckets onboard less than required quantity
1175 for i = 1, toBuild do -- fill required no of buckets up to max space in inventory
1176 emptySlots = lib.getEmptySlots()
1177 if emptySlots == 0 then -- inventory full
1178 break
1179 else
1180 if T:place("minecraft:bucket", -1, "down", false) then
1181 water = water + 1
1182 sleep(0.5)
1183 end
1184 end
1185 end
1186 end
1187
1188 return water
1189 end
1190
1191 function lib.buildLift(preferredBlock)
1192 local built = 0 -- measures completed lift height
1193 local height = 0 -- measures total height from starting position
1194 built, height = lib.goToWater(height) -- returns lift blocks already placed, total height of drop from starting point
1195 local toBuild = height - built -- no of blocks to increase lift size
1196 while toBuild > 0 do -- at least 1 block height remaining
1197 local water = lib.fillBuckets(toBuild) -- no of water buckets onboard (could be more than required)
1198 if water > toBuild then
1199 water = toBuild
1200 end
1201 while turtle.detect() do -- climb to top of existing lift
1202 turtle.up()
1203 height = height - 1
1204 end
1205 T:forward(1)
1206 for i = 1, water do -- build lift by no of water buckets
1207 if T:place("minecraft:water_bucket", -1, "forward", false) then
1208 T:up(1)
1209 height = height - 1
1210 toBuild = toBuild - 1
1211 T:place(preferredBlock, -1, "down", false)
1212 end
1213 end
1214 turtle.back()
1215 -- may still be some height to complete, but needs refill
1216 if toBuild > 0 then
1217 lib.goToWater(0) --return to source
1218 lib.fillBuckets(toBuild)
1219 end
1220 end
1221 if height > 0 then -- if any remaining distance
1222 T:up(height)
1223 end
1224
1225 end
1226
1227 function lib.buildSection(preferredBlock, solid) -- builds a section without any blocks in the centre
1228 if solid then
1229 T:go("C2F1 C2F1 C2F1 C2F1 C2R1", false, 0, false, preferredBlock) -- first side
1230 T:go("F1C2 F1R1", false, 0, false, preferredBlock) -- top side
1231 T:go("C2F1 C2F1 C2F1 C2F1 C2R1", false, 0, false, preferredBlock) -- far side
1232 T:go("F1C2 F1R1U1", false, 0, false, preferredBlock) -- top side
1233 else
1234 T:go("C2F1", false, 0, false, preferredBlock) -- first side
1235 if not T:place("fence", -1, "down", false) then-- first side
1236 T:place(preferredBlock, -1, "down", false)
1237 end
1238 T:go("F1C2 F2C2 R1", false, 0, false, preferredBlock) -- first side
1239 T:go("F2C2 R1", false, 0, false, preferredBlock) -- top side
1240 T:go("F2C2 F1", false, 0, false, preferredBlock) -- far side
1241 if not T:place("fence", -1, "down", false) then-- first side
1242 T:place(preferredBlock, -1, "down", false)
1243 end
1244 T:go("F1C2 R1", false, 0, false, preferredBlock) -- far side
1245 T:go("F1C2 F1R1U1", false, 0, false, preferredBlock) -- far side
1246 end
1247 end
1248
1249 function lib.decorate()
1250 lib.placeFence(1) -- move up 1 and place fence
1251 lib.placeFence(1) -- move up 1 and place fence
1252 for i = 1, 7 do
1253 lib.placeFence(2) -- move up 2 and place fence
1254 end
1255 -- under main platform
1256 lib.placeFence(6)
1257 lib.placeFence(3)
1258 while lib.placeFence(2) do end-- move up 2 and place fence until top reached
1259 end
1260
1261 function lib.placeFence(up)
1262 -- starting from chest level 0
1263 local success = true
1264 for i = 1, up do
1265 if turtle.detect() then
1266 T:up(1)
1267 else
1268 success = false -- reached the top
1269 break
1270 end
1271 end
1272 if success then
1273 T:place("fence", -1, "forward", false) -- level 1
1274 end
1275 return success
1276 end
1277
1278 --[[
1279 clsTurtle methods:
1280 clsTurtle.place(self, blockType, damageNo, direction, leaveExisting)
1281 clsTurtle.go(self, path, useTorch, torchInterval, leaveExisting, preferredBlock)
1282 ]]
1283 -- remove 1 stack stone from chest
1284 local preferredBlock = lib.getStone("down", 1) -- use this as default building block
1285 -- build base floor
1286 T:go("R2F2R1F3R1", false, 0, false, preferredBlock)
1287 for i = 1, 2 do
1288 lib.baseRun(preferredBlock, 8, "R1F1R1")
1289 lib.baseRun(preferredBlock, 8, "L1F1L1")
1290 lib.baseRun(preferredBlock, 8, "R1F4R1")
1291 end
1292 -- move back to centre, build water source, with soul sand at base of first source
1293 T:go("R1F3L1C2F1C2F2D1", false, 0, false, preferredBlock) --just behind chest, 1 below ground level
1294 T:place("minecraft:soul_sand", -1, "down", false) -- over block 1 of water source
1295 T:go("F1C2F1C2", false, 0, false, preferredBlock) -- over block 2 of water source
1296 T:go("F1C2U1C2", false, 0, false, preferredBlock) -- over block 4 of water source
1297 T:go("F1C2F1C2R2F5R2", false, 0, false, preferredBlock) -- over block 1 of water source
1298 T:place("minecraft:water_bucket", -1, "down", false)
1299 T:forward(2) -- over block 3 of water source
1300 T:place("minecraft:water_bucket", -1, "down", false)
1301 turtle.back() -- over block 2 of water source
1302 T:place("minecraft:bucket", -1, "down", false)
1303 T:go("F2D1R2C2") -- over block 4 of water source
1304 T:go("U1", false, 0, false, preferredBlock)
1305 T:place("minecraft:water_bucket", -1, "down", false)
1306 T:forward(4)
1307 lib.stackBuckets() -- put all buckets in same slot
1308 T:dropItem("minecraft:dirt", 0, "up") -- drop dirt up: clsTurtle.dropItem(self, item, keepAmount, direction)
1309 preferredBlock = lib.getStone("down", 6)
1310 T:go("R1F2R1U1") -- move to start position
1311 for i = 1, 2 do
1312 -- build first level of tower: 2 x outside run, 2 x sign run
1313 lib.outsideRun(preferredBlock)
1314 T:go("R1F1R1")
1315 lib.signRun(preferredBlock, "Pint size\nzombies\nProhibited")
1316 T:go("L1F1L1C2", false, 0, false, preferredBlock)
1317 T:forward(4) -- miss out centre block
1318 T:place(preferredBlock, -1, "down", false)
1319 T:go("R1F1R1")
1320 lib.signRun(preferredBlock, "Pint size\nzombies\nProhibited")
1321 T:go("L1F1L1")
1322 lib.outsideRun(preferredBlock)
1323 if i == 1 then -- layer 1
1324 T:go("L1F4L1F4R2U1")
1325 else -- layer 2
1326 T:go("L1F5L1F6R2U1") -- over corner of lower platform
1327 end
1328 end
1329 for i = 1, 2 do -- build both sides of platform, leave centre missing
1330 lib.baseRun(preferredBlock, 8, "R1F1R1")
1331 lib.baseRun(preferredBlock, 8, "L1F1L1")
1332 lib.baseRun(preferredBlock, 8, "R1F4R1")
1333 end
1334 T:go("R1F3L1C2F1C2F1C2F4C2F1C2F1C2", false, 0, false, preferredBlock) --fill in centre row
1335 T:go("R2F6R1F1R1U1") -- go to start of tower base
1336 for i = 1, 7 do -- build 14 block high tower
1337 lib.buildSection(preferredBlock, false)
1338 lib.buildSection(preferredBlock, true)
1339 end
1340
1341 T:go("R2F4R1F4R1", false, 0, false, preferredBlock) -- build upper platform (154 blocks remaining)
1342 for i = 1, 2 do -- build both sides of upper platform, leave centre missing
1343 lib.baseRun(preferredBlock, 12, "R1F1R1")
1344 lib.baseRun(preferredBlock, 12, "L1F1L1")
1345 lib.baseRun(preferredBlock, 12, "R1F1R1")
1346 lib.baseRun(preferredBlock, 12, "L1F1L1")
1347 lib.baseRun(preferredBlock, 12, "R1F6R1")
1348 end
1349 T:go("R1F5 L1C2 F1C2 F1C2 F1C2 F1C2 F4C2 F1C2 F1C2 F1C2 F1C2 ", false, 0, false, preferredBlock) --fill in centre row
1350 T:go("R2F5") -- return to drop area
1351 lib.buildLift(preferredBlock) -- build bubble lift
1352 T:go("F4D19R2") -- go down to chest: facing chest
1353 preferredBlock = lib.getStone("forward", 6)
1354 T:up(20)
1355 T:go("L1F1R1F1") -- go to start of tower base
1356 T:go("C2F4 C2R1F1R1", false, 0, false, preferredBlock) -- left side
1357 T:go("F2C2 F2C2 L1F1L1", false, 0, false, preferredBlock)
1358 T:go("C2F4 C2R2U1", false, 0, false, preferredBlock)
1359 T:go("C2F4 C2R1F1R1", false, 0, false, preferredBlock)
1360 T:place("fence", -1, "down", false)
1361 T:go("F2C2 F2L1F1L1", false, 0, false, preferredBlock)
1362 T:go("C2F4 C2R2F2L1F1R2D2", false, 0, false, preferredBlock) --ready to place ladder
1363 T:place("ladder", -1, "forward", false)
1364 T:up(1)
1365 T:place("ladder", -1, "forward", false)
1366 T:go("U2R1F4R1F1R1") -- ready to make upper tower base
1367
1368 for i = 1, 2 do -- build both sides of platform, leave centre missing
1369 lib.baseRun(preferredBlock, 6, "R1F1R1")
1370 lib.baseRun(preferredBlock, 6, "L1F1L1")
1371 lib.baseRun(preferredBlock, 6, "R1F2R1")
1372 end
1373
1374 T:go("R1F1 L1C2 F1C2 F1", false, 0, false, preferredBlock) --fill in centre row
1375 T:place("minecraft:soul_sand", -1, "down", false)
1376 T:go("F1C2 F2C2 F1C2", false, 0, false, preferredBlock)
1377 T:go("R2F5R1F1R1U1") -- go to start of tower base
1378 -- build 2 levels, finish signs and ladders
1379 T:go("C2F2 R1D2 U1", false, 0, false, preferredBlock)
1380 T:place("ladder", -1, "down", false)
1381 T:turnRight(1)
1382 T:place("sign", -1, "forward", false, "UP\n^\n|\n|")
1383 T:go("U1R2F2 R1F1C2 F2C2R1", false, 0, false, preferredBlock) --top right corner
1384 T:go("F4C2B2D1", false, 0, false, preferredBlock)
1385 T:place("sign", -1, "forward", false, "UP\n^\n|\n|")
1386 T:go("U1F2R1F1C2F1R1U1", false, 0, false, preferredBlock) --ready for second level
1387 T:go("C2F2 R2D1", false, 0, false, preferredBlock)
1388 T:place("sign", -1, "forward", false, "UP\n^\n|\n|")
1389 T:go("U1R2F2C2R1", false, 0, false, preferredBlock) --top left corner
1390 T:go("F1R1C2F4C2", false, 0, false, preferredBlock) --mid bottom row
1391 T:go("L1F1L1C2", false, 0, false, preferredBlock) -- bottom right corner
1392 T:go("F2R2D1", false, 0, false, preferredBlock)
1393 T:place("sign", -1, "forward", false, "UP\n^\n|\n|")
1394 T:go("U1R2F2C2", false, 0, false, preferredBlock) -- top right corner
1395 -- return to chest
1396 T:go("L1F1L1 F5D24R2", false, 0, false, preferredBlock) -- return to chest
1397 preferredBlock = lib.getStone("forward", 0)
1398 T:go("U25L1F1R1F1", false, 0, false, preferredBlock) -- return to finish tower
1399 -- tower 120 blocks high: first 72 layers
1400 for i = 1, 36 do -- build 72 block high tower 19 blocks/section = 720 (9 stacks)
1401 lib.buildSection(preferredBlock, true)
1402 lib.buildSection(preferredBlock, false)
1403 end
1404 T:go("D1F3R1F1R1", false, 0, false, preferredBlock) -- return to drop
1405 lib.buildLift(preferredBlock) -- build bubble lift
1406 T:go("F4R2", false, 0, false, preferredBlock) -- return to chest
1407 while turtle.down() do end
1408 preferredBlock = lib.getStone("forward", 0)
1409 turtle.select(16)
1410 turtle.drop() -- empty slot 16
1411 lib.decorate()-- replace blocks with fence
1412 T:go("L1F1R1F1U1", false, 0, false, preferredBlock) -- return to finish tower
1413 -- continue tower
1414 for i = 1, 19 do -- build 38 block high tower 19 blocks/section = 570 (9 stacks)
1415 lib.buildSection(preferredBlock, true)
1416 lib.buildSection(preferredBlock, false)
1417 end
1418 -- add small platform at the top
1419 T:go("L1F2L1F2R2", false, 0, false, preferredBlock)
1420 for i = 1, 2 do
1421 lib.baseRun(preferredBlock, 8, "R1F1R1")
1422 lib.baseRun(preferredBlock, 8, "L1F1L1")
1423 lib.baseRun(preferredBlock, 8, "R1F4R1")
1424 end
1425 T:go("R1F3 L1C2 F1C2 F1C2 F4C2 F1C2 F1C2 R2F3", false, 0, false, preferredBlock) --fill in centre row
1426 lib.buildLift(preferredBlock) -- build bubble lift
1427 -- go down outside and repair holes
1428 T:go("F4R2D2C0", false, 0, false, preferredBlock) -- 1 repair top platform
1429 -- 19 fences left
1430 for i = 1, 19 do
1431 T:place("fence", -1, "forward", false) -- level 1
1432 T:down(2)
1433 end
1434 T:turnRight(2)
1435 while not turtle.detect() do
1436 turtle.down()
1437 end
1438 T:go("D1C0", false, 0, false, preferredBlock) -- 2 repair main platform roof
1439 while not turtle.detect() do
1440 turtle.down()
1441 end
1442 T:go("D1C0", false, 0, false, preferredBlock) -- 3 repair main platform
1443 while not turtle.detect() do
1444 turtle.down()
1445 end
1446 T:go("D1C0", false, 0, false, preferredBlock) -- 4 repair base platform
1447 while turtle.down() do end -- go to bottom
1448 T:turnRight(2) -- face chest
1449 local slot = T:getItemSlot(preferredBlock)
1450 for i = 1, 16 do
1451 if i ~= slot then
1452 turtle.select(i)
1453 turtle.drop()
1454 end
1455 end
1456 turtle.select(slot)
1457 turtle.transferTo(16)
1458 turtle.select(16)
1459 turtle.transferTo(1, 1)
1460 turtle.transferTo(2, 1)
1461 turtle.transferTo(3, 1)
1462 turtle.drop()
1463 turtle.craft()
1464 while turtle.suck() do end
1465 turtle.dig()
1466 T:place(preferredBlock, -1, "forward", false)
1467 T:go("U1C2", false, 0, false, preferredBlock) -- repair ground
1468 -- go to upper platform to fix water drop
1469 T:go("R2F4R2 U21F4 L1F2 R1F4 R1F2", false, 0, false, preferredBlock) -- fill in drop hole
1470 T:place("slab", -1, "forward", false)
1471 T:turnRight(2)
1472 T:place("slab", -1, "forward", false)
1473 local drop = 0
1474 while turtle.down() do
1475 drop = drop + 1
1476 end
1477 T:up(1)
1478 T:place("minecraft:bucket", -1, "down", false)
1479 T:up(drop - 1)
1480 T:place(preferredBlock, -1, "down", false)
1481 T:up(1)
1482 T:place("minecraft:water_bucket", -1, "down", false)
1483 T:go("F1U2")
1484 T:place("slab", -1, "down", false)
1485 T:go("R2F2")
1486 T:place("slab", -1, "down", false)
1487end
1488
1489function createFarm(extend)
1490 lib = {}
1491 function lib.addWaterSource(pattern)
1492 -- pattern = {"d","c","c","d"}
1493 T:go("D1x2C2")
1494 for i = 1, 4 do
1495 T:dig("forward")
1496 if pattern[i] == "d" then
1497 T:place("minecraft:dirt", -1, "forward", false)
1498 elseif pattern[i] == "c" then
1499 T:place("minecraft:cobblestone", -1, "forward", false)
1500 end
1501 T:turnRight(1)
1502 end
1503 T:up(1)
1504 T:place("minecraft:water_bucket", -1, "down")
1505 end
1506
1507 function lib.placeDirt(count, atCurrent)
1508 if atCurrent then
1509 local blockType = T:getBlockType("down")
1510 if blockType ~= "minecraft:dirt" and blockType ~= "minecraft:grass_block" then
1511 T:place("minecraft:dirt", -1, "down", false)
1512 end
1513 end
1514 for i = 1, count do
1515 T:forward(1)
1516 T:dig("up")
1517 local blockType = T:getBlockType("down")
1518 if blockType ~= "minecraft:dirt" and blockType ~= "minecraft:grass_block" then
1519 T:place("minecraft:dirt", -1, "down", false)
1520 end
1521 end
1522 end
1523
1524 -- extend "", "right" or "forward". only adds a single new farm.
1525 -- right adds farm and checks for existing front extensions, dealt with separately
1526 -- clsTurtle.place(blockType, damageNo, direction, leaveExisting)
1527 if extend == nil then
1528 extend = ""
1529 end
1530 local blockType = ""
1531 -- extend = "right": placed on cobble corner of existing farm facing right side
1532 -- extend = "front": placed on cobble corner of existing farm facing front
1533 -- else placed on ground at corner of potential new farm facing front
1534
1535 -- step 1 dig ditch round perimeter wall
1536 if extend == "right" then
1537 -- move to front corner
1538 T:forward(12) -- over wall of existing farm, will be empty below if not extended
1539 blockType = T:getBlockType("down")
1540 if blockType == "minecraft:cobblestone" then -- already a farm extension on left side
1541 T:go("R1F1D1")
1542 else
1543 T:go("D1R1F1x0")
1544 end
1545 -- cut ditch round new farm extension
1546 for i = 1, 11 do
1547 T:go("x0F1")
1548 end
1549 T:go("R1x0")
1550 for i = 1, 13 do
1551 T:go("x0F1")
1552 end
1553 T:go("R1x0")
1554 -- now at lower right corner. if extension below, do not cut ditch
1555 blockType = T:getBlockType("forward")
1556 if blockType == "minecraft:cobblestone" then -- already a farm extension below
1557 -- return to start for adding chests and walls
1558 T:go("U1R1F1L1F12R1")
1559 else -- finish ditch
1560 for i = 1, 12 do
1561 T:go("x0F1")
1562 end
1563 T:go("R1U1F1") -- on corner of new extension
1564 end
1565 elseif extend == "forward" then
1566 -- cut ditch round new farm extension
1567 T:go("L1F1x0R1D1")
1568 for i = 1, 12 do
1569 T:go("x0F1")
1570 end
1571 T:go("R1x0")
1572 for i = 1, 13 do
1573 T:go("x0F1")
1574 end
1575 T:go("R1x0")
1576 for i = 1, 11 do
1577 T:go("x0F1")
1578 end
1579 T:go("U1x0F1R1F12R1") -- on corner of new extension
1580 else -- new farm. cut a groove round the entire farm base
1581 -- move to left side of intended wall
1582 T:go("L1F1x0R1")
1583 for j = 1, 4 do
1584 for i = 1, 12 do
1585 T:go("x0F1")
1586 end
1587 T:go("R1x0F1")
1588 end
1589 T:go("R1F1L1U1")
1590 end
1591 -- stage 2 place sapling and double chest
1592 T:dig("down") --remove cobble if present
1593 T:place("minecraft:dirt", -1, "down", false)
1594 T:go("F1R2")
1595 T:place("sapling", -1, "forward", false) -- plant sapling
1596 T:go("L1")
1597 T:dig("down")
1598 T:place("minecraft:chest", -1, "down", false)-- place chest below
1599 T:go("L1F1R1")
1600 T:dig("down")
1601 T:place("minecraft:chest", -1, "down", false) -- place chest 2 below
1602 T:turnLeft(1)
1603 if extend == "right" then -- cobble wall exists so go forward to its end
1604 T:forward(9)
1605 else -- new farm or extend forward
1606 for i = 1, 9 do -- complete left wall to end of farm
1607 T:go("F1x0x2C2")
1608 end
1609 end
1610 T:go("R1F1R1x0x2C2F1D1")-- turn round ready for first dirt col
1611 lib.addWaterSource({"d","c","c","d"}) -- water at top of farm
1612 lib.placeDirt(9, false) -- place dirt back to start
1613 lib.addWaterSource({"c","c","d","d"}) -- water source next to chests
1614 T:go("U1F1R2")
1615 if T:getBlockType("down") ~= "minecraft:chest" then
1616 T:dig("down")
1617 T:place("minecraft:chest", -1, "down", false)
1618 end
1619 T:go("R1F1L1")
1620 if T:getBlockType("down") ~= "minecraft:chest" then
1621 T:dig("down")
1622 T:place("minecraft:chest", -1, "down", false)
1623 end
1624 T:go("F1D1")
1625 lib.placeDirt(9, true)
1626 local turn = "R"
1627 for i = 1, 7 do
1628 T:go("F1U1x0C2"..turn.."1F1"..turn.."1x0x2C2F1D1")
1629 lib.placeDirt(9, true)
1630 if turn == "R" then
1631 turn = "L"
1632 else
1633 turn = "R"
1634 end
1635 end
1636 T:go("F1U1x0C2"..turn.."1F1"..turn.."1x0x2C2F1D1")
1637 lib.addWaterSource({"d","c","c","d"})
1638 lib.placeDirt(9, false)
1639 lib.addWaterSource({"c","c","d","d"})
1640 T:go("F1U1R1C2x0F1x0x2C2R1")
1641 for i = 1, 11 do
1642 T:go("F1x0x2C2")
1643 end
1644 -- add chest to any existing farm extension to the right
1645 T:go("L1F1L1")
1646 if T:getBlockType("down") ~= "minecraft:cobblestone" then -- farm extension already exists to right
1647 T:place("minecraft:chest", -1, "down", false) --single chest marks this as an extension
1648 end
1649 T:go("L1F11")
1650end
1651
1652function createFarmExtension()
1653 -- assume inventory contains 4 chests, 64 cobble, 128 dirt, 4 water, 1 sapling
1654 -- check position by rotating to face tree/sapling
1655 local doContinue = true
1656 local treePresent = false
1657 local blockType = T:getBlockType("down")
1658 local extend = "right" -- default
1659 if blockType ~= "minecraft:chest" then
1660 T:clear()
1661 print("Chest not present below\n")
1662 print("Unable to calculate position")
1663 print("Move me next to/front of the tree / sapling")
1664 print("lower left corner of the existing farm.")
1665 doContinue = false
1666 else
1667 for i = 1, 4 do
1668 blockType = T:getBlockType("forward")
1669 if blockType:find("log") ~= nil or blockType:find("sapling") ~= nil then
1670 treePresent = true
1671 break
1672 end
1673 T:turnRight()
1674 end
1675 if not treePresent then
1676 T:clear()
1677 print("Unable to locate tree or sapling")
1678 print("Plant a sapling on the lower left")
1679 print("corner of the farm, or move me there")
1680 doContinue = false
1681 end
1682 end
1683 if doContinue then -- facing tree. check if on front or l side of farm
1684 T:go("R1F1D1") -- will now be over water if at front
1685 if T:getBlockType("down"):find("water") == nil then
1686 extend = "forward"
1687 end
1688 T:go("R2U1F1L1") -- facing away from tree, either to front or right
1689 T:forward(9)
1690 -- if tree or sapling in front warn and stop
1691 blockType = T:getBlockType("forward")
1692 if blockType:find("log") ~= nil or blockType:find("sapling") ~= nil then
1693 doContinue = false
1694 else
1695 T:forward(1) -- on corner ? cobble
1696 blockType = T:getBlockType("down")
1697 if blockType ~= "minecraft:cobblestone" then
1698 doContinue = false
1699 end
1700 end
1701 if doContinue then -- extend farm.
1702 if extend == "right" then
1703 T:turnLeft(1)
1704 end
1705 createFarm(extend)
1706 else
1707 T:clear()
1708 print("This farm has already been extended")
1709 print("Move me next to/front of the tree / sapling")
1710 print("of the last extension in this direction.")
1711 end
1712 end
1713end
1714
1715function createHollow(width, length, height)
1716 -- this function currently not used
1717 --should be in bottom left corner at top of structure
1718 -- dig out blocks in front and place to the left side
1719 --go(path, useTorch, torchInterval, leaveExisting)
1720 -- go @# = place any block up/forward/down # = 0/1/2
1721 for h = 1, height do
1722 for i = 1, length - 1 do
1723 T:go("L1@1R1F1", false, 0, true)
1724 end
1725 T:go("L1@1R2", false, 0, true, false)
1726 for i = 1, width - 1 do
1727 T:go("L1@1R1F1", false, 0, true)
1728 end
1729 T:go("L1@1R2", false, 0, true, false)
1730 for i = 1, length - 1 do
1731 T:go("L1@1R1F1", false, 0, true)
1732 end
1733 T:go("L1@1R2", false, 0, true, false)
1734 for i = 1, width - 1 do
1735 T:go("L1@1R1F1", false, 0, true)
1736 end
1737 T:go("L1@1R2", false, 0, true, false)
1738 -- hollowed out, now clear water/ blocks still present
1739 clearRectangle(width, length)
1740 if h < height then
1741 T:down(1)
1742 end
1743 end
1744end
1745
1746function createLadder(destination, level, destLevel, extend)
1747 -- go(path, useTorch, torchInterval, leaveExisting)
1748 -- place(blockType, damageNo, direction, leaveExisting)
1749 local height = 0
1750 local ledge = 0
1751 if destLevel == nil then destLevel = 1 end
1752 if extend == nil then extend = 0 end
1753 if destination == "surface" then -- assume surface to be 64
1754 T:go("C1U1C1", false, 0, true)
1755 for j = destLevel, level, -1 do
1756 T:up(1)
1757 for i = 1, 4 do
1758 if i ~= 3 then
1759 T:go("C1R1", false, 0, true)
1760 else
1761 T:turnRight(1)
1762 end
1763 end
1764 height = height + 1
1765 end
1766 if extend > 0 then
1767 -- at specified level. check if still blocks above
1768 while turtle.inspectUp() do
1769 T:up(1)
1770 for i = 1, 4 do
1771 if i ~= 3 then
1772 T:go("C1R1", false, 0, true)
1773 else
1774 T:turnRight(1)
1775 end
1776 end
1777 height = height + 1
1778 end
1779 -- nothing above
1780 end
1781 T:go("U1R2F1L2", false, 0, true) -- face wall previously built
1782 for i = height, 1, -1 do
1783 ledge = ledge + 1
1784 if ledge >= 3 then
1785 ledge = 0
1786 if not T:place("minecraft:netherrack", -1, "up", true) then
1787 if not T:place("minecraft:cobblestone", -1, "up", true) then
1788 T:place("minecraft:dirt", -1, "up", true)
1789 end
1790 end
1791 end
1792 -- Place cobble on 3 sides (if required)
1793 for j = 1, 4 do
1794 if j == 1 then -- place ladder on first side
1795 T:place("minecraft:ladder", -1, "forward", false)
1796 else
1797 if not T:place("minecraft:netherrack", -1, "forward", true) then
1798 if not T:place("minecraft:cobblestone", -1, "forward", true) then
1799 T:place("minecraft:dirt", -1, "forward", true)
1800 end
1801 end
1802 end
1803 T:turnLeft(1)
1804 end
1805 T:down(1)
1806 end
1807 else -- ladder to bedrock
1808 -- dig shaft to bedrock and close all sides except facing
1809 -- create a working area at the base
1810 -- Return to surface facing towards player placing ladders
1811 local success = true
1812 local numBlocks, errorMsg
1813 while success do --success = false when hits bedrock
1814 height = height + 1
1815 for i = 1, 4 do
1816 if i ~= 1 then
1817 if not T:place("minecraft:netherrack", -1, "forward", true) then
1818 T:place("minecraft:cobblestone", -1, "forward", true)
1819 end
1820 end
1821 T:turnRight(1)
1822 end
1823 success, numBlocks, errorMsg = T:down(1)
1824 -- if turtle does not delete source blocks place and dig a block above
1825 if not T:place("minecraft:netherrack", -1, "up", true) then
1826 T:place("minecraft:cobblestone", -1, "up", true)
1827 end
1828 T:dig("up")
1829 end
1830 -- test to check if on safe level immediately above tallest bedrock
1831 height = T:findBedrockTop(height)
1832 -- In shaft, facing start direction, on lowest safe level
1833 -- create a square space round shaft base, end facing original shaft, 1 space back
1834 -- place ladder on back of column for mining marker
1835 T:go("F1R1m1R1m2R1m2R1m2R1F1R1F1C1U1C1D1R2F1R2", false, 0, true)
1836 T:go("R1F1L1F3L1F1R1F1C1R2", false, 0, true)
1837 T:place("minecraft:ladder", -1, "forward", true)
1838 T:go("U1C0F1C0L1F1R1F3R1F1R1D1", false, 0, true)
1839 ledge = 0
1840 --local atBedrock = true
1841 for i = height, 0, -1 do
1842 if ledge >= 3 then
1843 ledge = 0
1844 if not T:place("minecraft:cobblestone", -1, "down") then
1845 T:place("minecraft:netherrack", -1, "down")
1846 end
1847 elseif ledge == 1 then
1848 T:place("minecraft:torch", -1, "down")
1849 end
1850 -- Place cobble on 3 sides (if required)
1851 for j = 1, 4 do
1852 if j == 1 then -- place ladder on first side
1853 T:place("minecraft:ladder", -1, "forward", false)
1854 else
1855 if not T:place("minecraft:cobblestone", -1, "forward", true) then
1856 T:place("minecraft:netherrack", -1, "forward")
1857 end
1858 end
1859 T:turnLeft(1)
1860 end
1861 T:up(1)
1862 ledge = ledge + 1
1863 end
1864 end
1865end
1866
1867function createLadderToWater()
1868 -- go down to water/lava with alternaate solid/open layers
1869 -- create a working area at the base
1870 -- Return to surface facing towards player placing ladders
1871 local inAir = true
1872 local numBlocks, errorMsg
1873 local block, blockType
1874 local height = 2
1875 T:go("R2D2", false, 0, true) -- face player, go down 2
1876 while inAir do --success = false when hits water/lava
1877 T:go("C1R1C1R2C1R1", false, 0, true)
1878 T:go("D1C1", false, 0, true)
1879 height = height + 1
1880 block, blockType = T:isWaterOrLava("down")
1881 if string.find(block, "water") ~= nil or string.find(block, "lava") ~= nil then
1882 inAir = false
1883 else
1884 T:down(1)
1885 height = height + 1
1886 end
1887 end
1888 -- In shaft, facing opposite start direction, on water/lava
1889 -- create a square space round shaft base, end facing original shaft, 1 space back
1890 T:go("R2C2F1C2F1C2R1", false, 0, true)
1891 T:go("F1C2F1C2R1", false, 0, true)
1892 T:go("F1C2F1C2F1C2F1C2R1", false, 0, true)
1893 T:go("F1C2F1C2F1C2F1C2R1", false, 0, true)
1894 T:go("F1C2F1C2F1C2F1C2R1", false, 0, true)
1895 T:go("F2R1F1", false, 0, true) -- under the upward pillar
1896
1897 for i = height, 0, -1 do
1898 T:go("C2e1U1")
1899 end
1900 T:down(1)
1901end
1902
1903function createMine()
1904 T:clear()
1905 T:go("m32U1R2M16", true, 8) -- mine ground level, go up, reverse and mine ceiling to mid-point
1906 T:go("U2D2") -- create space for chest
1907 T:place("minecraft:chest", -1, "up", false)
1908 T:emptyTrash("up")
1909 T:go("D1R1m16U1R2M16", true, 8) -- mine floor/ceiling of right side branch
1910 T:emptyTrash("up")
1911 T:go("D1m16U1R2M16", true, 8) -- mine floor/ceiling of left side branch
1912 T:emptyTrash("up")
1913 T:go("L1M15F1R1D1", true, 8) -- mine ceiling of entry coridoor, turn right
1914 T:go("F1x0F1x0n14R1n32R1n32R1n32R1n14F1x0F1U1", true, 8)-- mine floor of 36 x 36 square coridoor
1915 T:go("R1F16R2") --return to centre
1916 T:emptyTrash("up")
1917 T:go("F16R1") --return to entry shaft
1918 T:go("F2Q14R1Q32R1Q32R1Q32R1Q14F2R1", true, 8) --mine ceiling of 36x36 square coridoor. return to entry shaft + 1
1919 T:go("F16R2") --return to centre
1920 T:emptyTrash("up")
1921 -- get rid of any remaining torches
1922 while T:getItemSlot("minecraft:torch", -1) > 0 do
1923 turtle.select(T:getItemSlot("minecraft:torch", -1))
1924 turtle.dropUp()
1925 end
1926 T:go("F16R1F1R1") --return to shaft + 1
1927 for i = 1, 8 do
1928 T:go("N32L1F1L1", true)
1929 T:go("N16L1F"..(i * 2).."R2", true)
1930 T:emptyTrash("up")
1931 if i < 8 then
1932 T:go("F"..(i * 2).."L1N16R1F1R1", true)
1933 else
1934 T:go("F"..(i * 2).."L1N16L1", true)
1935 end
1936 end
1937 T:go("F17L1") -- close gap in wall, return to ladder + 1
1938 for i = 1, 8 do
1939 T:go("N32R1F1R1", true)
1940 T:go("N16R1F"..(i * 2).."R2", true)
1941 T:emptyTrash("up")
1942 if i < 8 then
1943 T:go("F"..(i * 2).."R1N16L1F1L1", true)
1944 else
1945 T:go("F"..(i * 2).."R1N16R1", true)
1946 end
1947 end
1948 T:go("F16R1")
1949 T:clear()
1950 print("Mining operation complete")
1951end
1952
1953function createMineBase()
1954 T:clear()
1955 -- check ladder:
1956 T:turnRight(2)
1957 local blockType, modifier = T:getBlockType("forward")
1958 while blockType == "" do
1959 T:forward(1)
1960 blockType, modifier = T:getBlockType("forward")
1961 end
1962 if blockType ~= "minecraft:ladder" then -- in correct position
1963 -- no ladder, move back 1
1964 T:back(1)
1965 end
1966 -- build pond:
1967 T:go("R1F1x0L1F1x0F1x0R1") -- at side wall
1968 T:go("F1n4R2n4U1R2Q4R2Q4R2") -- cut pond 3x1
1969 T:go("C2F4C2R2F1")
1970 T:place("minecraft:water_bucket", 0, "down", false)
1971 T:forward(2)
1972 T:place("minecraft:water_bucket", 0, "down", false)
1973 T:go("F2L1F2R1F1L1") -- at start position
1974 --[[
1975 T:go("m32U1R2M16D1", true, 8) -- mine ground level, go up, reverse and mine ceiling to mid-point, drop to ground
1976 T:go("U1R1A15D1R2m15", false, 0) -- Create roof of coridoor, turn and create lower wall + floor
1977 T:go("U1A15D1R2m15U1x0", false, 0) -- Create roof of coridoor, turn and create lower wall + floor
1978 T:place("minecraft:chest", -1, "up", false) --place chest in ceiling
1979 T:emptyTrash("up")
1980 T:go("L1M15F1R1D1", true, 8) -- mine ceiling of entry coridoor, turn right, drop down
1981 T:go("F2n14R1n15", true, 8)-- mine floor of first quarter of square
1982 T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
1983 T:go("F1x0n14R1n32R1n15", true, 8)
1984 T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
1985 T:go("F1x0n14R1n14F2", true, 8)-- mine floor of last quarter of square
1986
1987 T:go("U1R1F16R2D1") --return to centre
1988 T:emptyTrash("up")
1989 T:go("U1F16R1") --return to entry shaft
1990 T:go("F2Q14R1Q15", true, 8) -- mine ceiling of first quarter
1991 T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
1992 T:go("C0F1Q14R1Q32R1Q15", true, 8) --mine ceiling of second half
1993 T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
1994 T:go("C0F1Q14R1Q14F2R1", true, 8) -- mine ceiling of last quarter
1995 T:go("F16D1") --return to centre
1996 T:emptyTrash("up")
1997 -- get rid of any remaining torches
1998 while T:getItemSlot("minecraft:torch", -1) > 0 do
1999 turtle.select(T:getItemSlot("minecraft:torch", -1))
2000 turtle.dropUp()
2001 end
2002
2003 for i = 1, 8 do
2004 T:go("N32L1F1L1", true)
2005 T:go("N16L1F"..(i * 2).."R2", true)
2006 T:emptyTrash("up")
2007 T:go("F"..(i * 2).."L1N16R1F1R1", true)
2008 end
2009 T:go("L1F17L1") -- close gap in wall, return to ladder + 1
2010 for i = 1, 8 do
2011 T:go("N32R1F1R1", true)
2012 T:go("N16R1F"..(i * 2).."R2", true)
2013 T:emptyTrash("up")
2014 T:go("F"..(i * 2).."R1N16L1F1L1", true)
2015 end
2016 -- fill water buckets
2017 -- return to centre
2018 T:go("R1F16R1")]]
2019
2020 T:clear()
2021 print("Mining operation complete")
2022end
2023
2024function createMineEnhanced()
2025 T:clear()
2026 T:go("m32U1R2M16D1x2", true, 8) -- mine ground level, go up, reverse and mine ceiling to mid-point, drop to ground, excavate
2027 T:emptyTrash("down")
2028 T:go("U1R1A15D1R2E13m2x2", false, 0) -- Create roof of coridoor, turn and create lower wall + remove floor
2029 T:emptyTrash("down")
2030 T:go("U1A15D1R2E13m2x2", false, 0) -- Create roof of coridoor, turn and create lower wall + remove floor
2031 T:emptyTrash("down")
2032 T:go("U1L1M15F1R1D1", true, 8) -- mine ceiling of entry coridoor, turn right, drop down
2033 T:go("F2n14R1n15", true, 8)-- mine floor of first quarter of square
2034
2035 T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
2036 T:go("F1x0n14R1n32R1n15", true, 8)
2037 T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
2038 T:go("F1x0n14R1n14F2", true, 8)-- mine floor of last quarter of square
2039 T:go("U1R1F16R2D1") --return to centre
2040 T:emptyTrash("down")
2041 T:go("U1F16R1") --return to entry shaft
2042 T:go("F2Q14R1Q15", true, 8) -- mine ceiling of first quarter
2043 T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
2044 T:go("C0F1Q14R1Q32R1Q15", true, 8) --mine ceiling of second half
2045 T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
2046 T:go("C0F1Q14R1Q14F2R1", true, 8) -- mine ceiling of last quarter
2047 T:go("F16D1") --return to centre
2048 T:emptyTrash("down")
2049 -- get rid of any remaining torches
2050 while T:getItemSlot("minecraft:torch", -1) > 0 do
2051 turtle.select(T:getItemSlot("minecraft:torch", -1))
2052 turtle.dropDown()
2053 end
2054 --cut access coridoors
2055 T:go("U1F2R1F1Q14F1 R1F1L1F1R1F2R1F1L1F1R1 F1Q14F2Q14F1 R1F1L1F1R1F2R1F1L1F1R1F1 Q14F1D1") --ceiling
2056 T:go("F1n14F1 R1F1L1F1R1F2R1F1L1F1R1 F1n14F2n14F1 R1F1L1F1R1F2R1F1L1F1R1F1 n14F1U1") --floor, then up
2057 T:go("R1F2D1")
2058 T:go("R1F1C1B1C1L1C1L1F1C1B1C1L1C1L2")
2059 T:emptyTrash("down")
2060 T:go("U1F16R1F1R1") --return to entry shaft + 1
2061
2062 for i = 1, 8 do
2063 T:go("N32L1F1L1", true)
2064 if i == 1 then
2065 T:go("N16L1F2R2", true)
2066 T:emptyTrash("down")
2067 T:go("F2L1N16R1F1R1", true)
2068 elseif i == 8 then
2069 T:go("L1F1R1N16", true)
2070 T:emptyTrash("down")
2071 T:go("N16R1F1R1", true)
2072 else
2073 T:go("N16", true)
2074 T:emptyTrash("down")
2075 T:go("N16R1F1R1", true)
2076 end
2077 end
2078 T:go("L1F16L1") -- return to shaft + 1
2079 for i = 1, 8 do
2080 T:go("N32R1F1R1", true)
2081 if i == 1 then
2082 T:go("N16R1F2R2", true)
2083 T:emptyTrash("down")
2084 T:go("F2R1N16L1F1L1", true)
2085 elseif i == 8 then
2086 T:go("R1F1L1N16", true)
2087 T:emptyTrash("down")
2088 T:go("N16R1F1R1", true)
2089 else
2090 T:go("N16", true)
2091 T:emptyTrash("down")
2092 T:go("N16L1F1L1", true)
2093 end
2094 end
2095 T:go("L1F15R1") -- return
2096 T:clear()
2097 print("Mining operation complete")
2098end
2099
2100function createMobBubbleLift(size)
2101 -- size = 0 or 1 (left/right)
2102 local lib = {}
2103
2104 function lib.down()
2105 local moves = 0
2106 while turtle.down() do
2107 moves = moves + 1
2108 end
2109 return moves
2110 end
2111
2112 function lib.up()
2113 local moves = 0
2114 while turtle.up() do
2115 moves = moves + 1
2116 end
2117 return moves
2118 end
2119 -- check if dirt or soulsand below
2120 local turn = "R"
2121 if size == 1 then
2122 turn = "L"
2123 end
2124 local onSand = false
2125 local blockType = T:getBlockType("down")
2126 if blockType == "minecraft:soul_sand" then
2127 onSand = true
2128 elseif blockType == "minecraft:dirt" then
2129 T:dig("down")
2130 if T:place("minecraft:soul_sand", -1, "down", false) then
2131 onSand = true
2132 end
2133 end
2134 if onSand then
2135 -- check facing sign, rotate if not
2136 blockType = T:getBlockType("forward")
2137 while blockType:find("sign") == nil do
2138 T:turnRight(1)
2139 blockType = T:getBlockType("forward")
2140 end
2141 for i = 1, 3 do
2142 -- fill in back and one side, go up
2143 if turn == "R" then
2144 T:go("R1C1R1C1R1x1R1U1", false, 0, true)
2145 else
2146 T:go("L1C1L1C1L1x1L1U1", false, 0, true)
2147 end
2148 end
2149 for i = 1, 17 do
2150 -- tunnel up, filling 3 sides
2151 if turn == "R" then
2152 T:go("R1C1R1C1R1x1R1C1U1", false, 0, true)
2153 else
2154 T:go("L1C1L1C1L1x1L1C1U1", false, 0, true)
2155 end
2156 end
2157 -- move either left/right 8 blocks, repairing ceiling and sides
2158 if turn == "R" then
2159 T:go("C0R2C1R1F1C0C1R1C1R2C1L1F1A8", false, 0, true) -- fill top of column
2160 else
2161 T:go("C0L2C1L1F1C0C1L1C1L2C1R1F1A8", false, 0, true) -- fill top of column
2162 end
2163 -- turn round, go down 1, forward 7 blocks repairing bottom and sides
2164 T:go("D1C1R2X7", false, 0, true)
2165 -- turn round, go up, place cobble, forward 4, place cobble
2166 T:go("R2U1C2F4C2", false, 0, true)
2167 -- turn round forward 1 place water, forward 2, place water
2168 T:go("R2F1", false, 0, true)
2169 T:place("minecraft:water_bucket", -1, "down", false)
2170 T:forward(2)
2171 T:place("minecraft:water_bucket", -1, "down", false)
2172 T:go("R2F1")
2173 repeat
2174 -- refill both buckets
2175 T:place("minecraft:bucket", -1, "down", false)
2176 sleep(0.5)
2177 T:place("minecraft:bucket", -1, "down", false)
2178 -- back 4, down to solid, place water,
2179 for i = 1, 4 do
2180 turtle.back()
2181 end
2182 local moves = lib.down() -- returns no of blocks descent 0 to 19
2183 if moves > 0 then
2184 T:place("minecraft:water_bucket", -1, "forward", false)
2185 T:go("U1C2")
2186 if moves > 1 then
2187 T:place("minecraft:water_bucket", -1, "forward", false)
2188 T:go("U1C2")
2189 end
2190 end
2191 lib.up() -- 0 - 19
2192 T:forward(4)
2193 until moves <= 1
2194 -- delete water sources and remove cobble
2195 T:go("R2F3C1R2F1")
2196 for i = 1, 7 do -- go to end of run placing cobble
2197 T:go("C2F1")
2198 end
2199 T:turnRight(2)
2200 for i = 1, 7 do -- go to end of run, down 2
2201 T:go("x2F1x2")
2202 end
2203 T:go("R2F7D2")
2204 for i = 1, 18 do
2205 -- tunnel down, filling all 4 sides
2206 T:go("R1C1R1C1R1C1R1C1D1", false, 0, true)
2207 end
2208 -- turn round, tunnel forward 6 blocks
2209 T:go("R2U1F1M5D1R2F1X5")-- end up under drop column
2210 else
2211 print("Unable to find or place soulsand.\nEnter to continue")
2212 read()
2213 end
2214end
2215
2216function createMobFarmCube(blaze)
2217 if blaze == nil then blaze = false end
2218 ]
2219 local lib = {}
2220 function lib.rail(move, isPowered, count)
2221 if move ~= "" then
2222 T:go(move)
2223 end
2224 for i = 1, count do
2225 if isPowered then
2226 if not T:place("minecraft:powered_rail", -1, "down", false) then
2227 T:place("minecraft:golden_rail", -1, "down", false)
2228 end
2229 else
2230 T:place("minecraft:rail", -1, "down", false)
2231 end
2232 if i < count then
2233 T:forward(1)
2234 end
2235 end
2236 end
2237
2238 -- clsTurtle.go(self, path, useTorch, torchInterval, leaveExisting, preferredBlock)
2239 -- determine spawner position level 4, move to top of spawner (level 6)
2240 local onTop = false
2241 local blockType = T:getBlockType("down")
2242 if blockType:find("spawner") ~= nil then
2243 onTop = true
2244 end
2245 if not onTop then
2246 blockType = T:getBlockType("up")
2247 if blockType:find("spawner") ~= nil then
2248 T:go("B1U2F1")
2249 onTop = true
2250 end
2251 end
2252 if not onTop then
2253 blockType = T:getBlockType("forward")
2254 if blockType:find("spawner") ~= nil then
2255 T:go("U1F1")
2256 onTop = true
2257 end
2258 end
2259 if onTop then
2260 -- place slab on top T:place(blockType, damageNo, direction, leaveExisting)
2261 T:up(1)
2262 T:place("slab", -1, "down", true)
2263 -- go up 2 blocks, forward 4, right, forward 4, right
2264 T:go("U2F4R1F4R1")
2265 -- clear 9x9 and plug ceiling (level 9)
2266 --"Q": mine block above and/or fill void + mine block below if valuable + left side
2267 T:go("R2C1R2Q8R1Q8R1Q8R1Q7R1F1", false, 0, false)
2268 -- 7x7 rectangle filling above
2269 for i = 1, 3 do
2270 T:go("M7R1F1R1M7L1F1L1", false, 0, false)
2271 end
2272 T:go("M7R2F8R1F7R1", false, 0, false) --back to corner
2273 -- mine wall: q# mine # blocks forward, check left side and patch
2274 for i = 1, 2 do
2275 -- down 1, clear 9x9 border, checking walls (level 8, 7)
2276 T:go("D1R2C1R2q8R1q8R1q8R1q7R1F1", false, 0, false)
2277 -- clear remaining 7x7 area
2278 clearRectangle(7, 7, false)
2279 T:go("R2F1R1F1R1", false, 0, false) --back to corner
2280 end
2281 for i = 1, 2 do
2282 -- down 1, clear 9x9 border (level 6, 5)
2283 T:go("D1R2C1R2q8R1q8R1q8R1q7R1", false, 0, false)
2284 T:go("F7R1F6R1F6R1F5R1", false, 0, false)
2285 T:go("F5R1F4R1F4R1F6L1F2R2", false, 0, false)
2286 end
2287 local count = 3
2288 if blaze then
2289 count = 2
2290 end
2291 for i = 1, count do
2292 -- down 1, clear 9x9 border, checking walls (level 4, 3, (2))
2293 T:go("D1R2C1R2q8R1q8R1q8R1q7R1F1")
2294 -- clear remaining 7x7 area
2295 clearRectangle(7, 7, false)
2296 T:go("R2F1R1F1R1", false, 0, false) --back to corner
2297 end
2298 if blaze then
2299 -- strart in top right corner. border is made of slabs placed up
2300 T:go("D1R2F1R1F1R1")
2301 for i = 1, 3 do
2302 clearRectangle(11, 11, false) --layer 2, 1, 0
2303 T:down(1)
2304 end
2305
2306 T:go("R2F1R1F1R1")
2307 -- ready to lay floor and border
2308 -- q# mine # blocks forward, check left side and patch
2309 T:go("R2C1R2 n12R1 n12R1 n12R1 n11R1F1", false, 0, false)
2310 -- fill in floor 11x11 rectangle below
2311 local brick = "minecraft:nether_bricks" -- 1.16+ name
2312 local a, b, numBricks = T:getItemSlot(brick)
2313 if numBricks == 0 then
2314 a, b, numBricks = T:getItemSlot("minecraft:nether_brick") -- pre 1.16+
2315 if numBricks == 0 then
2316 brick = "minecraft:nether_brick"
2317 end
2318 end
2319 for i = 2, 12 do -- 11 iterations (rows)
2320 T:go("m10", false, 0, false, brick)
2321 if i % 2 == 0 then -- 2, 4, 6, 8, 10
2322 if i < 12 then
2323 T:go("R1F1R1", false, 0, false, brick)
2324 end
2325 else -- 3,5,7,9,11
2326 T:go("L1F1L1", false, 0, false, brick)
2327 end
2328 end
2329 -- turn 180 and ask for supplies
2330 T:go("L1F1L1F1U1") -- lower left corner start
2331 T:sortInventory()
2332 T:emptyTrashItem("forward", "minecraft:netherrack", 0)
2333 T:emptyTrashItem("forward", brick, 128)
2334 T:emptyTrashItem("forward", "fence", 0)
2335 --clsTurtle.getItemSlot(self, item, useDamage): return slotData.lastSlot, slotData.leastModifier, total, slotData
2336 a, b, numBricks = T:getItemSlot(brick)
2337 if numBricks > 81 then -- enough for floor
2338 T:checkInventoryForItem({"minecraft:cobblestone"}, {339})
2339 else
2340 T:checkInventoryForItem({"minecraft:cobblestone", brick}, {420, 420})
2341 end
2342 T:checkInventoryForItem({"slab"}, {36})
2343 T:checkInventoryForItem({"minecraft:powered_rail", "minecraft:golden_rail"}, {8, 8})
2344 T:checkInventoryForItem({"minecraft:rail"}, {64})
2345 T:checkInventoryForItem({"minecraft:redstone_torch"}, {2})
2346 T:checkInventoryForItem({"minecraft:hopper_minecart"}, {1})
2347 T:checkInventoryForItem({"minecraft:stone_button"}, {1})
2348 print("Stand clear. Starting in 2 secs")
2349 os.sleep(2) -- pause for 2 secs to allow time to press esc
2350 lib.rail("", true, 2) -- lay 2 plain rail at start
2351 lib.rail("F1", false, 1) -- lay 1 plain rail
2352 lib.rail("F1", true, 3) -- lay 3 powered rail
2353 T:go("L1F1")
2354 T:place("minecraft:redstone_torch", -1, "down", false) --place redstone torch
2355 lib.rail("R2F1L1F1", false, 3)
2356 lib.rail("R1F1R1", false, 8)
2357 lib.rail("L1F1L1", false, 7)
2358 lib.rail("R1F1R1", false, 8)
2359 lib.rail("L1F1L1", false, 9)
2360 lib.rail("R1F1R1", false, 8)
2361 lib.rail("L1F1L1", false, 7)
2362 lib.rail("R1F1R1", false, 8)
2363 lib.rail("L1F1L1", false, 5) -- final strip
2364 lib.rail("F1", true, 3)
2365 T:go("F1C2R1F1R1F1")
2366 T:place("minecraft:redstone_torch", -1, "down", false)
2367 T:go("R2F1L1F1L1U1")
2368 -- lay floor 9 x 9 rectangle filling below
2369 for i = 2, 10 do -- repeat 9x
2370 T:go("m8", false, 0, false, brick)
2371 if i < 10 then
2372 if i % 2 == 0 then
2373 T:go("R1F1R1", false, 0, false, brick)
2374 else
2375 T:go("L1F1L1", false, 0, false, brick)
2376 end
2377 end
2378 end
2379 -- replace first rail with cobble and button
2380 T:go("R1F1R2D2x1C1B1", false, 0, false)
2381 T:place("minecraft:stone_button", -1, "forward", false)
2382 T:go("U2F2L1F1x2")
2383 T:place("minecraft:hopper_minecart", -1, "down", false)
2384 T:go("L1F1D1R2C1", false, 0, false, brick) -- cover minecart
2385 T:go("U1R1F2L1C0F1",false, 0, false)
2386 -- place slabs
2387 for j = 1, 4 do
2388 for i = 1, 9 do
2389 T:place("slab", -1, "up", false)
2390 T:forward(1)
2391 end
2392 if j < 4 then
2393 T:go("L1C0F1")
2394 end
2395 end
2396 T:go("L1F1L2") -- get in position
2397 -- build outer edge
2398 for j = 1, 4 do
2399 for i = 1, 9 do
2400 turtle.back()
2401 T:place("minecraft:cobblestone", -1, "forward", false)
2402 end
2403 if j < 4 then
2404 T:turnLeft(1)
2405 turtle.back()
2406 T:place("minecraft:cobblestone", -1, "forward", false)
2407 end
2408 end
2409 T:go("L1F1R2C1L1U1")
2410 for j = 1, 4 do
2411 for i = 1, 11 do
2412 T:go("C0x2F1")
2413 end
2414 T:go("C0x2R1F1")
2415 end
2416 T:go("R2F2R1F1R1")
2417 T:go("R2C1R2Q14R1Q14R1Q14R1Q13R1D1", false, 0, false)
2418 T:go("L1F1R1")
2419 T:go("R2C1R2n14R1n14R1n14R1n13R1", false, 0, false)
2420 else
2421 -- clear floor and plug holes
2422 -- n# mine block below and/or fill void + check left side
2423 T:down(2)
2424 for j = 1, 2 do
2425 T:go("R2C1R2n8R1n8R1n8R1n7R1F1", false, 0, true)
2426 -- 7x7 rectangle filling below
2427 for i = 1, 4 do
2428 if i < 4 then
2429 T:go("m6R1F1R1m6L1F1L1", false, 0, true)
2430 else
2431 T:go("m6R1F1R1m6", false, 0, true)
2432 end
2433 end
2434 if j == 1 then
2435 T:go("U1F1R1F8R1")
2436 end
2437 end
2438 end
2439 else
2440 T:clear()
2441 print("Spawner not found. Place me on top,")
2442 print("immediately below, or facing it.")
2443 print("\nEnter to quit")
2444 read()
2445 end
2446end
2447
2448function createMobSpawnerBase(pathLength)
2449 if pathLength > 0 then
2450 print("Building path to mob spawner base")
2451 createPath(pathLength)
2452 T:back(1)
2453 end
2454 T:place("stone", -1, "down", true)
2455 T:go("R1F1L1", false, 0, true)
2456 createPath(8)
2457 T:go("L1F1L1F1", false, 0, true)
2458 createPath(8)
2459 T:go("R1F1R1F1", false, 0, true)
2460 createPath(8)
2461 T:go("L1F1L1F1", false, 0, true)
2462 createPath(8)
2463 T:go("L1F2L1F1", false, 0, true)
2464end
2465
2466function createMobSpawnerTower(height)
2467 height = height or 2
2468 print("Building mob spawner base")
2469 -- assume placed at sea level on stone block (andesite / granite / diorite)
2470 --layers 2, 3 (layer 1 done at base construction)
2471 T:go("U1F7H2L1F1H2R1F2D1R2P1L1F1R1P1R2U1", false, 0, true)
2472 for i = 1, 8 do
2473 T:go("C2R1C1L1F1", false, 0, true)
2474 end
2475 T:go("L1F1L2C1R1F1R2C1R2", false, 0, true)
2476 for i = 1, 8 do
2477 T:go("C2R1C1L1F1", false, 0, true)
2478 end
2479 T:go("U1R2F8R1", false, 0, true)
2480 T:place("minecraft:water_bucket", -1, "down", false)
2481 T:go("F1R1", false, 0, true)
2482 T:place("minecraft:water_bucket", -1, "down", false)
2483 T:forward(16)
2484 T:go("R1F1D2", false, 0, true)
2485 for i = 1, 2 do
2486 sleep(0.5)
2487 T:place("minecraft:bucket", -1, "down", false)
2488 end
2489 T:go("R1F2", false, 0, true)
2490 for i = 1, 2 do
2491 T:go("C1R1C1R2C1R1U1")
2492 end
2493 -- height of tower
2494 height = math.ceil(height / 2)
2495 for i = 1, height do
2496 T:go("C1U1C1R1C1R1C1R1C1R1U1")
2497 end
2498 -- create platform for player
2499 T:go("R2F1L1C1R1C1R1C1U1C1L1C1L1C1L1F1L1C!R2C1L1U1F1", false, 0, true)
2500 -- place stone marker
2501 T:place("stone", -1, "down")
2502 -- will need to move back before completing
2503end
2504
2505function createMobSpawnerTank()
2506 --layer 1 of tower + walkway
2507 -- move back 1 block before continuing with tower top and walkway
2508 T:go("R2F1R2")
2509 T:go("C1U2R1F1L1") -- now dropping cobble from above
2510 T:go("m10L1F1L1")
2511 T:go("m9R1F1L1F1C2F1L1F1C2L1F1")
2512 --layer 2
2513 T:go("U1F1C2R1F1C2F1L1F1m8L1F3L1m8F2L1F1L1")
2514 --layer 3
2515 T:go("U1R1F1C2L1F1C2")
2516 T:go("F1R1F1L1C2F1C2F1L1F1C2")
2517 T:go("F1C2F1L1F1C2F1C2F2C2F1")
2518 T:go("L1F1C2L1F2C2B1")
2519 --layer 4
2520 T:go("U1F1L1F1R2")
2521 for i = 1, 4 do
2522 T:go("F1C2F1C2F1L1")
2523 end
2524 T:go("F1R1F1R2")
2525 --layer 5
2526 T:go("U1R2F1m7L1F1L1C2F1C2F7C2F1C2")
2527 T:go("F1R1F1L1C2F1C2F1L1F1C2F1C2F1")
2528 T:go("L1F1C2F1C2F2C2L1F1L1F1C2R2F1R2")
2529 -- layer 6
2530 T:go("U1R2F9C2L1F1C2F1L1F1C2F1L1F1C2R1F8L1F2R2")
2531 for i = 1, 4 do
2532 T:go("F1C2F1C2F1L1")
2533 end
2534 T:go("F1L1F1")
2535 T:place("minecraft:water_bucket", -1, "down")
2536 T:go("R1F1L1")
2537 T:place("minecraft:water_bucket", -1, "down")
2538 T:go("R2F2R1F1R1")
2539 -- layer 7
2540 T:go("U1R2F8L1F2C2L1F1L1F1C2R1F7C2L1F2R1C2F1R1")
2541 for i = 1, 4 do
2542 T:go("F1C2F1C2F1L1")
2543 end
2544 T:go("F1R1F1R2")
2545 T:go("F2")
2546 -- place stone inside column, ready for temp water source
2547 T:place("stone", -1, "down", false)
2548
2549 -- layer 8
2550 -- make temp water source in centre. destroy in createMobSpawnerRoof()
2551 T:go("F1C2R1F1C2R1F1C2F1R1F2U1R2")
2552 -- spiral construction
2553 for j = 3, 9, 2 do
2554 for i = 1, 4 do
2555 if i < 4 then
2556 T:go("m"..j.."L1")
2557 else
2558 T:go("m"..j.."F1R1F1L2")
2559 end
2560 end
2561 end
2562 -- fill water source
2563 T:go("F5L1F5")
2564 T:place("minecraft:water_bucket", -1, "down", false)
2565 T:go("F1R1F1R1")
2566 T:place("minecraft:water_bucket", -1, "down", false)
2567 T:go("F5m4F2C2F1R1F1C2F1R1F1C2F1R1F1L1C2F1m4")
2568 T:go("F8F2m3R1F1R1m3")
2569 T:go("F5L1F5m3R1F1R1m3")
2570 T:go("F9F2m3R1F1R1m3")
2571 -- layer 9
2572 T:up(1)
2573 for i = 1, 4 do
2574 T:go("L1F1L1m3R1F1R1m3L1F1L1m3R1F1R1m3F4")
2575 T:go("L1F1L1m7R1F1R1m7L1F1L1m7R1F1R1m7F1L1F1R1C2F1C2R1F4")
2576 end
2577 -- now add water
2578 T:go("F6")
2579 for i = 1, 4 do
2580 T:down(1)
2581 T:place("minecraft:bucket", -1, "down", false)
2582 sleep(0.5)
2583 T:place("minecraft:bucket", -1, "down")
2584 T:go("U1F8R1")
2585 T:place("minecraft:water_bucket", -1, "down", false)
2586 T:go("F1R1")
2587 T:place("minecraft:water_bucket", -1, "down", false)
2588 T:go("F8L1")
2589 end
2590 for i = 1, 2 do
2591 T:down(1)
2592 T:place("minecraft:bucket", -1, "down", false)
2593 sleep(0.5)
2594 T:place("minecraft:bucket", -1, "down", false)
2595 T:go("U1F4L1F4L1")
2596 T:place("minecraft:water_bucket", -1, "down", false)
2597 T:go("F9")
2598 T:place("minecraft:water_bucket", -1, "down", false)
2599 T:go("L1F5L1F4L2")
2600 end
2601 T:go("F9R1F10R1")
2602 -- layer 10 / 11
2603 for j = 1, 2 do
2604 T:go("U1F1m8L1F1C2F1R1F1C2F1R1F1C2F1R1F1R2m8F1R1")
2605 for i = 1, 3 do
2606 T:go("F1m17F1R1")
2607 end
2608 end
2609 T:go("F10R1F9D4")
2610end
2611
2612function createMobSpawnerRoof()
2613 -- destroy water source first
2614 T:go("x2C1R1F1x2L1F1x2L1F1x2L1F1x2L2")
2615 T:go("U5L1F8L1F8L2") -- top left corner facing e
2616 T:go("m17R1m17R1m17R1m17") -- outer ring. ends facing n
2617 T:go("R1F2R1F1L1") -- facing e
2618 for i = 1, 4 do -- outer ring - 1 (with torches) ends facing e
2619 T:go("m6t1m3t1m5R1F1t1")
2620 end
2621 T:go("R1F1L1") -- facing e
2622 for i = 1, 4 do -- outer ring - 2 ends facing e
2623 T:go("m13R1m13R1m13R1m13")
2624 end
2625 T:go("R1F1L1") -- ends facing e
2626 T:go("m11R1m11R1m11R1m11") -- ends facing e
2627 T:go("R1F1R1F1L1F1")
2628 for i = 1, 4 do
2629 T:go("m8R1F1t1")
2630 end
2631 T:go("R1F1L1")
2632 T:go("m7R1m7R1m7R1m7")
2633 T:go("R1F1R1F1L1")
2634 T:go("m5R1m5R1m5R1m5")
2635 T:go("R1F1R1F1L1F1")
2636 for i = 1, 4 do
2637 T:go("m2R1F1t1")
2638 end
2639 T:go("R1F1L1")
2640 T:go("m1R1m1R1m1R1m1")
2641end
2642
2643function createPath(length, isCanal)
2644 length = length or 0 --allow for choice of path length
2645 if isCanal == nil then
2646 isCanal = false
2647 end
2648 local numBlocks = 1
2649 local path = 0
2650 local distance = 0
2651 local torch = 0
2652 local continue = true
2653 local slot = 0
2654 local place = clearVegetation("down") --true if water, lava, or air below
2655 if place then
2656 placeAnyStone("down")
2657 end
2658 T:forward(1)
2659 place = clearVegetation("down")
2660 --while string.find(blockType, "water") ~= nil or string.find(blockType, "lava") ~= nil or blockType == "" do
2661 while place do -- while air, water or lava below
2662 continue = placeAnyStone("down")
2663 if continue then -- false if out of blocks
2664 T:forward(1)
2665 numBlocks = numBlocks + 1
2666 --blockType, blockModifier = T:getBlockType("down")
2667 distance = distance + 1
2668 torch = torch + 1
2669 slot = T:getItemSlot("minecraft:torch", -1)
2670 if torch == 8 and slot > 0 then
2671 torch = 0
2672 T:turnRight(2)
2673 T:place("minecraft:torch", -1, "forward", false)
2674 T:turnRight(2)
2675 end
2676 else
2677 break
2678 end
2679 path = path + 1
2680 if length > 0 and path >= length then
2681 break
2682 end
2683 place = clearVegetation("down")
2684 end
2685 if continue and not isCanal then
2686 T:forward(1)
2687 end
2688 return numBlocks
2689end
2690
2691function createPortal()
2692 T:go("D1x1", false, 0, true)
2693 T:place("minecraft:cobblestone", 0, "forward", true)
2694 for i = 1, 3 do
2695 T:go("U1x1", false, 0, true)
2696 T:place("minecraft:obsidian", 0, "forward", true)
2697 end
2698 T:go("U1x1", false, 0, true)
2699 T:place("minecraft:cobblestone", 0, "forward", true)
2700 for i = 1, 2 do
2701 T:go("R1F1L1x1")
2702 T:place("minecraft:obsidian", 0, "forward", true)
2703 end
2704 T:go("R1F1L1x1", false, 0, true)
2705 T:place("minecraft:cobblestone", 0, "forward", true)
2706 for i = 1, 3 do
2707 T:go("D1x1")
2708 T:place("minecraft:obsidian", 0, "forward", true)
2709 end
2710 T:go("D1x1", false, 0, true)
2711 T:place("minecraft:cobblestone", 0, "forward", true)
2712 for i = 1, 2 do
2713 T:go("L1F1R1x1")
2714 T:place("minecraft:obsidian", 0, "forward", true)
2715 end
2716 T:go("U1L1F1R1", false, 0, true)
2717end
2718
2719function createRailwayDown(userChoice, drop)
2720 --make sure torch placed on lowest level
2721 -- 1 block not required
2722 -- 2 - 3 blocks 1 torch at base
2723 -- 4 - 6 blocks 2 torch
2724 --
2725 for i = 1, drop - 1 do
2726 T:go("F1D1", false, 0, true)
2727 T:place(userChoice, -1, "down", false)
2728 end
2729end
2730
2731function createRailwayUp(userChoice, up)
2732 for i = 1, up do
2733 T:place(userChoice, -1, "forward", false)
2734 T:go("U1F1", false, 0, true)
2735 end
2736end
2737
2738function createRetainingWall(length, height)
2739 local place = false
2740 if height <= 0 then
2741 height = 30
2742 end
2743 local inWater = false
2744 for i = 1, 4 do
2745 if string.find(T:getBlockType("forward"), "water") ~= nil then
2746 inWater = true
2747 end
2748 T:turnRight(1)
2749 end
2750
2751 local y = 1
2752 -- go(path, useTorch, torchInterval, leaveExisting)
2753 -- start at surface, move back 1 block
2754 -- each iteration completes 3 columns
2755 local numBlocks = T:getSolidBlockCount()
2756
2757 if not inWater then
2758 T:down(1)
2759 end
2760 place = clearVegetation("down") -- returns true if air, water or lava below
2761 if length == 1 then --single column
2762 local place = clearVegetation("down")
2763 while place do -- loop will be entered at least once
2764 T:down(1)
2765 y = y + 1
2766 place = clearVegetation("down")
2767 end
2768 for i = 1, y - 1 do
2769 T:go("U1C2", false, 0, true, false)
2770 end
2771 elseif length == 2 then--down then up
2772 T:back(1) -- move 1 block away from wall edge
2773 local place = clearVegetation("down")
2774 while place do -- loop will be entered at least once
2775 T:go("C1D1", false, 0, true, false)
2776 y = y + 1
2777 place = clearVegetation("down")
2778 end
2779 T:forward(1) -- in case col in front is deeper
2780 place = clearVegetation("down")
2781 while place do -- loop will be entered at least once
2782 T:down(1)
2783 y = y + 1
2784 place = clearVegetation("down")
2785 end
2786 T:go("B1C1", false, 0, true)
2787 for i = 1, y - 1 do
2788 T:go("U1C2", false, 0, true)
2789 end
2790 T:go("C1", false, 0, true, false)
2791 else -- length 3 or more eg 3,22; 11
2792 local remain = length % 3 -- 0; 1; 2 only possible results
2793 length = length - remain -- 3-0=3; 4-1=3; 5-2=3; 6-0=6
2794 for i = 3, length, 3 do -- 3, 6, 9, 12 etc
2795 numBlocks = T:getSolidBlockCount()
2796 if numBlocks < height * 3 then
2797 --ask player for more
2798 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {height * 3, height * 3}, false)
2799 end
2800 T:go("B1C1", false, 0, true)
2801 if i > 3 then -- second iteration
2802 T:go("B1C1")
2803 end
2804 -- place blocks forward while descending
2805 place = clearVegetation("down")
2806 while place do -- loop will be entered at least once
2807 T:go("C1D1", false, 0, true)
2808 y = y + 1
2809 place = clearVegetation("down")
2810 end
2811 T:forward(1) -- in case col in front is deeper
2812 place = clearVegetation("down")
2813 while place do -- loop will be entered at least once
2814 T:down(1)
2815 y = y + 1
2816 place = clearVegetation("down")
2817 end
2818 while not turtle.detectUp() do -- go up until column base is met
2819 T:go("U1C2")
2820 y = y - 1
2821 if y < 0 then
2822 break
2823 end
2824 end
2825 T:go("B1C1B1", false, 0, true)
2826 -- return to surface, placing forward and below
2827 for i = 1, y - 1 do
2828 T:go("C1U1C2", false, 0, true)
2829 end
2830 -- put missing block down
2831 T:go("C1", false, 0, true)
2832 y = 1 -- reset counter
2833 end
2834 if remain == 1 then -- 1 more column
2835 y = 1
2836 T:back(1)
2837 place = clearVegetation("down")
2838 while place do -- loop will be entered at least once
2839 T:down(1)
2840 y = y + 1
2841 place = clearVegetation("down")
2842 end
2843 for i = 1, y - 1 do
2844 T:go("U1C2", false, 0, true)
2845 end
2846 -- put missing block down
2847 T:go("C1", false, 0, true)
2848 elseif remain == 2 then -- 2 cols
2849 y = 1
2850 T:back(1)
2851 place = clearVegetation("down")
2852 while place do -- loop will be entered at least once
2853 T:go("C1D1", false, 0, true)
2854 y = y + 1
2855 place = clearVegetation("down")
2856 end
2857 T:forward(1)
2858 place = clearVegetation("down")
2859 while place do
2860 T:down(1)
2861 y = y + 1
2862 place = clearVegetation("down")
2863 end
2864 T:go("B1C1", false, 0, true)
2865 for i = 1, y - 1 do
2866 T:go("U1C2", false, 0, true)
2867 end
2868 -- put missing block down
2869 T:go("C1", false, 0, true)
2870 end
2871 end
2872end
2873
2874function createSandWall(length)
2875 length = length or 0
2876 local success = true
2877 --move above water
2878 local maxMove = 2
2879 while turtle.detectDown() and maxMove > 0 do
2880 T:forward(1)
2881 maxMove = maxMove - 1
2882 end
2883 if length > 0 then
2884 for i = 1, length - 1 do
2885 success = dropSand()
2886 T:forward(1, false)
2887 end
2888 success = dropSand()
2889 else
2890 while not turtle.detectDown() do -- over water
2891 while not turtle.detectDown() do -- nested to allow forward movement
2892 success = dropSand() -- drops sand and checks supplies
2893 end
2894 if success then
2895 T:forward(1, false)
2896 else -- out of sand
2897 break
2898 end
2899 end
2900 end
2901end
2902
2903function createSolid(width, length, height)
2904 -- this function currently not used
2905 for i = 1, width do --width could be 1, 2, 3 etc
2906 createRetainingWall(length, height)
2907 if i < width then --width = 2 or more
2908 if i == 1 or i % 2 == 1 then -- iteration 1, 3, 5
2909 T:go("L1F1L2C1R1", false, 0, true)
2910 else
2911 T:go("R1F1R2C1L1", false, 0, true)
2912 end
2913 end
2914 end
2915end
2916
2917function createStaircase(destination, level)
2918 -- R# L# F# B# U# D# +0 -0 = Right, Left, Forward, Back, Up, Down, up while detect and return, down while not detect
2919 -- dig: x0,x1,x2 (up/fwd/down)
2920 -- suck: s0,s1,s2
2921 -- place chest: H0,H1,H2
2922 -- place sapling: S0,S1,S2
2923 -- place Torch: T0,T1,T2
2924 -- place Hopper: P0,P1,P2
2925 -- mine floor: m# = mine # blocks above and below, checking for valuable items below, and filling space with cobble or dirt
2926 -- mine ceiling: M# = mine # blocks, checking for valuable items above, and filling space with cobble or dirt
2927 -- mine ceiling: N# same as M but not mining block below unless valuable
2928 -- place: C,H,r,S,T,P,^ = Cobble / cHest / DIrT / Sapling / Torch / hoPper /stair in direction 0/1/2 (up/fwd/down) eg C2 = place cobble down
2929
2930 -- 3| |B| |
2931 -- - - -
2932 -- 2|A| |C|
2933 -- - - -
2934 -- 1|^|D| |
2935 -- - - -
2936 -- 1 2 3
2937
2938 local height = level -- eg 64 at top or 5 at bedrock
2939 local data = T:getStock("stone_stairs")
2940 --{rt.total, rt.mostSlot, rt.leastSlot, rt.mostCount, rt.leastCount}
2941 local numStairs = data.total
2942 local numStairsNeeded = 0
2943 if destination == "bedrock" then
2944 numStairsNeeded = math.ceil(level / 4) * 4
2945 else
2946 numStairsNeeded = math.ceil((64 - level) / 4) * 4
2947 end
2948 numStairsNeeded = numStairsNeeded - numStairs
2949 print('crafting '..numStairsNeeded..' '..numStairs.. ' in stock')
2950 if numStairsNeeded > 40 then
2951 T:craft('stone_stairs', 40) -- max 40 so repeat
2952 data = T:getStock("stone_stairs")
2953 if data.total == 0 then
2954 data = T:getStock("stone_stairs")
2955 end
2956 numStairs = data.total
2957 numStairsNeeded = numStairsNeeded - numStairs
2958 end
2959 if numStairsNeeded > 0 then
2960 T:craft('stone_stairs', numStairsNeeded)
2961 end
2962 if destination == "bedrock" then -- go down to bedrock
2963 while T:down() do
2964 height = height - 1
2965 end
2966 height = T:findBedrockTop(height) -- usually around 5
2967 T:go("R1F1R1", false, 0, true)
2968 end
2969 local onGround = true
2970 local top = (math.ceil((64 - height) / 4) * 4) + 4 + height
2971
2972 for i = height, top, 4 do
2973 for x = 1, 4 do
2974 onGround = createStaircaseSection(onGround)
2975 end
2976 end
2977 -- continue while block found above
2978 while T:getBlockType('up') ~= "" do
2979 onGround = createStaircaseSection(onGround)
2980 end
2981end
2982
2983function createStaircaseSection(onGround)
2984 -- start 1,1,1, n
2985 -- stage A
2986 local data = T:getStock("stone_stairs")
2987 if data.total == 0 then
2988 T:craft('stone_stairs', 4)
2989 end
2990 T:go("L1C1R1F1L1C1R1C1R1C1L1B1^1", false, 0, true) --start:1,1,1,n stairs A on level 1, going back to 1,1,1,n
2991 if not onGround then
2992 -- stage A1
2993 T:go("L2C1L2", false, 0, true) -- start 1,1,1,n fix corner on level 1 end: 1,1,1,n
2994 end
2995 -- stage B
2996 T:go("U1L1C1", false, 0, true) -- end 1,1,1,w layer 2
2997 if not onGround then
2998 T:go("L1C1R1", false, 0, true) -- end 1,1,1,w layer 2
2999 end
3000 -- stage C1
3001 T:go("R1F1L1C1R2C1L1B1", false, 0, true)
3002 -- stage C2
3003 T:go("U1L1C1L1C1L2F1L1C1R2C1L1B1D1", false, 0, true) -- end 1,1,2,n
3004 onGround = false
3005 -- stage D
3006 T:go("F2L1C1R1C1R1", false, 0, true) -- 3,1,2,e
3007
3008 return onGround
3009end
3010
3011function createTreefarm(size)
3012 local blockType
3013 local blockModifier
3014 local length
3015 local width
3016
3017 if size == 1 then
3018 length = 11
3019 width = 6
3020 clearArea(11, 11)
3021 else
3022 length = 19
3023 width = 10
3024 clearArea(19, 19)
3025 end
3026 -- now place dirt blocks and torches
3027 T:go("F2R1F2L1U1", false, 0, true)
3028 for x = 1, (width - 2) / 2 do
3029 for y = 1, (length - 3) / 2 do
3030 T:place("minecraft:dirt", -1, "down", false)
3031 if y < (length - 3) / 2 then
3032 T:forward(1)
3033 T:place("minecraft:torch", -1, "down", false)
3034 T:forward(1)
3035 end
3036 end
3037 T:go("R1F2R1", false, 0, true)
3038 for y = 1, (length - 3) / 2 do
3039 T:place("minecraft:dirt", -1, "down", false)
3040 if y < (length - 3) / 2 then
3041 T:forward(1)
3042 T:place("minecraft:torch", -1, "down", false)
3043 T:forward(1)
3044 end
3045 end
3046 if x < (width - 2) / 2 then
3047 T:go("L1F2L1", false, 0, true)
3048 else
3049 T:go("R1F6", false, 0, true)
3050 if size == 2 then
3051 T:go("F8", false, 0, true)
3052 end
3053 T:go("R1B1", false, 0, true)
3054 end
3055 end
3056end
3057
3058function createWalkway(length)
3059 local lengthParts = math.floor(length / 8) -- eg 12/8 = 1
3060 local lastPart = length - (lengthParts * 8) -- eg 12 - (1 * 8) = 4
3061 T:up(1)
3062 for j = 1, lengthParts do
3063 T:go("M8", false, 0, true)
3064 end
3065 if lastPart > 0 then
3066 T:go("M"..tostring(lastPart)) -- eg m4
3067 end
3068 T:go("R2D1", false, 0, true)
3069 T:place("minecraft:torch", 0, "up", false)
3070 for j = 1, lengthParts do
3071 T:go("m8", true)
3072 T:place("minecraft:torch", 0, "up", false)
3073 end
3074 if lastPart > 0 then
3075 T:go("m"..tostring(lastPart), true) -- eg m4
3076 end
3077 T:go("R2", false, 0, true)
3078end
3079
3080function createWaterSource(level)
3081 if level == nil then
3082 level = 0
3083 end
3084 if level > 0 then
3085 T:up(level)
3086 elseif level < 0 then
3087 T:down(math.abs(level))
3088 end
3089 -- assume on flat surface, but allow for blocks above
3090 T:go("x0C2F1 x0C2F1 x0C2F1 x0C2R1 F1 x0C2F1 x0C2F1 x0C2R1 F1 x0C2F1 x0C2F1 x0C2R1 F1 x0C2F1 x0C2", false, 0, false)
3091 T:go("R1F1D1", false, 0, false) --move to corner and drop down
3092 T:go("C2F1R1 C2F1R1 C2F1R1 C2F1R1", false, 0, false)
3093 T:go("U1")
3094 for i = 1, 2 do
3095 T:place("minecraft:water_bucket", -1, "down", false)
3096 T:go("F1R1F1R1", false, 0, false)
3097 end
3098 -- refill water buckets
3099 for i = 1, 2 do
3100 sleep(0.5)
3101 T:place("minecraft:bucket", -1, "down", false)
3102 end
3103 T:go("R2F1R1F1R1")
3104 -- end above lower left of pond (starting point)
3105end
3106
3107function decapitateBuilding(width, length)
3108 --clearRectangle with sand drop
3109 -- could be 1 wide x xx lenght (trench) up and return
3110 -- could be 2+ x 2+
3111 -- even no of runs return after last run
3112 -- odd no of runs forward, back, forward, reverse and return
3113 local success
3114 local directReturn = true
3115 if width % 2 == 1 then
3116 directReturn = false
3117 end
3118 if width == 1 then -- trench ahead, so fill then return
3119 for i = 1, length - 1 do
3120 success = dropSand()
3121 T:forward(1, false)
3122 end
3123 success = dropSand()
3124 T:go("R2F"..(length - 1).."R2", false, 0, false)
3125 else --2 or more columns
3126 if directReturn then -- width = 2,4,6,8 etc
3127 for i = 1, width, 2 do -- i = 1,3,5,7 etc
3128 -- move along length, dropping sand
3129 for j = 1, length - 1 do
3130 success = dropSand()
3131 T:forward(1, false)
3132 end
3133 success = dropSand()
3134 T:go("R1F1R1") --turn right and return on next column
3135 for j = 1, length - 1 do
3136 success = dropSand()
3137 T:forward(1, false)
3138 end
3139 success = dropSand()
3140 if i < width - 2 then -- eg width = 8, i compares with 6: 1, 3, 5, 7
3141 T:go("L1F1L1")
3142 end
3143 end
3144 T:go("R1F"..width - 1 .."R1") --return home
3145 else
3146 for i = 1, width, 2 do -- i = 1,3,5,7 etc
3147 -- move along length, dropping sand
3148 for j = 1, length - 1 do
3149 success = dropSand()
3150 T:forward(1, false)
3151 end
3152 success = dropSand()
3153 T:go("R1F1R1") --turn right and return on next column
3154 for j = 1, length - 1 do
3155 success = dropSand()
3156 T:forward(1, false)
3157 end
3158 success = dropSand()
3159 T:go("L1F1L1")
3160 end
3161 -- one more run then return
3162 for j = 1, length - 1 do
3163 success = dropSand()
3164 T:forward(1, false)
3165 end
3166 success = dropSand()
3167 T:go("R2F"..length.."R1F"..width - 1 .."R1")
3168 end
3169 end
3170end
3171
3172function demolishBuilding(width, length)
3173 -- start bottom left
3174 clearBuilding(width, length, 0, false)
3175end
3176
3177function demolishPortal()
3178 if T:getBlockType("forward") == "minecraft:obsidian" then
3179 T:down(1)
3180 end
3181 T:go("x1U1x1U1x1U1x1U1x1")
3182 for i = 1, 3 do
3183 T:go("R1F1L1x1")
3184 end
3185 T:go("D1x1D1x1D1x1D1x1")
3186 T:go("L1F1R1x1L1F1R1x1")
3187end
3188
3189function digMobTrench(height, length)
3190 local blockType
3191 -- go down 1 layer at a time height x, move forward length, fill voids
3192 if length == 0 then
3193 length = 8 --common length
3194 end
3195 for i = 1, height do
3196 T:down(1)
3197 -- tunnel bottom: E# fill voids both sides, remove floor
3198 T:go("E"..length - 1 .."R2", false, 0 , true)
3199 end
3200 T:up(height)
3201 if height % 2 == 1 then
3202 T:forward(length - 1)
3203 end
3204end
3205
3206function digTrench(height, length)
3207 local blockType
3208 -- go down height, move forward
3209 if length == 0 then
3210 length = 4096 -- will go out of loaded chunks and stop or max 4096 on a server
3211 end
3212 for i = 1, length, 2 do
3213 local count = 0
3214 for down = 1, height do
3215 blockType = T:isWaterOrLava("down")
3216 -- go down only if no water or lava below
3217 if string.find(blockType, "water") == nil and string.find(blockType, "lava") == nil then
3218 T:down(1)
3219 count = count + 1
3220 end
3221 end
3222 -- return to surface, continue if block above
3223 T:go("U"..count)
3224 -- go up while block in front
3225 while turtle.detect() do
3226 blockType = T:getBlockType("forward")
3227 --print("Ahead: "..blockType)
3228 if T:isVegetation(blockType) then
3229 T:dig("forward")
3230 break
3231 elseif blockType:find("log") ~= nil then
3232 T:harvestTree("forward", false)
3233 else
3234 T:up(1)
3235 end
3236 end
3237 -- move forward
3238 T:forward(1)
3239 -- go down until block detected
3240 while not turtle.detectDown() do
3241 blockType = T:isWaterOrLava("down")
3242 if string.find(blockType, "water") == nil and string.find(blockType, "lava") == nil then
3243 T:down(1)
3244 else
3245 break
3246 end
3247 end
3248 -- repeat
3249 end
3250end
3251
3252function drainLiquid(width, length, size)
3253 if size == 1 then --turtle replaces source so use clearSolid()
3254 --top-bottom =1
3255 clearSolid(width, length, 1, size)
3256 else -- mc 1.12.15+ turtle does NOT replace source blocks
3257 if width == 0 then
3258 width = 64
3259 end
3260 if length == 0 then
3261 length = 64
3262 end
3263 local drop = 0
3264 local calcLength = 1
3265 local calcWidth = 0
3266
3267 -- start above water
3268 if T:detect("down") then -- in case not over wall
3269 T:forward(1)
3270 end
3271 -- go down until water detected
3272 while not turtle.detectDown() do
3273 block, blockType = T:isWaterOrLava("down")
3274 if string.find(block, "water") == nil and string.find(block, "lava") == nil then
3275 T:down(1)
3276 drop = drop + 1
3277 else
3278 break
3279 end
3280 end
3281
3282 local place = true
3283 local block, blockType
3284 -- place first cobble along the length of water and measure length
3285 for l = 1, length do
3286 -- check for water/kelp below
3287 place = clearVegetation("down") -- returns true if water or removed kelp below
3288 if place then
3289 T:go("C2")
3290 end
3291 if T:getBlockType("forward") == "minecraft:cobblestone" then
3292 break
3293 end
3294 if l < length then
3295 if T:getBlockType("forward") == "minecraft:cobblestone" then
3296 break
3297 else
3298 T:forward(1)
3299 calcLength = calcLength + 1
3300 if T:getBlockType("down") == "minecraft:cobblestone" then
3301 turtle.back()
3302 calcLength = calcLength - 1
3303 break
3304 end
3305 end
3306 end
3307 end
3308 length = calcLength
3309 T:go("R1F1R1")
3310 print("calcLength = "..length)
3311 for w = 1, width- 2, 2 do
3312 -- place cobble along the length of water return journey
3313 for l = 1, length do
3314 -- check for water/kelp below
3315 place = clearVegetation("down") -- returns true if water or removed kelp below
3316 if place then
3317 T:go("C2")
3318 end
3319 if l < length then
3320 T:forward(1)
3321 T:go("C2")
3322 end
3323 end
3324 -- go to starting point
3325 T:go("R1F1R1")
3326 -- remove cobble along the length of water
3327 for d = 1, length do
3328 T:dig("down")
3329 if d < length then
3330 T:forward(1)
3331 end
3332 end
3333 -- turn right
3334 T:turnRight(1)
3335 -- move across to next col
3336 for i = 1, 2 do
3337 if not turtle.detect() then
3338 T:forward(1)
3339 calcWidth = calcWidth + 1
3340 end
3341 end
3342 T:turnRight(1)
3343 --check if now cobble below. If so run has finished
3344 if T:getBlockType("down") == "minecraft:cobblestone" then
3345 T:go("R1F1L1")
3346 calcWidth = calcWidth - 1
3347 break
3348 elseif turtle.detect() then
3349 -- end of line reached
3350 break
3351 end
3352 end
3353 -- now on retaining wall, return to last cobble strip
3354
3355 -- dig it out
3356 for d = 1, length do
3357 T:dig("down")
3358 if d < length then
3359 T:forward(1)
3360 end
3361 end
3362
3363 T:go("R1F"..calcWidth - 1 .."R1U"..drop)
3364
3365 end
3366end
3367
3368function dropSand()
3369 local success, slot
3370 while not turtle.detectDown() do -- over water. will be infinite loop if out of sand
3371 success, slot = T:place("minecraft:sand", -1, "down", false)
3372 if not success then
3373 print("Out of sand. Add more to continue...")
3374 sleep(2)
3375 end
3376 end
3377 return true --will only get to this point if turtle.detectDown() = true
3378end
3379
3380function floodMobFarm()
3381 -- turtle on floor, pointing towards water source wall
3382 -- move forward until hit wall
3383 while turtle.forward() do end
3384 -- turn left, move forward until hit wall
3385 T:turnLeft(1)
3386 while turtle.forward() do end
3387 -- back 1, place water
3388 turtle.back()
3389 T:place("minecraft:water_bucket", -1, "forward", true)
3390 -- turn round go forward 7, place water
3391 T:turnLeft(2)
3392 while turtle.forward() do end
3393 -- back 1, place water
3394 turtle.back()
3395 T:place("minecraft:water_bucket", -1, "forward", true)
3396
3397 -- turn round, go forward 3 (centre of wall), turn left, forward 4 (centre of chamber)
3398 T:go("L2F3L1F4")
3399 -- go down, left, forward, turn round
3400 T:go("D1L1F1R2")
3401 for i = 3, 9, 2 do
3402 -- check down, dig forward, go forward, check down (i blocks)
3403 T:go("m"..i-1, false, 0, true)
3404 if i == 3 or i == 7 then
3405 -- left, forward, right, forward, turn round
3406 T:go("L1F1R1F1R2")
3407 elseif i < 9 then
3408 T:go("R1F1L1F1R2")
3409 -- right, forward, left, forward, turn round
3410 end
3411 end
3412 -- right, forward, right, check down / forward 9 x
3413 T:go("R1F1R1m8R2F4R1") -- now facing bubble lift, next to wall
3414 -- go down 2, check floor, up 1, place fence
3415 T:go("D2C2U1", false, 0, true)
3416 T:place("fence", -1, "down", false)
3417 T:go("F1D1C2U1", false, 0, true)
3418 T:place("fence", -1, "down", false)
3419 T:go("F1U1R2", false, 0, true)
3420 if not T:place("minecraft:soul_sand", -1, "down", false) then
3421 T:place("minecraft:dirt", -1, "down", false)
3422 end
3423 T:go("F1R1U1")
3424 T:place("sign", -1, "down", false)
3425 T:go("U1C0D1")
3426 T:place("slab", -1, "up", false)
3427 T:go("R2F1R2")
3428 T:place("sign", -1, "forward", false)
3429 T:go("R1F1R2C1R1F1D1L1") --sitting on soul sand/dirt facing spawner
3430end
3431
3432function getDecision(choice)
3433 local decision = read()
3434 local retValue = 0
3435 if decision == "" or decision == "y" then -- allow for enter only
3436 retValue = choice
3437 end
3438 return tonumber(retValue)
3439end
3440
3441function getSize(clear, prompt, lowerLimit, upperLimit)
3442 local retValue = -1
3443 while tonumber(retValue) < lowerLimit or tonumber(retValue) > upperLimit do
3444 if clear then
3445 T:clear()
3446 end
3447 print(prompt)
3448 --term.write(prompt)
3449 --io.write(prompt.."_")
3450 retValue = read()
3451 if tonumber(retValue) == nil then
3452 retValue = 0
3453 end
3454 end
3455 return tonumber(retValue)
3456end
3457
3458function getTask()
3459 local lib = {}
3460
3461 function lib.waterWarning()
3462 T:clear()
3463 print(" IMPORTANT!\n")
3464 print("1.14+ turtles do NOT delete source\n")
3465 print("0 if I do NOT replace source blocks")
3466 print("1 if I do delete. (pre 1.14)")
3467 return getSize(false, "Option? (0 or 1)\n", 0, 1)
3468 end
3469
3470 local choice = nil
3471 local mainChoice = nil
3472 local size = 0
3473 local width = 0
3474 local length = 0
3475 local height = 0
3476 local prompt = "Choose your option:"
3477 local options = getTaskOptions()
3478 local text = getTaskText()
3479
3480
3481 while choice == nil do
3482 mainChoice = menu.new(prompt, options.main)
3483 if mainChoice == nil then
3484 break
3485 else
3486 choice = menu.new(prompt, options[mainChoice])
3487 end
3488 if choice ~= nil then
3489 if choice > 9 then
3490 choice = choice + (mainChoice * 100)
3491 else
3492 choice = choice + (mainChoice * 10)
3493 end
3494 end
3495 end
3496 T:clear()
3497 local instructions = "Enter to continue\nany other key to quit"
3498 if choice == nil then
3499 print("You chose quit from the main menu")
3500 else
3501 print(text[choice])
3502 end
3503 -- MINING
3504 if choice == 11 then -- Create Mine at this level
3505 choice = getDecision(choice)
3506 elseif choice == 12 then -- Ladder to bedrock
3507 choice = getDecision(choice)
3508 elseif choice == 13 then -- Ladder to surface
3509 choice = getDecision(choice)
3510 elseif choice == 14 then -- Stairs to bedrock
3511 choice = getDecision(choice)
3512 elseif choice == 15 then -- Stairs to surface
3513 choice = getDecision(choice)
3514 -- FORESTRY
3515 elseif choice == 21 then -- Fell Tree
3516 choice = getDecision(choice)
3517 elseif choice == 22 then --Create treefarm
3518 choice = getDecision(choice)
3519 if choice > 0 then
3520 options = {"4 x 4 trees(16)","8 x 8 trees(64)"}
3521 size = menu.new(prompt, options)
3522 end
3523 elseif choice == 23 then -- plant treefarm
3524 choice = getDecision(choice)
3525 if choice > 0 then
3526 options = {"4 x 4 trees(16)","8 x 8 trees(64)"}
3527 size = menu.new(prompt, options)
3528 end
3529 elseif choice == 24 then -- Harvest treefarm
3530 choice = getDecision(choice)
3531 if choice > 0 then
3532 options = {"4 x 4 trees(16)","8 x 8 trees(64)"}
3533 size = menu.new(prompt, options)
3534 end
3535 elseif choice == 25 then -- Create Auto-TreeFarm
3536 choice = getDecision(choice)
3537 elseif choice == 26 then -- Manage Auto-TreeFarm
3538 choice = getDecision(choice)
3539
3540 -- FARMING
3541 elseif choice == 31 then -- Create crop farm
3542 choice = getDecision(choice)
3543 elseif choice == 32 then -- Extend crop farm
3544 choice = getDecision(choice)
3545 elseif choice == 33 then -- Manage crop farm
3546 choice = getDecision(choice)
3547
3548 -- OBSIDIAN
3549 elseif choice == 41 then -- Harvest obsidian
3550 width = getSize(false, "Width of the area (1-64)\n", 1, 64)
3551 length = getSize(false, "Length of the area (1-64)\n", 1, 64)
3552 elseif choice == 42 then -- build Nether portal
3553 choice = getDecision(choice)
3554 elseif choice == 43 then -- demolish Nether portal
3555 choice = getDecision(choice)
3556
3557 -- CANAL BRIDGE
3558 elseif choice == 51 then --single path
3559 choice = getDecision(choice)
3560 elseif choice == 52 then --2 block coridoor
3561 length = getSize(false, "Coridoor length? 0 = continuous\n", 0, 1024)
3562 elseif choice == 53 then --return Path over void/water/lava
3563 size = getSize(false, "Length of the area (1-128)\n", 1, 128)
3564 elseif choice == 54 then --Covered walkway
3565 size = getSize(false, "Length of the walk (1-64)\n", 1, 64)
3566 elseif choice == 55 then --left/right side of new/existing canal
3567 width = lib.waterWarning()
3568 length = getSize(false, "Canal length? 0 = continuous\n", 0, 1024)
3569 height = getSize(false, "Am I on the floor(0) or wall(1)?\n", 0, 1)
3570 elseif choice == 56 then --left/right side of new/existing canal
3571 width = lib.waterWarning()
3572 length = getSize(false, "Canal length? 0 = continuous\n", 0, 1024)
3573 height = getSize(false, "Am I on the floor(0) or wall(1)?\n", 0, 1)
3574
3575
3576 -- MOB SPAWNER TOOLS
3577 elseif choice == 61 then -- Mob spawner cube
3578 choice = getDecision(choice)
3579 elseif choice == 62 then -- Mob trench
3580 length = getSize(false, "Length of trench (1-256)\n", 1, 256)
3581 height = getSize(false, "Depth of trench (1-50)\n", 1, 50)
3582 elseif choice == 63 then -- flood mobspawner cube
3583 choice = getDecision(choice)
3584 elseif choice == 64 then -- create bubble lift at mob spawner
3585 size = getSize(false, "Standing inside the cube:\n"..
3586 "Killzone on left(0)?\n"..
3587 "Killzone on right(1)?\n\n"..
3588 "Standing outside the cube:\n"..
3589 "Killzone on left(1)?\n"..
3590 "Killzone on right(0)?", 0, 1)
3591 elseif choice == 65 then -- Blaze spawner
3592 choice = getDecision(choice)
3593 elseif choice == 66 then -- Enderman tower
3594 choice = getDecision(choice)
3595
3596 --[[
3597 elseif choice == 66 then -- Path to ocean base
3598 size = getSize(false, "Path length (0-128)?\n", 0, 128)
3599 elseif choice == 67 then -- Ocean base complete. Place on polished block to start
3600 size = getSize(false, "Tower Height (32-128)?\n", 32, 128)
3601 elseif choice == 68 then -- Mob tower complete Place on polished block to start
3602 choice = getDecision(choice)
3603 elseif choice == 69 then -- Mob tower roof Place on polished block to start
3604 choice = getDecision(choice)]]
3605
3606 -- AREA CARVING
3607 elseif choice == 71 then --Clear field
3608 width = getSize(false, "Width of the area (1-64)\n", 1, 64)
3609 length = getSize(false, "Length of the area (1-64)\n", 1, 64)
3610 elseif choice == 72 then -- Clear solid rectangle width, length
3611 width = getSize(false, "Width of the area (1-256)\n", 1, 256)
3612 length = getSize(false, "Length of the area (1-256)\n", 1, 256)
3613 elseif choice == 73 then -- Clear wall height, length, direction
3614 width = 1
3615 length = getSize(false, "Length of wall (1-256)\n", 1, 256)
3616 height = getSize(false, "Height of wall (1-50)\n", 1, 50)
3617 elseif choice == 74 then -- Clear rectangle perimeter only width, length
3618 width = getSize(false, "Width of walled area (1-256)\n", 1, 256)
3619 length = getSize(false, "Length of walled area (1-256)\n", 1, 256)
3620 height = 1
3621 elseif choice == 75 then -- Clear sructure floor/walls/ceiling
3622 size = getSize(false, "Bottom->Top (0), Top->bottom(1)",0, 1)
3623 width = getSize(false, "Hollow structure width (1-256)", 1, 256)
3624 length = getSize(false, "Hollow structure length (1-256)", 1, 256)
3625 if size == 0 then
3626 height = getSize(false, "Height (1-256)", 1, 256)
3627 else
3628 height = getSize(false, "Depth/Height (1-256)", 1, 256)
3629 end
3630 elseif choice == 76 then -- clear solid structure
3631 size = getSize(false, "Bottom->Top (0), Top->bottom(1)",0, 1)
3632 width = getSize(false, "Solid structure width (1-60)", 1, 60)
3633 length = getSize(false, "Solid structure length (1-60)", 1, 60)
3634 if size == 0 then
3635 height = getSize(false, "Height (1-256)", 1, 256)
3636 else
3637 height = getSize(false, "Depth/Height (1-256)", 1, 256)
3638 end
3639 elseif choice == 77 then -- Dig a trench
3640 height = getSize(false, "Depth of the trench (1-64)", 1, 64)
3641 length = getSize(false, "Trench length? 0 = continuous\n", 0, 1024)
3642
3643 -- WATER LAVA
3644 elseif choice == 81 then -- build wall from water or lava surface downwards
3645 width = 1
3646 length = getSize(false, "Length of the wall (1-60)\n", 1, 60)
3647 height = getSize(false, "Estimated depth (1-60) 0=default\n", 0, 60)
3648 elseif choice == 82 then -- drop sand into water or lava surface until solid grond reached
3649 width = 1
3650 length = getSize(false, "Length of dam (0=to solid block)\n", 0, 60)
3651 elseif choice == 83 then -- clear rectangle on top of building and fill with sand
3652 width = getSize(false, "Width of roof (<=30)\n", 1, 30)
3653 length = getSize(false, "Length of of roof (<=30)\n", 1, 30)
3654 elseif choice == 84 then -- clear sand wall or harvest sand
3655 width = 1
3656 length = getSize(false, "Length of sand \n", 1, 250)
3657 elseif choice == 85 then -- remove sand from cube. start at top
3658 width = getSize(false, "Width of sand (<=30)\n", 1, 30)
3659 length = getSize(false, "Length of of sand (<=30)\n", 1, 30)
3660 elseif choice == 86 then -- remove floor, walls (and sand) from building. start at base
3661 width = getSize(false, "Width of floor (<=30)\n", 1, 30)
3662 length = getSize(false, "Length of of floor (<=30)\n", 1, 30)
3663 elseif choice == 87 then -- Clear all blocks top of water
3664 T:clear()
3665 print(" IMPORTANT!\n")
3666 print("1.14+ turtles do NOT delete source\n")
3667 print("0 if I do NOT replace source blocks")
3668 print("1 to recover blocks, leaving water")
3669 size = getSize(false, "Option? (0 or 1)\n", 0, 1)
3670 elseif choice == 88 then -- clear monument layer
3671 width = getSize(false, "Width of monument area (1 to 64)\n", 1, 64)
3672 length = getSize(false, "Length of monument area (1 to 64)", 1, 64)
3673 size = getSize(false, "Clear above and below? 0:no 1:yes", 0, 1)
3674 elseif choice == 89 then -- Ladder to water/lava
3675 choice = getDecision(choice)
3676 if choice > 0 then
3677 height = getSize(false, "Est. height above (?F3)\n", 1, 256)
3678 end
3679 elseif choice == 810 then -- Clear seaweed from enclosed area
3680 width = getSize(false, "water width (1-64)\n", 1, 64)
3681 length = getSize(false, "water length (1-64)\n", 1, 64)
3682
3683 -- RAILWAY
3684 elseif choice == 91 then -- place redstone torch under current block
3685
3686 elseif choice == 92 then -- place redstone torch on upward slope
3687
3688 elseif choice == 93 then -- build downward slope
3689 height = getSize(false, "Drop down by how many blocks?\n", 1, 64)
3690 elseif choice == 94 then -- build upward slope
3691 height = getSize(false, "Go up by how many blocks?\n", 1, 64)
3692 end
3693
3694 return choice, size, width, length, height -- eg 86, 0, 8, 8, 4
3695end
3696
3697function getTaskOptions()
3698 local o = {}
3699 o.main =
3700 {
3701 "Mining (includes Nether)",
3702 "Forestry",
3703 "Farming",
3704 "Obsidian and Nether Portal",
3705 "Canal, bridge and walkway",
3706 "Mob farm tools",
3707 "Area shaping and clearing",
3708 "Lava and Water",
3709 "Railway"
3710 }
3711 table.insert(o,
3712 {
3713 "Create mine at this level",
3714 "Ladder down (to bedrock)",
3715 "Ladder up (to surface)",
3716 "Stairs down (to bedrock)",
3717 "Stairs up (to surface)"
3718 })
3719 table.insert(o,
3720 {
3721 "Fell Tree",
3722 "Create tree farm",
3723 "Plant tree farm",
3724 "Harvest tree farm",
3725 "Create Auto-treeFarm",
3726 "Manage Auto-treeFarm"
3727 })
3728 table.insert(o,
3729 {
3730 "Create modular crop farm",
3731 "Extend modular crop farm",
3732 "Manage modular crop farm"
3733 })
3734 table.insert(o,
3735 {
3736 "Dig obsidian field",
3737 "Build Nether Portal",
3738 "Demolish Nether Portal"
3739 })
3740 table.insert(o,
3741 {
3742 "Continuous path",
3743 "2 block high tunnel",
3744 "2 block wide over air/water/lava",
3745 "Covered walkway",
3746 "Left side of canal",
3747 "Right side of canal",
3748
3749 })
3750 table.insert(o,
3751 {
3752 "Create 9x9 cube around spawner",
3753 "Dig mob drop trench",
3754 "Flood mob farm floor",
3755 "Create mob bubble lift",
3756 "Create Blaze farm around spawner",
3757 "Create Endermen observation tower",
3758 --[[
3759 "Mob spawner base & ocean path",
3760 "Mob spawner tower",
3761 "Mob spawner chamber",
3762 "Mob spawner roof"]]
3763 })
3764 table.insert(o,
3765 {
3766 "Clear field (inc trees)",
3767 "Clear a rectangle",
3768 "Clear single wall",
3769 "Clear rectangular wall section",
3770 "Clear hollow structure up/down",
3771 "Clear solid structure up/down",
3772 "Dig a trench"
3773 })
3774 table.insert(o,
3775 {
3776 "Vertical wall from surface",
3777 "Drop sand or gravel wall",
3778 "Decapitate and fill with sand",
3779 "Clear sand wall",
3780 "Clear sand filled building",
3781 "Demolish sand filled structure",
3782 "Clear top layer of water",
3783 "Clear monument layer",
3784 "Ladder down to water/lava",
3785 "Clear water plants"
3786 })
3787 table.insert(o,
3788 {
3789 "Place Redstone:torch level track",
3790 "Place Redstone:torch upward track",
3791 "Build downward track",
3792 "Build upward track"
3793 })
3794
3795 return o
3796end
3797
3798function getTaskText()
3799 local text = {}
3800 local instructions = "Enter to continue\nany other key to quit"
3801 --MINING
3802 text[11] = "Press F3 to check level. Look for 'Y'\n"..
3803 "Place at level 5, 8, 12 (11 nether)\n\n"..instructions --mine this level
3804 text[12] = "Place me on the ground\n"..
3805 "The ladder will start at this level\n"..
3806 "and drop to bedrock\n\n"..instructions -- ladder to bedrock
3807 text[13] = "Place me on the ground\n"..
3808 "The ladder will start at this level\n"..
3809 "and rise to chosen level/surface\n\n"..instructions -- ladder to surface
3810 text[14] = "Place me on the ground\n"..
3811 "The stairs will start at this level\n"..
3812 "and drop to bedrock in a 5x5 block\n\n"..instructions -- Stairs to bedrock
3813 text[15] = "Place me on the ground\n"..
3814 "The stairs will start at this level\n"..
3815 "and rise to level 64 in a 5x5 block\n\n"..instructions-- Stairs to surface
3816
3817 -- FORESTRY
3818 text[21] = "Place me in front of the tree\n"..
3819 "you want to fell\n\n"..
3820 "Fuel not required as logs will be used.\n\n"..instructions -- Fell Tree
3821 text[22] = "Place me on grass, lower left corner\n"..
3822 "of a 11x11 OR 19x19 square\n"..
3823 "Trees to be grown on alternate blocks\n"..
3824 "in a square 4x4 or 8x8 trees\n"..
3825 "with a 2 block wide margin\n"..instructions --Create treefarm
3826 text[23] = "Place me in front of first tree base\n"..
3827 "or dirt on the lower left corner\n"..
3828 "of a 4x4 trees OR 8x8 trees square\n\n"..
3829 "Provide 2 types of saplings for a\n"..
3830 "mixed tree farm\n\n"..instructions --plant treefarm
3831 text[24] = "Place me in front of first tree\n"..
3832 "on the lower left corner\n"..
3833 "of a 4x4 trees OR 8x8 trees square\n\n"..
3834 "Fuel not required as logs will be used.\n\n"..instructions-- Harvest treefarm
3835 text[25] = "For a new Auto-TreeFarm:\n"..
3836 "Place me on left side of a 19x14 area\n\n"..instructions -- Create Auto-TreeFarm
3837 text[26] = "Place me in front of sapling\n"..
3838 "or tree with the chest behind me\n\n"..instructions -- Manage Auto-TreeFarm
3839
3840 -- FARMING
3841 text[31] = "Place me on the ground lower left\n"..
3842 "of an area 14 x 14. A crop farm\n"..
3843 "12 x 12 with cobble wall will be \n"..
3844 "built forward and to the right\n\n"..instructions -- Create modular crop farm
3845 text[32] = "Place me next to the tree on\n"..
3846 "a chest, either left side of farm\n"..
3847 "or facing front wall to add a farm\n"..
3848 "in that direction.\n\n"..instructions-- extend farm
3849 text[33] = "Place me over the water on the\n"..
3850 "left corner. There should be\n"..
3851 "chests on 2 sides\n\n"..instructions -- Manual harvest and auto setup
3852
3853 -- OBSIDIAN
3854 text[41] = "Place me on any block\n"..
3855 "on the left side facing the\n"..
3856 "obsidian field.\n\n"..instructions -- Harvest obsidian
3857 text[42] = "Place me on the ground\n"..
3858 "on the left side\n"..
3859 " of the portal base\n\n"..instructions -- build Nether portal
3860 text[43] = "Place me on the ground\n"..
3861 "on the left side\n"..
3862 " of the portal base\n\n"..instructions -- demolish Nether portal
3863
3864 --CANALS BRIDGES WALKWAYS
3865 text[51] = "Place me on the ground in front\n"..
3866 "of water, lava or air.\n"..
3867 "Follow and supply blocks for a path\n\n"..instructions --single path
3868 text[52] = "Place me on the ground at start\n"..
3869 "of coridoor.\n\n"..instructions --2 block coridoor
3870 text[53] = "Place me on the ground\n"..
3871 "The bridge will start in front,\n"..
3872 "continue for your chosen length\n"..
3873 "and return\n" --Bridge over void/water/lava
3874 text[54] = "Place me on the ground\n"..
3875 "The covered walkway will start in front,\n"..
3876 "continue for your chosen length\n"..
3877 "and return\n" --Covered walkway
3878
3879 text[55] = "I should be on either an existing canal\n"..
3880 "on the left side\n"..
3881 "or ready to start a new canal\n\n"..
3882 "If crossing water I should be on top\n"..
3883 "of a solid block making up the left wall\n" -- left side of new/existing canal
3884 text[56] = "I should be on either an existing canal\n"..
3885 "on the right side\n"..
3886 "or ready to start a new canal\n\n"..
3887 "If crossing water I should be on top\n"..
3888 "of a solid block making up the right wall\n" -- right side of new/existing canal
3889
3890 -- MOB FARM
3891 text[61] = "Place me in contact with spawner\n"..
3892 "above/below/facing spawner block\n"..
3893 "to create a 9 x 9 hollow cube\n\n"..
3894 instructions -- 9x9 cube round spawner
3895 text[62] = "Place me at start of trench\n"..
3896 "facing required direction\n"
3897 text[63] = "Place me on the floor facing the wall\n"..
3898 "where the water sources will start\n\n"..
3899 "If you do not have soul sand, add dirt\n"..
3900 "as a temporary place marker\n\n"..
3901 "Make sure you have an escape route!\n\n"..
3902 instructions -- flood spawner chamber
3903 text[64] = "Place me on the soul sand/dirt block\n"..
3904 "facing any direction\n"
3905
3906 text[65] = "Place me in contact with Blaze spawner\n"..
3907 "above/facing spawner block\n"..
3908 "to create a safe killzone\n\n"..
3909 instructions -- 9x9 cube round spawner
3910 text[66] = "Find an open plains area.\n"..
3911 "Bury a chest in the ground.\n"..
3912 "I will need 29 stacks of cobble,\n"..
3913 "andesite, diorite or granite in total\n"..
3914 "(can be polished) in the chest.\n\n"..
3915 instructions -- build endermen observation tower
3916 --[[
3917 text[66] = "Place me on the ground in front\n"..
3918 "of the ocean.\n"..
3919 "Follow me as I create a path\n" -- Path to mob spawner ocean base
3920 text[67] = "Place me on the stone block\n"..
3921 "(granite / andesite / diorite)\n"..
3922 "in the ocean base.\n"..
3923 "Facing the sea\n" -- Ocean base complete. Place on polished block to start
3924 text[68] = "Place me on the stone block\n"..
3925 "(granite / andesite / diorite)\n"..
3926 "at the top of the tower.\n"..
3927 "Facing the sea\n\n"..
3928 instructions -- Mob tower complete Place on polished block to start
3929 text[69] = "Place me on the stone block\n"..
3930 "(granite / andesite / diorite)\n"..
3931 "at the top of the tower.\n"..
3932 "Facing the sea\n\n"..
3933 instructions-- Mob tower roof Place on polished block to start
3934 ]]
3935
3936 -- AREA CARVING
3937 text[71] = "Place me on grass, lower left corner\n"..
3938 "of the area\n"..
3939 "To be levelled and cleared\n\n"..
3940 "Provide dirt to plug voids in the floor\n" --Clear field
3941 text[72] = "Place me inside the left corner\n"..
3942 "of the rectangle to be cleared.\n"..
3943 "At the level to be worked on\n"..
3944 "I will include this corner in\n"..
3945 "the area to be cleared\n"-- Clear rectangle width, length
3946 text[73] = "Place me inside top/bottom corner\n"..
3947 "of the wall to be cleared.\n"-- Clear wall height, length
3948 text[74] = "Place me inside top/bottom left corner\n"..
3949 "of the rectangular wall to be cleared.\n"..
3950 "At the level to be worked on\n"..
3951 "I will include this corner in\n"..
3952 "the area to be cleared\n"-- Clear rectangle perimeter only width, length
3953 text[75] = "Place me INSIDE top/bottom left corner\n"..
3954 "in the floor/ceiling.\n"..
3955 "I will include this corner in\n"..
3956 "the area to be cleared\n" -- Clear structure floor/walls/ceiling
3957 text[76] = text[75]
3958 text[77] = "Place me on the ground\n"..
3959 "facing the trench direction\n" -- Dig a trench
3960
3961 --LAVA WATER
3962 text[81] = "Place me on the surface facing wall END\n"..
3963 "(Any block below will be removed)\n"..
3964 "Wall will be built DOWN and BACKWARDS\n"-- build wall from water or lava surface downwards
3965 text[82] = "Place me on the surface of water or lava\n"..
3966 "Sand will be dropped DOWN and Forwards\n"-- drop sand into water or lava surface until solid grond reached
3967 text[83] = "Place me on top left corner of roof\n"..
3968 "Sand will be dropped into the hollow\n"-- clear rectangle on top of building and fill with sand
3969 text[84] = "Place me on the surface of sand\n"..
3970 "Sand will be mined DOWN then forwards\n"-- clear sand wall or harvest sand
3971 text[85] = "Place me on top left corner of sand\n"..
3972 "Sand cleared down, then left to right\n"-- remove sand from cube. start at top
3973 text[86] = "Place me on lower left corner of floor\n"..
3974 "Floor + walls removed + sand cleared\n" -- remove floor, walls (and sand) from building. start at base
3975 text[87] = "Place me on the left corner of the top\n"..
3976 "of retaining wall facing water/lava\n"-- Clear all blocks top of water
3977 text[88] = "Place me on lower left corner of area\n"..
3978 "on wall or over air\n" -- clear monument layer
3979 text[89] = "Place me on the ground\n"..
3980 "The ladder will start here\n"..
3981 "and drop to water/lava\n\n"..instructions -- Ladder to water/lava
3982 text[810] = "Place me on the left corner of the top\n"..
3983 "of retaining wall facing water\n"-- Clear seaweed from enclosed area
3984
3985 -- RAILWAY
3986 text[91] = "Place me on suspended railway stone\n"..
3987 "Redstone torch will go below me\n"-- place redstone torch under current block
3988 text[92] = "Place me on railway stone going up\n"..
3989 "Redstone torch will go below me\n"-- place redstone torch on upward slope
3990 text[93] = "Place me on last stone\n"..
3991 "Track will go down from this point\n"-- build downward slope
3992 text[94] = "Place me on last stone\n"..
3993 "Track will go up from this point\n"-- build upward slope
3994 return text
3995end
3996
3997function getTaskInventory(choice, size, width, length, height)
3998 -- run this loop 2x per second to check if player has put anything in the inventory
3999 -- fuel 1 coal = 60 = 4 planks. 64 planks = 16 coal = 960 units
4000 local retValue = ""
4001 local gotBirchSaplings = 0
4002 local gotCoal = 0
4003 local gotCobble = 0
4004 local gotDirt = 0
4005 local gotOakSaplings = 0
4006 local gotPlanks = 0
4007 local gotTorches = 0
4008 local thanks = "Thank you.\n\nPress the ESC key\n\nStand Back..\n"
4009
4010 T:clear()
4011 if choice == 0 then --Missing pickaxe
4012 T:checkInventoryForItem({"minecraft:diamond_pickaxe"}, {1})
4013 print("Diamond Pickaxe being tested...")
4014 T:setEquipment()
4015 elseif choice == 1 then --Missing crafting table
4016 T:checkInventoryForItem({"minecraft:crafting_table", ""}, {1, 0}) -- 0 if not present
4017 print("Crafting table being tested...")
4018 T:setEquipment()
4019 elseif choice == 2 then --Missing chest
4020 retValue = T:checkInventoryForItem({"minecraft:chest"}, {1}) -- 0 if not present
4021 sleep(1.5)
4022
4023 -- MINING
4024 elseif choice == 11 then --Create Mine at this level
4025 checkFuelNeeded(960)
4026 T:checkInventoryForItem({"minecraft:torch"}, {24}, false)
4027 T:checkInventoryForItem({"minecraft:bucket"}, {1}, false)
4028 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:netherrack"}, {64, 128})
4029 T:checkInventoryForItem({"minecraft:chest"}, {1})
4030 sleep(2)
4031 print("CreateMine starting")
4032 createMine()
4033 elseif choice == 12 then -- ladder to bedrock
4034 local level = T:getY()
4035 print("Current saved y level = "..level)
4036 print("\nIs this correct? (y/n + Enter)")
4037 if read() ~= "y" then
4038 level = getSize(true, "Current level (F3->Y coord)?_", 4, 300)
4039 end
4040 checkFuelNeeded(level * 2)
4041 T:checkInventoryForItem({"minecraft:ladder"}, {level})
4042 T:checkInventoryForItem({"minecraft:torch"}, {16}, false)
4043 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt", "minecraft:netherrack"}, {64, 64, 128})
4044 print(thanks)
4045 os.sleep(2) -- pause for 2 secs to allow time to press esc
4046 print("Creating ladder to bedrock")
4047 createLadder("bedrock", level)
4048 elseif choice == 13 then -- ladder to surface
4049 local currentLevel = getSize(true,"Current level (F3->Y coord)?_", 4, 300)
4050 local destLevel = getSize(true, "Go up to level? "..currentLevel + 2 .."-"..currentLevel + 300 ..")", currentLevel + 2, currentLevel + 300)
4051 local extend = getSize(true, "Continue until in open air? (n:0 y:1)", 0, 1)
4052 local range = destLevel - currentLevel
4053 checkFuelNeeded(range * 2)
4054 T:checkInventoryForItem({"minecraft:ladder"}, {range})
4055 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt", "minecraft:netherrack"}, {4 * range, 4 * range, 4 * range})
4056 print(thanks)
4057 os.sleep(2) -- pause for 2 secs to allow time to press esc
4058 print("Creating ladder to surface")
4059 createLadder("surface", currentLevel, destLevel, extend)
4060 elseif choice == 14 or choice == 15 then -- stairs to bedrock or surface
4061 local level = getSize(true,"Current level (F3->Y coord)?_", 4, 300)
4062 if level >= 64 then --assume going down
4063 checkFuelNeeded(level * 10)
4064 else -- assume going up
4065 checkFuelNeeded((64 - level) * 10)
4066 end
4067 local numStairsNeeded = 0
4068 if choice == 14 then -- to bedrock
4069 numStairsNeeded = math.ceil(level / 4)
4070 else
4071 numStairsNeeded = math.ceil((64 - level) / 4)
4072 end
4073 local data = T:getStock("stairs")
4074 --{rt.total, rt.mostSlot, rt.leastSlot, rt.mostCount, rt.leastCount}
4075 local numStairs = data.total
4076 --print(numStairs..' stairs onboard')
4077 local cobbleNeeded = 256 - (level * 2)
4078 if numStairs > 0 then
4079 cobbleNeeded = 192 - (math.floor((2 * numStairs) / 3))
4080 if cobbleNeeded < 64 then
4081 cobbleNeeded = 64
4082 end
4083 end
4084 T:checkInventoryForItem({"stairs"}, {numStairsNeeded}, false)
4085 T:checkInventoryForItem({"minecraft:cobblestone"}, {cobbleNeeded})
4086 T:checkInventoryForItem({"minecraft:chest"}, {1}) -- needed for crafting
4087 print(thanks)
4088 os.sleep(2) -- pause for 2 secs to allow time to press esc
4089 if choice == 14 then
4090 print("Creating stairs to bedrock")
4091 createStaircase("bedrock", level)
4092 else
4093 print("Creating stairs to surface")
4094 createStaircase("surface", level)
4095 end
4096
4097 -- FORESTRY
4098 elseif choice == 21 then -- Fell tree
4099 if T:isLog("forward") then
4100 T:checkInventoryForItem({"minecraft:chest"}, {1}, false)
4101 T:forward(1)
4102 T:harvestWholeTree("up")
4103 print("Press esc within 2 seconds!")
4104 os.sleep(2) -- pause for 2 secs to allow time to press esc
4105 print("Felling tree")
4106 else
4107 print("No log in front..")
4108 print("Move me in front of a tree!")
4109 os.sleep(2) -- pause for 2 secs to allow time to press esc
4110 retValue = ""
4111 end
4112 elseif choice == 22 then --Create treefarm
4113 if size == 1 then
4114 checkFuelNeeded(300)
4115 else
4116 checkFuelNeeded(900)
4117 end
4118 T:checkInventoryForItem({"minecraft:dirt"}, {64})
4119 if size == 1 then
4120 T:checkInventoryForItem({"minecraft:torch"}, {16}, false)
4121 else
4122 T:checkInventoryForItem({"minecraft:torch"}, {64}, false)
4123 end
4124 print(thanks)
4125 sleep(2)
4126 print("CreateTreefarm starting: size "..size)
4127 createTreefarm(size)
4128 elseif choice == 23 then -- Plant treefarm
4129 if size == 1 then
4130 checkFuelNeeded(180)
4131 else
4132 checkFuelNeeded(480)
4133 end
4134 T:checkInventoryForItem({"sapling"}, {4})
4135 print(thanks)
4136 print("plantTreefarm starting: size "..size)
4137 plantTreefarm(size)
4138 elseif choice == 24 then -- Harvest treefarm
4139 print(thanks)
4140 os.sleep(2)
4141 print("Harvesting treefarm starting: size "..size)
4142 harvestTreeFarm(size)
4143 elseif choice == 25 then -- create auto tree farm
4144 checkFuelNeeded(1000)
4145 T:checkInventoryForItem({"minecraft:chest"}, {3})
4146 T:checkInventoryForItem({"minecraft:dirt"}, {128})
4147 T:checkInventoryForItem({"minecraft:cobblestone"}, {128})
4148 T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
4149 T:checkInventoryForItem({"minecraft:hopper"}, {1})
4150 T:checkInventoryForItem({"minecraft:torch"}, {21})
4151 T:checkInventoryForItem({"sapling"}, {21}, false)
4152 print(thanks)
4153 os.sleep(2) -- pause for 2 secs to allow time to press esc
4154 print("Creating automatic tree farm...")
4155 createAutoTreeFarm()
4156 elseif choice == 26 then -- Manage auto-treefarm
4157 manageFarmSetup("tree")
4158
4159 -- FARMING
4160 elseif choice == 31 then -- Create modular farm
4161 checkFuelNeeded(300)
4162 T:checkInventoryForItem({"minecraft:cobblestone"}, {64})
4163 T:checkInventoryForItem({"minecraft:dirt"}, {128}, false)
4164 T:checkInventoryForItem({"minecraft:water_bucket"}, {4})
4165 T:checkInventoryForItem({"minecraft:chest"}, {4})
4166 T:checkInventoryForItem({"sapling"}, {1})
4167 print(thanks)
4168 os.sleep(2) -- pause for 2 secs to allow time to press esc
4169 print("Creating modular wheat farm")
4170 createFarm()
4171 elseif choice == 32 then -- Extend modular farm
4172 checkFuelNeeded(300)
4173 T:checkInventoryForItem({"minecraft:cobblestone"}, {64})
4174 T:checkInventoryForItem({"minecraft:dirt"}, {128}, false)
4175 T:checkInventoryForItem({"minecraft:water_bucket"}, {4})
4176 T:checkInventoryForItem({"minecraft:chest"}, {5})
4177 T:checkInventoryForItem({"sapling"}, {1})
4178 print("Checking position...\n")
4179 os.sleep(2) -- pause for 2 secs to allow time to press esc
4180 createFarmExtension()
4181 elseif choice == 33 then -- manage modular farm
4182 manageFarmSetup("farm")
4183
4184 -- OBSIDIAN
4185 elseif choice == 41 then --harvest obsidian
4186 checkFuelNeeded(width * length * 3)
4187 T:checkInventoryForItem({"minecraft:cobblestone"}, {width * length})
4188 print(thanks)
4189 sleep(2)
4190 print("Harvesting obsidian area: size "..width.. " x "..length)
4191 harvestObsidian(width, length)
4192 elseif choice == 42 then --build nether portal
4193 checkFuelNeeded(20)
4194 T:checkInventoryForItem({"minecraft:obsidian"}, {10})
4195 T:checkInventoryForItem({"minecraft:cobblestone"}, {8})
4196 print(thanks)
4197 sleep(2)
4198 print("Building Nether portal")
4199 createPortal()
4200 elseif choice == 43 then --demolish nether portal
4201 checkFuelNeeded(20)
4202 print("Demolishing Nether portal")
4203 demolishPortal()
4204
4205 -- CANAL BRIDGE
4206 elseif choice == 51 then -- continuous path over void/water/lava
4207 checkFuelNeeded(512) -- allow for 512 length
4208 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {64, 64}, false)
4209 T:checkInventoryForItem({"minecraft:torch"}, {64}, false)
4210 print(thanks)
4211 os.sleep(2) -- pause for 2 secs to allow time to press esc
4212 print("Building continuous path")
4213 createPath()
4214 elseif choice == 52 then -- simple 2 block coridoor
4215 checkFuelNeeded(length)
4216 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {64, 64}, false)
4217 T:checkInventoryForItem({"minecraft:torch"}, {64}, false)
4218 print(thanks)
4219 os.sleep(2) -- pause for 2 secs to allow time to press esc
4220 print("Building simple coridoor")
4221 createCoridoor(length)
4222 elseif choice == 53 then -- bridge over void/water/lava
4223 checkFuelNeeded((size + 1) * 2)
4224 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {size * 2, size * 2})
4225 print(thanks)
4226 os.sleep(2) -- pause for 2 secs to allow time to press esc
4227 print("Building bridge ".. size.." blocks")
4228 createBridge(size)
4229 elseif choice == 54 then -- covered walkway
4230 checkFuelNeeded((size + 1) * 2)
4231 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {size * 2, size * 2})
4232 T:checkInventoryForItem({"minecraft:torch"}, {math.ceil(size / 8)})
4233 print(thanks)
4234 os.sleep(2) -- pause for 2 secs to allow time to press esc
4235 print("Building bridge ".. size.." blocks")
4236 createWalkway(size)
4237 elseif choice == 55 or choice == 56 then -- canal management
4238 checkFuelNeeded(2048) -- allow for 1024 length
4239 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {256, 256})
4240 T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
4241 T:checkInventoryForItem({"minecraft:torch"}, {64}, false)
4242 print(thanks)
4243 os.sleep(2) -- pause for 2 secs to allow time to press esc
4244 print("Building canal")
4245 createCanal(choice, length, height, width) -- eg 55, 312, 1 = complete a canal 312 blocks long on top of the wall
4246
4247 -- MOB SPAWNER
4248 elseif choice == 61 then -- 9x9 hollow cube cobble lined
4249 checkFuelNeeded(600) -- allow for 600 moves
4250 T:checkInventoryForItem({"minecraft:cobblestone"}, {256})
4251 T:checkInventoryForItem({"slab"}, {1})
4252 print(thanks)
4253 os.sleep(2) -- pause for 2 secs to allow time to press esc
4254 createMobFarmCube(false)
4255 elseif choice == 62 then -- dig mob trench
4256 checkFuelNeeded(length * height) -- allow for 600 moves
4257 T:checkInventoryForItem({"minecraft:cobblestone"}, {128})
4258 print(thanks)
4259 os.sleep(2) -- pause for 2 secs to allow time to press esc
4260 digMobTrench(height, length)
4261 elseif choice == 63 then -- flood mob spawner
4262 checkFuelNeeded(60) -- allow for 60 moves
4263 T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
4264 T:checkInventoryForItem({"fence"}, {2})
4265 T:checkInventoryForItem({"sign"}, {2})
4266 T:checkInventoryForItem({"slab"}, {1})
4267 T:checkInventoryForItem({"minecraft:soul_sand", "minecraft:dirt"}, {1, 1}, true)
4268 print(thanks)
4269 os.sleep(2) -- pause for 2 secs to allow time to press esc
4270 floodMobFarm()
4271 elseif choice == 64 then -- build bubble lift on top of soul sand
4272 checkFuelNeeded(200) -- allow for 200 moves
4273 T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
4274 T:checkInventoryForItem({"minecraft:cobblestone"}, {128})
4275 if T:getBlockType("down") ~= "minecraft:soul_sand" then
4276 T:checkInventoryForItem({"minecraft:soul_sand"}, {1})
4277 end
4278 print(thanks)
4279 os.sleep(2) -- pause for 2 secs to allow time to press esc
4280 createMobBubbleLift(size)
4281 elseif choice == 65 then -- Blaze spawner
4282 checkFuelNeeded(2500) -- allow for 2500 moves
4283 T:checkInventoryForItem({"minecraft:cobblestone"}, {640})
4284 T:checkInventoryForItem({"slab"}, {1})
4285 print("You will be asked for more assets later\n")
4286 print(thanks)
4287 os.sleep(2) -- pause for 2 secs to allow time to press esc
4288 createMobFarmCube(true)
4289 elseif choice == 66 then -- build endermen tower
4290 checkFuelNeeded(5000) -- allow for 5000 moves
4291 if T:getBlockType("down") ~= "minecraft:chest" then
4292 T:checkInventoryForItem({"minecraft:chest"}, {1})
4293 T:place("chest", -1, "down", false)
4294 T:checkInventoryForItem({"stone"}, {1024}) -- 16 stacks
4295 for i = 1, 16 do
4296 turtle.select(i)
4297 turtle.dropDown()
4298 end
4299 T:checkInventoryForItem({"stone"}, {832}) -- 13 stacks
4300 for i = 1, 16 do
4301 turtle.select(i)
4302 turtle.dropDown()
4303 end
4304 end
4305 T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
4306 T:checkInventoryForItem({"minecraft:bucket"}, {10})
4307 T:checkInventoryForItem({"fence"}, {192})
4308 T:checkInventoryForItem({"sign"}, {8})
4309 T:checkInventoryForItem({"ladder"}, {3})
4310 T:checkInventoryForItem({"minecraft:soul_sand"}, {2})
4311 print(thanks)
4312 os.sleep(2) -- pause for 2 secs to allow time to press esc
4313 createEnderTower()
4314 --[[
4315 elseif choice == 66 then -- block path over water
4316 checkFuelNeeded(size + 24) -- allow for 88 moves
4317 T:checkInventoryForItem({"minecraft:cobblestone"}, {88})
4318 T:checkInventoryForItem({"stone"}, {1})
4319 T:checkInventoryForItem({"minecraft:torch"}, {8}, false)
4320 print(thanks)
4321 os.sleep(2) -- pause for 2 secs to allow time to press esc
4322 createMobSpawnerBase(size)
4323 elseif choice == 67 then -- mob spawner tower
4324 checkFuelNeeded(1500) -- allow for 1000 blocks + moves
4325 T:checkInventoryForItem({"minecraft:chest"}, {2})
4326 T:checkInventoryForItem({"minecraft:hopper"}, {2})
4327 T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
4328 T:checkInventoryForItem({"minecraft:cobblestone"}, {576})
4329 T:checkInventoryForItem({"stone"}, {1})
4330 print(thanks)
4331 os.sleep(2) -- pause for 2 secs to allow time to press esc
4332 createMobSpawnerTower(size)
4333 elseif choice == 68 then -- mob spawner tank
4334 checkFuelNeeded(1000) -- allow for 500 blocks + moves
4335 T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
4336 T:checkInventoryForItem({"minecraft:cobblestone"}, {576})
4337 T:checkInventoryForItem({"stone"}, {1})
4338 print(thanks)
4339 os.sleep(2) -- pause for 2 secs to allow time to press esc
4340 createMobSpawnerTank()
4341 elseif choice == 69 then -- mob spawner roof
4342 checkFuelNeeded(500) -- allow for 400 blocks + moves
4343 T:checkInventoryForItem({"minecraft:cobblestone"}, {384})
4344 T:checkInventoryForItem({"minecraft:torch"}, {20}, false)
4345 print(thanks)
4346 os.sleep(2) -- pause for 2 secs to allow time to press esc
4347 createMobSpawnerRoof()
4348 ]]
4349
4350 -- AREA CARVING
4351 elseif choice == 71 then--Clear area
4352 checkFuelNeeded(width * length * 3)
4353 T:checkInventoryForItem({"minecraft:dirt"}, {64})
4354 print(thanks)
4355 sleep(2)
4356 print("Clearing area: size "..width.. " x "..length)
4357 clearArea(width, length, true)
4358 elseif choice == 72 then --Clear rectangle
4359 checkFuelNeeded(width * length)
4360 print("Clearing rectangle: size "..width.. " x "..length)
4361 clearRectangle(width, length)
4362 elseif choice == 73 then --Clear wall
4363 checkFuelNeeded(length * height)
4364 print("Recycling wall "..height.." blocks high")
4365 clearWall(1, length, height)
4366 elseif choice == 74 then --Clear single height perimeter wall
4367 checkFuelNeeded((width + length) * 2)
4368 print("Recycling wall section "..width.." x "..length)
4369 clearPerimeterWall(width, length, 1)
4370 elseif choice == 75 then --Clear hollow structure
4371 --size = Bottom->Top (0), Top->bottom(1)
4372 local withCeiling = true
4373 local withFloor = true
4374 local r = getSize(false, "Remove ceiling? (1 (y), 0 (n))", 0, 1)
4375 if r == 0 then
4376 withCeiling = false
4377 end
4378 local r = getSize(false, "Remove floor? (1 (y), 0 (n))", 0, 1)
4379 if r == 0 then
4380 withFloor = false
4381 end
4382 checkFuelNeeded((width * length) + ((width + length) * height))
4383 print("Recycling hollow structure "..width.." x "..length.." height: "..height)
4384 clearBuilding(width, length, height, size, withCeiling, withFloor)
4385 elseif choice == 76 then --Clear solid structure
4386 --size = Bottom->Top (0), Top->bottom(1)
4387 checkFuelNeeded((width * length) + ((width + length) * height))
4388 print("Recycling solid structure "..width.." x "..length.." height: "..height)
4389 clearSolid(width, length, height, size) -- size is 'up' or 'down'
4390 elseif choice == 77 then -- Dig trench
4391 checkFuelNeeded(height * length * 2)
4392 print(thanks)
4393 os.sleep(2) -- pause for 2 secs to allow time to press esc
4394 if length == 0 then
4395 print("Digging continuous trench "..height.." blocks deep")
4396 else
4397 print("Digging trench "..length.." blocks long, "..height.." blocks deep")
4398 end
4399 digTrench(height, length)
4400
4401 -- LAVA WATER
4402 elseif choice == 81 then --build containing wall in water or lava
4403 checkFuelNeeded(length * length)
4404 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {1024, 1024}, false)
4405 print("Building retaining wall in lava/water. length"..length)
4406 createRetainingWall(length, height)
4407 elseif choice == 82 then --drop sand
4408 checkFuelNeeded(100)
4409 T:checkInventoryForItem({"minecraft:sand"}, {1024}, false)
4410 print("Building sand wall. length: "..length)
4411 createSandWall(length)
4412 elseif choice == 83 then --decapitate and drop sand
4413 checkFuelNeeded(length * width)
4414 T:checkInventoryForItem({"minecraft:sand"}, {768}, false)
4415 print("Decapiating structure. length: "..length.." width: "..width)
4416 decapitateBuilding(width, length)
4417 elseif choice == 84 then --harvest sand
4418 checkFuelNeeded(100)
4419 print("Digging sand. length: "..length)
4420 clearSandWall(length)
4421 elseif choice == 85 then --remove sand cube
4422 checkFuelNeeded(length * width * 4)
4423 print("Removing sand cube. length: "..length.." width: "..width)
4424 clearSandCube(width, length)
4425 elseif choice == 86 then --
4426 --[[
4427 checkFuelNeeded(length * width + 64)
4428 print("Clearing monument layer: "..length.." width: "..width)
4429 clearMonumentLayer(width, length, size)]]
4430 elseif choice == 87 then -- Drain water/lava
4431 if length == 0 or width == 0 then
4432 checkFuelNeeded(width * length)
4433 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {128, 128}, false)
4434 print("Draining enclosed area with auto settings")
4435 else
4436 checkFuelNeeded(width * length)
4437 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {length * 2, length * 2}, false)
4438 print("Draining enclosed area "..width.." x "..length)
4439 end
4440 drainLiquid(width, length, size)
4441 elseif choice == 88 then --clear monument layer
4442 checkFuelNeeded(length * width + 64)
4443 print("Clearing monument layer: "..length.." width: "..width)
4444 clearMonumentLayer(width, length, size)
4445 elseif choice == 89 then --ladder to water/lava
4446 checkFuelNeeded(height * 2)
4447 T:checkInventoryForItem({"minecraft:ladder"}, {height})
4448 local cobble = height * 3 + 10
4449 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt", "minecraft:netherrack"}, {cobble, cobble, cobble})
4450 print(thanks)
4451 os.sleep(2) -- pause for 2 secs to allow time to press esc
4452 print("Creating ladder to bedrock")
4453 createLadderToWater()
4454 elseif choice == 810 then --remove plants
4455 checkFuelNeeded(length * width * 4)
4456 T:checkInventoryForItem({"minecraft:sand"}, {64})
4457 print("Removing seaweed. length: "..length.." width: "..width)
4458 clearSeaweed(width, length)
4459
4460 -- RAILWAY
4461 elseif choice == 91 then --place redstone torch level or downward slope
4462 checkFuelNeeded(10)
4463 local userChoice = T:checkInventoryForItem({"userChoice"}, {1})
4464 T:checkInventoryForItem({"minecraft:redstone_torch"}, {1})
4465 print("Placing redstone torch on ".. userChoice)
4466 placeRedstoneTorch("level", userChoice)
4467 elseif choice == 92 then --place redstone torch on upward slope
4468 checkFuelNeeded(10)
4469 local userChoice = T:checkInventoryForItem({"userChoice"}, {1})
4470 T:checkInventoryForItem({"minecraft:redstone_torch"}, {1})
4471 print("Placing redstone torch and ".. userChoice)
4472 placeRedstoneTorch("up", userChoice)
4473 elseif choice == 93 then --build downward slope
4474 checkFuelNeeded(height * 2)
4475 local userChoice = T:checkInventoryForItem({"userChoice"}, {height})
4476 T:checkInventoryForItem({"minecraft:redstone_torch"}, {math.ceil(height / 3)}, false)
4477 print("Building downward slope with ".. userChoice)
4478 createRailwayDown(userChoice, height)
4479 elseif choice == 94 then --build upward slope
4480 checkFuelNeeded(height * 2)
4481 local userChoice = T:checkInventoryForItem({"userChoice"}, {height + math.ceil(height / 3)})
4482 T:checkInventoryForItem({"minecraft:redstone_torch"}, {math.ceil(height / 3)}, false)
4483 print("Building upward slope with ".. userChoice)
4484 createRailwayUp(userChoice, height)
4485 end
4486 return retValue
4487end
4488
4489function harvestObsidian(width, length)
4490 local heightParts = math.floor(length / 8) -- eg 12/8 = 1
4491 local lastPart = length - (heightParts * 8) -- eg 12 - (1 * 8) = 4
4492 if width % 2 ~= 0 then
4493 width = width + 1
4494 end
4495 for y = 1, width do
4496 print("Mining column "..tostring(y).." of "..tostring(width))
4497 for j = 1, heightParts do
4498 T:go("m8")
4499 end
4500 if lastPart > 0 then
4501 T:go("m"..tostring(lastPart)) -- eg m4
4502 end
4503 -- width = tonumber(width)
4504 if y < width then
4505 if y % 2 == 0 then
4506 T:go("L1F1L1")
4507 else
4508 T:go("R1F1R1")
4509 end
4510 end
4511 end
4512end
4513
4514function harvestRun(runLength)
4515 local blockType
4516 local blockModifier
4517
4518 for i = 1, runLength do
4519 blockType, blockModifier = T:getBlockType("forward") -- store information about the block in front in a table
4520 if blockType ~= "" then
4521 if string.find(blockType, "log") ~= nil then
4522 T:harvestTree(true, false)
4523 else
4524 T:forward(1)
4525 end
4526 else
4527 T:forward(1)
4528 end
4529 end
4530end
4531
4532function harvestTreeFarm(size)
4533 local loopCount
4534 -- return blockType, blockModifier -- eg 'minecraft:log', 0 on older versions, "minecraft:oak_log" , nil on newer
4535 local blockType, _ = T:getBlockType("forward") -- store information about the block in front in a table
4536 if size == 0 then --fell single tree
4537 if blockType ~= "" then
4538 if string.find(blockType, "log") ~= nil then
4539 T:harvestTree(true, false)
4540 end
4541 end
4542 else
4543 if size == 1 then
4544 loopCount = 4
4545 else
4546 loopCount = 8
4547 end
4548 if blockType ~= "" then
4549 if string.find(blockType, "dirt") ~= nil or string.find(blockType, "grass") ~= nil then
4550 T:up(1)
4551 end
4552 end
4553 for i = 1, loopCount do
4554 harvestRun(loopCount * 2)
4555 turtle.turnRight()
4556 harvestRun(1)
4557 turtle.turnRight() --now facing opposite direction
4558 harvestRun(loopCount * 2)
4559 if i < loopCount then -- turn left if not on last run
4560 turtle.turnLeft()
4561 harvestRun(1)
4562 turtle.turnLeft()
4563 end
4564 end
4565 --return to starting position
4566 turtle.turnRight()
4567 harvestRun(loopCount * 2 - 1)
4568 turtle.turnRight()
4569 end
4570end
4571
4572function manageFarm(useFile)
4573 local lib = {}
4574
4575 function lib.checkPosition(currentRow)
4576 local atHome = false
4577 local blockType = T:getBlockType("down")
4578 print("Checking position\n"..blockType.. " below")
4579 if string.find(blockType, "water") ~= nil then --over water
4580 if T:getBlockType("forward") == "minecraft:chest" then
4581 atHome = true
4582 T:turnRight(1)
4583 if T:getBlockType("forward") == "minecraft:chest" then
4584 T:turnRight(2)
4585 else
4586 T:turnRight(1)
4587 end
4588 else -- not a chest
4589 T:turnRight(1)
4590 if T:getBlockType("forward") == "minecraft:chest" then
4591 atHome = true
4592 T:turnLeft(1)
4593 end
4594 end
4595 end
4596 if currentRow == nil and not atHome then -- no position file
4597 print("Unable to determine my position.\n")
4598 print("Place me in the lower left corner")
4599 print("over water, facing the crops")
4600 print("with chests to my right and behind")
4601 print("\nEnter to continue")
4602 read()
4603 end
4604 --[[
4605 --debug
4606 if atHome then
4607 print("Position ok. Enter")
4608 else
4609 print("NOt atHome?. Enter")
4610 end
4611 read()]]
4612 return atHome
4613 end
4614
4615 function lib.crossFarm(stopAtFirst)
4616 local blockType = ""
4617 if stopAtFirst == nil then
4618 stopAtFirst = false
4619 end
4620 -- will go forward until chest or cobble detected below
4621 -- if detected within 1 move, this is ignored
4622 local numMoves = 0
4623 local endOfPath = false
4624 while not endOfPath do
4625 local success, data = turtle.inspectDown()
4626 if data.name == nil then --nothing below
4627 turtle.forward()
4628 elseif data.name == "minecraft:chest" or data.name =="minecraft:cobblestone" then
4629 blockType = data.name
4630 if stopAtFirst then -- do not move further if first instance of cobble or chest
4631 endOfPath = true
4632 else
4633 if numMoves <= 1 then -- has chest been detected after 0 or 1 move?
4634 turtle.forward()
4635 else -- chest found after >1 move
4636 endOfPath = true
4637 end
4638 end
4639 else
4640 turtle.forward()
4641 end
4642 numMoves = numMoves + 1
4643 end
4644 return blockType -- either "" or chest/cobble
4645 end
4646
4647 function lib.emptyCropItem(direction, item, keepAmount)
4648 local lib2 = {}
4649
4650 function lib2.getInventory(tbl)
4651 local indexes = {"carrot", "potato", "wheat_seeds", "beetroot_seeds", "wheat", "beetroot", "sapling"} --order important wheat_seeds before wheat
4652 local inventory = {}
4653 for i = 1, #indexes do
4654 inventory[indexes[i]] = {}
4655 inventory[indexes[i]].leastSlot = 0
4656 inventory[indexes[i]].minQ = 0
4657 inventory[indexes[i]].mostSlot = 0
4658 inventory[indexes[i]].maxQ = 0
4659 end
4660 -- eg inventory["sapling"].leastSlot = 0
4661 for i = 1, 16 do
4662 --print("index :"..i)
4663 if turtle.getItemCount(i) > 0 then -- only check if items in slot
4664 local data = turtle.getItemDetail(i)
4665 local crop = ""
4666 for j = 1, #indexes do
4667 if data.name:find(indexes[j]) ~= nil then
4668 crop = indexes[j]
4669 break
4670 end
4671 end
4672 -- eg carrot = tbl["minecraft:carrot"], sapling = tbl["minecraft:oak_sapling"]
4673 if crop ~= "" then
4674 if inventory[crop].leastSlot == 0 then
4675 inventory[crop].leastSlot = i
4676 inventory[crop].minQ = data.count
4677 else -- crop already found
4678 if data.count < inventory[crop].minQ then
4679 if data.count > inventory[crop].maxQ then
4680 inventory[crop].mostSlot = i
4681 inventory[crop].maxQ = data.count
4682 end
4683 inventory[crop].leastSlot = i
4684 inventory[crop].minQ = data.count
4685 else -- current quantity > minQ. check if > maxQ
4686 if data.count >= inventory[crop].maxQ then
4687 inventory[crop].mostSlot = i
4688 inventory[crop].maxQ = data.count
4689 end
4690 end
4691 end
4692 --print("Slot "..i.."-"..crop..": minQ:"..inventory[crop].minQ)
4693 --read()
4694 end
4695 end
4696 end
4697 -- only one slot available == leastSlot, mostSlot = 0
4698 -- 2 or more slots available == smallest in leastSlot, largest in mostSlot
4699 return inventory -- inventory["sapling"].leastSlot = 1, inventory["carrots"].leastSlot = 3
4700 end
4701
4702 function lib2.drop(slot, direction, count)
4703 if direction == nil then
4704 direction = "forward"
4705 end
4706 local drop = turtle.drop
4707 if direction == "down" then
4708 drop = turtle.dropDown
4709 elseif direction == "up" then
4710 drop = turtle.dropUp
4711 end
4712
4713 local success = true
4714 if slot == nil then
4715 success = false
4716 else
4717 --print("slot = "..slot)
4718 if slot > 0 then
4719 turtle.select(slot)
4720 if count == 0 then
4721 if drop() then
4722 success = true
4723 end
4724 else
4725 if drop(count) then
4726 success = true
4727 end
4728 end
4729 end
4730 end
4731 return success
4732 end
4733
4734 function lib2.main(direction, item, keepAmount)
4735 if keepAmount == nil then
4736 keepAmount = 0
4737 end
4738 --local tbl = lib2.createTable() -- eg tbl["minecraft:sapling"] = "sapling"
4739 local inventory = lib2.getInventory() -- get table of crop items
4740 --print("Inventory obtained. Enter")
4741 --read()
4742 local search = inventory[item] -- returns inventory["sapling"] if it exists
4743 if search ~= nil then
4744 --print("Search: "..tostring(search.minQ).." slot: "..tostring(search.leastSlot))
4745 local total = search.minQ + search.maxQ
4746 --print("Total: "..total.." keep: "..keepAmount)
4747 while total > keepAmount do
4748 if keepAmount == -1 then -- drop 1 stack only
4749 if search.maxQ > 0 then
4750 lib2.drop(search.mostSlot, direction, 0)
4751 elseif search.minQ > 1 then
4752 lib2.drop(search.leastSlot, direction, 1) -- drop 1 item to reserve a place
4753 end
4754 break
4755 elseif keepAmount == 0 then
4756 lib2.drop(search.leastSlot, direction, 0)
4757 lib2.drop(search.mostSlot, direction, 0)
4758 else -- calculate ideal slot to drop based on keepAmount
4759 if keepAmount == 64 and total > 64 then -- some needs dropping
4760 --print("About to drop from "..search.leastSlot..", "..direction)
4761 lib2.drop(search.leastSlot, direction, 0)
4762 else
4763 local count = search.minQ - keepAmount
4764 lib2.drop(search.mostSlot, direction, 0)
4765 lib2.drop(search.leastSlot, direction, count)
4766 end
4767 end
4768 inventory = lib2.getInventory()
4769 search = inventory[item]
4770 total = search.minQ + search.maxQ
4771 end
4772 end
4773 end
4774
4775 lib2.main(direction, item, keepAmount)
4776 turtle.select(1)
4777 end
4778
4779 function lib.farmToRight(isFarmToRight, isFarmToFront, farmPos, waiting)
4780 while isFarmToRight do -- move to next farm
4781 --get some seeds and veg to take to next farm
4782 lib.getCrops()
4783 T:up(1)
4784 lib.crossFarm(false)
4785 T:go("F1D1")
4786 farmPos[1] = farmPos[1] + 1 -- change x position
4787 currentRow = 1
4788 lib.manageTree(true, farmPos)
4789 isFarmToRight, isFarmToFront, farmPos, waiting = lib.watchFarm(waiting, farmPos, currentRow, going)
4790 end
4791 return isFarmToRight, isFarmToFront, farmPos, waiting
4792 end
4793
4794 function lib.getCrops()
4795 T:turnRight(1)
4796 if T:getBlockType("forward") == "minecraft:chest" then
4797 lib.getSeeds("forward")
4798 end
4799 T:turnRight(1)
4800 if T:getBlockType("forward") == "minecraft:chest" then
4801 lib.getVeg("forward")
4802 end
4803 T:turnRight(2)
4804 end
4805
4806 function lib.getSaplings(direction)
4807 if direction == nil then
4808 direction = "forward"
4809 end
4810 -- get saplings if available
4811 local saplingSlot = 0
4812 local logSlot = 0
4813 local quantity = 0
4814 local slotContains = ""
4815 local toolSlot = lib.getToolSlot()
4816 for i = 1, 16 do -- fill inventory with seeds and saplings
4817 turtle.suck()
4818 end
4819 for i = 1, 16 do
4820 -- slotContains, slotCount, slotDamage
4821 slotContains, quantity = T:getSlotContains(i)
4822 if string.find(slotContains, "log") ~= nil then
4823 logSlot = i
4824 elseif string.find(slotContains, "sapling") ~= nil then
4825 saplingSlot = i
4826 end
4827 end
4828 lib.refuel(0) --use any sticks or planks for fuel
4829 lib.emptyCropItem(direction, "sapling", 1) -- ensure saplings occupy first slot in chest
4830 lib.emptyCropItem(direction, "wheat_seeds", 0)
4831 lib.emptyCropItem(direction, "beetroot_seeds", 0)
4832 turtle.select(1)
4833 return saplingSlot
4834 end
4835
4836 function lib.getSeeds(direction)
4837 -- Inside inventory: minecraft:beetroot, minecraft:beetroot_seeds
4838 -- minecraft:carrot, minecraft:potato
4839 -- minecraft:wheat_seeds
4840 -- planted: minecraft:carrots, minecraft:beetroots, minecraft:potatoes, minecraft:wheat
4841 -- get 1 stack of wheat seeds, 1 stack of beetroot seeds
4842 if direction == nil then
4843 direction = "forward"
4844 end
4845 local suck = turtle.suck
4846 if direction == "down" then
4847 suck = turtle.suckDown
4848 end
4849 turtle.select(1)
4850 for i = 1, 16 do -- fill inventory with seeds/ saplings/planks/sticks
4851 suck()
4852 end
4853 lib.refuel(0) -- remove any sticks or planks
4854 -- keep 1 stack of seeds, beetroot seeds
4855 lib.emptyCropItem(direction, "sapling", 0) -- ensure sapling fills first chest slot
4856 lib.emptyCropItem(direction, "beetroot_seeds", 64)
4857 lib.emptyCropItem(direction, "wheat_seeds", 64)
4858 end
4859
4860 function lib.getToolSlot()
4861 local item = "minecraft:diamond_hoe"
4862 local toolSlot = T:getItemSlot(item)
4863 if toolSlot == 0 then
4864 item = "minecraft:diamond_pickaxe"
4865 toolSlot = T:getItemSlot(item)
4866 if toolSlot == 0 then
4867 item = "minecraft:crafting_table"
4868 toolSlot = T:getItemSlot(item)
4869 end
4870 end
4871 return toolSlot, item
4872 end
4873
4874 function lib.getVeg(direction)
4875 if direction == nil then
4876 direction = "forward"
4877 end
4878 suck = turtle.suck
4879 if direction == "down" then
4880 suck = turtle.suckDown
4881 end
4882 -- get 1 stack of carrots, 1 stack of potatoes
4883 turtle.select(1)
4884 for i = 1, 16 do -- fill inventory with carrots and potatoes
4885 suck()
4886 end
4887 lib.emptyCropItem(direction, "carrot", -1) -- drop one stack only if >1 slot
4888 lib.emptyCropItem(direction, "potato", -1) -- drop one stack only if >1 slot
4889 lib.emptyCropItem(direction, "carrot", 64)
4890 lib.emptyCropItem(direction, "potato", 64)
4891 lib.emptyCropItem(direction, "wheat", 0)
4892 lib.emptyCropItem(direction, "beetroot", 0)
4893 end
4894
4895 function lib.goHome(currentRow)
4896 -- after a re-boot go to start
4897 local success = false
4898 local onWater = false
4899 local onChest = false
4900 local onCobble = false
4901 local onAir = false
4902 if currentRow == -1 then -- harvesting tree
4903 -- is tree above or in front
4904 -- check if log in front
4905 if string.find(T:getBlockType("forward"), "log") ~= nil then
4906 lib.harvestTree("forward")
4907 elseif string.find(T:getBlockType("up"), "log") ~= nil then
4908 lib.harvestTree("up")
4909 else
4910 while turtle.down() do end
4911 end
4912 -- should be on tree's dirt block
4913 local blockType = T:getBlockType("down")
4914 if blockType == "minecraft:chest" then
4915 onChest = true
4916 elseif blockType == "minecraft:dirt" or blockType == "minecraft:grass_block" then --on tree block
4917 local cobble = -1
4918 for i = 1, 4 do
4919 T:forward(1)
4920 blockType = T:getBlockType("down")
4921 if blockType == "minecraft:chest" then
4922 onChest = true
4923 break
4924 elseif blockType == "minecraft:cobblestone" then
4925 cobble = i
4926 end
4927 turtle.back()
4928 T:turnRight(1)
4929 end
4930 if not onChest then
4931 if cobble >= 0 then
4932 T:turnRight(cobble)
4933 T:forward(1)
4934 onCobble = true
4935 else
4936 onAir = true
4937 end
4938 end
4939 else -- not over tree block
4940 onAir = true
4941 end
4942 else -- could be anywhere, currentRow 1-10 -2,-3,-4
4943 local blockType = T:getBlockType("down")
4944 -- is water below?
4945 if blockType:find("water") ~= nil then
4946 onWater = true
4947 elseif blockType:find("chest") ~= nil then
4948 onChest = true
4949 elseif blockType:find("cobble") ~= nil then
4950 onCobble = true
4951 else
4952 onAir = true -- over crops, bare soil or water source
4953 end
4954 end
4955
4956 if onAir then -- if onAir find cobble or chest
4957 local blockType = lib.crossFarm(true) -- go along until chest or cobble found
4958 if blockType == "minecraft:cobblestone" then
4959 onCobble = true
4960 elseif blockType == "minecraft:chest" then
4961 onChest = true
4962 end
4963 end
4964
4965 if onCobble then -- if onCobble find chest
4966 -- check which direction cobble continues
4967 for i = 1, 4 do
4968 if turtle.forward() then -- no obstruction
4969 local blockType = T:getBlockType("down")
4970 if blockType == "minecraft:cobblestone" then --continue this route
4971 break
4972 elseif blockType == "minecraft:chest" then --stay here and exit loop
4973 onChest = true
4974 break
4975 end
4976 else -- blocked ? tree/sapling
4977 local blockType = T:getBlockType("forward")
4978 if blockType:find("log") ~= nil or blockType:find("sapling") ~= nil then
4979 -- next to tree/sapling, but not on chest, must be behind extended farm
4980 T:go("R2F1") -- turn round and continue forwards
4981 break
4982 end
4983 end
4984 turtle.back()
4985 T:turnLeft(1)
4986 end
4987 if not onChest then
4988 -- move forward until cobble runs out-- will be over retaining wall, or on chest
4989 while T:getBlockType("down") == "minecraft:cobblestone" do
4990 local success = turtle.forward()
4991 if not success then -- movement obstructed, must be tree/sapling
4992 local blockType = T:getBlockType("forward")
4993 if blockType:find("log") ~= nil or blockType:find("sapling") ~= nil then
4994 -- next to tree/sapling, but not on chest, must be behind extended farm
4995 T:go("R2F1") -- turn round and continue forwards
4996 end
4997 end
4998 end
4999 -- no longer on cobble, could be a chest
5000 if T:getBlockType("down") == "minecraft:chest" then
5001 onChest = true
5002 end
5003 end
5004 -- cobble ended, over edge of wall, on tree base with no sapling, or on chest
5005 end
5006
5007 if onChest then -- if onChest find water
5008 -- check if next block is a chest
5009 for i = 1, 4 do
5010 if turtle.forward() then -- no obstruction
5011 local blockType = T:getBlockType("down")
5012 if blockType == "minecraft:dirt" or blockType == "minecraft:grass_block" then -- on tree base
5013 turtle.back()
5014 break
5015 elseif blockType == "minecraft:chest" then --stay here and exit loop
5016 onChest = true
5017 break
5018 end
5019 else -- blocked ? tree/sapling
5020 local blockType = T:getBlockType("forward")
5021 if blockType:find("log") ~= nil or blockType:find("sapling") ~= nil then
5022 -- next to tree/sapling
5023 break
5024 end
5025 end
5026 turtle.back()
5027 T:turnLeft(1)
5028 end
5029 -- now on chest next to tree
5030 T:go("R1F1D1")
5031 blockType = T:getBlockType("down")
5032 if blockType:find("water") ~= nil then
5033 onWater = true
5034 else -- no water so return to other side of chest
5035 T:go("R2U1F2D1")
5036 blockType = T:getBlockType("down")
5037 if blockType:find("water") ~= nil then
5038 onWater = true
5039 end
5040 end
5041 end
5042
5043 if onWater then -- if onWater check position to discover if at start
5044 --orientate
5045 onWater = lib.checkPosition(currentRow)
5046 -- move over chest and look for cobble
5047 success = false
5048 while not success do
5049 T:go("R1U1F2R1F2L1") -- behind tree/sapling if cobble below continue on this route
5050 blockType = T:getBlockType("down")
5051 if blockType == "minecraft:cobblestone" then --continue
5052 while T:getBlockType("down") == "minecraft:cobblestone" do
5053 turtle.forward()
5054 end
5055 T:go("F1L1F1D1")
5056 else -- go back
5057 T:go("L1F2L1F2D1R1")
5058 success = true
5059 end
5060 end
5061 end
5062
5063 return success
5064 end
5065
5066 function lib.gotoTree(farmPos)
5067 turtle.select(1)
5068 T:turnRight(1)
5069 lib.getSaplings("forward")
5070 T:go("U1F1R1")
5071 lib.writePosition(farmPos, 0)
5072 lib.harvestTree("forward") -- fell tree or plant sapling, return to start
5073 end
5074
5075 function lib.harvest(waiting, farmPos, currentRow, going)
5076 if currentRow == 0 then
5077 T:go("U1") --ready to farm field
5078 end
5079 lib.writePosition(farmPos,"1") --field 1,1 row 1
5080 local isFarmToRight = false
5081 local isFarmToFront = false
5082 going = true
5083 local width = 11
5084 local length = 10
5085 for l = 1, length do
5086 for w = 1, width do
5087 isReady, blockType, status = lib.isCropReady("down")
5088 turtle.select(1)
5089 if blockType == "" then -- ? untilled soil or air above water
5090 turtle.digDown()
5091 turtle.digDown()
5092 lib.plantCrop("", "down")
5093 elseif isReady then
5094 turtle.digDown()
5095 lib.plantCrop(blockType, "down")
5096 end
5097 if w == width and T:getBlockType("down") == "minecraft:chest" then
5098 isFarmToRight = true
5099 end
5100 if w < width then
5101 T:forward(1)
5102 end
5103 end
5104 -- end of the row: over cobble or chest of next farm
5105 if l < length then
5106 if going then
5107 T:go("L1F1L1")
5108 else
5109 T:go("R1F1R1")
5110 end
5111 end
5112 currentRow = currentRow + 1
5113 going = not going
5114 end
5115 T:go("R1F1") -- goes over chest/cobble on top wall
5116 local blockType = T:getBlockType("down")
5117 if blockType == "minecraft:chest" then
5118 isFarmToFront = true
5119 end
5120 T:go("R2F1R1F1L1")
5121 -- now on cobble wall
5122 lib.writePosition(farmPos, "-2") -- heading towards start on left cobble
5123 while T:getBlockType("down") == "minecraft:cobblestone" do
5124 T:forward(1)
5125 end
5126 -- now above first chest
5127 T:go("F1L1F1D1") -- facing crops at start position
5128 lib.storeCrops() -- moves from start to deposit seeds and crops
5129 return isFarmToRight, isFarmToFront, farmPos, waiting
5130 end
5131
5132 function lib.harvestTree(direction)
5133 --[[
5134 start in front of / during tree harvest
5135 Check if sapling present
5136 Harvest tree if present, replant sapling
5137 Dispose of apples. Use sticks as fuel
5138 Return to base
5139 ]]
5140 local gotLogs = false
5141 if direction == nil then
5142 direction = "forward"
5143 end
5144 local inFront = T:getBlockType("forward")
5145 local saplingSlot = T:getSaplingSlot()
5146 if inFront == "" and saplingSlot > 0 then --no tree or sapling
5147 turtle.select(saplingSlot)
5148 turtle.place()
5149 elseif string.find(inFront, "log") ~= nil or direction == "up" then -- tree above or in front
5150 -- clsTurtle.harvestTree(self, extend, craftChest, direction)
5151 T:harvestTree(false, false, direction) --do not investigate side branches in case chunk unloaded
5152 T:go("R2F1R2")
5153 saplingSlot = T:getSaplingSlot()
5154 if saplingSlot > 0 then
5155 turtle.select(saplingSlot)
5156 turtle.place()
5157 end
5158 end
5159 T:sortInventory()
5160 -- drop any apples
5161 local item = T:getItemSlot("minecraft:apple")
5162 if item > 0 then
5163 T:drop(item, "up")
5164 end
5165 item = T:getItemSlot("minecraft:stick")
5166 if item > 0 then
5167 turtle.select(item)
5168 turtle.refuel()
5169 end
5170 -- return to base
5171 T:go("R1F1D1R2")
5172 end
5173
5174 function lib.manageTree(toTree, farmPos)
5175 if toTree then
5176 lib.gotoTree(farmPos) --check for sapling or harvest tree, retuns to start
5177 end
5178 lib.refuelWithLogs() -- use any logs for fuel and store saplings
5179 lib.getSeeds("forward") -- get 1 stack of beetroot / wheat seeds
5180 T:turnRight(1)
5181 lib.getVeg("forward")
5182 T:turnRight(2)
5183 waiting = true
5184 --print("SortInventory. Enter")
5185 --read()
5186 T:sortInventory()
5187 lib.writePosition(farmPos, -1)
5188 end
5189
5190 function lib.initialise()
5191 local doExit = false
5192 T:setEquipment()-- will ensure pickaxe on left and crafting table on right are equipped
5193 T:checkInventoryForItem({"minecraft:diamond_hoe"}, {1}, true) -- if already in place will continue
5194 -- equip hoe, swapping out crafting chest
5195 if not T:equip("right", "minecraft:diamond_hoe", 0) then
5196 print("Unable to equip hoe. Enter to quit")
5197 read()
5198 doExit = true
5199 end
5200 return doExit
5201 end
5202
5203 function lib.isCropReady(direction)
5204 local isReady = false
5205 local status = ""
5206 local blockType = ""
5207 if direction == nil then
5208 direction = "forward"
5209 end
5210 local success = false
5211 local data = {}
5212 if direction == "down" then
5213 success, data = turtle.inspectDown()
5214 else
5215 success, data = turtle.inspect()
5216 end
5217 if success then
5218 blockType = data.name
5219 if data.name == "minecraft:carrots" then
5220 status = data.state.age.." / 7"
5221 if data.state.age == 7 then
5222 isReady = true
5223 end
5224 elseif data.name == "minecraft:potatoes" then
5225 status = data.state.age.." / 7"
5226 if data.state.age == 7 then
5227 isReady = true
5228 end
5229 elseif data.name == "minecraft:wheat" then
5230 status = data.state.age.." / 7"
5231 if data.state.age == 7 then
5232 isReady = true
5233 end
5234 elseif data.name == "minecraft:beetroots" then
5235 status = data.state.age.." / 3"
5236 if data.state.age == 3 then
5237 isReady = true
5238 end
5239 end
5240 end
5241 return isReady, blockType, status
5242 end
5243
5244 function lib.plantCrop(crop, direction)
5245 if direction == nil then
5246 direction = "down"
5247 end
5248 local place = turtle.place
5249 if direction == "down" then
5250 place = turtle.placeDown
5251 end
5252
5253 local crops = {}
5254 crops.carrot = 0
5255 crops.potato = 0
5256 crops.wheat = 0
5257 crops.beetroot = 0
5258
5259 local success = false
5260 local data = {}
5261 local cropList = {}
5262 for i = 1, 16 do
5263 local count = turtle.getItemCount(i)
5264 if count > 0 then
5265 data = turtle.getItemDetail(i)
5266 if data.name == "minecraft:carrot" then
5267 crops.carrot = i
5268 elseif data.name == "minecraft:potato" then
5269 crops.potato = i
5270 elseif data.name == "minecraft:wheat_seeds" then
5271 crops.wheat = i
5272 elseif data.name == "minecraft:beetroot_seeds" then
5273 crops.beetroot = i
5274 end
5275 end
5276 end
5277 local anyCropSlot = 0
5278
5279 if crops.carrot > 0 then
5280 table.insert(cropList, crops.carrot)
5281 end
5282 if crops.potato > 0 then
5283 table.insert(cropList, crops.potato)
5284 end
5285 if crops.wheat > 0 then
5286 table.insert(cropList, crops.wheat)
5287 end
5288 if crops.beetroot > 0 then
5289 table.insert(cropList, crops.beetroot)
5290 end
5291 if crop == nil or crop == "" then -- choose any crop randomly
5292 if #cropList > 0 then
5293 math.randomseed(os.time())
5294 anyCropSlot = cropList[math.random(1, #cropList)]
5295 turtle.select(anyCropSlot)
5296 place()
5297 end
5298 else
5299 if crop:find("carrot") ~= nil and crops.carrot > 0 then
5300 turtle.select(crops.carrot)
5301 place()
5302 elseif crop:find("potato") ~= nil and crops.potato > 0 then
5303 turtle.select(crops.potato)
5304 place()
5305 elseif crop:find("wheat") ~= nil and crops.wheat > 0 then
5306 turtle.select(crops.wheat)
5307 place()
5308 elseif crop:find("beetroot") ~= nil and crops.beetroot > 0 then
5309 turtle.select(crops.beetroot)
5310 place()
5311 else
5312 if anyCropSlot > 0 and anyCropSlot ~= toolSlot then
5313 turtle.select(anyCropSlot)
5314 place()
5315 end
5316 end
5317 end
5318 turtle.select(1)
5319 end
5320
5321 function lib.readPosition()
5322 local farmPos = {nil, nil}
5323 local row = nil
5324 if fs.exists("farmPosition.txt") then
5325 local h = fs.open("farmPosition.txt", "r")
5326 farmPos[1] = h.readLine()
5327 farmPos[2] = h.readLine()
5328 row = h.readLine()
5329 h.close()
5330 end
5331 return farmPos, row
5332 end
5333
5334 function lib.refuel(slot)
5335 if slot == nil or slot == 0 then
5336 for i = 1, 16 do --search for sticks or planks
5337 if turtle.getItemCount(i) > 0 then
5338 -- slotContains, slotCount, slotDamage
5339 slotContains, quantity = T:getSlotContains(i)
5340 if string.find(slotContains, "planks") ~= nil then
5341 --refuel with planks unless full
5342 turtle.select(i)
5343 while turtle.getFuelLevel() < turtle.getFuelLimit() do
5344 if not turtle.refuel(1) then
5345 break
5346 end
5347 end
5348 elseif string.find(slotContains, "stick") ~= nil then
5349 turtle.select(i)
5350 turtle.refuel()
5351 end
5352 end
5353 end
5354 else
5355 turtle.select(slot)
5356 turtle.refuel()
5357 end
5358 turtle.select(1)
5359 end
5360
5361 function lib.refuelWithLogs()
5362 -- assume positioned in front of seed/sapling chest
5363 local toolSlot, item = lib.getToolSlot()
5364 local logSlot = 0
5365 for i = 1, 16 do -- drop everything except crafting table and logs into chest
5366 if i ~= toolSlot then
5367 --return slotContains, slotCount, slotDamage
5368 if turtle.getItemCount(i) > 0 then
5369 local slotContains, slotCount, slotDamage = T:getSlotContains(i)
5370 if string.find(slotContains, "log") == nil then --not a log
5371 T:drop(i, "forward")
5372 else
5373 logSlot = i
5374 end
5375 end
5376 end
5377 end
5378 if logSlot > 0 and toolSlot > 0 then -- logs onboard so need to craft
5379 --slotContains, slotCount, slotDamage
5380 if item == "minecraft:crafting_table" then
5381 turtle.select(toolSlot)
5382 if not T:equip("right", item, 0) then
5383 print("Unable to equip "..item..". Enter to quit")
5384 read()
5385 toolEquipped = false
5386 end
5387 end
5388 local slot = T:getFirstEmptySlot() --find an empty slot in the inventory
5389 turtle.select(slot)
5390 turtle.suck() --take first item from chest into empty slot eg saplings
5391 turtle.select(toolSlot)
5392 turtle.drop() -- put hoe into chest
5393 turtle.select(slot) --contains item from chest
5394 turtle.dropDown() -- drop into water below
5395 turtle.craft() --craft logs into planks
5396 turtle.select(toolSlot)
5397 turtle.suck() --remove hoe/pickaxe from chest
5398 turtle.select(slot)
5399 turtle.suckDown() --retrieve other item from below
5400 turtle.drop() -- put item back into chest
5401 toolSlot, item = lib.getToolSlot()
5402 turtle.select(toolSlot)
5403 if not T:equip("right", item, 0) then
5404 print("Unable to equip "..item..". Enter to quit")
5405 read()
5406 toolEquipped = false
5407 end
5408 lib.refuel(0) --refuel to max limit
5409 end
5410 turtle.select(1)
5411 return toolEquipped
5412 end
5413
5414 function lib.returnToFront(farmPos)
5415 if farmPos[2] > 1 then
5416 currentRow = -5
5417 T:go("U1R1")
5418 lib.writePosition(farmPos, currentRow)
5419 while farmPos[2] > 1 do -- return to start
5420 lib.crossFarm(false)
5421 turtle.back()
5422 farmPos[2] = farmPos[2] - 1 -- change x position
5423 lib.writePosition(farmPos, currentRow)
5424 end
5425 T:go("D1L1")
5426 end
5427 return farmPos
5428 end
5429
5430 function lib.returnToLeft(farmPos)
5431 if farmPos[1] > 1 then
5432 currentRow = -4
5433 T:go("U1R2")
5434 lib.writePosition(farmPos, currentRow)
5435 while farmPos[1] > 1 do -- return to start
5436 lib.crossFarm(false)
5437 turtle.back()
5438 farmPos[1] = farmPos[1] - 1 -- change x position
5439 lib.writePosition(farmPos, currentRow)
5440 end
5441 T:go("D1R2")
5442 end
5443 return farmPos
5444 end
5445
5446 function lib.storeCrops()
5447 T:turnRight(1)
5448 if T:getBlockType("forward") == "minecraft:chest" then
5449 lib.storeSeeds("forward", true)
5450 end
5451 T:turnRight(1)
5452 if T:getBlockType("forward") == "minecraft:chest" then
5453 lib.storeVeg("forward", true)
5454 end
5455 T:turnRight(2)
5456 end
5457
5458 function lib.storeSeeds(direction, all)
5459 if direction == nil then
5460 direction = "forward"
5461 end
5462 if all == nil then
5463 all = true
5464 end
5465 if string.find(T:getBlockType(direction), "chest") ~= nil then -- chest exists
5466 lib.emptyCropItem(direction, "beetroot_seeds", 64)
5467 lib.emptyCropItem(direction, "wheat_seeds", 64)
5468 if all then
5469 lib.emptyCropItem(direction, "beetroot_seeds", 0)
5470 lib.emptyCropItem(direction, "wheat_seeds", 0)
5471 end
5472 end
5473 turtle.select(1)
5474 end
5475
5476 function lib.storeVeg(direction, all)
5477 if direction == nil then
5478 direction = "forward"
5479 end
5480 if all == nil then
5481 all = true
5482 end
5483 for i = 1, 16 do
5484 if turtle.getItemCount(i) > 0 then
5485 local item = T:getItemName(i)
5486 if item == "minecraft:poisonous_potato" or item == "minecraft:apple" then
5487 T:drop(i, "up")
5488 end
5489 end
5490 end
5491 if string.find(T:getBlockType(direction), "chest") ~= nil then
5492 lib.emptyCropItem(direction, "carrot", 64)
5493 lib.emptyCropItem(direction, "potato", 64)
5494 if all then
5495 lib.emptyCropItem(direction, "carrot", 0)
5496 lib.emptyCropItem(direction, "potato", 0)
5497 end
5498 lib.emptyCropItem(direction, "wheat", 0)
5499 lib.emptyCropItem(direction, "beetroot", 0)
5500
5501 end
5502 turtle.select(1)
5503 end
5504
5505 function lib.watchFarm(waiting, farmPos, currentRow, going)
5506 local isFarmToRight = false
5507 local isFarmToFront = false
5508 local isReady, blockType, status
5509 -- check state of crop below. Harvest if ripe
5510 while waiting do
5511 isReady, blockType, status = lib.isCropReady("forward")
5512 if blockType == "" or isReady then
5513 waiting = false
5514 else
5515 print("Waiting for "..blockType.." status: "..status)
5516 sleep(60)
5517 end
5518 end
5519 currentRow = 0 -- force turtle up ready to harvest
5520 isFarmToRight, isFarmToFront, farmPos, waiting = lib.harvest(waiting, farmPos, currentRow, going)
5521 return isFarmToRight, isFarmToFront, farmPos, waiting
5522 --return waiting, farmPos, currentRow, going
5523 end
5524
5525 function lib.writePosition(farmPos, currentRow)
5526 local h = fs.open("farmPosition.txt", "w")
5527 h.writeLine(tostring(farmPos[1]))
5528 h.writeLine(tostring(farmPos[2]))
5529 h.writeLine(tostring(currentRow))
5530 h.close()
5531 end
5532
5533 function lib.main(useFile)
5534 --[[
5535 called from args on start, or from user choice
5536 farm already built, needs planting and/or harvesting
5537 needs both pickaxe and hoe
5538 may start in any position if chunk unloaded while running
5539 ]]
5540 if useFile == nil then
5541 useFile = true
5542 end
5543 local farmPos = {nil, nil}
5544 local currentRow = nil
5545 local waiting = false
5546 local going = true
5547 local doExit = false
5548 if useFile then -- read file
5549 farmPos, currentRow = lib.readPosition() -- nil or a farm position and row number
5550 --print("File read:"..farmPos[1]..", "..farmPos[2]..", "..currentRow)
5551 end
5552 if farmPos[1] == nil then
5553 farmPos[1] = 1
5554 farmPos[2] = 1
5555 end
5556 if lib.checkPosition(currentRow) then -- ? already at home
5557 currentRow = nil
5558 farmPos[1] = 1
5559 farmPos[2] = 1
5560 --print("CurrentRow reset to nil. Enter")
5561 --read()
5562 else -- not at home
5563 if currentRow == nil then -- no position file and not at home
5564 doExit = true -- break out of this task
5565 end
5566 end
5567 if currentRow == nil then -- no text file, so assume at beginning
5568 lib.storeCrops()
5569 doExit = lib.initialise() -- false if missing hoe
5570 if not doExit then
5571 currentRow = 0
5572 lib.manageTree(true, farmPos)
5573 waiting = true
5574 end
5575 else
5576 if lib.goHome(currentRow) then
5577 waiting = true
5578 else
5579 doExit = true
5580 end
5581 end
5582 while not doExit do -- start loop of watching crops, farming all modules
5583 isFarmToRight, isFarmToFront, farmPos, waiting = lib.watchFarm(waiting, farmPos, currentRow, going) --waits if required, harvests farm
5584 isFarmToRight, isFarmToFront, farmPos, waiting = lib.farmToRight(isFarmToRight, isFarmToFront, farmPos, waiting) -- no action if no farmToRight
5585 -- return home and continue with front
5586 farmPos = lib.returnToLeft(farmPos)
5587 while isFarmToFront do
5588 lib.getCrops()
5589 T:go("U1L1")
5590 lib.crossFarm(false)
5591 T:go("F1D1R1")
5592 currentRow = 0
5593 farmPos[2] = farmPos[2] + 1 -- change y position
5594 lib.manageTree(true, farmPos)
5595 isFarmToRight, isFarmToFront, farmPos, waiting = lib.watchFarm(waiting, farmPos, currentRow, going)
5596 isFarmToRight, isFarmToFront, farmPos, waiting = lib.farmToRight(isFarmToRight, isFarmToFront, farmPos, waiting)
5597 end
5598 farmPos = lib.returnToLeft(farmPos)
5599 farmPos = lib.returnToFront(farmPos)
5600 waiting = true -- reset when returned to the start
5601 end
5602 end
5603
5604 lib.main(useFile)
5605end
5606
5607function manageFarmSetup(farmType)
5608 -- check if startup.lua exists
5609 T:clear()
5610 if fs.exists("start.txt") then
5611 print("This turtle has been configured to")
5612 print("start automatically and run the farm")
5613 print("management program.\n")
5614 print("Do you want to disable this? (y/n)")
5615 response = string.lower(read())
5616 if response == "y" then
5617 fs.delete("start.txt")
5618 else
5619 if farmType == "farm" then
5620 manageFarm(false)
5621 else
5622 manageTreeFarm()
5623 end
5624 end
5625 else
5626 print("This turtle can be configured")
5627 print("to be a dedicated farm manager.")
5628 print("It will start automatically and")
5629 print("monitor the farm complex, harvesting")
5630 print("and replanting automatically.\n")
5631 if farmType == "farm" then
5632 print("You must provide a diamond hoe")
5633 print("and place me over the water source")
5634 else
5635 print("Place me between the chest and")
5636 print("first sapling / tree")
5637 end
5638 print("\nAre you ready? (y/n)")
5639 local response = string.lower(read())
5640 if response == "y" then
5641 if not fs.exists("startup.lua") then
5642 local h = fs.open("startup.lua", "w")
5643 h.writeLine('function main()')
5644 h.writeLine(' if fs.exists("start.txt") then')
5645 h.writeLine(' local handle = fs.open("start.txt", "r")')
5646 h.writeLine(' local cmd = handle.readLine()')
5647 h.writeLine(' handle.close()')
5648 h.writeLine(' shell.run("tk.lua "..cmd)')
5649 h.writeLine(' end')
5650 h.writeLine('end')
5651 h.writeLine('main()')
5652 h.close()
5653 end
5654 local h = fs.open("start.txt", "w")
5655 if farmType == "farm" then
5656 h.writeLine('farm')
5657 else
5658 h.writeLine('tree')
5659 end
5660 h.close()
5661 end
5662 T:clear()
5663 print("Startup files written")
5664 if farmType == "farm" then
5665 print("Press Enter to check equipment")
5666 read()
5667 local equippedRight, equippedLeft = T:setEquipment()
5668 if equippedRight ~= "minecraft:crafting_table" then
5669 T:checkInventoryForItem({"minecraft:crafting_table"}, {1})
5670 local equippedRight, equippedLeft = T:setEquipment()
5671 end
5672 T:checkInventoryForItem({"minecraft:diamond_hoe"}, {1})
5673 print("Place oak, birch, spruce saplings in")
5674 print("the chest on the right of the tree")
5675 print("Also wheat and beetroot seeds.\n")
5676 print("Place carrots and potatoes in")
5677 print("the chest on the left of the tree\n")
5678 else
5679 print("Drop saplings into the water")
5680 print("if none are planted")
5681 end
5682 print("Do you want to start now? (y/n)")
5683 local response = string.lower(read())
5684 if response == "y" then
5685 if farmType == "farm" then
5686 manageFarm(false)
5687 else
5688 manageTreeFarm()
5689 end
5690 end
5691 end
5692end
5693
5694function manageTreeFarm()
5695 local lib = {}
5696
5697 function lib.emptyLogs()
5698 for i = 1, 16 do
5699 if turtle.getItemCount(i) > 0 then
5700 turtle.select(i)
5701 local name = T:getItemName(i)
5702 if name:find("sapling") ~= nil then
5703 turtle.dropDown()
5704 elseif name:find("apple") ~= nil then
5705 turtle.drop()
5706 elseif name:find("stick") ~= nil then
5707 turtle.refuel()
5708 end
5709 end
5710 end
5711 T:sortInventory()
5712 -- convert 6 logs-->planks-->360 fuel
5713 local logsKept = false
5714 local logSlot = 0
5715 for i = 1, 16 do
5716 if turtle.getItemCount(i) > 0 then
5717 if T:getSlotContains(i):find("log") ~= nil and turtle.getItemCount(i) > 10 then -- 10+ logs in this slot
5718 turtle.select(i)
5719 if not logsKept then
5720 turtle.drop(turtle.getItemCount(i) - 10)
5721 logsKept = true
5722 logSlot = i
5723 else
5724 turtle.drop()
5725 end
5726 else
5727 turtle.drop()
5728 end
5729 end
5730 end
5731 if logsKept then
5732 T:sortInventory()
5733 turtle.select(16)
5734 turtle.craft()
5735 turtle.refuel()
5736 end
5737 end
5738
5739 function lib.initialise()
5740 local ready = false
5741 local blockType = ""
5742 local chest = false
5743 for i = 1, 4 do
5744 blockType = T:getBlockType("forward")
5745 if blockType == "minecraft:chest" then
5746 chest = true
5747 break
5748 end
5749 T:turnRight(1)
5750 end
5751 if chest then
5752 T:turnRight(2)
5753 ready = true
5754 else
5755 -- allow 10 secs to stop else find start position
5756 local countDown = 10
5757 for i = countDown, 1, -1 do
5758 T:clear()
5759 print("Hit Ctrl+T to terminate program")
5760 print("Starting in "..i.." seconds...")
5761 end
5762 if lib.goHome() then
5763 ready = true
5764 end
5765 end
5766 return ready
5767 end
5768
5769 function lib.getSaplings()
5770 T:go("L1F2L1F1R1D5F1R2") -- over sapling chest, facing water
5771 turtle.select(1)
5772 while turtle.suckDown() do end
5773 local saplingsKept = false
5774 for i = 1, 16 do
5775 if turtle.getItemCount(i) > 0 then
5776 -- slotContains, slotCount, slotDamage
5777 item = T:getSlotContains(i)
5778 if item == "minecraft:stick" then
5779 turtle.select(i)
5780 turtle.refuel()
5781 elseif item:find("sapling") == nil then -- not saplings
5782 turtle.select(i)
5783 turtle.dropDown()
5784 elseif item:find("sapling") ~= nil then --saplings
5785 if saplingsKept then
5786 turtle.select(i)
5787 turtle.dropDown()
5788 else
5789 saplingsKept = true
5790 end
5791 end
5792 end
5793 end
5794 -- max one stack of saplings, sticks used for fuel, others returned
5795 T:sortInventory()
5796 T:go("F1U5L1F1R1F2L1")
5797 end
5798
5799 function lib.goHome()
5800 local atHome = false
5801 local onCobble = false
5802 local hitCobble = false
5803 local onChest = false
5804 local onWater = false
5805 -- find starting position
5806 -- not at home as lib.initialise failed
5807 -- ? tree above
5808 local blockType = T:getBlockType("up")
5809 if blockType:find("log") ~= nil then -- tree above
5810 T:harvestTree(false, false, "up")
5811 end
5812 -- ? chest/hopper below
5813 blockType = T:getBlockType("down")
5814 if blockType == "minecraft:chest" then --over sapling chest
5815 while turtle.detect() do
5816 turtle.turnRight()
5817 onChest = true
5818 end
5819 elseif blockType == "minecraft:hopper" then --over hopper
5820 for i = 1, 4 do
5821 if turtle.forward() then
5822 if T:getBlockType("down") == "minecraft:chest" then
5823 T:turnRight(2)
5824 onChest = true
5825 break
5826 else
5827 turtle.back()
5828 end
5829 end
5830 turtle.turnRight()
5831 end
5832 end
5833 if onChest then
5834 T:go("F1U5L1F1R1F2L1")
5835 if lib.initialise() then
5836 atHome = true
5837 end
5838 else
5839 -- ? in the treetops
5840 blockType = T:getBlockType("down")
5841 if blockType == "" or blockType:find("leaves") ~= nil then
5842 while blockType == "" or blockType:find("leaves") ~= nil do
5843 T:down(1)
5844 blockType = T:getBlockType("down")
5845 end
5846 end
5847 blockType = T:getBlockType("down")
5848 if blockType:find("sapling") ~= nil then
5849 T:go("F1D1")
5850 blockType = T:getBlockType("down")
5851 end
5852 if blockType:find("torch") ~= nil or
5853 blockType == "minecraft:dirt" or
5854 blockType == "minecraft:grass_block" then
5855
5856 for i = 1, 4 do
5857 if turtle.forward() then
5858 if T:getBlockType("down") == "" then
5859 T:down(2)
5860 onWater = true
5861 break
5862 end
5863 turtle.back()
5864 end
5865 T:turnRight(1)
5866 end
5867 elseif blockType == "minecraft:cobblestone" then
5868 onCobble = true
5869 elseif blockType:find("water") ~= nil then
5870 onWater = true
5871 end
5872 if onWater then --move to cobble
5873 while T:getBlockType("down"):find("water") ~= nil do
5874 if not turtle.forward() then
5875 --hit the one cobble block above sapling chest
5876 hitCobble = true
5877 break
5878 end
5879 end
5880 if not hitCobble then
5881 -- now not over water: should be cobble or over ditch to hopper
5882 if T:getBlockType("down") == "minecraft:cobblestone" then
5883 onCobble = true
5884 else
5885 T:forward(1)
5886 if T:getBlockType("down") == "minecraft:cobblestone" then
5887 onCobble = true
5888 end
5889 end
5890 end
5891 end
5892 if onCobble then -- find home
5893 -- find cobble direction
5894 onCobble = false
5895 for i = 1, 4 do
5896 T:go("L1F1")
5897 if T:getBlockType("down") == "minecraft:cobblestone" then
5898 onCobble = true
5899 break
5900 end
5901 turtle.back()
5902 end
5903 -- continue on cobble until hitCobble
5904 while not hitCobble do
5905 while T:getBlockType("down") == "minecraft:cobblestone" do
5906 if not turtle.forward() then
5907 if T:getBlockType("forward") == "minecraft:cobblestone" then
5908 hitCobble = true
5909 break
5910 end
5911 end
5912 end
5913 if not hitCobble then
5914 -- not cobble below, on corner
5915 turtle.back()
5916 T:turnLeft(1)
5917 end
5918 end
5919 end
5920 if hitCobble then -- find home
5921 hitCobble = false
5922 -- probably hit from widest cobble path. look for space under cobble block
5923 if T:getBlockType("down") == "" then --could be over hopper
5924 T:down(1)
5925 if T:getBlockType("forward") == "" then
5926 hitCobble = true
5927 end
5928 else -- not over hopper
5929 T:go("L1F1R1F1R1D1")
5930 if T:getBlockType("forward") == "" then
5931 hitCobble = true
5932 else
5933 T:go("U2F2D2")
5934 if T:getBlockType("forward") == "" then
5935 hitCobble = true
5936 end
5937 end
5938 end
5939 if hitCobble then-- now over hopper column
5940 T:go("R2U3L1F1R1F2R1")
5941 blockType = T:getBlockType("forward")
5942 if blockType == "minecraft:chest" then
5943 atHome = true
5944 lib.emptyLogs()
5945 end
5946 T:turnRight(2)
5947 end
5948 end
5949 end
5950
5951 return atHome
5952 end
5953
5954 function lib.harvest()
5955 -- started from manageTreeFarm as first sapling grown
5956 local success = true
5957 local blockType
5958 local firstDirt = true
5959 for j = 1, 7 do
5960 for i = 1, 3 do
5961 blockType = T:getBlockType("forward")
5962 if blockType == "" then --nothing ahead, so plant sapling
5963 if firstDirt then
5964 firstDirt = false
5965 T:forward(2)
5966 else
5967 T:go("U1F1")
5968 local saplingSlot, name, count = T:getSaplingSlot("sapling")
5969 if count > 1 then
5970 T:place("sapling", -1, "down", false)
5971 end
5972 T:go("F1D1")
5973 end
5974 else -- block ahead, sapling or tree
5975 if string.find(blockType, "log") ~= nil then
5976 -- clsTurtle.harvestTree(extend, craftChest, direction)
5977 T:harvestTree(true, false, "forward")
5978 if firstDirt then
5979 firstDirt = false
5980 T:forward(1)
5981 else
5982 turtle.up()
5983 local saplingSlot, name, count = T:getSaplingSlot("sapling")
5984 if count > 1 then
5985 T:place("sapling", -1, "down", false)
5986 end
5987 T:go("F1D1")
5988 end
5989 elseif string.find(blockType, "sapling") ~= nil then
5990 T:go("U1F2D1")
5991 end
5992 end
5993 end
5994 if j % 2 == 1 then --odd 1,3,5,7
5995 T:go("R1F2R1")
5996 else
5997 T:go("L1F2L1")
5998 end
5999 end
6000 T:go("F6R1F14L1") --facing chest
6001 blockType = T:getBlockType("forward")
6002 if blockType == "minecraft:chest" then -- back home
6003 T:turnRight(2)
6004 blockType = T:getBlockType("forward")
6005 if blockType == "" then --nothing ahead, so plant sapling
6006 T:place("sapling", -1, "forward", false)
6007 end
6008 T:turnRight(2)
6009 lib.emptyLogs()
6010 T:turnRight(2)
6011 else
6012 success = false
6013 end
6014 return success
6015 end
6016
6017 function lib.main()
6018 if lib.initialise() then
6019 while true do
6020 local blockType = ""
6021 local waiting = true
6022 local needsPlanting = false
6023 local hasSaplings = false
6024 -- check state of sapling in front. Harvest if changed to log
6025 while waiting do
6026 blockType = T:getBlockType("forward")
6027 if blockType == "" then --no sapling or log
6028 needsPlanting = true
6029 break
6030 elseif blockType:find("log") ~= nil then
6031 waiting = false
6032 else --sapling
6033 print("Waiting for "..blockType)
6034 sleep(60)
6035 end
6036 end
6037 lib.getSaplings()
6038 if T:getItemSlot("sapling", -1) > 0 then
6039 hasSaplings = true
6040 end
6041 if (hasSaplings and needsPlanting) or not waiting then
6042 if not lib.harvest() then-- harvest trees and plant saplings
6043 break
6044 end
6045 end
6046 end
6047 end
6048 end
6049
6050 lib.main()
6051end
6052
6053function placeAnyStone(direction)
6054 success = true
6055 if not T:place("minecraft:cobblestone", -1, direction) then
6056 if not T:place("minecraft:dirt", -1, direction) then
6057 if not T:place("minecraft:netherrack", -1, direction) then
6058 if not T:place("minecraft:stone", -1, direction) then
6059 if not T:place("minecraft:granite", -1, direction) then
6060 if not T:place("minecraft:diorite", -1, direction) then
6061 if not T:place("minecraft:andesite", -1, direction) then
6062 success = false
6063 end
6064 end
6065 end
6066 end
6067 end
6068 end
6069 end
6070 return success
6071end
6072
6073function placeRedstoneTorch(direction, userChoice)
6074 if direction == "level" then
6075 T:go("R1F1D2L2F1R1")
6076 --clsTurtle.place(self, blockType, damageNo, direction, leaveExisting)
6077 T:place(userChoice, -1, "forward", false)
6078 T:back(1)
6079 T:place("minecraft:redstone_torch", -1, "forward", true)
6080 T:go("R1F1L1F1U2L1F1R1")
6081 elseif direction == "up" then
6082 T:go("R1F1D3R2F1L1")
6083 T:place("minecraft:redstone_torch", -1, "up", false)
6084 T:go("R1B1U3F1R1")
6085 T:place(userChoice, -1, "forward", false)
6086 end
6087end
6088
6089function plantTreefarm(size)
6090 -- .name = "minecraft:sapling"
6091 -- .state.type = "dark_oak"
6092 -- .metadata = 5
6093 local saplings = {"oak","spruce","birch","jungle","acacia","dark oak"}
6094 local leastSlot = 0
6095 local total = 0
6096 local leastModifier = 0
6097 local most = 0
6098 local mostID = -1
6099 local mostName = ""
6100 local secondMost = 0
6101 local secondMostID = -1
6102 local secondMostName = ""
6103
6104 -- slotData.leastSlot, slotData.leastModifier, total, slotData -- integer, integer, integer, table
6105 leastSlot, leastModifier, total, data = T:getItemSlot("sapling", i) -- eg 3xoak, 9x spruce Data.leastSlot, Data.leastModifier, total, Data
6106 --[[
6107 -- return table
6108 slotData.mostSlot = 0
6109 slotData.mostName = ""
6110 slotData.mostCount = 0
6111 slotData.mostModifier = 0
6112 slotData.leastSlot = 0
6113 slotData.leastName = ""
6114 slotData.leastCount = 0
6115 slotData.leastModifier = 0
6116 ]]
6117 -- example <= 1.12.2: 1, 0, 13, {1, 'minecraft:sapling', 13, 0, 1, 'minecraft:sapling', 13, 0}
6118 -- example > 1.12.2: 1, nil, 13, {1, 'minecraft:oak_sapling', 13, nil, 1, 'minecraft:oak_sapling', 13, nil}
6119 if leastSlot > 0 then -- item found
6120 mostID = data.mostModifier -- number or nil if mc > 1.12.2
6121 mostName = data.mostName
6122 secondMostID = data.leastModifier -- number or nil if mc > 1.12.2
6123 secondMostName = data.leastName
6124 if mostID == nil then
6125 for i = 1, #saplings do
6126 if string.find(mostName, saplings[i]) ~= nil then
6127 print("first sapling choice: "..saplings[i])
6128 end
6129 if string.find(secondMostName, saplings[i]) ~= nil then
6130 print("second sapling choice: "..saplings[i])
6131 end
6132 end
6133 else -- older mc "minecraft:sapling" with damage = 0, 1, 2 etc
6134 print("first sapling choice: "..saplings[mostID + 1])
6135 print("second sapling choice: "..saplings[secondMostID + 1])
6136 end
6137 end
6138
6139
6140 local outerCount = 4
6141 local innerCount = 1
6142 local repeatCount = 1
6143 if size > 1 then
6144 outerCount = 8
6145 innerCount = 5
6146 repeatCount = 3
6147 end
6148 -- user may have put turtle on the ground
6149 if T:getBlockType("forward") == "minecraft:dirt" or T:getBlockType("forward") == "minecraft:grass" then
6150 T:up(1)
6151 end
6152 -- start at base of first tree LL corner
6153 T:go("U1F1")
6154 for x = 1, 4 do -- place most in a ring on outside of planting area
6155 for i = 1, outerCount do
6156 T:place(mostName, mostID, "down", false)
6157 if i < outerCount then
6158 T:forward(1)
6159 T:place(mostName, mostID, "down", false)
6160 T:forward(1)
6161 end
6162 end
6163 T:turnRight(1)
6164 end
6165 -- over first sapling, facing forward
6166 T:go("F2R1F2L1")
6167 -- place secondMost sapling in centre
6168 -- T:place(blockType, damageNo, direction, leaveExisting)
6169 for x = 1, repeatCount do
6170 -- plant first column
6171 for i = 1, innerCount do
6172 if not T:place(secondMostName, secondMostID, "down", false) then
6173 T:place(mostName, mostID, "down", false)
6174 end
6175 if i < innerCount + 1 then
6176 T:forward(2)
6177 if not T:place(secondMostName, secondMostID, "down", false) then
6178 T:place(mostName, mostID, "down", false)
6179 end
6180 end
6181 end
6182 -- turn round and move to next column
6183 T:go("R1F2R1")
6184 -- plant return column
6185 for i = 1, innerCount do
6186 if not T:place(secondMostName, secondMostID, "down", false) then
6187 T:place(mostName, mostID, "down", false)
6188 end
6189 if i < innerCount + 1 then
6190 T:forward(2)
6191 if not T:place(secondMostName, secondMostID, "down", false) then
6192 T:place(mostName, mostID, "down", false)
6193 end
6194 end
6195 end
6196 if x < repeatCount then
6197 T:go("L1F2L1")
6198 end
6199 end
6200 if size == 1 then
6201 T:go("F1R1F3L1F2R1F1R1D2")
6202 else
6203 T:go("F1R1F9F2L1F2R1F1R1D2")
6204 end
6205end
6206
6207function repairWall(startAt, height, width, replaceWith)
6208 -- go up to startAt
6209
6210 -- if width = 1
6211
6212 -- for h = startAt, height, 1 do
6213
6214 -- replace block with replaceWith ("" = any)
6215
6216 -- move up
6217
6218 --end
6219
6220 -- move back to beginning
6221
6222 -- else
6223
6224 -- remain = height % 2
6225
6226 -- for w = 1, width - remain do
6227
6228 -- for h = startAt, height, 1 do
6229
6230 -- replace block with replaceWith ("" = any)
6231
6232 -- move up
6233
6234 --end
6235
6236 -- move to the right 1 block
6237
6238 -- for i = height, startAt, -1 do
6239
6240 -- replace block with replaceWith ("" = any)
6241
6242 -- move down
6243
6244 --end
6245
6246 -- end
6247
6248 -- end
6249
6250end
6251
6252function searchForSpawner(level)
6253 -- go down 8 with ladder above
6254 -- go(path, useTorch, torchInterval, leaveExisting)
6255 -- depth = math.floor(level / 8)
6256
6257 T:down(1)
6258 for i = 1, 6 do
6259 T:go("C1R1C1R1C1R1C1R1D1e0", false, 0, true, true)
6260 end
6261 -- go down 1 further
6262 T:down(1)
6263
6264 local distance = 0
6265 local returnLength = 0
6266 local actualLength = 32
6267 for j = 1, 4 do
6268 for i = 1, 3 do
6269 actualLength = 32
6270 actualLength = T:createTunnel(actualLength, true) --may cut short if in ocean
6271 T:turnRight(1)
6272 T:createTunnel(9, false)
6273 T:turnRight(1)
6274 T:createTunnel(actualLength, false)
6275 returnLength = returnLength + 8
6276 -- ready to cut next section
6277 if i < 3 then
6278 T:turnLeft(1)
6279 actualLength = T:createTunnel(9, true) --may cut short if in ocean
6280 if actualLength == 9 then
6281 returnLength = returnLength + 8
6282 T:turnLeft(1)
6283 else
6284 -- cut short, block tunnel and return
6285 T:go("C2R1C1L1C1L1C1R1U1L1C1R1C1R1C1R1C0", false, 0, true, false)
6286 T:go("F"..actualLength.."D1", false, 0, true, true)
6287 break
6288 end
6289 else
6290 T:turnRight(1)
6291 end
6292 T:dumpRefuse(3) -- keep 4 stacks cobble
6293 end
6294 T:createTunnel(returnLength + 1, false, false)
6295 -- move 9 places forward and repeat
6296 T:createTunnel(9, false)
6297 end
6298end
6299
6300function main()
6301 local doContinue = true
6302 checkLabel() -- make sure turtle label is set
6303 --check if lib folder exists
6304 if not checkLibs("lib", "clsTurtle") then
6305 -- use pastebin get to download clsTurtle to libs folder
6306 print("Missing clsTurtle.lua in libs directory")
6307 print("Attempting to obtain from Pastebin...")
6308 if shell.run("pastebin","get","tvfj90gK","lib/clsTurtle.lua") then
6309 print("clsTurtle.lua installed from Pastebin")
6310 else
6311 print("failed to install clsTurtle.lua from Pastebin")
6312 doContinue = false
6313 end
6314 end
6315 if not checkLibs("lib", "menu") then
6316 -- use pastebin get to download menu.lua to libs folder
6317 print("Missing menu.lua in libs directory")
6318 print("Attempting to obtain from Pastebin...")
6319 if shell.run("pastebin","get","BhjbYsw4","lib/menu.lua") then
6320 print("menu.lua installed from Pastebin")
6321 else
6322 print("failed to install menu.lua from Pastebin")
6323 doContinue = false
6324 end
6325 end
6326 if doContinue then
6327 menu = require("lib.menu")
6328 T = require("lib.clsTurtle"):new(1) -- 1 sent for debug purposes
6329 if args[1] ~= nil then
6330 if args[1] == "farm" then
6331 if not T:isEmpty() then -- will not run when turtle placed down
6332 manageFarm(true) -- use file to read status
6333 end
6334 elseif args[1] == "tree" then
6335 manageTreeFarm() -- use file to read status
6336 end
6337 else
6338 local choice, size, width, length, height = getTask()
6339 if choice ~= nil then
6340 getTaskInventory(choice, size, width, length, height)
6341 end
6342 end
6343 T:clear()
6344 print("Thank you for using 'survival toolkit'")
6345 else
6346 print("Add missing files and restart")
6347 end
6348end
6349
6350main()