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