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