· 5 years ago · Apr 20, 2020, 03:32 PM
1--**********Toolkit v2**********
2
3-- Last edited 10/04/2020 20:46
4-- Make sure you create a folder 'lib' and place menu.lua and clsTurtle.lua into it
5
6local menu, T
7
8function buildPortal()
9 T:go("D1x1")
10 T:place("minecraft:cobblestone", 0, "forward", true)
11 for i = 1, 3 do
12 T:go("U1x1")
13 T:place("minecraft:obsidian", 0, "forward", true)
14 end
15 T:go("U1x1")
16 T:place("minecraft:cobblestone", 0, "forward", true)
17 for i = 1, 2 do
18 T:go("R1F1L1x1")
19 T:place("minecraft:obsidian", 0, "forward", true)
20 end
21 T:go("R1F1L1x1")
22 T:place("minecraft:cobblestone", 0, "forward", true)
23 for i = 1, 3 do
24 T:go("D1x1")
25 T:place("minecraft:obsidian", 0, "forward", true)
26 end
27 T:go("D1x1")
28 T:place("minecraft:cobblestone", 0, "forward", true)
29 for i = 1, 2 do
30 T:go("L1F1R1x1")
31 T:place("minecraft:obsidian", 0, "forward", true)
32 end
33 T:go("U1L1F1R1")
34end
35
36function buildHollow(width, length, height)
37 --should be in bottom left corner at top of structure
38 -- dig out blocks in front and place to the left side
39 --go(path, useTorch, torchInterval, leaveExisting)
40 -- go @# = place any block up/forward/down # = 0/1/2
41 for h = 1, height do
42 for i = 1, length - 1 do
43 T:go("L1@1R1F1", false, 0, true, false)
44 end
45 T:go("L1@1R2", false, 0, true, false)
46 for i = 1, width - 1 do
47 T:go("L1@1R1F1", false, 0, true, false)
48 end
49 T:go("L1@1R2", false, 0, true, false)
50 for i = 1, length - 1 do
51 T:go("L1@1R1F1", false, 0, true, false)
52 end
53 T:go("L1@1R2", false, 0, true, false)
54 for i = 1, width - 1 do
55 T:go("L1@1R1F1", false, 0, true, false)
56 end
57 T:go("L1@1R2", false, 0, true, false)
58 -- hollowed out, now clear water/ blocks still present
59 clearRectangle(width, length)
60 if h < height then
61 T:down(1)
62 end
63 end
64end
65
66function buildRetainingWall(length, height)
67 if height <= 0 then
68 height = 30
69 end
70 local y = 1
71 -- go(path, useTorch, torchInterval, leaveExisting)
72 -- start at surface, move back 1 block
73 -- each iteration completes 3 columns
74 local numBlocks = T:getSolidBlockCount()
75 if length == 1 then --single column
76 while not turtle.detectDown() do
77 T:down(1)
78 y = y + 1
79 end
80 for i = 1, y - 1 do
81 T:go("U1C2", false, 0, true, false)
82 end
83 elseif length == 2 then--down then up
84 T:back(1)
85 while not turtle.detectDown() do
86 T:go("C1D1", false, 0, true, false)
87 y = y + 1
88 end
89 T:forward(1)
90 while not turtle.detectDown() do
91 T:down(1)
92 y = y + 1
93 end
94 T:go("B1C1", false, 0, true, false)
95 for i = 1, y - 1 do
96 T:go("U1C2", false, 0, true, false)
97 end
98 T:go("C1", false, 0, true, false)
99 else -- length 3 or more eg 3,22; 11
100 local remain = length % 3 -- 0; 1; 2 only possible results
101 length = length - remain -- 3-0=3; 4-1=3; 5-2=3; 6-0=6
102 for i = 3, length, 3 do -- 3, 6, 9, 12 etc
103 numBlocks = T:getSolidBlockCount()
104 if numBlocks < height * 3 then
105 --ask player for more
106 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {height * 3, height * 3}, false)
107 end
108 T:go("B1C1")
109 if i > 3 then -- second iteration
110 T:go("B1C1")
111 end
112 -- place blocks forward while descending
113 while not turtle.detectDown() do
114 T:go("C1D1", false, 0, true, false)
115 y = y + 1
116 end
117 -- may be higher than column in front
118 T:forward(1)
119 while not turtle.detectDown() do
120 T:down(1)
121 y = y + 1
122 end
123 while not turtle.detectUp() do
124 T:go("U1C2")
125 y = y - 1
126 end
127 T:go("B1C1B1", false, 0, true, false)
128 -- return to surface, placing forward and below
129 for i = 1, y - 1 do
130 T:go("C1U1C2", false, 0, true, false)
131 end
132 -- put missing block down
133 T:go("C1", false, 0, true, false)
134 y = 1 -- reset counter
135 end
136 if remain == 1 then -- 1 more column
137 y = 1
138 T:back(1)
139 while not turtle.detectDown() do
140 T:down(1)
141 y = y + 1
142 end
143 for i = 1, y - 1 do
144 T:go("U1C2", false, 0, true, false)
145 end
146 -- put missing block down
147 T:go("C1", false, 0, true, false)
148 elseif remain == 2 then -- 2 cols
149 y = 1
150 T:back(1)
151 while not turtle.detectDown() do
152 T:go("C1D1", false, 0, true, false)
153 y = y + 1
154 end
155 T:forward(1)
156 while not turtle.detectDown() do
157 T:down(1)
158 y = y + 1
159 end
160 T:go("B1C1", false, 0, true, false)
161 for i = 1, y - 1 do
162 T:go("U1C2", false, 0, true, false)
163 end
164 -- put missing block down
165 T:go("C1", false, 0, true, false)
166 end
167 end
168end
169
170function buildSandWall(length)
171 length = length or 0
172 local success = true
173 if length > 0 then
174 for i = 1, length - 1 do
175 success = dropSand()
176 T:forward(1, false)
177 end
178 success = dropSand()
179 else
180 while not turtle.detectDown() do -- over water
181 while not turtle.detectDown() do -- over water
182 success = dropSand()
183 end
184 if success then
185 T:forward(1, false)
186 else -- out of sand
187 break
188 end
189 end
190 end
191end
192
193function buildSolid(width, length, height)
194 for i = 1, width do --width could be 1, 2, 3 etc
195 buildRetainingWall(length, height)
196 if i < width then --width = 2 or more
197 if i == 1 or i % 2 == 1 then -- iteration 1, 3, 5
198 T:go("L1F1L2C1R1", false, 0, true, false)
199 else
200 T:go("R1F1R2C1L1", false, 0, true, false)
201 end
202 end
203 end
204end
205
206function checkFuelNeeded(quantity)
207 local fuelNeeded = quantity - turtle.getFuelLevel() -- eg 600
208 if fuelNeeded > 0 then
209 T:checkInventoryForItem({"minecraft:lava_bucket", "minecraft:coal", "minecraft:planks"}, {1, math.ceil(fuelNeeded / 60), math.ceil(fuelNeeded / 15)}) -- 0 if not present
210 end
211end
212
213function checkInventory(choice, size, width, length, height)
214 -- run this loop 2x per second to check if player has put anything in the inventory
215 -- fuel 1 coal = 60 = 4 planks. 64 planks = 16 coal = 960 units
216 local retValue = ""
217 local gotBirchSaplings = 0
218 local gotCoal = 0
219 local gotCobble = 0
220 local gotDirt = 0
221 local gotOakSaplings = 0
222 local gotPlanks = 0
223 local gotTorches = 0
224 local thanks = "Thank you.\n\nPress the ESC key\n\nStand Back..\n"
225
226 --[[if choice >= 12 and choice <= 16 then
227 T:getCoords(true)
228 home = createCoordinatesObject("homeLocation")
229 home:setAllValues(T:getX(), T:getY(), T:getZ(), T:getFacing())
230 end]]
231 T:clear()
232 if choice == 0 then --Missing pickaxe
233 T:checkInventoryForItem({"minecraft:diamond_pickaxe"}, {1})
234 print("Diamond Pickaxe being tested...")
235 T:setEquipment()
236 elseif choice == 1 then --Missing crafting table
237 T:checkInventoryForItem({"minecraft:crafting_table", ""}, {1, 0}) -- 0 if not present
238 print("Crafting table being tested...")
239 T:setEquipment()
240 elseif choice == 2 then --Missing chest
241 retValue = T:checkInventoryForItem({"minecraft:chest"}, {1}) -- 0 if not present
242 sleep(1.5)
243 elseif choice == 11 then -- ladder to bedrock
244 local level = T:getY()
245 print("Current saved y level = "..level)
246 print("\nIs this correct? (y/n + Enter)")
247 if read() ~= "y" then
248 level = getSize(true, "Current level (F3->Y coord)?_", 4, 300)
249 end
250 checkFuelNeeded(level * 2)
251 T:checkInventoryForItem({"minecraft:ladder"}, {level})
252 T:checkInventoryForItem({"minecraft:torch"}, {16}, false)
253 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {64, 64})
254 print(thanks)
255 os.sleep(2) -- pause for 2 secs to allow time to press esc
256 print("Creating ladder to bedrock")
257 createLadder("bedrock", level)
258 elseif choice == 12 then --Create Mine at this level
259 checkFuelNeeded(960)
260 T:checkInventoryForItem({"minecraft:torch"}, {24}, false)
261 T:checkInventoryForItem({"minecraft:cobblestone"}, {64})
262 T:checkInventoryForItem({"minecraft:chest"}, {1})
263 sleep(2)
264 print("CreateMine starting")
265 createMine()
266 elseif choice == 13 then -- ladder to surface
267 local level = T:getY()
268 print("Current saved y level = "..level)
269 print("\nIs this correct? (y/n + Enter)")
270 if read() ~= "y" then
271 level = getSize(true,"Current level (F3->Y coord)?_", 4, 300)
272 end
273 checkFuelNeeded((64 - level) * 2)
274 T:checkInventoryForItem({"minecraft:ladder"}, {64 - level + 10}) -- allow 10 extra for luck
275 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {192, 192})
276 print(thanks)
277 os.sleep(2) -- pause for 2 secs to allow time to press esc
278 print("Creating ladder to surface")
279 createLadder("surface", level)
280 elseif choice == 14 or choice == 15 then -- stairs to bedrock or surface
281 local level = T:getY()
282 print("Current saved y level = "..level)
283 print("\nIs this correct? (y/n + Enter)")
284 if read() ~= "y" then
285 level = getSize(true,"Current level (F3->Y coord)?_", 4, 300)
286 end
287 if level >= 60 then --assume going down
288 checkFuelNeeded(level * 10)
289 else -- assume going up
290 checkFuelNeeded((64 - level) * 10)
291 end
292 T:clear()
293 print("Add any stairs already crafted")
294 print("Press enter when ready")
295 read()
296 local numStairsNeeded = 0
297 if choice == 15 then
298 numStairsNeeded = math.ceil(level / 4)
299 else
300 numStairsNeeded = math.ceil((64 - level) / 4)
301 end
302 local numStairs = T:getItemCount("minecraft:stone_stairs", 0)
303 local cobbleNeeded = 256
304 if numStairs > 0 then
305 cobbleNeeded = 192 - (math.floor((2 * numStairs) / 3))
306 if cobbleNeeded < 64 then
307 cobbleNeeded = 64
308 end
309 end
310 T:checkInventoryForItem({"minecraft:cobblestone"}, {cobbleNeeded})
311 print(thanks)
312 os.sleep(2) -- pause for 2 secs to allow time to press esc
313 if choice == 15 then
314 print("Creating stairs to bedrock")
315 createStaircase("bedrock", level)
316 else
317 print("Creating stairs to surface")
318 createStaircase("surface", level)
319 end
320 elseif choice == 16 then -- search for mob spawner
321 local level = T:getY()
322 print("Current saved y level = "..level)
323 print("\nIs this correct? (y/n + Enter)")
324 if read() ~= "y" then
325 level = getSize(true,"Current level (F3->Y coord)?_", 4, 300)
326 end
327 checkFuelNeeded(3000)
328 --T:checkInventoryForItem({"minecraft:ladder"}, {level})
329 T:checkInventoryForItem({"minecraft:ladder"}, {6}) -- single level per turtle max 6 needed
330 T:checkInventoryForItem({"minecraft:bucket"}, {1}) -- in case lava found
331 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {192, 192})
332 T:checkInventoryForItem({"minecraft:torch"}, {160}, false)
333 print(thanks)
334 os.sleep(2) -- pause for 2 secs to allow time to press esc
335 print("Searching for mob spawner")
336 searchForSpawner(level)
337 elseif choice == 17 then --Decapitate volcano
338 checkFuelNeeded(width * length * 8)
339 T:checkInventoryForItem({"minecraft:bucket"}, {1}) -- in case lava found
340 print(thanks)
341 os.sleep(2) -- pause for 2 secs to allow time to press esc
342 print("Decapitatin volcano: size "..width.. " x "..length)
343 clearArea(width, length, false)
344 elseif choice == 18 then --Create Mine at bedrock
345 checkFuelNeeded(960)
346 T:checkInventoryForItem({"minecraft:torch"}, {24}, false)
347 T:checkInventoryForItem({"minecraft:cobblestone"}, {64})
348 T:checkInventoryForItem({"minecraft:chest"}, {9})
349 T:checkInventoryForItem({"minecraft:glass"}, {4})
350 T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
351 sleep(2)
352 print("CreateMineBase starting")
353 createMineBase()
354 elseif choice == 21 or choice == 31 then --Clear area
355 checkFuelNeeded(width * length * 3)
356 T:checkInventoryForItem({"minecraft:dirt"}, {64})
357 print(thanks)
358 sleep(2)
359 print("Clearing area: size "..width.. " x "..length)
360 clearArea(width, length, true)
361 elseif choice == 22 then --Create treefarm
362 if size == 1 then
363 checkFuelNeeded(300)
364 else
365 checkFuelNeeded(900)
366 end
367 T:checkInventoryForItem({"minecraft:dirt"}, {64})
368 if size == 1 then
369 T:checkInventoryForItem({"minecraft:torch"}, {16}, false)
370 else
371 T:checkInventoryForItem({"minecraft:torch"}, {64}, false)
372 end
373 print(thanks)
374 sleep(2)
375 print("CreateTreefarm starting: size "..size)
376 createTreefarm(size)
377 elseif choice == 23 then -- Plant treefarm
378 if size == 1 then
379 checkFuelNeeded(180)
380 else
381 checkFuelNeeded(480)
382 end
383 T:checkInventoryForItem({"minecraft:sapling"}, {4})
384 print(thanks)
385 print("plantTreefarm starting: size "..size)
386 plantTreefarm(size)
387 elseif choice == 24 then -- Harvest treefarm
388 print(thanks)
389 os.sleep(2)
390 print("Harvesting treefarm starting: size "..size)
391 harvestTreeFarm(size)
392 elseif choice == 25 then -- Fell tree
393 if T:isLog("forward") then
394 T:checkInventoryForItem({"minecraft:chest"}, {1}, false)
395 T:forward(1)
396 T:harvestWholeTree("up")
397 print("Press esc within 2 seconds!")
398 os.sleep(2) -- pause for 2 secs to allow time to press esc
399 print("Felling tree")
400 else
401 print("No log in front..")
402 print("Move me in front of a tree!")
403 os.sleep(2) -- pause for 2 secs to allow time to press esc
404 retValue = ""
405 end
406 elseif choice == 26 then -- Manage auto-treefarm
407 -- if turtle in front of:
408 -- empty block: assume not constructed, but check air below / chest behind
409 -- sapling: wait for growth to tree
410 -- tree: assume harvest
411 local inFront, subType = T:getBlockType("forward")
412 local createNew = false
413 sleep(1.5)
414 if inFront == nil then -- check if air below
415 print("No sapling or tree found\nChecking block below")
416 inFront, subType = T:getBlockType("down")
417 if inFront == nil then -- air below
418 print("No block found below, but no sapling")
419 print("or tree in front.\n")
420 print("please repair the farm and try again")
421 retValue = ""
422 else
423 createNew = true
424 end
425 elseif inFront == "minecraft:log" or inFront == "minecraft:log2" then
426 harvestAutoTreeFarm()
427 plantAutoTreeFarm()
428 elseif inFront == "minecraft:sapling" then
429 -- wait for trees, or player removes it
430 -- if changes to log, harvest tree farm
431 local timePassed = 0
432 local blockType, blockModifier = T:getBlockType("forward")
433 while true do
434 T:clear()
435 blockType, blockModifier = T:getBlockType("forward")
436 if blockType == "minecraft:sapling" then
437 print("Waiting for sapling to grow...")
438 print(timePassed.." seconds passed...")
439 sleep(10)
440 timePassed = timePassed + 10
441 elseif blockType == "minecraft:log" or blockType == "minecraft:log2" then
442 harvestAutoTreeFarm()
443 plantAutoTreeFarm()
444 timePassed = 0
445 -- wait for next sapling growth
446 else
447 print("No log or sapling in front..")
448 print("terminating program")
449 break
450 end
451 end
452 else
453 createNew = true
454 end
455 if createNew then
456 print("On ground. Creating tree farm...")
457 checkFuelNeeded(300)
458 T:checkInventoryForItem({"minecraft:chest"}, {3})
459 T:checkInventoryForItem({"minecraft:dirt"}, {64})
460 T:checkInventoryForItem({"minecraft:cobblestone"}, {128})
461 T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
462 T:checkInventoryForItem({"minecraft:hopper"}, {1})
463 T:checkInventoryForItem({"minecraft:torch"}, {6})
464 T:checkInventoryForItem({"minecraft:sapling"}, {6})
465 print(thanks)
466 os.sleep(2) -- pause for 2 secs to allow time to press esc
467 print("Creating automatic tree farm...")
468 createAutoTreeFarm()
469 -- plant saplings
470 -- wait for trees
471 -- harvest tree farm
472 end
473 elseif choice == 32 then -- Create wheat farm
474 -- needs a diamond hoe and axe either in the inventory, or already equipped (NOT together)
475 local itemEquipped = T:getEquipped("left") --tools already swapped to put crafting table on the right
476 if itemEquipped == "minecraft:diamond_hoe" then
477 if T:getItemSlot("minecraft:diamond_pickaxe", 0) == 0 then
478 T:checkInventoryForItem({"minecraft:diamond_pickaxe"}, {1})
479 end
480 -- ensure pickaxe is equipped
481 T:equip("left", "minecraft:diamond_pickaxe", 0)
482 print("\nDO NOT REMOVE THE HOE FROM MY INVENTORY!")
483 sleep(2)
484 end
485 local clearFirst = false
486 local decision = ""
487 local fuelNeeded = 0
488 while decision ~= "y" and decision ~= "n" do
489 T:clear()
490 print("Is there a clear flat area at least\n9 x 12 in front of me? (y/n)\n\n(Area will be cleared first if not)")
491 decision = read()
492 end
493 if decision == "n" then -- area needs clearing
494 clearFirst = true
495 checkFuelNeeded(480)
496 else
497 checkFuelNeeded(480)
498 T:checkInventoryForItem({"minecraft:dirt"}, {64})
499 end
500 T:checkInventoryForItem({"minecraft:cobblestone"}, {40})
501 T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
502 T:checkInventoryForItem({"minecraft:chest"}, {2})
503 T:checkInventoryForItem({"minecraft:hopper"}, {1})
504 print(thanks)
505 os.sleep(2) -- pause for 2 secs to allow time to press esc
506 print("Creating 8x8 Wheat farm")
507 createWheatFarm(clearFirst)
508 elseif choice == 33 then -- Plant wheat farm
509 -- needs a diamond hoe either in the inventory, or already equipped (NOT together)
510 local itemEquipped = T:getEquipped("left") --tools already swapped to put crafting table on the right
511 local itemAvailable = ""
512 if itemEquipped == "minecraft:diamond_pickaxe" then
513 if T:getItemSlot("minecraft:diamond_hoe", 0) == 0 then
514 T:checkInventoryForItem({"minecraft:diamond_hoe"}, {1})
515 end
516 itemAvailable = "minecraft:diamond_hoe"
517 end
518 --ensure hoe is equipped
519 if itemEquipped ~= "minecraft:diamond_hoe" then
520 T:equip("left", "minecraft:diamond_hoe", 0)
521 print("\nDO NOT REMOVE THE PICKAXE FROM MY INVENTORY!")
522 sleep(2)
523 end
524 checkFuelNeeded(180)
525 T:checkInventoryForItem({"minecraft:wheat_seeds"}, {8})
526 print(thanks)
527 os.sleep(2) -- pause for 2 secs to allow time to press esc
528 print("Planting 8x8 Wheat farm")
529 plantWheatFarm()
530 elseif choice == 34 then -- Harvest wheat farm
531 checkFuelNeeded(180)
532 T:checkInventoryForItem({"minecraft:bucket", "minecraft:water_bucket"}, {1, 1})
533 print(thanks)
534 os.sleep(2) -- pause for 2 secs to allow time to press esc
535 print("Harvesting 8x8 Wheat farm")
536 harvestWheatFarm()
537 elseif choice == 41 then --harvest obsidian
538 checkFuelNeeded(width * length * 3)
539 T:checkInventoryForItem({"minecraft:cobblestone"}, {width * length})
540 print(thanks)
541 sleep(2)
542 print("Harvesting obsidian area: size "..width.. " x "..length)
543 harvestObsidian(width, length)
544 elseif choice == 42 then --build nether portal
545 checkFuelNeeded(20)
546 T:checkInventoryForItem({"minecraft:obsidian"}, {10})
547 T:checkInventoryForItem({"minecraft:cobblestone"}, {8})
548 print(thanks)
549 sleep(2)
550 print("Building Nether portal")
551 buildPortal()
552 elseif choice == 43 then --demolish nether portal
553 checkFuelNeeded(20)
554 print("Demolishing Nether portal")
555 demolishPortal()
556 elseif choice == 51 then -- bridge over void/water/lava
557 checkFuelNeeded((size + 1) * 2)
558 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {size * 2, size * 2})
559 print(thanks)
560 os.sleep(2) -- pause for 2 secs to allow time to press esc
561 print("Building bridge ".. size.." blocks")
562 createBridge(size)
563 elseif choice == 52 then -- covered walkway
564 checkFuelNeeded((size + 1) * 2)
565 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {size * 2, size * 2})
566 T:checkInventoryForItem({"minecraft:torch"}, {math.ceil(size / 8)})
567 print(thanks)
568 os.sleep(2) -- pause for 2 secs to allow time to press esc
569 print("Building bridge ".. size.." blocks")
570 createWalkway(size)
571 elseif choice == 53 then -- continuous path over void/water/lava
572 checkFuelNeeded(512) -- allow for 512 length
573 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {64, 64}, false)
574 T:checkInventoryForItem({"minecraft:torch"}, {64}, false)
575 print(thanks)
576 os.sleep(2) -- pause for 2 secs to allow time to press esc
577 print("Building continuous path")
578 createPath()
579 elseif choice == 54 or choice == 55 then -- canal management
580 checkFuelNeeded(1024) -- allow for 1024 length
581 --T:checkInventoryForItem({"minecraft:chest"}, {1})
582 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {256, 256})
583 if choice == 54 then
584 T:checkInventoryForItem({"minecraft:torch"}, {64}, false)
585 else --right side, flood canal
586 T:checkInventoryForItem({"minecraft:water_bucket"}, {3})
587 end
588 print(thanks)
589 os.sleep(2) -- pause for 2 secs to allow time to press esc
590 print("Building canal")
591 createCanal(choice, size, length) -- eg 55, 312, 1 = complete a canal 312 blocks long on top of the wall
592 elseif choice == 61 then -- block path over water
593 checkFuelNeeded(size + 24) -- allow for 88 moves
594 T:checkInventoryForItem({"minecraft:cobblestone"}, {88})
595 T:checkInventoryForItem({"minecraft:stone"}, {1})
596 T:checkInventoryForItem({"minecraft:torch"}, {8}, false)
597 print(thanks)
598 os.sleep(2) -- pause for 2 secs to allow time to press esc
599 createMobSpawnerBase(size)
600 elseif choice == 62 then -- mob spawner tower
601 checkFuelNeeded(1500) -- allow for 1000 blocks + moves
602 T:checkInventoryForItem({"minecraft:chest"}, {2})
603 T:checkInventoryForItem({"minecraft:hopper"}, {2})
604 T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
605 T:checkInventoryForItem({"minecraft:cobblestone"}, {576})
606 T:checkInventoryForItem({"minecraft:stone"}, {1})
607 print(thanks)
608 os.sleep(2) -- pause for 2 secs to allow time to press esc
609 createMobSpawnerTower(size)
610 elseif choice == 63 then -- mob spawner tank
611 checkFuelNeeded(1000) -- allow for 500 blocks + moves
612 T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
613 T:checkInventoryForItem({"minecraft:cobblestone"}, {576})
614 T:checkInventoryForItem({"minecraft:stone"}, {1})
615 print(thanks)
616 os.sleep(2) -- pause for 2 secs to allow time to press esc
617 createMobSpawnerTank()
618 elseif choice == 64 then -- mob spawner roof
619 checkFuelNeeded(500) -- allow for 400 blocks + moves
620 T:checkInventoryForItem({"minecraft:cobblestone"}, {384})
621 T:checkInventoryForItem({"minecraft:torch"}, {20}, false)
622 print(thanks)
623 os.sleep(2) -- pause for 2 secs to allow time to press esc
624 createMobSpawnerRoof()
625 elseif choice == 71 then --Clear rectangle
626 checkFuelNeeded(width * length)
627 print("Clearing rectangle: size "..width.. " x "..length)
628 clearRectangle(width, length)
629 elseif choice == 72 then --Clear wall
630 checkFuelNeeded(length * height)
631 print("Recycling wall "..height.." blocks high")
632 clearWall(1, length, height)
633 elseif choice == 73 then --Clear single height perimeter wall
634 checkFuelNeeded((width + length) * 2)
635 print("Recycling wall section "..width.." x "..length)
636 clearPerimeterWall(width, length, 1)
637 elseif choice == 74 then --Clear floor and perimeter walls
638 checkFuelNeeded((width * length) + ((width + length) * height))
639 print("Recycling building and floor "..width.." x "..length.." height: "..height)
640 clearBuilding(width, length, height, false)
641 elseif choice == 76 or choice == 87 then --Hollow structure
642 checkFuelNeeded(width * length * height)
643 print("Creating hollow cube "..width.." x "..length.." height: "..height)
644 buildHollow(width, length, height)
645 elseif choice == 77 or choice == 88 then --solid structure
646 checkFuelNeeded(width * length * height)
647 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {width * length * height, width * length * height}, false)
648 print("Creating solid cube "..width.." x "..length.." height: "..height)
649 buildSolid(width, length, height)
650 elseif choice == 78 then --remove hollow structure bottom up
651 checkFuelNeeded(width * length * height)
652 print("Removing structure "..width.." x "..length.." height: "..height)
653 clearHollow(width, length, height)
654 elseif choice == 79 then --remove solid structure bottom up
655 checkFuelNeeded(width * length * height)
656 print("Removing structure "..width.." x "..length.." height: "..height)
657 clearSolid(width, length, height)
658 elseif choice == 81 then --build containing wall in water or lava
659 checkFuelNeeded(length * length)
660 T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {1024, 1024}, false)
661 print("Building retaining wall in lava/water. length"..length)
662 buildRetainingWall(length, height)
663 elseif choice == 82 then --drop sand
664 checkFuelNeeded(100)
665 T:checkInventoryForItem({"minecraft:sand"}, {1024}, false)
666 print("Building sand wall. length: "..length)
667 buildSandWall(length)
668 elseif choice == 83 then --decapitate and drop sand
669 checkFuelNeeded(length * width)
670 T:checkInventoryForItem({"minecraft:sand"}, {768}, false)
671 print("Decapiating structure. length: "..length.." width: "..width)
672 decapitateBuilding(width, length)
673 elseif choice == 84 then --harvest sand
674 checkFuelNeeded(100)
675 print("Digging sand. length: "..length)
676 clearSandWall(length)
677 elseif choice == 85 then --remove sand cube
678 checkFuelNeeded(length * width * 4)
679 print("Removing sand cube. length: "..length.." width: "..width)
680 clearSandCube(width, length)
681 elseif choice == 86 then --remove floor and walls
682 checkFuelNeeded(length * width * 4)
683 print("Demolishing structure. length: "..length.." width: "..width)
684 demolishBuilding(width, length)
685 --elseif choice == 87 then check 76
686 --elseif choice == 88 then check 77
687 elseif choice == 91 then --place redstone torch level or downward slope
688 checkFuelNeeded(10)
689 local userChoice = T:checkInventoryForItem({"userChoice"}, {1})
690 T:checkInventoryForItem({"minecraft:redstone_torch"}, {1})
691 print("Placing redstone torch on ".. userChoice)
692 placeRedstoneTorch("level", userChoice)
693 elseif choice == 92 then --place redstone torch on upward slope
694 checkFuelNeeded(10)
695 local userChoice = T:checkInventoryForItem({"userChoice"}, {1})
696 T:checkInventoryForItem({"minecraft:redstone_torch"}, {1})
697 print("Placing redstone torch and ".. userChoice)
698 placeRedstoneTorch("up", userChoice)
699 elseif choice == 93 then --build downward slope
700 checkFuelNeeded(height * 2)
701 local userChoice = T:checkInventoryForItem({"userChoice"}, {height})
702 T:checkInventoryForItem({"minecraft:redstone_torch"}, {math.ceil(height / 3)}, false)
703 print("Building downward slope with ".. userChoice)
704 createRailwayDown(userChoice, height)
705 elseif choice == 94 then --build upward slope
706 checkFuelNeeded(height * 2)
707 local userChoice = T:checkInventoryForItem({"userChoice"}, {height + math.ceil(height / 3)})
708 T:checkInventoryForItem({"minecraft:redstone_torch"}, {math.ceil(height / 3)}, false)
709 print("Building upward slope with ".. userChoice)
710 createRailwayUp(userChoice, height)
711 end
712 return retValue
713end
714
715function checkLabel()
716 if os.getComputerLabel() == nil then
717 os.setComputerLabel("toolkit")
718 print("Computer label set to "..os.getComputerLabel())
719 end
720end
721
722function checkLibs(libDir, filename)
723 local fileExists = false
724 if fs.exists(libDir) then
725 if not fs.isDir(libDir) then
726 fs.move(libDir, libDir.."Renamed")
727 fs.makeDir(libDir)
728 end
729 else
730 fs.makeDir(libDir)
731 end
732 if fs.exists(fs.combine(libDir, filename)) or fs.exists(fs.combine(libDir, filename..".lua")) then
733 fileExists = true
734 end
735 return fileExists
736end
737
738function clearArea(width, length, useDirt)
739 if useDirt == nil then
740 useDirt = true
741 end
742 local evenWidth = false
743 local evenHeight = false
744 local loopWidth
745 -- go(path, useTorch, torchInterval, leaveExisting)
746 if width % 2 == 0 then
747 evenWidth = true
748 loopWidth = width / 2
749 else
750 loopWidth = math.ceil(width / 2)
751 end
752 if length % 2 == 0 then
753 evenHeight = true
754 end
755 -- clear an area between 2 x 4 and 32 x 32
756 -- if width is even no, then complete the up/down run
757 -- if width odd no then finish at top of up run and reverse
758 -- should be on flat ground, check voids below, harvest trees
759 for x = 1, loopWidth do
760 -- Clear first column (up)
761 for y = 1, length do
762 if useDirt then
763 if not turtle.detectDown() then
764 T:place("minecraft:dirt", -1, "down", true)
765 else --if not water, dirt, grass , stone then replace with dirt
766 blockType, blockModifier = T:getBlockType("down")
767 if blockType ~= "minecraft:grass" and blockType ~= "minecraft:dirt" and blockType ~= "minecraft:stone" and blockType ~= "minecraft:water" then
768 turtle.digDown()
769 T:place("minecraft:dirt", -1, "down", true)
770 end
771 end
772 end
773 blockType, blockModifier = T:getBlockType("forward")
774 if blockType == "minecraft:log" or blockType == "minecraft:log2" then -- tree in front, so harvest it
775 T:harvestTree() --automatically moves forward 1 block
776 if y == length then -- move back 1 if already at max length
777 T:back(1)
778 end
779 else
780 if y < length then
781 T:go("F1+1", false,0,false,true)
782 end
783 end
784 end
785 -- clear second column (down)
786 if x < loopWidth or (x == loopWidth and evenWidth) then -- go down if on width 2,4,6,8 etc
787 T:go("R1F1+1R1", false,0,false,true)
788 for y = 1, length do
789 if useDirt then
790 if not turtle.detectDown() then
791 T:place("minecraft:dirt", -1, "down", true)
792 else
793 blockType, blockModifier = T:getBlockType("down")
794 if blockType ~= "minecraft:grass" and blockType ~= "minecraft:dirt" and blockType ~= "minecraft:stone" and blockType ~= "minecraft:water" then
795 turtle.digDown()
796 T:place("minecraft:dirt", -1, "down", true)
797 end
798 end
799 end
800 blockType, blockModifier = T:getBlockType("forward")
801 if blockType == "minecraft:log" or blockType == "minecraft:log2" then -- tree in front, so harvest it
802 T:harvestTree()
803 if y == length then
804 T:back(1)
805 end
806 else
807 if y < length then
808 T:go("F1+1", false,0,false,true)
809 end
810 end
811 end
812 if x < loopWidth then
813 T:go("L1F1+1L1", false,0,false,true)
814 else
815 T:turnRight(1)
816 T:forward(width - 1)
817 T:turnRight(1)
818 end
819 else -- equals width but is 1,3,5,7 etc
820 T:turnLeft(2) --turn round 180
821 T:forward(length - 1)
822 T:turnRight(1)
823 T:forward(width - 1)
824 T:turnRight(1)
825 end
826 end
827end
828
829function clearBuilding(width, length, height, withCeiling)
830 --clear floor
831 clearRectangle(width, length)
832 T:up(1)
833 if withCeiling then
834 clearPerimeterWall(width, length, height - 2)
835 T:up(1)
836 clearRectangle(width, length)
837 T:down(1)
838 else
839 clearPerimeterWall(width, length, height - 1)
840 end
841 T:down(height - 1)
842end
843
844function clearHollow(width, length, height)
845 if height == 0 then
846 --need to check if anything above except bedrock
847 local totalItemCount = 0
848 repeat
849 totalItemCount = T:getTotalItemCount()
850 clearPerimeterWall(width, length, 1)
851 T:up(1)
852 height = height + 1
853 until T:getTotalItemCount() == totalItemCount -- nothing collected or full inventory
854 else
855 clearPerimeterWall(width, length, height)
856 end
857 T:down(height)
858end
859
860function clearSolid(width, length, height)
861 if height == 0 then
862 --need to check if anything above except bedrock
863 local totalItemCount = 0
864 repeat
865 totalItemCount = T:getTotalItemCount()
866 clearRectangle(width, length)
867 T:up(1)
868 height = height + 1
869 until T:getTotalItemCount() == totalItemCount -- nothing collected or full inventory
870 else
871 for i = 1, height do
872 clearRectangle(width, length)
873 T:up(1)
874 end
875
876 end
877 T:down(height)
878end
879
880function clearPerimeterWall(width, length, height)
881 -- go(path, useTorch, torchInterval, leaveExisting)
882 -- if height <= 0 then stop when nothing above
883 if height > 0 then
884 for i = 1, height do
885 T:go("F"..tostring(length - 1)..
886 "R1F"..tostring(width - 1)..
887 "R1F"..tostring(length - 1)..
888 "R1F"..tostring(width - 1)..
889 "R1", false, 0, false, false)
890 if i < height then
891 T:up(1)
892 end
893 end
894 else
895 repeat
896 T:go("F"..tostring(length - 1)..
897 "R1F"..tostring(width - 1)..
898 "R1F"..tostring(length - 1)..
899 "R1F"..tostring(width - 1)..
900 "R1", false, 0, false, false)
901 if turtle.detectUp() then
902 T:up(1)
903 end
904 until not turtle.detectUp()
905 end
906end
907
908function clearRectangle(width, length)
909 -- could be 1 wide x xx lenght (trench) up and return
910 -- could be 2+ x 2+
911 -- even no of runs return after last run
912 -- odd no of runs forward, back, forward, reverse and return
913 local directReturn = true
914 if width % 2 == 1 then
915 directReturn = false
916 end
917 if width == 1 then -- trench ahead
918 T:go("F"..length - 1 .."R2F"..length - 1 .."R2")
919 else
920 if directReturn then -- width = 2,4,6,8 etc
921 for i = 1, width, 2 do -- i = 1,3,5,7 etc
922 T:go("F"..length - 1 .."R1F1R1F"..length - 1)
923 if i < width - 2 then -- eg width = 8, i compares with 6: 1, 3, 5, 7
924 T:go("L1F1L1")
925 end
926 end
927 T:go("R1F"..width - 1 .."R1")
928 else -- width = 3, 5, 7, 9 eg width 7
929 for i = 1, width - 1, 2 do -- i = 1,3,5
930 T:go("F"..length - 1 .."R1F1R1F"..length - 1 .."L1F1L1")
931 end
932 -- one more run then return
933 T:go("F"..length - 1 .."R2F"..length - 1 .."R1F"..width - 1 .."R1")
934 end
935 end
936end
937
938function clearSandWall(length)
939 --dig down while on top of sand
940 while T:getBlockType("down") == "minecraft:sand" do
941 T:down(1)
942 end
943 -- repeat length times
944 for i = 1, length do
945 --if sand in front, dig
946 while turtle.detect() do
947 if T:getBlockType("forward") == "minecraft:sand" then
948 T:dig("forward")
949 else --solid block, not sand so move up
950 T:up(1)
951 end
952 end
953 --move forward
954 T:forward(1)
955 while T:getBlockType("down") == "minecraft:sand" do
956 T:down(1)
957 end
958 end
959end
960
961function clearSandCube(width, length)
962 --go down to bottom of sand
963 while T:getBlockType("down") == "minecraft:sand" do
964 T:down(1)
965 end
966 clearBuilding(width, length, 0, false)
967end
968
969function clearWall(width, length, height)
970 local evenHeight = false
971 local atStart = true
972 local drop = height - 2
973 -- go(path, useTorch, torchInterval, leaveExisting)
974 if height % 2 == 0 then
975 evenHeight = true
976 end
977
978 -- dig along and up for specified length
979 if evenHeight then --2, 4 , 6 etc
980 for h = 2, height, 2 do
981 for i = 1, length - 1 do
982 T:go("x0F1", false, 0, false, false)
983 end
984 if h < height then
985 T:go("R2U2", false, 0, false, false)
986 end
987 atStart = not atStart
988 end
989 else
990 drop = height - 1
991 for h = 1, height, 2 do
992 if h == height then
993 T:go("F"..tostring(length - 1), false, 0, false, false)
994 else
995 for i = 1, length - 1 do
996 T:go("x0F1", false, 0, false, false)
997 end
998 end
999 atStart = not atStart
1000 if h < height then
1001 T:go("R2U2", false, 0, false, false)
1002 end
1003 end
1004 end
1005 if evenHeight then
1006 T:go("x0", false, 0, false, false)
1007 end
1008 T:go("R2D"..drop, false, 0, false, false)
1009 if not atStart then
1010 T:go("F"..tostring(length - 1).."R2", false, 0, false, false)
1011 end
1012end
1013
1014function createAutoTreeFarm()
1015 T:clear()
1016 print("Clear the area first? (y/n)")
1017 local response = read()
1018 if response == "y" then
1019 createWheatFarm(true, 11, 14)
1020 else
1021 createWheatFarm(false)
1022 end
1023 -- flood area to collect saplings
1024 -- refill water buckets
1025 T:forward(1)
1026 for i = 1, 2 do
1027 sleep(0.5)
1028 T:place("minecraft:bucket", -1, "down", false)
1029 end
1030 T:go("F1U1F10R1F8R2")
1031 T:place("minecraft:water_bucket", -1, "down", false)
1032 T:forward(2)
1033 T:place("minecraft:water_bucket", -1, "down", false)
1034 T:go("F5L1F10D1")
1035 for i = 1, 2 do
1036 sleep(0.5)
1037 T:place("minecraft:bucket", -1, "down", false)
1038 end
1039 T:go("U1R2F10R1F3R2")
1040 T:place("minecraft:water_bucket", -1, "down", false)
1041 T:forward(2)
1042 T:place("minecraft:water_bucket", -1, "down", false)
1043 T:go("F1L1F10D1R2")
1044 for i = 1, 2 do
1045 sleep(0.5)
1046 T:place("minecraft:bucket", -1, "down", false)
1047 end
1048 T:go("U1F10R1")
1049 T:place("minecraft:water_bucket", -1, "down", false)
1050 T:go("F2R1U1F2")
1051 for i = 1, 3 do
1052 T:place("minecraft:dirt", -1, "down", false)
1053 T:up(1)
1054 T:place("minecraft:sapling", -1, "down", false)
1055 T:forward(1)
1056 T:down(1)
1057 T:place("minecraft:torch", -1, "down", false)
1058 T:forward(1)
1059 end
1060 T:go("L1F3L1F2")
1061 for i = 1, 3 do
1062 T:place("minecraft:dirt", -1, "down", false)
1063 T:up(1)
1064 T:place("minecraft:sapling", -1, "down", false)
1065 T:forward(1)
1066 T:down(1)
1067 T:place("minecraft:torch", -1, "down", false)
1068 T:forward(1)
1069 end
1070 T:go("L1F4L1F7L1F1R1")
1071 T:place("minecraft:chest", -1, "forward", false)
1072 T:turnLeft(2)
1073end
1074
1075function createBridge(numBlocks)
1076 for i = 1, numBlocks do
1077 T:go("m1")
1078 end
1079 T:go("R1F1R1")
1080 for i = 1, numBlocks do
1081 T:go("m1")
1082 end
1083end
1084
1085function createCanal(choice, size, length)
1086 -- choice = 54/55: left/right side
1087 -- size = 0-1024 o = continuousheight = 0/1 0 = floor, 1 = wall
1088 -- T:place(blockType, damageNo, direction, leaveExisting)
1089 -- T:go(path, useTorch, torchInterval, leaveExisting)
1090 -- T:harvestTree(extend, craftChest, direction)
1091 -- start with forward run:
1092 local doContinue = true
1093 local numBlocks = 0
1094 local doTunnel = false
1095 local requestTunnel = false
1096 local maxLength = 1024
1097 if size ~= 0 then
1098 maxLength = size
1099 end
1100 local blockType, modifier
1101 -- if height = 0 then already at correct height on canal floor
1102 -- check block below, block to left and block above, move forward tunnelling
1103 -- if entering water then move up, onto canal wall and continue pathway
1104 -- if 55 and tunnelling then flood canal
1105 -- else height = 1 then above water and on path across
1106 -- move forward, checking for water below
1107 -- if water finishes, move into canal, drop down and continue tunnelling
1108 if choice == 54 then -- left side
1109 while doContinue and numBlocks < maxLength do
1110 if height == 0 then -- canal floor
1111 blockType, modifier = T:getBlockType("down")
1112 if blockType == nil or blockType == "minecraft:lava" then -- air or lava below, so place block
1113 T:place("minecraft:cobblestone", -1, "down", false)
1114 end
1115 -- place side block
1116 T:go("L1C1R1", false , 0, true, true)
1117 -- check above
1118 blockType, modifier = T:getBlockType("up")
1119 if blockType == "minecraft:log" or blockType == "minecraft:log2" then
1120 T:harvestTree(false, false, "up")
1121 elseif blockType == "minecraft:lava" or blockType == "minecraft:water" then
1122 T:up(1)
1123 T:place("minecraft:cobblestone", -1, "up", false)
1124 T:down(1)
1125 else --solid block or air above
1126 if blockType ~= nil then
1127 T:dig("up")
1128 end
1129 end
1130 -- check if block in front is water source
1131 blockType, modifier = T:getBlockType("forward")
1132 if blockType == "minecraft:water" and modifier == 0 then -- source block in front could be lake/ocean
1133 -- move up, to left and continue as height = 1
1134 T:go("U1L1F1R1")
1135 height = 1
1136 else
1137 T:forward(1, true)
1138 numBlocks = numBlocks + 1
1139 end
1140 else -- height = 1, on canal wall
1141 numBlocks = numBlocks + createPath(0, true)
1142 -- if path finished, then move back to canal floor and continue tunnelling
1143 T:go("R1F1D1L1")
1144 height = 0
1145 end
1146 end
1147 else -- right side
1148 -- assume left side already under construction
1149 local poolCreated = false
1150 while doContinue and numBlocks < maxLength do
1151 if height == 0 then-- canal floor
1152 -- create first infinity pool
1153 if not poolCreated then
1154 T:up(1)
1155 T:place("minecraft:water_bucket", -1, "down", false)
1156 T:go("L1F1R1")
1157 T:place("minecraft:water_bucket", -1, "down", false)
1158 T:forward(1)
1159 T:place("minecraft:water_bucket", -1, "down", false)
1160 T:back(1)
1161 -- refill buckets
1162 for j = 1, 3 do
1163 T:place("minecraft:bucket", -1, "down", false)
1164 sleep(0,5)
1165 end
1166 T:go("R1F1L1F2", false , 0, true, false)
1167 T:down(1)
1168 poolCreated = true
1169 end
1170 blockType, modifier = T:getBlockType("down")
1171 if blockType == nil or blockType == "minecraft:lava"
1172 or blockType == "minecraft:water" or blockType == "minecraft:flowing_water" then -- air, water or lava below, so place block
1173 T:place("minecraft:cobblestone", -1, "down", false)
1174 end
1175 -- place side block
1176 T:go("R1C1L1", false , 0, true, false)
1177 T:up(1)
1178 blockType, modifier = T:getBlockType("up")
1179 if blockType == "minecraft:log" or blockType == "minecraft:log2" then
1180 T:harvestTree(false, false, "up")
1181 elseif blockType == "minecraft:lava" or blockType == "minecraft:water" then
1182 T:place("minecraft:cobblestone", -1, "up", false)
1183 end
1184 T:place("minecraft:water_bucket", -1, "down", false)
1185 for j = 1, 2 do
1186 T:forward(1)
1187 blockType, modifier = T:getBlockType("up")
1188 if blockType == "minecraft:log" or blockType == "minecraft:log2" then
1189 T:harvestTree(false, false, "up")
1190 elseif blockType == "minecraft:lava" or blockType == "minecraft:water" then
1191 T:place("minecraft:cobblestone", -1, "up", false)
1192 end
1193 -- at ceiling level
1194 T:go("D1R1C1L1", false, 0, true, false)
1195 blockType, modifier = T:getBlockType("down")
1196 if blockType == nil or blockType == "minecraft:lava"
1197 or blockType == "minecraft:water" or blockType == "minecraft:flowing_water" then -- air, water or lava below, so place block
1198 T:place("minecraft:cobblestone", -1, "down", false)
1199 end
1200 -- check if block in front is water source
1201 blockType, modifier = T:getBlockType("forward")
1202 T:up(1)
1203 T:place("minecraft:water_bucket", -1, "down", false)
1204 if blockType == "minecraft:water" and modifier == 0 then -- source block in front could be lake/ocean
1205 -- move to right and continue as height = 1
1206 T:go("R1F1L1")
1207 height = 1
1208 break
1209 end
1210 end
1211 if height == 0 then
1212 T:back(2)
1213 for j = 1, 3 do
1214 T:place("minecraft:bucket", -1, "down", false)
1215 sleep(0,5)
1216 end
1217 T:go("F3D1", false, 0, true, false)
1218 end
1219 else -- height = 1: on wall
1220 numBlocks = numBlocks + createPath(0, true)
1221 -- if path finished, then move back to canal floor and continue tunnelling
1222 T:go("L1F1L1F1") -- facing backwards, collect water
1223 for j = 1, 3 do
1224 T:place("minecraft:bucket", -1, "down", false)
1225 sleep(0,5)
1226 end
1227 T:go("R2F1D1") --canal floor
1228 height = 0
1229 end
1230 end
1231 end
1232end
1233
1234function createMobSpawnerBase(pathLength)
1235 if pathLength > 0 then
1236 print("Building path to mob spawner base")
1237 createPath(pathLength)
1238 T:back(1)
1239 end
1240 T:place("minecraft:stone", -1, "down", true)
1241 T:go("R1F1L1")
1242 createPath(8)
1243 T:go("L1F1L1F1")
1244 createPath(8)
1245 T:go("R1F1R1F1")
1246 createPath(8)
1247 T:go("L1F1L1F1")
1248 createPath(8)
1249 T:go("L1F2L1F1")
1250end
1251
1252function createMobSpawnerTower(height)
1253 height = height or 2
1254 print("Building mob spawner base")
1255 -- assume placed at sea level on stone block (andesite / granite / diorite)
1256 --layers 2, 3 (layer 1 done at base construction)
1257 T:go("U1F7H2L1F1H2R1F2D1R2P1L1F1R1P1R2U1")
1258 for i = 1, 8 do
1259 T:go("C2R1C1L1F1")
1260 end
1261 T:go("L1F1L2C1R1F1R2C1R2")
1262 for i = 1, 8 do
1263 T:go("C2R1C1L1F1")
1264 end
1265 T:go("U1R2F8R1")
1266 T:place("minecraft:water_bucket", -1, "down", false)
1267 T:go("F1R1")
1268 T:place("minecraft:water_bucket", -1, "down", false)
1269 T:forward(16)
1270 T:go("R1F1D2")
1271 for i = 1, 2 do
1272 sleep(0.5)
1273 T:place("minecraft:bucket", -1, "down", false)
1274 end
1275 T:go("R1F2")
1276 for i = 1, 2 do
1277 T:go("C1R1C1R2C1R1U1")
1278 end
1279 -- height of tower
1280 height = math.ceil(height / 2)
1281 for i = 1, height do
1282 T:go("C1U1C1R1C1R1C1R1C1R1U1")
1283 end
1284 -- create platform for player
1285 T:go("R2F1L1C1R1C1R1C1U1C1L1C1L1C1L1F1L1C!R2C1L1U1F1")
1286 -- place stone marker
1287 T:place("minecraft:stone", -1, "down")
1288 -- will need to move back before completing
1289end
1290
1291function createMobSpawnerTank()
1292 --layer 1 of tower + walkway
1293 -- move back 1 block before continuing with tower top and walkway
1294 T:go("R2F1R2")
1295 T:go("C1U2R1F1L1") -- now dropping cobble from above
1296 T:go("m10L1F1L1")
1297 T:go("m9R1F1L1F1C2F1L1F1C2L1F1")
1298 --layer 2
1299 T:go("U1F1C2R1F1C2F1L1F1m8L1F3L1m8F2L1F1L1")
1300 --layer 3
1301 T:go("U1R1F1C2L1F1C2")
1302 T:go("F1R1F1L1C2F1C2F1L1F1C2")
1303 T:go("F1C2F1L1F1C2F1C2F2C2F1")
1304 T:go("L1F1C2L1F2C2B1")
1305 --layer 4
1306 T:go("U1F1L1F1R2")
1307 for i = 1, 4 do
1308 T:go("F1C2F1C2F1L1")
1309 end
1310 T:go("F1R1F1R2")
1311 --layer 5
1312 T:go("U1R2F1m7L1F1L1C2F1C2F7C2F1C2")
1313 T:go("F1R1F1L1C2F1C2F1L1F1C2F1C2F1")
1314 T:go("L1F1C2F1C2F2C2L1F1L1F1C2R2F1R2")
1315 -- layer 6
1316 T:go("U1R2F9C2L1F1C2F1L1F1C2F1L1F1C2R1F8L1F2R2")
1317 for i = 1, 4 do
1318 T:go("F1C2F1C2F1L1")
1319 end
1320 T:go("F1L1F1")
1321 T:place("minecraft:water_bucket", -1, "down")
1322 T:go("R1F1L1")
1323 T:place("minecraft:water_bucket", -1, "down")
1324 T:go("R2F2R1F1R1")
1325 -- layer 7
1326 T:go("U1R2F8L1F2C2L1F1L1F1C2R1F7C2L1F2R1C2F1R1")
1327 for i = 1, 4 do
1328 T:go("F1C2F1C2F1L1")
1329 end
1330 T:go("F1R1F1R2")
1331 T:go("F2")
1332 -- place stone inside column, ready for temp water source
1333 T:place("minecraft:stone", -1, "down", false)
1334
1335 -- layer 8
1336 -- make temp water source in centre. destroy in createMobSpawnerRoof()
1337 T:go("F1C2R1F1C2R1F1C2F1R1F2U1R2")
1338 -- spiral construction
1339 for j = 3, 9, 2 do
1340 for i = 1, 4 do
1341 if i < 4 then
1342 T:go("m"..j.."L1")
1343 else
1344 T:go("m"..j.."F1R1F1L2")
1345 end
1346 end
1347 end
1348 -- fill water source
1349 T:go("F5L1F5")
1350 T:place("minecraft:water_bucket", -1, "down", false)
1351 T:go("F1R1F1R1")
1352 T:place("minecraft:water_bucket", -1, "down", false)
1353 T:go("F5m4F2C2F1R1F1C2F1R1F1C2F1R1F1L1C2F1m4")
1354 T:go("F8F2m3R1F1R1m3")
1355 T:go("F5L1F5m3R1F1R1m3")
1356 T:go("F9F2m3R1F1R1m3")
1357 -- layer 9
1358 T:up(1)
1359 for i = 1, 4 do
1360 T:go("L1F1L1m3R1F1R1m3L1F1L1m3R1F1R1m3F4")
1361 T:go("L1F1L1m7R1F1R1m7L1F1L1m7R1F1R1m7F1L1F1R1C2F1C2R1F4")
1362 end
1363 -- now add water
1364 T:go("F6")
1365 for i = 1, 4 do
1366 T:down(1)
1367 T:place("minecraft:bucket", -1, "down", false)
1368 sleep(0.5)
1369 T:place("minecraft:bucket", -1, "down")
1370 T:go("U1F8R1")
1371 T:place("minecraft:water_bucket", -1, "down", false)
1372 T:go("F1R1")
1373 T:place("minecraft:water_bucket", -1, "down", false)
1374 T:go("F8L1")
1375 end
1376 for i = 1, 2 do
1377 T:down(1)
1378 T:place("minecraft:bucket", -1, "down", false)
1379 sleep(0.5)
1380 T:place("minecraft:bucket", -1, "down", false)
1381 T:go("U1F4L1F4L1")
1382 T:place("minecraft:water_bucket", -1, "down", false)
1383 T:go("F9")
1384 T:place("minecraft:water_bucket", -1, "down", false)
1385 T:go("L1F5L1F4L2")
1386 end
1387 T:go("F9R1F10R1")
1388 -- layer 10 / 11
1389 for j = 1, 2 do
1390 T:go("U1F1m8L1F1C2F1R1F1C2F1R1F1C2F1R1F1R2m8F1R1")
1391 for i = 1, 3 do
1392 T:go("F1m17F1R1")
1393 end
1394 end
1395 T:go("F10R1F9D4")
1396end
1397
1398function createMobSpawnerRoof()
1399 -- destroy water source first
1400 T:go("x2C1R1F1x2L1F1x2L1F1x2L1F1x2L2")
1401 T:go("U5L1F8L1F8L2") -- top left corner facing e
1402 T:go("m17R1m17R1m17R1m17") -- outer ring. ends facing n
1403 T:go("R1F2R1F1L1") -- facing e
1404 for i = 1, 4 do -- outer ring - 1 (with torches) ends facing e
1405 T:go("m6t1m3t1m5R1F1t1")
1406 end
1407 T:go("R1F1L1") -- facing e
1408 for i = 1, 4 do -- outer ring - 2 ends facing e
1409 T:go("m13R1m13R1m13R1m13")
1410 end
1411 T:go("R1F1L1") -- ends facing e
1412 T:go("m11R1m11R1m11R1m11") -- ends facing e
1413 T:go("R1F1R1F1L1F1")
1414 for i = 1, 4 do
1415 T:go("m8R1F1t1")
1416 end
1417 T:go("R1F1L1")
1418 T:go("m7R1m7R1m7R1m7")
1419 T:go("R1F1R1F1L1")
1420 T:go("m5R1m5R1m5R1m5")
1421 T:go("R1F1R1F1L1F1")
1422 for i = 1, 4 do
1423 T:go("m2R1F1t1")
1424 end
1425 T:go("R1F1L1")
1426 T:go("m1R1m1R1m1R1m1")
1427end
1428
1429function createPath(length, isCanal)
1430 length = length or 0 --allow for choice of path length
1431 if isCanal == nil then
1432 isCanal = false
1433 end
1434 local numBlocks = 1
1435 local path = 0
1436 local distance = 0
1437 local torch = 0
1438 local continue = true
1439 local slot = 0
1440 T:forward(1)
1441 local blockType, blockModifier = T:getBlockType("down")
1442 while blockType == "minecraft:water" or blockType == "minecraft:lava" or blockType == nil do
1443 continue = true
1444 if not T:place("minecraft:cobblestone", -1, "down") then
1445 if not T:place("minecraft:dirt", -1, "down") then
1446 if not T:place("minecraft:end_stone", -1, "down") then
1447 continue = false -- stop if out of cobble / dirt
1448 end
1449 end
1450 end
1451 if continue then
1452 T:forward(1)
1453 numBlocks = numBlocks + 1
1454 blockType, blockModifier = T:getBlockType("down")
1455 distance = distance + 1
1456 torch = torch + 1
1457 slot = T:getItemSlot("minecraft:torch", -1)
1458 if torch == 8 and slot > 0 then
1459 torch = 0
1460 T:turnRight(2)
1461 T:place("minecraft:torch", -1, "forward", false)
1462 T:turnRight(2)
1463 end
1464 else
1465 break
1466 end
1467 path = path + 1
1468 if length > 0 and path >= length then
1469 break
1470 end
1471 end
1472 if continue and not isCanal then
1473 T:forward(1)
1474 end
1475 return numBlocks
1476end
1477
1478function createLadder(destination, level)
1479 local height = 0
1480 local ledge = 0
1481 if destination == "surface" then
1482 T:go("C1U1C1")
1483 for j = level - 2, 1, -1 do
1484 T:up(1)
1485 for i = 1, 4 do
1486 if i ~= 3 then
1487 T:go("C1R1")
1488 else
1489 T:turnRight(1)
1490 end
1491 end
1492 height = height + 1
1493 end
1494 -- at level 64. check if still blocks above
1495 while turtle.inspectUp() do
1496 T:up(1)
1497 for i = 1, 4 do
1498 if i ~= 3 then
1499 T:go("C1R1")
1500 else
1501 T:turnRight(1)
1502 end
1503 end
1504 height = height + 1
1505 end
1506 -- nothing above
1507 T:go("U1R2F1L2") -- face wall previously built
1508 for i = height, 1, -1 do
1509 ledge = ledge + 1
1510 if ledge >= 3 then
1511 ledge = 0
1512 T:place("minecraft:cobblestone", 0, "up")
1513 end
1514 -- Place cobble on 3 sides (if required)
1515 for j = 1, 4 do
1516 if j == 1 then -- place ladder on first side
1517 T:place("minecraft:ladder", 0, "forward", false)
1518 else
1519 T:place("minecraft:cobblestone", 0, "forward")
1520 end
1521 T:turnLeft(1)
1522 end
1523 T:down(1)
1524 end
1525 else -- ladder to bedrock
1526 -- dig shaft to bedrock and close all sides except facing
1527 -- create a working area at the base
1528 -- Return to surface facing towards player placing ladders
1529 repeat
1530 height = height + 1
1531 for i = 1, 4 do
1532 if i ~= 1 then
1533 T:place("minecraft:cobblestone", 0, "forward")
1534 end
1535 T:turnRight(1)
1536 end
1537 local numBlocks, errorMsg = T:down(1)
1538 until numBlocks == 0
1539 -- test to check if on safe level immediately above tallest bedrock
1540 height = T:findBedrockTop(height)
1541 -- In shaft, facing start direction, on lowest safe level
1542 -- create a square space round shaft base, end facing original shaft, 1 space back
1543 -- place ladder on back of column for mining marker
1544 T:go("F1R1m1R1m2R1m2R1m2R1F1R1F1C1U1C1D1R2F1R2")
1545 T:go("R1F1L1F3L1F1R1F1C1R2")
1546 T:place("minecraft:ladder", 0, "forward")
1547 T:go("U1C0F1C0L1F1R1F3R1F1R1D1")
1548 ledge = 0
1549 --local atBedrock = true
1550 for i = height, 0, -1 do
1551 if ledge >= 3 then
1552 ledge = 0
1553 --T:go("R2F1C1R2F1")
1554 T:place("minecraft:cobblestone", 0, "down")
1555 elseif ledge == 1 then
1556 T:place("minecraft:torch", 0, "down")
1557 end
1558 -- Place cobble on 3 sides (if required)
1559 for j = 1, 4 do
1560 if j == 1 then -- place ladder on first side
1561 T:place("minecraft:ladder", 0, "forward", false)
1562 else
1563 T:place("minecraft:cobblestone", 0, "forward")
1564 end
1565 T:turnLeft(1)
1566 end
1567 T:up(1)
1568 ledge = ledge + 1
1569 end
1570 end
1571end
1572
1573function createMine()
1574 T:clear()
1575 T:go("m32U1R2M16", true, 8) -- mine ground level, go up, reverse and mine ceiling to mid-point
1576 T:go("U2D2") -- create space for chest
1577 T:place("minecraft:chest", -1, "up", false)
1578 T:emptyTrash("up")
1579 T:go("D1R1m16U1R2M16", true, 8) -- mine floor/ceiling of right side branch
1580 T:emptyTrash("up")
1581 T:go("D1m16U1R2M16", true, 8) -- mine floor/ceiling of left side branch
1582 T:emptyTrash("up")
1583 T:go("L1M15F1R1D1", true, 8) -- mine ceiling of entry coridoor, turn right
1584 T:go("F1x0F1x0n14R1n32R1n32R1n32R1n14F1x0F1U1", true, 8)-- mine floor of 36 x 36 square coridoor
1585 T:go("R1F16R2") --return to centre
1586 T:emptyTrash("up")
1587 T:go("F16R1") --return to entry shaft
1588 T:go("F2Q14R1Q32R1Q32R1Q32R1Q14F2R1", true, 8) --mine ceiling of 36x36 square coridoor. return to entry shaft + 1
1589 T:go("F16R2") --return to centre
1590 T:emptyTrash("up")
1591 -- get rid of any remaining torches
1592 while T:getItemSlot("minecraft:torch", -1) > 0 do
1593 turtle.select(T:getItemSlot("minecraft:torch", -1))
1594 turtle.dropUp()
1595 end
1596 T:go("F16R1F1R1") --return to shaft + 1
1597 for i = 1, 8 do
1598 T:go("N32L1F1L1", true)
1599 T:go("N16L1F"..(i * 2).."R2", true)
1600 T:emptyTrash("up")
1601 if i < 8 then
1602 T:go("F"..(i * 2).."L1N16R1F1R1", true)
1603 else
1604 T:go("F"..(i * 2).."L1N16L1", true)
1605 end
1606 end
1607 T:go("F17L1") -- close gap in wall, return to ladder + 1
1608 for i = 1, 8 do
1609 T:go("N32R1F1R1", true)
1610 T:go("N16R1F"..(i * 2).."R2", true)
1611 T:emptyTrash("up")
1612 if i < 8 then
1613 T:go("F"..(i * 2).."R1N16L1F1L1", true)
1614 else
1615 T:go("F"..(i * 2).."R1N16R1", true)
1616 end
1617 end
1618 T:go("F16R1")
1619 T:clear()
1620 print("Mining operation complete")
1621end
1622
1623function createMineBase()
1624 T:clear()
1625 -- check ladder:
1626 T:turnRight(2)
1627 local blockType, modifier = T:getBlockType("forward")
1628 while blockType == nil do
1629 T:forward(1)
1630 blockType, modifier = T:getBlockType("forward")
1631 end
1632 if blockType ~= "minecraft:ladder" then -- in correct position
1633 -- no ladder, move back 1
1634 T:back(1)
1635 end
1636 -- build pond:
1637 T:go("R1F1x0L1F1x0F1x0R1") -- at side wall
1638 T:go("F1n4R2n4U1R2Q4R2Q4R2") -- cut pond 3x1
1639 T:go("C2F4C2R2F1")
1640 T:place("minecraft:water_bucket", 0, "down", false)
1641 T:forward(2)
1642 T:place("minecraft:water_bucket", 0, "down", false)
1643 T:go("F2L1F2R1F1L1") -- at start position
1644 --[[
1645 T:go("m32U1R2M16D1", true, 8) -- mine ground level, go up, reverse and mine ceiling to mid-point, drop to ground
1646 T:go("U1R1A15D1R2m15", false, 0) -- Create roof of coridoor, turn and create lower wall + floor
1647 T:go("U1A15D1R2m15U1x0", false, 0) -- Create roof of coridoor, turn and create lower wall + floor
1648 T:place("minecraft:chest", -1, "up", false) --place chest in ceiling
1649 T:emptyTrash("up")
1650 T:go("L1M15F1R1D1", true, 8) -- mine ceiling of entry coridoor, turn right, drop down
1651 T:go("F2n14R1n15", true, 8)-- mine floor of first quarter of square
1652 T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
1653 T:go("F1x0n14R1n32R1n15", true, 8)
1654 T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
1655 T:go("F1x0n14R1n14F2", true, 8)-- mine floor of last quarter of square
1656
1657 T:go("U1R1F16R2D1") --return to centre
1658 T:emptyTrash("up")
1659 T:go("U1F16R1") --return to entry shaft
1660 T:go("F2Q14R1Q15", true, 8) -- mine ceiling of first quarter
1661 T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
1662 T:go("C0F1Q14R1Q32R1Q15", true, 8) --mine ceiling of second half
1663 T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
1664 T:go("C0F1Q14R1Q14F2R1", true, 8) -- mine ceiling of last quarter
1665 T:go("F16D1") --return to centre
1666 T:emptyTrash("up")
1667 -- get rid of any remaining torches
1668 while T:getItemSlot("minecraft:torch", -1) > 0 do
1669 turtle.select(T:getItemSlot("minecraft:torch", -1))
1670 turtle.dropUp()
1671 end
1672
1673 for i = 1, 8 do
1674 T:go("N32L1F1L1", true)
1675 T:go("N16L1F"..(i * 2).."R2", true)
1676 T:emptyTrash("up")
1677 T:go("F"..(i * 2).."L1N16R1F1R1", true)
1678 end
1679 T:go("L1F17L1") -- close gap in wall, return to ladder + 1
1680 for i = 1, 8 do
1681 T:go("N32R1F1R1", true)
1682 T:go("N16R1F"..(i * 2).."R2", true)
1683 T:emptyTrash("up")
1684 T:go("F"..(i * 2).."R1N16L1F1L1", true)
1685 end
1686 -- fill water buckets
1687 -- return to centre
1688 T:go("R1F16R1")]]
1689
1690 T:clear()
1691 print("Mining operation complete")
1692end
1693
1694function createMineEnhanced()
1695 T:clear()
1696 T:go("m32U1R2M16D1x2", true, 8) -- mine ground level, go up, reverse and mine ceiling to mid-point, drop to ground, excavate
1697 T:emptyTrash("down")
1698 T:go("U1R1A15D1R2E13m2x2", false, 0) -- Create roof of coridoor, turn and create lower wall + remove floor
1699 T:emptyTrash("down")
1700 T:go("U1A15D1R2E13m2x2", false, 0) -- Create roof of coridoor, turn and create lower wall + remove floor
1701 T:emptyTrash("down")
1702 T:go("U1L1M15F1R1D1", true, 8) -- mine ceiling of entry coridoor, turn right, drop down
1703 T:go("F2n14R1n15", true, 8)-- mine floor of first quarter of square
1704
1705 T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
1706 T:go("F1x0n14R1n32R1n15", true, 8)
1707 T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
1708 T:go("F1x0n14R1n14F2", true, 8)-- mine floor of last quarter of square
1709 T:go("U1R1F16R2D1") --return to centre
1710 T:emptyTrash("down")
1711 T:go("U1F16R1") --return to entry shaft
1712 T:go("F2Q14R1Q15", true, 8) -- mine ceiling of first quarter
1713 T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
1714 T:go("C0F1Q14R1Q32R1Q15", true, 8) --mine ceiling of second half
1715 T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
1716 T:go("C0F1Q14R1Q14F2R1", true, 8) -- mine ceiling of last quarter
1717 T:go("F16D1") --return to centre
1718 T:emptyTrash("down")
1719 -- get rid of any remaining torches
1720 while T:getItemSlot("minecraft:torch", -1) > 0 do
1721 turtle.select(T:getItemSlot("minecraft:torch", -1))
1722 turtle.dropDown()
1723 end
1724 --cut access coridoors
1725 T:go("U1F2R1F1Q14F1 R1F1L1F1R1F2R1F1L1F1R1 F1Q14F2Q14F1 R1F1L1F1R1F2R1F1L1F1R1F1 Q14F1D1") --ceiling
1726 T:go("F1n14F1 R1F1L1F1R1F2R1F1L1F1R1 F1n14F2n14F1 R1F1L1F1R1F2R1F1L1F1R1F1 n14F1U1") --floor, then up
1727 T:go("R1F2D1")
1728 T:go("R1F1C1B1C1L1C1L1F1C1B1C1L1C1L2")
1729 T:emptyTrash("down")
1730 T:go("U1F16R1F1R1") --return to entry shaft + 1
1731
1732 for i = 1, 8 do
1733 T:go("N32L1F1L1", true)
1734 if i == 1 then
1735 T:go("N16L1F2R2", true)
1736 T:emptyTrash("down")
1737 T:go("F2L1N16R1F1R1", true)
1738 elseif i == 8 then
1739 T:go("L1F1R1N16", true)
1740 T:emptyTrash("down")
1741 T:go("N16R1F1R1", true)
1742 else
1743 T:go("N16", true)
1744 T:emptyTrash("down")
1745 T:go("N16R1F1R1", true)
1746 end
1747 end
1748 T:go("L1F16L1") -- return to shaft + 1
1749 for i = 1, 8 do
1750 T:go("N32R1F1R1", true)
1751 if i == 1 then
1752 T:go("N16R1F2R2", true)
1753 T:emptyTrash("down")
1754 T:go("F2R1N16L1F1L1", true)
1755 elseif i == 8 then
1756 T:go("R1F1L1N16", true)
1757 T:emptyTrash("down")
1758 T:go("N16R1F1R1", true)
1759 else
1760 T:go("N16", true)
1761 T:emptyTrash("down")
1762 T:go("N16L1F1L1", true)
1763 end
1764 end
1765 T:go("L1F15R1") -- return
1766 T:clear()
1767 print("Mining operation complete")
1768end
1769
1770function createRailwayDown(userChoice, drop)
1771 --make sure torch placed on lowest level
1772 -- 1 block not required
1773 -- 2 - 3 blocks 1 torch at base
1774 -- 4 - 6 blocks 2 torch
1775 --
1776 for i = 1, drop - 1 do
1777 T:go("F1D1")
1778 T:place(userChoice, -1, "down", false)
1779 end
1780end
1781
1782function createRailwayUp(userChoice, up)
1783 for i = 1, up do
1784 T:place(userChoice, -1, "forward", false)
1785 T:go("U1F1")
1786 end
1787end
1788
1789function createStaircase(destination, level)
1790 -- R# L# F# B# U# D# +0 -0 = Right, Left, Forward, Back, Up, Down, up while detect and return, down while not detect
1791 -- dig: x0,x1,x2 (up/fwd/down)
1792 -- suck: s0,s1,s2
1793 -- place chest: H0,H1,H2
1794 -- place sapling: S0,S1,S2
1795 -- place Torch: T0,T1,T2
1796 -- place Hopper: P0,P1,P2
1797 -- mine floor: m# = mine # blocks above and below, checking for valuable items below, and filling space with cobble or dirt
1798 -- mine ceiling: M# = mine # blocks, checking for valuable items above, and filling space with cobble or dirt
1799 -- mine ceiling: N# same as M but not mining block below unless valuable
1800 -- 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
1801
1802 -- 3| |B| |
1803 -- - - -
1804 -- 2|A| |C|
1805 -- - - -
1806 -- 1|^|D| |
1807 -- - - -
1808 -- 1 2 3
1809
1810 local height = level -- eg 64 at top or 5 at bedrock
1811 local numStairs = T:getItemCount("minecraft:stone_stairs", 0)
1812 local numStairsNeeded = 0
1813 if destination == "bedrock" then
1814 numStairsNeeded = math.ceil(level / 4) * 4
1815 else
1816 numStairsNeeded = math.ceil((64 - level) / 4) * 4
1817 end
1818 numStairsNeeded = numStairsNeeded - numStairs
1819 if numStairsNeeded > 40 then
1820 T:craft("minecraft:stone_stairs", 40) -- max 40 so repeat
1821 numStairsNeeded = numStairsNeeded - 40
1822 end
1823 if numStairsNeeded > 0 then
1824 T:craft("minecraft:stone_stairs", numStairsNeeded)
1825 end
1826 if destination == "bedrock" then -- go down to bedrock
1827 while T:down() do
1828 height = height - 1
1829 end
1830 height = T:findBedrockTop(height) -- usually around 5
1831 T:go("R1F1R1")
1832 end
1833 local onGround = true
1834 local top = (math.ceil((64 - height) / 4) * 4) + 4
1835
1836 for i = height, top, 4 do
1837 for x = 1, 4 do
1838 -- start 1,1,1, n
1839 -- stage A
1840 T:go("L1C1R1F1L1C1R1C1R1C1L1B1^1") --start:1,1,1,n stairs A on level 1, going back to 1,1,1,n
1841 if not onGround then
1842 -- stage A1
1843 T:go("L2C1L2") -- start 1,1,1,n fix corner on level 1 end: 1,1,1,n
1844 end
1845 -- stage B
1846 T:go("U1L1C1") -- end 1,1,1,w layer 2
1847 if not onGround then
1848 T:go("L1C1R1") -- end 1,1,1,w layer 2
1849 end
1850 -- stage C1
1851 T:go("R1F1L1C1R2C1L1B1")
1852 -- stage C2
1853 T:go("U1L1C1L1C1L2F1L1C1R2C1L1B1D1") -- end 1,1,2,n
1854 onGround = false
1855 -- stage D
1856 T:go("F2L1C1R1C1R1") -- 3,1,2,e
1857 end
1858 end
1859end
1860
1861function createTreefarm(size)
1862 local blockType
1863 local blockModifier
1864 local length
1865 local width
1866
1867 if size == 1 then
1868 length = 11
1869 width = 6
1870 clearArea(11, 11)
1871 else
1872 length = 19
1873 width = 10
1874 clearArea(19, 19)
1875 end
1876 -- now place dirt blocks and torches
1877 T:go("F2R1F2L1U1")
1878 for x = 1, (width - 2) / 2 do
1879 for y = 1, (length - 3) / 2 do
1880 T:place("minecraft:dirt", -1, "down", false)
1881 if y < (length - 3) / 2 then
1882 T:forward(1)
1883 T:place("minecraft:torch", -1, "down", false)
1884 T:forward(1)
1885 end
1886 end
1887 T:go("R1F2R1")
1888 for y = 1, (length - 3) / 2 do
1889 T:place("minecraft:dirt", -1, "down", false)
1890 if y < (length - 3) / 2 then
1891 T:forward(1)
1892 T:place("minecraft:torch", -1, "down", false)
1893 T:forward(1)
1894 end
1895 end
1896 if x < (width - 2) / 2 then
1897 T:go("L1F2L1")
1898 else
1899 T:go("R1F6")
1900 if size == 2 then
1901 T:go("F8")
1902 end
1903 T:go("R1B1")
1904 end
1905 end
1906end
1907
1908function createWalkway(length)
1909 local lengthParts = math.floor(length / 8) -- eg 12/8 = 1
1910 local lastPart = length - (lengthParts * 8) -- eg 12 - (1 * 8) = 4
1911 T:up(1)
1912 for j = 1, lengthParts do
1913 T:go("M8")
1914 end
1915 if lastPart > 0 then
1916 T:go("M"..tostring(lastPart)) -- eg m4
1917 end
1918 T:go("R2D1")
1919 T:place("minecraft:torch", 0, "up", false)
1920 for j = 1, lengthParts do
1921 T:go("m8", true)
1922 T:place("minecraft:torch", 0, "up", false)
1923 end
1924 if lastPart > 0 then
1925 T:go("m"..tostring(lastPart), true) -- eg m4
1926 end
1927 T:go("R2")
1928end
1929
1930function createWaterSource()
1931 T:go("F1D1") --move to corner and drop down
1932 for i = 1, 4 do
1933 T:go("L1C1L1C1L2C2F1R1")
1934 end
1935 T:go("U1")
1936 for i = 1, 2 do
1937 T:place("minecraft:water_bucket", -1, "down", false)
1938 T:go("F1R1F1R1")
1939 end
1940 -- refill water buckets
1941 for i = 1, 2 do
1942 sleep(0.5)
1943 T:place("minecraft:bucket", -1, "down", false)
1944 end
1945 -- end facing towards farm above lower left pond
1946end
1947
1948function createWheatFarm(clearFirst, width, height)
1949 width = width or 11
1950 height = height or 14
1951 if clearFirst then
1952 clearArea(width, height)
1953 while turtle.down() do end
1954 end
1955 createWaterSource()
1956 -- place chest and hopper
1957 T:go("F3L1F1R2D1x2")
1958 T:place("minecraft:chest", -1, "down", false)
1959 T:go("F1D1F1R2")
1960 T:place("minecraft:hopper", -1, "forward", false)
1961 -- dig trench and ensure base is solid
1962 T:go("U1p2R2m7U1R2")
1963 T:place("minecraft:water_bucket", -1, "down", false) -- collection stream
1964 T:go("R2F1U1R1m1R1m9R1m9m1R1F1D2")
1965 T:go("m7U1R2") -- dig trench and ensure base is solid
1966 T:place("minecraft:water_bucket", -1, "down", false) -- watering stream
1967 T:go("U1B1m9R2F9R1m9F1R1F9L1F3R2D1") -- back to start
1968end
1969
1970function decapitateBuilding(width, length)
1971 --clearRectangle with sand drop
1972 -- could be 1 wide x xx lenght (trench) up and return
1973 -- could be 2+ x 2+
1974 -- even no of runs return after last run
1975 -- odd no of runs forward, back, forward, reverse and return
1976 local success
1977 local directReturn = true
1978 if width % 2 == 1 then
1979 directReturn = false
1980 end
1981 if width == 1 then -- trench ahead, so fill then return
1982 for i = 1, length - 1 do
1983 success = dropSand()
1984 T:forward(1, false)
1985 end
1986 success = dropSand()
1987 T:go("R2F"..(length - 1).."R2")
1988 else --2 or more columns
1989 if directReturn then -- width = 2,4,6,8 etc
1990 for i = 1, width, 2 do -- i = 1,3,5,7 etc
1991 -- move along length, dropping sand
1992 for j = 1, length - 1 do
1993 success = dropSand()
1994 T:forward(1, false)
1995 end
1996 success = dropSand()
1997 T:go("R1F1R1") --turn right and return on next column
1998 for j = 1, length - 1 do
1999 success = dropSand()
2000 T:forward(1, false)
2001 end
2002 success = dropSand()
2003 if i < width - 2 then -- eg width = 8, i compares with 6: 1, 3, 5, 7
2004 T:go("L1F1L1")
2005 end
2006 end
2007 T:go("R1F"..width - 1 .."R1") --return home
2008 else
2009 for i = 1, width, 2 do -- i = 1,3,5,7 etc
2010 -- move along length, dropping sand
2011 for j = 1, length - 1 do
2012 success = dropSand()
2013 T:forward(1, false)
2014 end
2015 success = dropSand()
2016 T:go("R1F1R1") --turn right and return on next column
2017 for j = 1, length - 1 do
2018 success = dropSand()
2019 T:forward(1, false)
2020 end
2021 success = dropSand()
2022 T:go("L1F1L1")
2023 end
2024 -- one more run then return
2025 for j = 1, length - 1 do
2026 success = dropSand()
2027 T:forward(1, false)
2028 end
2029 success = dropSand()
2030 T:go("R2F"..length.."R1F"..width - 1 .."R1")
2031 end
2032 end
2033end
2034
2035function demolishBuilding(width, length)
2036 -- start bottom left
2037 clearBuilding(width, length, 0, false)
2038end
2039
2040function demolishPortal()
2041 if T:getBlockType("forward") == "minecraft:obsidian" then
2042 T:down(1)
2043 end
2044 T:go("x1U1x1U1x1U1x1U1x1")
2045 for i = 1, 3 do
2046 T:go("R1F1L1x1")
2047 end
2048 T:go("D1x1D1x1D1x1D1x1")
2049 T:go("L1F1R1x1L1F1R1x1")
2050end
2051
2052function dropSand()
2053 local success, slot
2054 while not turtle.detectDown() do -- over water. will be infinite loop if out of sand
2055 success, slot = T:place("minecraft:sand", -1, "down", false)
2056 if not success then
2057 print("Out of sand. Add more to continue...")
2058 sleep(2)
2059 end
2060 end
2061 return true --will only get to this point if turtle.detectDown() = true
2062end
2063
2064function getDecision(choice)
2065 local decision = read()
2066 local retValue = 0
2067 if decision == "" or decision == "y" then -- allow for enter only
2068 retValue = choice
2069 end
2070 return tonumber(retValue)
2071end
2072
2073function getSize(clear, prompt, lowerLimit, upperLimit)
2074 local retValue = -1
2075 while tonumber(retValue) < lowerLimit or tonumber(retValue) > upperLimit do
2076 if clear then
2077 T:clear()
2078 end
2079 term.write(prompt)
2080 --io.write(prompt.."_")
2081 retValue = read()
2082 if tonumber(retValue) == nil then
2083 retValue = 0
2084 end
2085 end
2086 return tonumber(retValue)
2087end
2088
2089function getTask()
2090 local choice = nil
2091 local mainChoice = nil
2092 local size = 4
2093 local width = 0
2094 local length = 0
2095 local height = 0
2096 --local menuOffset = 0 -- added to user choice
2097 local options = ""
2098 local prompt = "Choose your option:"
2099 local options = {}
2100 while choice == nil do
2101 options = { "Mining tools",
2102 "Tree management tools",
2103 "Land management and farming tools",
2104 "Obsidian and nether portal tools",
2105 "Canal, bridge and walkway tools",
2106 "Mob farm creation tools",
2107 "Area carving tools",
2108 "Lava and Water tools",
2109 "Railway tools"}
2110 -- main menu choice
2111 mainChoice = menu.new(prompt, options)
2112 if mainChoice == nil then
2113 break
2114 elseif mainChoice == 1 then
2115 options = { "Ladder to bedrock",
2116 "Create mine at this level",
2117 "Ladder to the surface",
2118 "Stairs to bedrock",
2119 "Stairs to the surface",
2120 "Search for Mob Spawner",
2121 "Decapitate volcano",
2122 "Experimental mine level 5"}
2123 elseif mainChoice == 2 then
2124 options = { "Clear Field",
2125 "Create tree farm",
2126 "Plant tree farm",
2127 "Harvest tree farm",
2128 "Fell Tree",
2129 "Manage Auto-treeFarm"}
2130 elseif mainChoice == 3 then
2131 options = { "Clear Field",
2132 "Create 8x8 wheat farm",
2133 "Plant 8x8 wheat farm",
2134 "Harvest 8x8 wheat farm"}
2135 elseif mainChoice == 4 then
2136 options = { "Dig obsidian patch\n",
2137 "Build Nether Portal\n",
2138 "Demolish Nether Portal"}
2139 elseif mainChoice == 5 then
2140 options = { "Bridge over space or water",
2141 "Covered walkway",
2142 "Continuous single path",
2143 "Left side canal (dry passageway)",
2144 "Right side canal (flooded passage)"}
2145 elseif mainChoice == 6 then
2146 options = { "Spawner base & ocean path",
2147 "Create mob spawner tower",
2148 "Create mob spawner chamber",
2149 "Create mob spawner roof"}
2150 elseif mainChoice == 7 then
2151 options = { "Clear a rectangle",
2152 "Clear single wall",
2153 "Clear rectangular wall section",
2154 "Clear building floor and walls",
2155 "Clear building floor/walls/ceiling",
2156 "Hollow structure top->down",
2157 "Solid structure top->down",
2158 "Hollow structure bottom->up",
2159 "Solid structure bottom->up"}
2160 elseif mainChoice == 8 then
2161 options = { "Vertical wall from surface",
2162 "Drop sand or gravel wall",
2163 "Decapitate and fill with sand",
2164 "Clear sand wall",
2165 "Clear sand filled building",
2166 "Demolish sand filled structure",
2167 "Hollow structure top->down",
2168 "Solid structure top->down"}
2169 elseif mainChoice == 9 then
2170 options = { "Place Redstone:torch level track",
2171 "Place Redstone:torch upward track",
2172 "Build downward track",
2173 "Build upward track"}
2174 end
2175 choice = menu.new(prompt, options)
2176 if choice ~= nil then
2177 choice = choice + (mainChoice * 10)
2178 end
2179 end
2180 T:clear()
2181 local instructions = "Enter to continue\nany other key to quit"
2182 if choice == nil then
2183 print("You chose quit from the main menu")
2184 elseif choice == 11 then -- Ladder to bedrock
2185 print( "Place me on the ground\n"..
2186 "The ladder will start at this level\n"..
2187 "and drop to bedrock\n\n"..
2188 instructions)
2189 choice = getDecision(choice)
2190 elseif choice == 12 then --Create Mine at this level
2191 print( "Press F3 to check level. Look for 'Y'\n"..
2192 "Place me at level 5 (bedrock layer)\n"..
2193 "(Equivalent to eye level 6)\n\n"..
2194 instructions)
2195 choice = getDecision(choice)
2196 elseif choice == 13 then -- Ladder to surface
2197 print( "Place me on the ground\n"..
2198 "The ladder will start at this level\n"..
2199 "and rise to the surface\n\n"..
2200 instructions)
2201 choice = getDecision(choice)
2202 elseif choice == 14 then -- Stairs to bedrock
2203 print( "Place me on the ground\n"..
2204 "The stairs will start at this level\n"..
2205 "and drop to bedrock in a 5x5 block\n\n"..
2206 instructions)
2207 choice = getDecision(choice)
2208 elseif choice == 15 then -- Stairs to surface
2209 print( "Place me on the ground\n"..
2210 "The stairs will start at this level\n"..
2211 "and rise to level 64 in a 5x5 block\n\n"..
2212 instructions)
2213 choice = getDecision(choice)
2214 elseif choice == 16 then -- Search for mob spawner
2215 print( "Place me anywhere on the ground\n"..
2216 "When a spawner is found the\n"..
2217 "coordinates are saved to file\n\n"..
2218 instructions)
2219 choice = getDecision(choice)
2220 elseif choice == 17 then -- Decapitate volcano
2221 print( "Place me on a basalt block\n"..
2222 "on the left side of a volcano\n")
2223 width = getSize(false, "Volcano width at this level\n", 1, 64)
2224 length = getSize(false, "Volcano length at this level\n", 1, 64)
2225 elseif choice == 18 then --Create experimental Mine at level 5
2226 print( "Press F3 to check level. Look for 'Y'\n"..
2227 "Place me down at level 9 or above\n\n"..
2228 instructions)
2229 choice = getDecision(choice)
2230 elseif choice == 21 or choice == 31 then --Clear field
2231 print( "Place me on grass, lower left corner\n"..
2232 "of the area\n"..
2233 "To be levelled and cleared\n\n"..
2234 "Provide Dirt to plug voids in the floor\n")
2235 width = getSize(false, "Width of the area (1-64)\n", 1, 64)
2236 length = getSize(false, "Length of the area (1-64)\n", 1, 64)
2237 elseif choice == 22 then --Create treefarm
2238 print( "Place me on grass, lower left corner\n"..
2239 "of a 11x11 OR 19x19 square\n"..
2240 "Trees to be grown on alternate blocks\n"..
2241 "in a square 4x4 or 8x8 trees\n"..
2242 "with a 2 block wide margin\n"..
2243 instructions)
2244 choice = getDecision(choice)
2245 if choice > 0 then
2246 options = {"4 x 4 trees(16)","8 x 8 trees(64)"}
2247 size = menu.new(prompt, options)
2248 end
2249 elseif choice == 23 then --Replant treefarm
2250 print("Place me in front of first tree base\n"..
2251 "or dirt on the lower left corner\n"..
2252 "of a 4x4 trees OR 8x8 trees square\n\n"..
2253 "Provide Birch and Oak Saplings for a\n"..
2254 "mixed tree farm\n\n"..
2255 instructions)
2256 choice = getDecision(choice)
2257 if choice > 0 then
2258 options = {"4 x 4 trees(16)","8 x 8 trees(64)"}
2259 size = menu.new(prompt, options)
2260 end
2261 elseif choice == 24 then -- Harvest treefarm
2262 print( "Place me in front of first tree\n"..
2263 "on the lower left corner\n"..
2264 "of a 4x4 trees OR 8x8 trees square\n\n"..
2265 "Fuel not required as logs will be used.\n\n"..
2266 instructions)
2267 choice = getDecision(choice)
2268 if choice > 0 then
2269 options = {"4 x 4 trees(16)","8 x 8 trees(64)"}
2270 size = menu.new(prompt, options)
2271 end
2272 elseif choice == 25 then -- Fell Tree
2273 print( "Place me in front of the tree\n"..
2274 "you want to fell\n\n"..
2275 "Fuel not required as logs will be used.\n\n"..
2276 instructions)
2277 choice = getDecision(choice)
2278 elseif choice == 26 then -- Manage Auto-TreeFarm
2279 print( "For a new Auto-TreeFarm:\n"..
2280 "Place me on left side of a 13x10 area\n\n"..
2281 "For an existing farm:\n"..
2282 "Place me in front of sapling\n"..
2283 "or tree with the chest behind me\n\n"..
2284 instructions)
2285 choice = getDecision(choice)
2286 elseif choice == 32 then -- Create 8x8 wheat field farm
2287 print( "Place me on left side of a cleared area\n"..
2288 "or rough land if you want to use\n"..
2289 "the option to clear the field first\n\n"..
2290 instructions)
2291 choice = getDecision(choice)
2292 elseif choice == 33 then -- Plant 8x8 wheat field
2293 print( "Place me in front of the 2x2 pond\n"..
2294 "on the left side facing the\n"..
2295 "corner of the farm wall\n\n"..
2296 instructions)
2297 choice = getDecision(choice)
2298 elseif choice == 34 then -- Harvest 8x8 wheat field
2299 print( "Place me in front of the 2x2 pond\n"..
2300 "on the left side facing the\n"..
2301 "corner of the farm wall\n\n"..
2302 instructions)
2303 choice = getDecision(choice)
2304 elseif choice == 41 then -- Harvest obsidian
2305 print( "Place me on any block\n"..
2306 "on the left side facing the\n"..
2307 "obsidian patch.\n")
2308 width = getSize(false, "Width of the area (1-64)\n", 1, 64)
2309 length = getSize(false, "Length of the area (1-64)\n", 1, 64)
2310 elseif choice == 42 then -- build Nether portal
2311 print( "Place me on the ground\n"..
2312 "on the left side\n"..
2313 " of the portal base\n\n"..
2314 instructions)
2315 choice = getDecision(choice)
2316 elseif choice == 43 then -- demolish Nether portal
2317 print( "Place me on the ground\n"..
2318 "on the left side\n"..
2319 " of the portal base\n\n"..
2320 instructions)
2321 choice = getDecision(choice)
2322 elseif choice == 51 then --Bridge over void/water/lava
2323 print( "Place me on the ground\n"..
2324 "The bridge will start in front,\n"..
2325 "continue for your chosen length\n"..
2326 "and return\n")
2327 size = getSize(false, "Length of the area (1-32)\n", 1, 32)
2328 elseif choice == 52 then --Covered walkway
2329 print( "Place me on the ground\n"..
2330 "The covered walkway will start in front,\n"..
2331 "continue for your chosen length\n"..
2332 "and return\n")
2333 size = getSize(false, "Length of the walk (1-32)\n", 1, 32)
2334 elseif choice == 53 then --single path
2335 print( "Place me on the ground in front\n"..
2336 "of water, lava or air.\n"..
2337 "Follow and supply blocks for a path\n\n"..
2338 instructions)
2339 choice = getDecision(choice)
2340 elseif choice == 54 or choice == 55 then --left/right side of new/existing canal
2341 local side = "left"
2342 if choice == 55 then
2343 side = "right"
2344 end
2345 print( "I should be on either an existing canal\n"..
2346 "on the "..side.." side\n"..
2347 "or ready to start a new canal\n\n"..
2348 "If crossing water I should be on top\n"..
2349 "of a solid block making up the "..side.." wall\n")
2350 size = getSize(false, "Canal length? 0 = continuous\n", 0, 1024)
2351 length = getSize(false, "Am I on the floor(0) or wall(1)?\n", 0, 1)
2352 elseif choice == 61 then -- Path to ocean base
2353 print( "Place me on the ground in front\n"..
2354 "of the ocean.\n"..
2355 "Follow me as I create a path\n")
2356 size = getSize(false, "Path length (0-128)?\n", 0, 128)
2357 elseif choice == 62 then -- Ocean base complete. Place on polished block to start
2358 print( "Place me on the stone block\n"..
2359 "(granite / andesite / diorite)\n"..
2360 "in the ocean base.\n"..
2361 "Facing the sea\n")
2362 size = getSize(false, "Tower Height (32-128)?\n", 32, 128)
2363 elseif choice == 63 then -- Mob tower complete Place on polished block to start
2364 print( "Place me on the stone block\n"..
2365 "(granite / andesite / diorite)\n"..
2366 "at the top of the tower.\n"..
2367 "Facing the sea\n\n"..
2368 instructions)
2369 choice = getDecision(choice)
2370 elseif choice == 64 then -- Mob tower roof Place on polished block to start
2371 print( "Place me on the stone block\n"..
2372 "(granite / andesite / diorite)\n"..
2373 "at the top of the tower.\n"..
2374 "Facing the sea\n\n"..
2375 instructions)
2376 choice = getDecision(choice)
2377 elseif choice == 71 then -- Clear rectangle width, length
2378 print( "Place me inside the lower left corner\n"..
2379 "of the rectangle to be cleared.\n"..
2380 "At the level to be worked on\n"..
2381 "I will include this corner in\n"..
2382 "the area to be cleared\n")
2383 width = getSize(false, "Width of the area (1-256)\n", 1, 256)
2384 length = getSize(false, "Length of the area (1-256)\n", 1, 256)
2385 elseif choice == 72 then -- Clear wall height, length
2386 print( "Place me inside the lower corner\n"..
2387 "of the wall to be cleared.\n")
2388 width = 1
2389 length = getSize(false, "Length of wall (1-256)\n", 1, 256)
2390 height = getSize(false, "Height of wall (1-50)\n", 1, 50)
2391 elseif choice == 73 then -- Clear rectangle perimeter only width, length
2392 print( "Place me inside the left corner\n"..
2393 "of the rectangular wall to be cleared.\n"..
2394 "At the level to be worked on\n"..
2395 "I will include this corner in\n"..
2396 "the area to be cleared\n")
2397 width = getSize(false, "Width of walled area (1-256)\n", 1, 256)
2398 length = getSize(false, "Length of walled area (1-256)\n", 1, 256)
2399 height = 1
2400 elseif choice == 74 then -- Clear building floor/walls
2401 print( "Place me inside the left corner\n"..
2402 "in the floor of the building to be recycled.\n"..
2403 "At the level to be worked on\n"..
2404 "I will include this corner in\n"..
2405 "the area to be cleared\n")
2406 width = getSize(false, "Ext. building width (1-256)\n", 1, 256)
2407 length = getSize(false, "Ext. building length (1-256)\n", 1, 256)
2408 height = getSize(false, "Ext. building height (1-256)\n", 1, 256)
2409 elseif choice == 75 then -- Clear building floor/walls/ceiling
2410 print( "Place me inside the lower left corner\n"..
2411 "in the floor of the building to be recycled.\n"..
2412 "At the level to be worked on\n"..
2413 "I will include this corner in\n"..
2414 "the area to be cleared\n")
2415 width = getSize(false, "Ext. building width (1-256)\n", 1, 256)
2416 length = getSize(false, "Ext. building length (1-256)\n", 1, 256)
2417 height = getSize(false, "Ext. building height (1-256)\n", 1, 256)
2418 elseif choice == 76 or choice == 87 then -- Hollow structure top down
2419 print( "Place me inside the left corner\n"..
2420 "of the top of the hollow.\n")
2421 width = getSize(false, "Hollow section width (1-60)\n", 1, 60)
2422 length = getSize(false, "Hollow section length (1-60)\n", 1, 60)
2423 height = getSize(false, "Hollow section height (1-64)\n", 1, 64)
2424 elseif choice == 77 or choice == 88 then -- solid structure top down
2425 print( "Place me inside the left corner\n"..
2426 "of the top of the cube.\n")
2427 width = getSize(false, "Solid section width (1-60)\n", 1, 60)
2428 length = getSize(false, "Solid section length (1-60)\n", 1, 60)
2429 height = getSize(false, "Solid section height (1-64)\n", 1, 64)
2430 elseif choice == 78 or choice == 79 then -- remove hollow/solid structure bottom up
2431 print( "Place me inside the left corner\n"..
2432 "of the bottom of the structure.\n")
2433 width = getSize(false, "Structure width (1-60)\n", 1, 60)
2434 length = getSize(false, "Structure length (1-60)\n", 1, 60)
2435 height = getSize(false, "Structure height (1-64, 0=top)\n", 0, 64)
2436 elseif choice == 81 then -- build wall from water or lava surface downwards
2437 print( "Place me on the surface facing wall END\n"..
2438 "(Any block below will be removed)\n"..
2439 "Wall will be built DOWN and BACKWARDS\n")
2440 width = 1
2441 length = getSize(false, "Length of the wall (1-60)\n", 1, 60)
2442 height = getSize(false, "Estimated depth (1-60) 0=default\n", 0, 60)
2443 elseif choice == 82 then -- drop sand into water or lava surface until solid grond reached
2444 print( "Place me on the surface of water or lava\n"..
2445 "Sand will be dropped DOWN and Forwards\n")
2446 width = 1
2447 length = getSize(false, "Length of dam (0=to solid block)\n", 0, 60)
2448 elseif choice == 83 then -- clear rectangle on top of building and fill with sand
2449 print( "Place me on top left corner of roof\n"..
2450 "Sand will be dropped into the hollow\n")
2451 width = getSize(false, "Width of roof (<=30)\n", 1, 30)
2452 length = getSize(false, "Length of of roof (<=30)\n", 1, 30)
2453 elseif choice == 84 then -- clear sand wall or harvest sand
2454 print( "Place me on the surface of sand\n"..
2455 "Sand will be mined DOWN then forwards\n")
2456 width = 1
2457 length = getSize(false, "Length of sand \n", 1, 250)
2458 elseif choice == 85 then -- remove sand from cube. start at top
2459 print( "Place me on top left corner of sand\n"..
2460 "Sand cleared down, then left to right\n")
2461 width = getSize(false, "Width of sand (<=30)\n", 1, 30)
2462 length = getSize(false, "Length of of sand (<=30)\n", 1, 30)
2463 elseif choice == 86 then -- remove floor, walls (and sand) from building. start at base
2464 print( "Place me on lower left corner of floor\n"..
2465 "Floor + walls removed + sand cleared\n")
2466 width = getSize(false, "Width of floor (<=30)\n", 1, 30)
2467 length = getSize(false, "Length of of floor (<=30)\n", 1, 30)
2468 -- elseif choice == 87 then check 76 above
2469 -- elseif choice == 88 then check 77 above
2470 elseif choice == 91 then -- place redstone torch under current block
2471 print( "Place me on suspended railway stone\n"..
2472 "Redstone torch will go below me\n")
2473 width = 0
2474 length = 0
2475 elseif choice == 92 then -- place redstone torch on upward slope
2476 print( "Place me on railway stone going up\n"..
2477 "Redstone torch will go below me\n")
2478 width = 0
2479 length = 0
2480 elseif choice == 93 then -- build downward slope
2481 print( "Place me on last stone\n"..
2482 "Track will go down from this point\n")
2483 width = 0
2484 length = 0
2485 height = getSize(false, "Drop down by how many blocks?\n", 1, 64)
2486 elseif choice == 94 then -- build upward slope
2487 print( "Place me on last stone\n"..
2488 "Track will go up from this point\n")
2489 width = 0
2490 length = 0
2491 height = getSize(false, "Go up by how many blocks?\n", 1, 64)
2492 end
2493
2494 return choice, size, width, length, height -- eg 86, 0, 8, 8, 4
2495end
2496
2497function harvestAutoTreeFarm()
2498 local blockType, blockModifier
2499 for j = 1, 2 do
2500 for i = 1, 3 do
2501 blockType, blockModifier = T:getBlockType("forward")
2502 if blockType == "minecraft:log" or blockType == "minecraft:log2" then
2503 T:harvestTree(true, false)
2504 T:forward(1)
2505 elseif blockType == "minecraft:sapling" then
2506 T:go("U1F2D1")
2507 else
2508 T:forward(1)
2509 end
2510 end
2511 if j == 1 then
2512 T:go("R1F3R1")
2513 else
2514 T:go("R1F3L1")
2515 end
2516 end
2517 T:dropItem("minecraft:log", 0, "forward")
2518 T:dropItem("minecraft:log2", 0, "forward")
2519 T:dropItem("minecraft:apple", 0, "forward")
2520 T:turnRight(2)
2521end
2522
2523function harvestObsidian(width, length)
2524 local heightParts = math.floor(length / 8) -- eg 12/8 = 1
2525 local lastPart = length - (heightParts * 8) -- eg 12 - (1 * 8) = 4
2526 if width % 2 ~= 0 then
2527 width = width + 1
2528 end
2529 for y = 1, width do
2530 print("Mining column "..tostring(y).." of "..tostring(width))
2531 for j = 1, heightParts do
2532 T:go("m8")
2533 end
2534 if lastPart > 0 then
2535 T:go("m"..tostring(lastPart)) -- eg m4
2536 end
2537 -- width = tonumber(width)
2538 if y < width then
2539 if y % 2 == 0 then
2540 T:go("L1F1L1")
2541 else
2542 T:go("R1F1R1")
2543 end
2544 end
2545 end
2546end
2547
2548function harvestRun(runLength)
2549 local blockType
2550 local blockModifier
2551
2552 for i = 1, runLength do
2553 blockType, blockModifier = T:getBlockType("forward") -- store information about the block in front in a table
2554 if blockType == "minecraft:log" or blockType == "minecraft:log2" then -- tree in front, so harvest it
2555 T:harvestTree(true, false)
2556 else
2557 T:forward(1)
2558 end
2559 end
2560end
2561
2562function harvestTreeFarm(size)
2563 local loopCount
2564 local blockType, blockModifier = T:getBlockType("forward") -- store information about the block in front in a table
2565 if size == 0 then --fell single tree
2566 blockType, blockModifier = T:getBlockType("forward") -- store information about the block in front in a table
2567 if blockType == "minecraft:log" or blockType == "minecraft:log2" then -- tree in front, so harvest it
2568 T:harvestTree(true, false)
2569 end
2570 else
2571 if size == 1 then
2572 loopCount = 4
2573 else
2574 loopCount = 8
2575 end
2576 if blockType == "minecraft:dirt" or blockType == "minecraft:grass" then
2577 T:up(1)
2578 end
2579 for i = 1, loopCount do
2580 harvestRun(loopCount * 2)
2581 turtle.turnRight()
2582 harvestRun(1)
2583 turtle.turnRight() --now facing opposite direction
2584 harvestRun(loopCount * 2)
2585 if i < loopCount then -- turn left if not on last run
2586 turtle.turnLeft()
2587 harvestRun(1)
2588 turtle.turnLeft()
2589 end
2590 end
2591 --return to starting position
2592 turtle.turnRight()
2593 harvestRun(loopCount * 2 - 1)
2594 turtle.turnRight()
2595 end
2596end
2597
2598function harvestWheatFarm()
2599 T:forward(1)
2600 -- check if bucket or water bucket onboard
2601 --T:place(blockType, damageNo, direction, leaveExisting)
2602 T:place("minecraft:bucket", -1, "down", false)
2603 sleep(0.5)
2604 T:place("minecraft:bucket", -1, "down", false)
2605 -- assume 2x waterbuckets now onboard
2606 T:go("U1F9F2R1F8R2")
2607 for i = 1, 8 do
2608 T:place("minecraft:water_bucket", -1, "down", false)
2609 sleep(2)
2610 T:place("minecraft:bucket", -1, "down", false)
2611 if i > 1 then
2612 -- go back and repeat
2613 T:back(1)
2614 T:place("minecraft:water_bucket", -1, "down", false)
2615 sleep(2)
2616 T:place("minecraft:bucket", -1, "down", false)
2617 T:forward(1)
2618 end
2619 T:forward(1)
2620 end
2621 T:go("L1F9F3R2D1")
2622end
2623
2624function placeRedstoneTorch(direction, userChoice)
2625 if direction == "level" then
2626 T:go("R1F1D2L2F1R1")
2627 --clsTurtle.place(self, blockType, damageNo, direction, leaveExisting)
2628 T:place(userChoice, -1, "forward", false)
2629 T:back(1)
2630 T:place("minecraft:redstone_torch", -1, "forward", true)
2631 T:go("R1F1L1F1U2L1F1R1")
2632 elseif direction == "up" then
2633 T:go("R1F1D3R2F1L1")
2634 T:place("minecraft:redstone_torch", -1, "up", false)
2635 T:go("R1B1U3F1R1")
2636 T:place(userChoice, -1, "forward", false)
2637 end
2638end
2639
2640function plantAutoTreeFarm()
2641 local blockType, blockModifier
2642 T:go("L1F4L1F1D3")
2643 while turtle.suckDown() do end
2644 T:go("L2U3F1R1F4L1")
2645 for j = 1, 2 do
2646 for i = 1, 3 do
2647 blockType, blockModifier = T:getBlockType("forward")
2648 if blockType == "minecraft:log" or blockType == "minecraft:log2" then
2649 T:harvestTree(true, false)
2650 T:forward(1)
2651 elseif blockType == "minecraft:sapling" then
2652 T:go("U1F2D1")
2653 else
2654 T:go("U1F1")
2655 T:place("minecraft:sapling", -1, "down", false)
2656 T:go("F1D1")
2657 end
2658 end
2659 T:go("R1F3R1")
2660 end
2661 T:dropItem("minecraft:sapling", 0, "down")
2662 T:turnRight(2)
2663 T:dropItem("minecraft:log", 0, "forward")
2664 T:dropItem("minecraft:log2", 0, "forward")
2665 T:dropItem("minecraft:apple", 0, "forward")
2666 T:turnRight(2)
2667end
2668
2669function plantWheatFarm()
2670 --player gets minecraft:wheat_seeds from hopper and are already onboard
2671 local turn = {"F2U1F2R1F8L1F1L1","R1F1R1F1","L1F1L1F1","R1F1R1F1",
2672 "L1F1L1F1","R1F1R1F1","L1F1L1F1","R1F1R1F1"}
2673 local goHome = {"", "L1F3D1F2R2", "R1F3R1F9L1F1D1F2R2", "L1F5D1F3R2", "R1F5R1F9L1F1D1F2R2", "L1F7D1F2R2", "R1F7R1F9L1F1D1F2R2",
2674 "L1F9D1F2R2", "R1F9R1F9L1F1D1F2R2"}
2675 for i = 1, 9 do
2676 if T:getItemSlot("minecraft:wheat_seeds", 0) > 0 and i < 9 then -- min 8 seeds to get here
2677 T:go(turn[i])
2678 for j = 1, 8 do
2679 turtle.digDown()
2680 T:place("minecraft:wheat_seeds", 0, "down", false)
2681 T:forward(1)
2682 end
2683 else
2684 T:go(goHome[i])
2685 break
2686 end
2687 end
2688end
2689
2690function plantTreefarm(size)
2691 -- .name = "minecraft:sapling"
2692 -- .state.type = "dark_oak"
2693 -- .metadata = 5
2694 local saplings = {"oak","spruce","birch","jungle","acacia","dark oak"}
2695 local slot = 0
2696 local quantity = 0
2697 local id = 0
2698 local most = 0
2699 local mostID = -1
2700 local secondMost = 0
2701 local secondMostID = -1
2702
2703 for i = 0, 5 do
2704 slot, id, quantity = T:getItemSlot("minecraft:sapling", i) -- eg 3xoak, 9x spruce
2705 if slot > 0 then -- item found
2706 print(quantity.." "..saplings[i + 1].." found in slot "..slot)
2707 if quantity > most then -- this sapling quantity is > 0
2708 if most > 0 then -- another sapling already found, but quantity is greater
2709 secondMost = most
2710 secondMostID = mostID
2711 print("second sapling choice: "..saplings[secondMostID + 1])
2712 end
2713 most = quantity
2714 mostID = i
2715 print("first sapling choice: "..saplings[mostID + 1])
2716 else
2717 if most > 0 then
2718 secondMost = quantity
2719 secondMostID = i
2720 end
2721 end
2722 end
2723 end
2724 if secondMostID < 0 then
2725 secondMost = most
2726 secondMostID = mostID
2727 print("first and second sapling choice: "..saplings[secondMostID + 1])
2728 end
2729
2730 local outerCount = 4
2731 local innerCount = 1
2732 local repeatCount = 1
2733 if size > 1 then
2734 outerCount = 8
2735 innerCount = 5
2736 repeatCount = 3
2737 end
2738 -- user may have put turtle on the ground
2739 if T:getBlockType("forward") == "minecraft:dirt" or T:getBlockType("forward") == "minecraft:grass" then
2740 T:up(1)
2741 end
2742 -- start at base of first tree LL corner
2743 T:go("U1F1")
2744 for x = 1, 4 do -- place most in a ring on outside of planting area
2745 for i = 1, outerCount do
2746 T:place("minecraft:sapling", mostID, "down", false)
2747 if i < outerCount then
2748 T:forward(1)
2749 T:place("minecraft:sapling", mostID, "down", false)
2750 T:forward(1)
2751 end
2752 end
2753 T:turnRight(1)
2754 end
2755 -- over first sapling, facing forward
2756 T:go("F2R1F2L1")
2757 -- place secondMost sapling in centre
2758 for x = 1, repeatCount do
2759 -- plant first column
2760 for i = 1, innerCount do
2761 if not T:place("minecraft:sapling", secondMostID, "down", false) then
2762 T:place("minecraft:sapling", mostID, "down", false)
2763 end
2764 if i < innerCount + 1 then
2765 T:forward(2)
2766 if not T:place("minecraft:sapling", secondMostID, "down", false) then
2767 T:place("minecraft:sapling", mostID, "down", false)
2768 end
2769 end
2770 end
2771 -- turn round and move to next column
2772 T:go("R1F2R1")
2773 -- plant return column
2774 for i = 1, innerCount do
2775 if not T:place("minecraft:sapling", secondMostID, "down", false) then
2776 T:place("minecraft:sapling", mostID, "down", false)
2777 end
2778 if i < innerCount + 1 then
2779 T:forward(2)
2780 if not T:place("minecraft:sapling", secondMostID, "down", false) then
2781 T:place("minecraft:sapling", mostID, "down", false)
2782 end
2783 end
2784 end
2785 if x < repeatCount then
2786 T:go("L1F2L1")
2787 end
2788 end
2789 if size == 1 then
2790 T:go("F1R1F3L1F2R1F1R1D2")
2791 else
2792 T:go("F1R1F9F2L1F2R1F1R1D2")
2793 end
2794end
2795
2796function repairWall(startAt, height, width, replaceWith)
2797 -- go up to startAt
2798
2799 -- if width = 1
2800
2801 -- for h = startAt, height, 1 do
2802
2803 -- replace block with replaceWith ("" = any)
2804
2805 -- move up
2806
2807 --end
2808
2809 -- move back to beginning
2810
2811 -- else
2812
2813 -- remain = height % 2
2814
2815 -- for w = 1, width - remain do
2816
2817 -- for h = startAt, height, 1 do
2818
2819 -- replace block with replaceWith ("" = any)
2820
2821 -- move up
2822
2823 --end
2824
2825 -- move to the right 1 block
2826
2827 -- for i = height, startAt, -1 do
2828
2829 -- replace block with replaceWith ("" = any)
2830
2831 -- move down
2832
2833 --end
2834
2835 -- end
2836
2837 -- end
2838
2839end
2840
2841function searchForSpawner(level)
2842 -- go down 8 with ladder above
2843 -- go(path, useTorch, torchInterval, leaveExisting)
2844 -- depth = math.floor(level / 8)
2845
2846 T:down(1)
2847 for i = 1, 6 do
2848 T:go("C1R1C1R1C1R1C1R1D1e0", false, 0, true, true)
2849 end
2850 -- go down 1 further
2851 T:down(1)
2852
2853 local distance = 0
2854 local returnLength = 0
2855 local actualLength = 32
2856 for j = 1, 4 do
2857 for i = 1, 3 do
2858 actualLength = 32
2859 actualLength = T:createTunnel(actualLength, true) --may cut short if in ocean
2860 T:turnRight(1)
2861 T:createTunnel(9, false)
2862 T:turnRight(1)
2863 T:createTunnel(actualLength, false)
2864 returnLength = returnLength + 8
2865 -- ready to cut next section
2866 if i < 3 then
2867 T:turnLeft(1)
2868 actualLength = T:createTunnel(9, true) --may cut short if in ocean
2869 if actualLength == 9 then
2870 returnLength = returnLength + 8
2871 T:turnLeft(1)
2872 else
2873 -- cut short, block tunnel and return
2874 T:go("C2R1C1L1C1L1C1R1U1L1C1R1C1R1C1R1C0", false, 0, true, false)
2875 T:go("F"..actualLength.."D1", false, 0, true, true)
2876 break
2877 end
2878 else
2879 T:turnRight(1)
2880 end
2881 T:dumpRefuse(3) -- keep 4 stacks cobble
2882 end
2883 T:createTunnel(returnLength + 1, false, false)
2884 -- move 9 places forward and repeat
2885 T:createTunnel(9, false)
2886 end
2887end
2888
2889function main()
2890 local doContinue = true
2891 checkLabel() -- make sure turtle label is set
2892 --check if lib folder exists
2893 if not checkLibs("lib", "clsTurtle") then
2894 -- use pastebin get to download clsTurtle to libs folder
2895 print("Missing clsTurtle.lua in libs directory")
2896 print("Attempting to obtain from Pastebin...")
2897 if shell.run("pastebin","get","tvfj90gK","lib/clsTurtle.lua") then
2898 print("clsTurtle.lua installed from Pastebin")
2899 else
2900 print("failed to install clsTurtle.lua from Pastebin")
2901 doContinue = false
2902 end
2903
2904 end
2905 if not checkLibs("lib", "menu") then
2906 -- use pastebin get to download menu.lua to libs folder
2907 print("Missing menu.lua in libs directory")
2908 print("Attempting to obtain from Pastebin...")
2909 if shell.run("pastebin","get","BhjbYsw4","lib/menu.lua") then
2910 print("menu.lua installed from Pastebin")
2911 else
2912 print("failed to install menu.lua from Pastebin")
2913 doContinue = false
2914 end
2915 end
2916 if doContinue then
2917 menu = require("lib.menu")
2918 T = require("lib.clsTurtle"):new(1) -- 1 sent for debug purposes
2919 local choice, size, width, length, height = getTask()
2920 if choice ~= nil then
2921 checkInventory(choice, size, width, length, height)
2922 end
2923 T:clear()
2924 print("Thank you for using 'survival toolkit'")
2925 else
2926 print("Add missing files and restart")
2927 end
2928end
2929
2930main()