Inksaver

Survival tooolkit v.2 (requires library):2021/02/27

Apr 20th, 2020 (edited)
1,344
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. version = 20210227.1427
  2. --[[
  3.     **********Toolkit v2**********
  4.     https://pastebin.com/UFvjc1bw
  5.     Last edited: see version YYYYMMDD.HHMM
  6.     if NOT online:
  7.         Make sure you create a folder 'lib' and place menu.lua and clsTurtle.lua into it
  8.     else
  9.         lib folder will be created and files obtained automatically!
  10.     end
  11. ]]
  12.  
  13. args = {...} -- eg "farm", "tree"
  14.  
  15. local menu, T
  16.  
  17. function checkFuelNeeded(quantity)
  18.     local fuelNeeded = quantity - turtle.getFuelLevel() -- eg 600
  19.     if fuelNeeded > 0 then
  20.         T:checkInventoryForItem({"minecraft:lava_bucket", "minecraft:coal", "minecraft:planks"}, {1, math.ceil(fuelNeeded / 60), math.ceil(fuelNeeded / 15)}) -- 0 if not present  
  21.     end
  22. end
  23.  
  24. function checkLabel()
  25.     if os.getComputerLabel() == nil then
  26.         os.setComputerLabel("toolkit")
  27.         print("Computer label set to "..os.getComputerLabel())
  28.     end
  29. end
  30.  
  31. function checkLibs(libDir, filename)
  32.     local fileExists = false
  33.     if fs.exists(libDir) then
  34.         if not fs.isDir(libDir) then
  35.             fs.move(libDir, libDir.."Renamed")
  36.             fs.makeDir(libDir)
  37.         end
  38.     else
  39.         fs.makeDir(libDir)
  40.     end
  41.     if fs.exists(fs.combine(libDir, filename)) or fs.exists(fs.combine(libDir, filename..".lua")) then
  42.         fileExists = true
  43.     end
  44.     return fileExists
  45. end
  46.  
  47. function clearArea(width, length, useDirt)
  48.     if useDirt == nil then
  49.         useDirt = true
  50.     end
  51.     local evenWidth = false
  52.     local evenHeight = false
  53.     local loopWidth
  54.     -- go(path, useTorch, torchInterval, leaveExisting)
  55.     if width % 2 == 0 then
  56.         evenWidth = true
  57.         loopWidth = width / 2
  58.     else
  59.         loopWidth = math.ceil(width / 2)
  60.     end
  61.     if length % 2 == 0 then
  62.         evenHeight = true
  63.     end
  64.     turtle.select(1)
  65.     -- clear an area between 2 x 4 and 32 x 32
  66.     -- if width is even no, then complete the up/down run
  67.     -- if width odd no then finish at top of up run and reverse
  68.     -- should be on flat ground, check voids below, harvest trees
  69.     for x = 1, loopWidth do
  70.         -- Clear first column (up)
  71.         for y = 1, length do
  72.             if useDirt then
  73.                 if not turtle.detectDown() then
  74.                     T:place("minecraft:dirt", -1, "down", true)
  75.                 else --if not water, dirt, grass , stone then replace with dirt
  76.                     blockType, blockModifier = T:getBlockType("down")
  77.                     if blockType ~= "" then
  78.                         if blockType ~= "minecraft:dirt" and blockType ~= "minecraft:grass_block" then
  79.                             turtle.digDown()
  80.                             T:place("minecraft:dirt", -1, "down", true)
  81.                         end
  82.                     end
  83.                 end
  84.             end
  85.             blockType, blockModifier = T:getBlockType("forward")
  86.             if blockType ~= "" then
  87.                 if string.find(blockType, "log") ~= nil then -- tree in front, so harvest it
  88.                     T:harvestTree() --automatically moves forward 1 block
  89.                     if y == length then -- move back 1 if already at max length
  90.                         T:back(1)
  91.                     end
  92.                 else
  93.                     if y < length then
  94.                         T:go("F1+1", false,0,false)
  95.                     end
  96.                 end
  97.             else
  98.                 if y < length then
  99.                     T:go("F1+1", false,0,false)
  100.                 end
  101.             end
  102.         end
  103.         -- clear second column (down)
  104.         if x < loopWidth or (x == loopWidth and evenWidth) then -- go down if on width 2,4,6,8 etc
  105.             T:go("R1F1+1R1", false,0,false)
  106.             for y = 1, length do
  107.                 if useDirt then
  108.                     if not turtle.detectDown() then
  109.                         T:place("minecraft:dirt", -1, "down", true)
  110.                     else
  111.                         blockType, blockModifier = T:getBlockType("down")
  112.                         if blockType ~= "" then
  113.                             if blockType ~= "minecraft:dirt" and blockType ~= "minecraft:grass_block" then
  114.                                 turtle.digDown()
  115.                                 T:place("minecraft:dirt", -1, "down", true)
  116.                             end
  117.                         end
  118.                     end
  119.                 end
  120.                 blockType, blockModifier = T:getBlockType("forward")
  121.                 if blockType ~= "" then
  122.                     if string.find(blockType, "log") ~= nil then -- tree in front, so harvest it
  123.                         T:harvestTree()
  124.                         if y == length then
  125.                             T:back(1)
  126.                         end
  127.                     else
  128.                         if y < length then
  129.                             T:go("F1+1", false,0,false)
  130.                         end
  131.                     end
  132.                 else
  133.                     if y < length then
  134.                         T:go("F1+1", false,0,false)
  135.                     end
  136.                 end
  137.             end
  138.             if x < loopWidth then
  139.                 T:go("L1F1+1L1", false,0,false)
  140.             else
  141.                 T:turnRight(1)
  142.                 T:forward(width - 1)
  143.                 T:turnRight(1)
  144.             end
  145.         else -- equals width but is 1,3,5,7 etc
  146.             T:turnLeft(2) --turn round 180
  147.             T:forward(length - 1)
  148.             T:turnRight(1)
  149.             T:forward(width - 1)
  150.             T:turnRight(1)
  151.         end
  152.     end
  153. end
  154.  
  155. function clearBuilding(width, length, height, direction, withCeiling, withFloor)
  156.     -- direction = Bottom->Top (0), Top->bottom(1)
  157.     if (direction == 0 and withFloor) or (direction == 1 and withCeiling) then
  158.         --clear floor/ceiling
  159.         clearRectangle(width, length)      
  160.     else --perimeter only
  161.         clearPerimeterWall(width, length, 1)
  162.     end
  163.     if direction == 0 then -- bottom to top
  164.         T:up(1)
  165.     else
  166.         T:down(1)
  167.     end
  168.     clearPerimeterWall(width, length, height - 2, direction) -- if height set to 0, will auto find top
  169.     if direction == 0 and withCeiling then
  170.         --clear ceiling
  171.         T:up(1)
  172.         clearRectangle(width, length)
  173.     elseif direction == 1 and withFloor then
  174.         --clear floor
  175.         T:down(1)
  176.         clearRectangle(width, length)
  177.     else --perimeter only
  178.         clearPerimeterWall(width, length, 1)
  179.     end
  180.     if direction == 0 then -- bottom to top
  181.         T:down(height - 1)
  182.     else
  183.         T:up(height - 1)
  184.     end
  185. end
  186.  
  187. function clearMonumentLayer(width, length, size)
  188.     local extend = true
  189.     if size == 0 then
  190.         extend = false
  191.     end
  192.     -- send turtle down until it hits bottom
  193.     -- then clear rectangle of given size
  194.     -- start above water, usually on cobble scaffold above monument
  195.     if T:detect("down") then -- in case not over wall
  196.         T:forward(1)
  197.     end
  198.     height = 1
  199.     -- go down until solid block detected
  200.     while clearVegetation("down") do
  201.         T:down(1)
  202.         height = height + 1
  203.     end
  204.     T:down(1)
  205.     height = height + 1
  206.     clearRectangle(width, length, extend)
  207.     T:up(height - 1)
  208. end
  209.  
  210. function clearSeaweed(width, length)
  211.     -- move over water
  212.     turtle.select(1)
  213.     T:clear()
  214.     print("Checking water length")
  215.     while not clearVegetation("down") do
  216.         T:forward(1)
  217.     end
  218.     local odd = false
  219.     local calcLength = 0
  220.     while clearVegetation("down") do
  221.         T:forward(1)
  222.         calcLength = calcLength + 1
  223.     end
  224.     -- now check on correct side: wall to the right
  225.     print("Checking position")
  226.     T:go("R2F1R1F1") -- over ? wall
  227.     if clearVegetation("down") then -- over water, so return to start on correct side
  228.         T:go("R2F1R1F"..calcLength - 1 .."R2")
  229.     else
  230.         T:go("R2F1R1") -- over water
  231.     end
  232.     if calcLength % 2 == 1 then
  233.         odd = true
  234.     end
  235.     local forward = true
  236.     --print("calcLength:"..calcLength.. " odd:"..tostring(odd))
  237.     for w = 1, width do
  238.         for l = 1, calcLength, 2 do -- 1,3,5,7 etc length 3 runs 1, 5 runs 2 etc
  239.             local depth = 0
  240.             if l == 1 or (l % 2 == 1 and l == calcLength) then
  241.                 if forward then
  242.                     T:turnLeft(1)
  243.                 else
  244.                     T:turnRight(1)
  245.                 end
  246.             else
  247.                 T:turnLeft(2)
  248.             end
  249.             -- go down destroying vegetation until on floor, checking in front at same time
  250.             while clearVegetation("down") do
  251.                 clearVegetation("forward")
  252.                 T:down()
  253.                 depth = depth + 1
  254.             end
  255.             -- if slab at bottom, cover with solid block
  256.             if string.find(T:getBlockType("down"), "slab") then
  257.                 T:up(1)
  258.                 T:place("minecraft:sand", "down")
  259.                 depth = depth + 1
  260.             end
  261.             if l == 1 or (l % 2 == 1 and l == calcLength) then
  262.                 if forward then
  263.                     T:turnRight(1)
  264.                 else
  265.                     T:turnLeft(1)
  266.                 end
  267.             else
  268.                 T:turnLeft(2)
  269.             end
  270.             for d = depth, 1, -1 do
  271.                 clearVegetation("forward")
  272.                 T:up(1)
  273.             end
  274.             -- first corner complete, back at surface above water
  275.             if l < calcLength then
  276.                 T:forward(2)
  277.             end
  278.         end
  279.         if forward then
  280.             T:go("L1F1L1")
  281.         else
  282.             T:go("R1F1R1")
  283.         end
  284.         forward = not forward
  285.         if not clearVegetation("down") then -- reached  far wall
  286.             break
  287.         end
  288.     end
  289. end
  290.  
  291. function clearMountainSide(width, length, size)
  292.     local lib = {}
  293.     function lib.excavate(blocksFromOrigin, going, length, digDown)
  294.         local firstUp = 0
  295.         for i = 1, length do
  296.             -- record first block dug above
  297.             if turtle.digUp() then
  298.                 if firstUp == 0 then
  299.                     firstUp = i -- will record first successful dig up
  300.                 end
  301.             end
  302.             if digDown then
  303.                 turtle.digDown()
  304.             end
  305.             T:forward(1)
  306.             if going then
  307.                 blocksFromOrigin = blocksFromOrigin + 1
  308.             else
  309.                 blocksFromOrigin = blocksFromOrigin - 1
  310.             end
  311.         end
  312.        
  313.         return blocksFromOrigin, firstUp
  314.     end
  315.    
  316.     function lib.cutSection(blocksFromOrigin, going, length, firstUp)
  317.         local height = 0
  318.         local digDown = false
  319.         blocksFromOrigin, firstUp = lib.excavate(blocksFromOrigin, going, length, digDown)
  320.         -- while at least 1 block dug above do
  321.         while firstUp > 0 do
  322.             if digDown then
  323.                 turtle.digDown()
  324.             else
  325.                 digDown = true
  326.             end
  327.             T:go("R2U1x1U1x1U1x1x0") -- go up 3 turn round
  328.             going = not going
  329.             height = height + 3
  330.             if firstUp > 1 then
  331.                 length = length - firstUp + 1
  332.             end
  333.             -- go forward length digging up/down
  334.             blocksFromOrigin, firstUp = lib.excavate(blocksFromOrigin, going, length,  true)
  335.         end
  336.         T:down(height)
  337.        
  338.         return blocksFromOrigin, going
  339.     end
  340.    
  341.     local originalLength = length
  342.     local going = true
  343.     local firstUp = 0
  344.     local blocksFromOrigin = 0
  345.     --T:forward(1) -- get into position
  346.     blocksFromOrigin, going = lib.cutSection(blocksFromOrigin, going, length, firstUp)
  347.     if width > 1 then --move left/right and repeat
  348.         for i = 2, width do
  349.             if going then
  350.                 T:turnRight(2)         
  351.             end
  352.             if blocksFromOrigin > 0 then
  353.                 T:forward(blocksFromOrigin)
  354.             end
  355.             T:turnRight(2)
  356.             blocksFromOrigin = 0
  357.             if size == 0 then --Left <- Right
  358.                 T:go("L1F1R1")
  359.             else
  360.                 T:go("R1F1L1")
  361.             end
  362.             going = true
  363.             blocksFromOrigin, going = lib.cutSection(blocksFromOrigin, going, length, firstUp)
  364.         end
  365.     end
  366. end
  367.  
  368. function clearPerimeterWall(width, length, height, direction)
  369.     -- go(path, useTorch, torchInterval, leaveExisting)
  370.     -- if height <= 0 then stop when nothing above
  371.     turtle.select(1)
  372.     if direction == nil then
  373.         direction = 0
  374.     end
  375.     --if height > 0 then
  376.         for i = 1, height do
  377.             T:go("F"..tostring(length - 1)..
  378.                  "R1F"..tostring(width - 1)..
  379.                  "R1F"..tostring(length - 1)..
  380.                  "R1F"..tostring(width - 1)..
  381.                  "R1", false, 0, false)
  382.             if direction == 0 then
  383.                 if i < height then
  384.                     T:up(1)
  385.                 end
  386.             else
  387.                 if i < height then
  388.                     T:down(1)
  389.                 end
  390.             end
  391.         end
  392.     --[[else -- 0 set as height
  393.         local go = true
  394.         repeat
  395.             T:go("F"..tostring(length - 1)..
  396.                  "R1F"..tostring(width - 1)..
  397.                  "R1F"..tostring(length - 1)..
  398.                  "R1F"..tostring(width - 1)..
  399.                  "R1", false, 0, false)
  400.             if direction == 0 then
  401.                 if turtle.detectUp() then
  402.                     T:up(1)
  403.                 else
  404.                     go = false
  405.                 end
  406.             else
  407.                 if turtle.detectDown() then
  408.                     T:down(1)
  409.                 else
  410.                     go = false
  411.                 end
  412.             end
  413.         until not go
  414.     end]]
  415. end
  416.  
  417. function clearRectangle(width, length, extend)
  418.     if extend == nil then --remove blocks above and below
  419.         extend = false
  420.     end
  421.     -- could be 1 wide x xx length (trench) up and return
  422.     -- could be 2+ x 2+
  423.     -- even no of runs return after last run
  424.     -- odd no of runs forward, back, forward, reverse and return
  425.     local directReturn = true
  426.     turtle.select(1)
  427.     if width % 2 == 1 then
  428.         directReturn = false
  429.     end
  430.     if width == 1 then -- trench ahead
  431.         if extend then
  432.             for l = 1, length - 1 do
  433.                 T:go("x0x2F1x0x2")
  434.             end
  435.             T:go("R2")
  436.             for l = 1, length - 1 do
  437.                 T:go("x0x2F1x0x2")
  438.             end
  439.             T:go("R2")
  440.         else
  441.             T:go("F"..length - 1 .."R2F"..length - 1 .."R2", false, 0, false)
  442.         end
  443.     else
  444.         if directReturn then -- width = 2,4,6,8 etc
  445.             for i = 1, width, 2 do -- i = 1,3,5,7 etc
  446.                 if extend then
  447.                     for l = 1, length - 1 do
  448.                         T:go("x0x2F1", false, 0, false)
  449.                     end
  450.                     T:go("x0x2R1F1x0x2R1x0x2")
  451.                     for l = 1, length - 1 do
  452.                         T:go("F1x0x2", false, 0, false)
  453.                     end
  454.                     if i < width - 2 then -- eg width = 8, i compares with 6: 1, 3, 5, 7
  455.                         T:go("L1F1x0x2L1", false, 0, false)
  456.                     end
  457.                 else
  458.                     T:go("F"..length - 1 .."R1F1R1F"..length - 1, false, 0, false)
  459.                     if i < width - 2 then -- eg width = 8, i compares with 6: 1, 3, 5, 7
  460.                         T:go("L1F1L1", false, 0, false)
  461.                     end
  462.                 end
  463.             end
  464.             if extend then
  465.                 T:go("R1")
  466.                 for w = 1, width - 1 do
  467.                     T:go("F1", false, 0, false)
  468.                 end
  469.                 T:go("R1")
  470.             else
  471.                 T:go("R1F"..width - 1 .."R1", false, 0, false)
  472.             end
  473.         else -- width = 3, 5, 7, 9 eg width 7
  474.             if extend then
  475.                 for i = 1, width - 1, 2 do -- i = 1,3,5
  476.                     for l = 1, length -1 do
  477.                         T:go("x0x2F1", false, 0, false)
  478.                     end
  479.                     T:go("R1x0x2F1R1x0x2", false, 0, false)
  480.                     for l = 1, length -1 do
  481.                         T:go("x0x2F1", false, 0, false)
  482.                     end
  483.                     T:go("L1x0x2F1L1")
  484.                 end
  485.                 -- one more run then return
  486.                 for l = 1, length -1 do
  487.                     T:go("x0x2F1", false, 0, false)
  488.                 end
  489.                 T:go("R2")
  490.                 for l = 1, length -1 do
  491.                     T:go("x0x2F1", false, 0, false)
  492.                 end
  493.                 T:go("R1")
  494.                 for w = 1, width -1 do
  495.                     T:go("x0x2F1", false, 0, false)
  496.                 end
  497.                 T:go("R1")
  498.             else
  499.                 for i = 1, width - 1, 2 do -- i = 1,3,5
  500.                     T:go("F"..length - 1 .."R1F1R1F"..length - 1 .."L1F1L1", false, 0, false)
  501.                 end
  502.                 -- one more run then return
  503.                 T:go("F"..length - 1 .."R2F"..length - 1 .."R1F"..width - 1 .."R1", false, 0, false)
  504.             end
  505.         end
  506.     end
  507. end
  508.  
  509. function clearSandWall(length)
  510.     --dig down while on top of sand/soul_sand
  511.     local height = 0
  512.     turtle.select(1)
  513.     T:clear()
  514.     print("Checking sand length")
  515.     local search = 0
  516.     local blockType = T:getBlockType("down")
  517.     while blockType ~= "minecraft:sand" and blockType ~= "minecraft:soul_sand" do --move forward until sand detected or 3 moves
  518.         T:forward(1)
  519.         search = search + 1
  520.         blockType = T:getBlockType("down")
  521.         if search > 3 then
  522.             break
  523.         end
  524.     end
  525.     if search <= 3 then
  526.         local calcLength = 0
  527.         blockType = T:getBlockType("down")
  528.         while blockType == "minecraft:sand" or blockType == "minecraft:soul_sand" do
  529.             T:forward(1)
  530.             calcLength = calcLength + 1
  531.             blockType = T:getBlockType("down")
  532.         end
  533.         T:go("R2F1") -- over sand
  534.         blockType = T:getBlockType("down")
  535.         while blockType == "minecraft:sand" or blockType == "minecraft:soul_sand" do
  536.             T:down(1)
  537.             height = height + 1
  538.             blockType = T:getBlockType("down")
  539.         end
  540.         -- repeat length times
  541.         for i = 1, calcLength do
  542.             --if sand in front, dig
  543.             while turtle.detect() do
  544.                 blockType = T:getBlockType("forward")
  545.                 if blockType == "minecraft:sand" or blockType == "minecraft:soul_sand" then
  546.                     T:dig("forward")
  547.                 else --solid block, not sand so move up
  548.                     T:up(1)
  549.                     height = height - 1
  550.                 end
  551.             end
  552.             --move forward
  553.             if i < calcLength then
  554.                 T:forward(1)
  555.                 blockType = T:getBlockType("down")
  556.                 while blockType == "minecraft:sand" or blockType == "minecraft:soul_sand" do
  557.                     T:down(1)
  558.                     height = height + 1
  559.                     blockType = T:getBlockType("down")
  560.                 end
  561.             end
  562.         end
  563.         -- go up, but reverse if block above
  564.         for i = 1, height do
  565.             if not turtle.detectUp() then
  566.                 T:up(1)
  567.             else
  568.                 T:back(1)
  569.             end
  570.         end
  571.         T:go("R2")
  572.     end
  573. end
  574.  
  575. function clearSandCube(width, length)
  576.     --go down to bottom of sand
  577.     turtle.select(1)
  578.     while T:getBlockType("down") == "minecraft:sand" do
  579.         T:down(1)
  580.     end
  581.     clearBuilding(width, length, 0, false)
  582. end
  583.  
  584. function clearSolid(width, length, height, direction)
  585.     -- direction = Bottom->Top (0), Top->bottom(1)
  586.     if direction == nil then
  587.         direction = 0
  588.     end
  589.     if height <= 0 then --move up until no more solid
  590.         local totalItemCount = 0
  591.         repeat
  592.             totalItemCount = T:getTotalItemCount()
  593.             clearRectangle(width, length)
  594.             if direction == 0 then
  595.                 T:up(1)
  596.             else
  597.                 T:down(1)
  598.             end
  599.             height = height + 1
  600.         until T:getTotalItemCount() == totalItemCount -- nothing collected or full inventory
  601.     else
  602.         for i = 1, height do
  603.             clearRectangle(width, length)
  604.             if direction == 0 then
  605.                 T:up(1)
  606.             else
  607.                 T:down(1)
  608.             end
  609.         end
  610.     end
  611.     if direction == 0 then
  612.         T:down(height)
  613.     else
  614.         T:up(height)
  615.     end
  616. end
  617.  
  618. function clearWall(width, length, height, direction)
  619.     -- direction = Bottom->Top (0), Top->bottom(1)
  620.     -- width preset to 1
  621.     if direction == nil then direction = 0 end-- bottom to top
  622.     local atStart = true
  623.     local offset = height - 2
  624.     -- go(path, useTorch, torchInterval, leaveExisting)
  625.     local evenHeight = false
  626.     if height % 2 == 0 then
  627.         evenHeight = true
  628.     end
  629.     turtle.select(1)
  630.     -- dig along and up/down for specified length
  631.     if evenHeight then --2, 4 , 6 etc
  632.         for h = 2, height, 2 do
  633.             for i = 1, length - 1 do
  634.                 T:go("x0F1", false, 0, false)
  635.             end
  636.             if h < height then
  637.                 if direction == 0 then --bottom to top
  638.                     T:go("R2U2", false, 0, false)
  639.                 else
  640.                     T:go("R2D2", false, 0, false)
  641.                 end
  642.             end
  643.             atStart = not atStart
  644.         end
  645.     else
  646.         offset = height - 1
  647.         for h = 1, height, 2 do
  648.             if h == height then
  649.                 T:go("F"..tostring(length - 1), false, 0, false)
  650.             else
  651.                 for i = 1, length - 1 do
  652.                     if direction == 0 then --bottom to top
  653.                         T:go("x0F1", false, 0, false)
  654.                     else
  655.                         T:go("x2F1", false, 0, false)
  656.                     end
  657.                 end
  658.             end
  659.             atStart = not atStart
  660.             if h < height then
  661.                 if direction == 0 then --bottom to top
  662.                     T:go("R2U2", false, 0, false)
  663.                 else
  664.                     T:go("R2D2", false, 0, false)
  665.                 end
  666.             end
  667.         end
  668.     end
  669.     if evenHeight then
  670.         if direction == 0 then
  671.             T:go("x0", false, 0, false)
  672.         else
  673.             T:go("x2", false, 0, false)
  674.         end
  675.     end
  676.     if direction == 0 then
  677.         T:go("R2D"..offset, false, 0, false)
  678.     else
  679.         T:go("R2U"..offset, false, 0, false)
  680.     end
  681.     if not atStart then
  682.         T:go("F"..tostring(length - 1).."R2", false, 0, false)
  683.     end
  684. end
  685.  
  686. function clearVegetation(direction)
  687.     local isAirWaterLava = true
  688.     -- blockType, blockModifier, data
  689.     local blockType, blockModifier = T:getBlockType(direction)
  690.     if blockType ~= "" then --not air
  691.         if T:isVegetation(blockType) then
  692.             T:dig(direction)
  693.         elseif string.find(blockType, "water") == nil and string.find(blockType, "lava") == nil then
  694.             -- NOT water or lava
  695.             isAirWaterLava = false -- solid block
  696.         end
  697.     end
  698.    
  699.     return isAirWaterLava --clears any grass or sea plants, returns true if air or water
  700. end
  701.  
  702. function createAutoTreeFarm()
  703.     lib = {}
  704.    
  705.     function lib.fillWaterBuckets()
  706.         T:place("minecraft:bucket", -1, "down", false)
  707.         sleep(0.5)
  708.         T:place("minecraft:bucket", -1, "down", false)
  709.     end
  710.    
  711.     createWaterSource(1)
  712.     -- clsTurtle.go(path, useTorch, torchInterval, leaveExisting)
  713.     -- place chest and hopper  
  714.     T:go("x0F1x0F1x0F1x0F1R1")
  715.     for i = 1, 4 do
  716.         T:go("D1R1C1R1C1R1C1R1")
  717.     end
  718.     T:up(1)
  719.     T:place("minecraft:chest", -1, "down", false)
  720.     T:go("F1x0D1F1x0R2", false, 0, true)
  721.     T:place("minecraft:hopper", -1, "forward", false)
  722.     -- dig trench and ensure base is solid
  723.     T:go("U1R2X7U1", false, 0, true)
  724.     T:place("minecraft:water_bucket", -1, "down", false) -- collection stream
  725.     T:go("F1X7U1", false, 0, true)
  726.     T:place("minecraft:water_bucket", -1, "down", false) -- upper collection stream
  727.     T:go("U1F1R1C2F1R1C2") --now on corner
  728.     for i = 1, 14 do --place cobble
  729.         T:go("F1C2", false, 0, false)
  730.     end
  731.     T:go("F4R1F2C2R2C1R2")
  732.     for i = 1, 8 do --place cobble
  733.         T:go("F1C2", false, 0, false)
  734.     end
  735.     T:turnRight(1)
  736.     for i = 1, 18 do --place cobble
  737.         T:go("F1C2", false, 0, false)
  738.     end
  739.     T:turnRight(1)
  740.     for i = 1, 8 do --place cobble
  741.         T:go("F1C2", false, 0, false)
  742.     end
  743.     T:go("R1F1R1D1") -- ready to clear ground inside cobble wall
  744.     for i = 1, 17 do
  745.         T:go("C2F1C2F1C2F1C2F1C2F1C2F1C2F1C2", false, 0, true)
  746.         if i < 17 then
  747.             if i % 2 == 1 then -- odd no
  748.                 T:go("L1F1L1")
  749.             else
  750.                 T:go("R1F1R1")
  751.             end
  752.         end
  753.     end
  754.     T:go("U1R2F10R2") -- over pond
  755.     lib.fillWaterBuckets()
  756.     for i = 0, 16, 2 do
  757.         T:go("F10R1")
  758.         if i > 0 then
  759.             T:go("F"..i)
  760.         end
  761.         T:place("minecraft:water_bucket", -1, "down", false)
  762.         T:go("F1R2")
  763.         if i < 16 then
  764.             T:place("minecraft:water_bucket", -1, "down", false)
  765.         end
  766.         T:go("F"..i + 1 .."L1")
  767.         T:go("F10R2")
  768.         lib.fillWaterBuckets()
  769.     end
  770.     -- place dirt/torch/sapling
  771.     T:go("F1U1R1F1L1")
  772.     for i = 1, 7 do
  773.         T:go("F6R1F1L1")
  774.         for j = 1, 3 do
  775.             T:place("minecraft:dirt", -1, "forward", false)
  776.             T:up(1)
  777.             T:place("sapling", -1, "forward", false)
  778.             T:down(1)
  779.             turtle.back()
  780.             T:place("minecraft:torch", -1, "forward", false)
  781.             turtle.back()
  782.         end
  783.         if i < 7 then
  784.             T:go("R1F1L1")
  785.         end
  786.     end
  787.     T:go("L1F12")
  788.     T:place("minecraft:chest", -1, "up", false)
  789.     T:go("R1F1L1")
  790.     T:place("minecraft:chest", -1, "up", false)
  791.     T:go("F1U1R1F1R1F1L1")
  792.     T:clear()
  793.     print("Auto TreeFarm completed")
  794.     print("\nDO NOT PLACE ANY TORCHES OR OTHER")
  795.     print("BLOCKS ON THE COBBLE PERIMETER!")
  796.     print("\nUse option 5 Manage Auto Tree farm")
  797.     print("to setup monitoring\n\nEnter to continue")
  798.     read()
  799. end
  800.  
  801. function createBridge(numBlocks)
  802.     for i = 1, numBlocks do
  803.         T:go("m1", false, 0, true)
  804.     end
  805.     T:go("R1F1R1", false, 0, true)
  806.     for i = 1, numBlocks do
  807.         T:go("m1", false, 0, true)
  808.     end
  809. end
  810.  
  811. function createCanal(side, length, height, effect)
  812.     -- go(path, useTorch, torchInterval, leaveExisting)
  813.     -- effect 0 or 1: 1 = delete source blocks
  814.     -- if height = 0 then already at correct height on canal floor
  815.         -- check block below, block to left and block above, move forward tunnelling
  816.         -- if entering water then move up, onto canal wall and continue pathway
  817.         -- if 55 and tunnelling then flood canal
  818.     -- else height = 1 then above water and on path across
  819.         -- move forward, checking for water below
  820.         -- if water finishes, move into canal, drop down and continue tunnelling
  821.     local lib = {}
  822.    
  823.     function lib.side(side, length, maxLength, height, effect)
  824.         local turnA = "R"
  825.         local turnB = "L"
  826.         local isWater = false
  827.         local isSource = false
  828.         local onWater = false
  829.         local numBlocks = 0
  830.         local doContinue = true
  831.         if side == 56 then -- right
  832.             turnA = "L"
  833.             turnB = "R"
  834.         end
  835.         -- if starting on wall, probably already on water
  836.         if height == 1 then -- if on wall, move to floor, turn to face opposite canal wall
  837.             T:forward(1)
  838.             isWater, isSource = T:isWater("down")
  839.             if isSource then --on river/ocean so just construct walkway
  840.                 onWater = true
  841.                 numBlocks = createPath(length - 1, true)
  842.                 if numBlocks < maxLength then -- continue with canal
  843.                     T:go(turnA.."1F1D1"..turnA.."1")
  844.                 else
  845.                     doContinue = false
  846.                 end
  847.             else
  848.                 T:go(turnA.."1F1D1")
  849.             end
  850.         else -- on canal floor, but could be open water
  851.             isWater, isSource = T:isWater("forward")
  852.             if isSource then -- water source ahead. Assume on open water   
  853.                 T:go(turnB.."1U1F1"..turnA.."1")
  854.                 onWater = true
  855.                 numBlocks = createPath(length - 1, true)
  856.                 if numBlocks < maxLength then -- continue with canal
  857.                     T:go(turnA.."1F1D1"..turnA.."1")
  858.                 else
  859.                     doContinue = false
  860.                 end
  861.             else
  862.                 T:go(turnA.."1")
  863.             end    
  864.         end
  865.         if not onWater then
  866.             if turtle.detect() then --block to side, check is not turtle
  867.                 if not redstone.getInput("front") then
  868.                 --if T:getBlockType("forward"):find("turtle") == nil then --not a turtle
  869.                     T:dig("forward") --automatically avoids turtle
  870.                 end
  871.             end
  872.             T:go(turnA.."1")
  873.             -- facing canal start wall
  874.             if turtle.detect() then -- solid block behind: at start of canal   
  875.                 T:go(turnB.."2C2F1"..turnB.."1C1"..turnB.."1C2x0", false, 0, true) --move forward and check base/side, face start
  876.                 T:place("minecraft:water_bucket", -1, "forward")
  877.             else -- air or water behind
  878.                 -- check if water already present behind. if not create source
  879.                 isWater, isSource = T:isWater("forward")
  880.                 if not isSource then
  881.                     T:place("minecraft:water_bucket", -1, "forward")
  882.                 end
  883.             end
  884.         end
  885.         -- could be over water, just need walls
  886.         --print("Loop starting. Enter")
  887.         --read()
  888.         local blockType, modifier
  889.         local torch = 0
  890.         local sourceCount = 0
  891.         --loop from here. Facing backwards over existing canal/start
  892.         while doContinue and numBlocks < maxLength do
  893.             isWater, isSource = T:isWater("forward")
  894.             while not isSource do
  895.                 sleep(10)
  896.                 print("waiting for water...")
  897.                 isWater, isSource = T:isWater("forward")
  898.             end
  899.             T:place("minecraft:bucket", -1, "forward") -- take water from source
  900.             -- move forward check canal wall for block, below for block
  901.             --T:go(turnA.."2F1C2"..turnB.."1C1", false, 0, true) -- face canal wall, repair if req
  902.             T:go(turnA.."2F1C2", false, 0, true) --move forward, close floor
  903.             isWater, isSource = T:isWater("forward")
  904.             --print("Source in front: "..tostring(isSource).." Enter")
  905.             --read()
  906.             if isSource then --now on open water. move up and continue
  907.                 sourceCount = sourceCount + 1
  908.                 if sourceCount > 3 then
  909.                     sourceCount = 0
  910.                     T:go(turnB.."1U1F1"..turnA.."1")
  911.                     numBlocks = createPath(length - 1, true)
  912.                     if numBlocks < maxLength then -- continue with canal
  913.                         T:go(turnA.."1F1D1"..turnA.."1x1"..turnA.."2") --return to canal bottom, break any block behind
  914.                     else
  915.                         doContinue = false
  916.                     end
  917.                 end
  918.             end
  919.             T:go(turnB.."1C1", false, 0, true) -- face canal wall, repair if req
  920.             --print("facing wall. Enter")
  921.             --read()
  922.             T:go("U1x1") --go up and remove any block
  923.             torch = torch + 1
  924.             numBlocks = numBlocks + 1
  925.             if turtle.detectUp() then -- block above
  926.                 T:go("U1x1")
  927.                 if torch == 8 then
  928.                     torch = 0
  929.                     T:place("minecraft:torch", -1, "forward")
  930.                 end
  931.                 T:down(1)
  932.             end
  933.             if torch == 8 then
  934.                 torch = 0
  935.                 T:place("minecraft:torch", -1, "forward")
  936.             end
  937.             T:down(1) -- on canal floor facing wall
  938.             T:go(turnB.."1", false, 0, true)
  939.             -- place water behind if some water is present
  940.             isWater, isSource = T:isWater("forward")
  941.             if not isWater then --no flowing water behind so deploy both sources
  942.                 T:forward(1)
  943.                 T:place("minecraft:water_bucket", -1, "forward")
  944.                 turtle.back()
  945.             end
  946.             T:place("minecraft:water_bucket", -1, "forward")
  947.             -- check opposite canal wall
  948.             T:go(turnB.."1")
  949.             if turtle.detect() then --block to side, check is not turtle
  950.                 if not redstone.getInput("front") then
  951.                 --if T:getBlockType("forward"):find("turtle") == nil then --not a turtle
  952.                     T:dig("forward")
  953.                 end
  954.             end
  955.             T:go(turnA.."1")
  956.         end
  957.     end
  958.    
  959.     function lib.leftSideLegacy(side, length, maxLength, height, effect)
  960.         local doContinue = true
  961.         local numBlocks  = 0
  962.         local doTunnel = false
  963.         local requestTunnel = false
  964.         local blockType, modifier
  965.         while doContinue and numBlocks < maxLength do
  966.             if height == 0 then -- canal floor
  967.                 blockType, modifier = T:getBlockType("down")
  968.                 if blockType == "" or blockType == "minecraft:lava" then -- air or lava below, so place block
  969.                     T:place("minecraft:cobblestone", -1, "down", false)
  970.                 end
  971.                 -- place side block
  972.                 T:go("L1C1R1", false , 0, true)
  973.                 -- check above
  974.                 blockType, modifier = T:getBlockType("up")
  975.                 --if blockType == "minecraft:log" or blockType == "minecraft:log2" then
  976.                 if blockType ~= "" then
  977.                     if string.find(blockType, "log") ~= nil then
  978.                         T:harvestTree(false, false, "up")
  979.                     elseif blockType == "minecraft:lava" or blockType == "minecraft:water" then
  980.                         T:up(1)
  981.                         T:place("minecraft:cobblestone", -1, "up", false)
  982.                         T:down(1)
  983.                     else --solid block or air above
  984.                         if blockType ~= "" then
  985.                             T:dig("up")
  986.                         end
  987.                     end
  988.                 end
  989.                 -- check if block in front is water source
  990.                 blockType, modifier = T:getBlockType("forward")
  991.                 --if block:find("water") ~= nil then
  992.                 if blockType == "minecraft:water" and modifier == 0 then -- source block in front could be lake/ocean
  993.                     -- move up, to left and continue as height = 1
  994.                     T:go("U1L1F1R1", false, 0, true)
  995.                     height = 1
  996.                 else
  997.                     T:forward(1, true)
  998.                     numBlocks = numBlocks + 1
  999.                 end
  1000.             else -- height = 1, on canal wall
  1001.                 numBlocks = numBlocks + createPath(0, true)
  1002.                 -- if path finished, then move back to canal floor and continue tunnelling
  1003.                 T:go("R1F1D1L1", false, 0, true)
  1004.                 height = 0
  1005.             end
  1006.         end
  1007.     end
  1008.    
  1009.     function lib.rightSideLegacy(side, length, maxLength, height, effect)
  1010.         -- assume left side already under construction
  1011.         local doContinue = true
  1012.         local numBlocks  = 0
  1013.         local doTunnel = false
  1014.         local requestTunnel = false
  1015.         local blockType, modifier
  1016.         local poolCreated = false
  1017.         while doContinue and numBlocks < maxLength do
  1018.             if height == 0 then-- canal floor
  1019.                 -- create first infinity pool
  1020.                 if not poolCreated then
  1021.                     T:up(1)
  1022.                     T:place("minecraft:water_bucket", -1, "down", false)
  1023.                     T:go("L1F1R1", false, 0, true)
  1024.                     T:place("minecraft:water_bucket", -1, "down", false)
  1025.                     T:forward(1)
  1026.                     T:place("minecraft:water_bucket", -1, "down", false)
  1027.                     T:back(1)
  1028.                     -- refill buckets
  1029.                     for j = 1, 3 do
  1030.                         T:place("minecraft:bucket", -1, "down", false)
  1031.                         sleep(0,5)
  1032.                     end
  1033.                     T:go("R1F1L1F2", false , 0, true)
  1034.                     T:down(1)
  1035.                     poolCreated = true
  1036.                 end
  1037.                 blockType, modifier = T:getBlockType("down")
  1038.                 if blockType == "" or blockType == "minecraft:lava"
  1039.                    or blockType == "minecraft:water" or blockType == "minecraft:flowing_water" then -- air, water or lava below, so place block
  1040.                     T:place("minecraft:cobblestone", -1, "down", false)
  1041.                 end
  1042.                 -- place side block
  1043.                 T:go("R1C1L1", false , 0, true)
  1044.                 T:up(1)
  1045.                 blockType, modifier = T:getBlockType("up")
  1046.                 if blockType == "minecraft:log" or blockType == "minecraft:log2" then
  1047.                     T:harvestTree(false, false, "up")
  1048.                 elseif blockType == "minecraft:lava" or blockType == "minecraft:water" then
  1049.                     T:place("minecraft:cobblestone", -1, "up", false)
  1050.                 end
  1051.                 T:place("minecraft:water_bucket", -1, "down", false)
  1052.                 for j = 1, 2 do
  1053.                     T:forward(1)
  1054.                     blockType, modifier = T:getBlockType("up")
  1055.                     --if blockType == "minecraft:log" or blockType == "minecraft:log2" then
  1056.                     if blockType ~= "" then
  1057.                         if string.find(blockType, "log") ~= nil then
  1058.                             T:harvestTree(false, false, "up")
  1059.                         elseif blockType == "minecraft:lava" or blockType == "minecraft:water" then
  1060.                             T:place("minecraft:cobblestone", -1, "up", false)
  1061.                         end
  1062.                     end
  1063.                     -- at ceiling level
  1064.                     T:go("D1R1C1L1", false, 0, true)
  1065.                     blockType, modifier = T:getBlockType("down")
  1066.                     if blockType == "" or blockType == "minecraft:lava"
  1067.                        or blockType == "minecraft:water" or blockType == "minecraft:flowing_water" then -- air, water or lava below, so place block
  1068.                         T:place("minecraft:cobblestone", -1, "down", false)
  1069.                     end
  1070.                     -- check if block in front is water source
  1071.                     blockType, modifier = T:getBlockType("forward")
  1072.                     T:up(1)
  1073.                     T:place("minecraft:water_bucket", -1, "down", false)
  1074.                     if blockType == "minecraft:water" and modifier == 0 then -- source block in front could be lake/ocean
  1075.                         -- move to right and continue as height = 1
  1076.                         T:go("R1F1L1", false, 0, true)
  1077.                         height = 1
  1078.                         break  
  1079.                     end
  1080.                 end
  1081.                 if height == 0 then
  1082.                     T:back(2)
  1083.                     for j = 1, 3 do
  1084.                         T:place("minecraft:bucket", -1, "down", false)
  1085.                         sleep(0,5)
  1086.                     end
  1087.                     T:go("F3D1", false, 0, true)
  1088.                 end
  1089.             else -- height = 1: on wall
  1090.                 numBlocks = numBlocks + createPath(0, true)
  1091.                 -- if path finished, then move back to canal floor and continue tunnelling
  1092.                 T:go("L1F1L1F1", false, 0, true) -- facing backwards, collect water
  1093.                 for j = 1, 3 do
  1094.                     T:place("minecraft:bucket", -1, "down", false)
  1095.                     sleep(0,5)
  1096.                 end
  1097.                 T:go("R2F1D1", false, 0, true) --canal floor
  1098.                 height = 0
  1099.             end
  1100.         end
  1101.     end
  1102.    
  1103.     -- side = 55/56: left/right side
  1104.     -- size = 0-1024 0 = continuous
  1105.     -- height = 0/1 0 = floor, 1 = wall
  1106.     -- T:place(blockType, damageNo, direction, leaveExisting)
  1107.     -- T:go(path, useTorch, torchInterval, leaveExisting)
  1108.     -- T:harvestTree(extend, craftChest, direction)
  1109.     -- start with forward run:
  1110.    
  1111.     local maxLength = 1024
  1112.     if length ~= 0 then
  1113.         maxLength = length
  1114.     end
  1115.     if effect == nil then
  1116.         effect = 1 -- old versions, water source is deleted by turtle
  1117.     end
  1118.     -- turn on redstone on all sides
  1119.     redstone.setOutput("left", true)
  1120.     redstone.setOutput("back", true)
  1121.     redstone.setOutput("right", true)
  1122.     redstone.setOutput("front", true)
  1123.     if side == 55 then -- left side
  1124.         if effect == 0 then -- new version
  1125.             lib.side(side, length, maxLength, height, effect)
  1126.             --lib.leftSide(side, size, length, maxLength)
  1127.         else
  1128.             lib.leftSideLegacy(side, length, maxLength, height, effect)
  1129.         end
  1130.     else -- right side (56)
  1131.         if effect == 0 then -- new version
  1132.             --lib.rightSide(side, size, length, maxLength)
  1133.             lib.side(side, length, maxLength, height, effect)
  1134.         else
  1135.             lib.rightSideLegacy(side, length, maxLength, height, effect)
  1136.         end
  1137.     end
  1138. end
  1139.  
  1140. function createCoridoor(length)
  1141.     if length == 0 then
  1142.         length = 2048
  1143.     end
  1144.     turtle.select(1)
  1145.     -- pause every 64 blocks
  1146.     local numSteps = 0
  1147.     local total = 0
  1148.     for steps = 1, length do
  1149.         if numSteps >= 64 then
  1150.             -- request permission to continue
  1151.             T:clear()
  1152.             print("Coridoor length: "..total.." blocks")
  1153.             print("Do you want to continue? (y/n)")
  1154.             response = read()
  1155.             if response:lower() ~= "y" then
  1156.                 break
  1157.             end
  1158.             numSteps = 0
  1159.         end
  1160.         --go(path, useTorch, torchInterval, leaveExisting)
  1161.         T:go("F1x0C2", false, 0, true)
  1162.         numSteps = numSteps + 1
  1163.         total = total + 1
  1164.     end
  1165. end
  1166.  
  1167. function createEnderTower()
  1168.    
  1169.     local lib = {}
  1170.    
  1171.     function lib.getEmptySlots()
  1172.         local empty = 0
  1173.         for i = 1, 16 do
  1174.             if turtle.getItemCount(i) == 0 then
  1175.                 empty = empty + 1
  1176.             end
  1177.         end
  1178.         return empty
  1179.     end
  1180.  
  1181.     function lib.getStone(direction, stacks)
  1182.         local suck = turtle.suck
  1183.         if direction == "down" then
  1184.             suck = turtle.suckDown
  1185.         end
  1186.         T:sortInventory()
  1187.         local slot = T:getFirstEmptySlot() --find spare slot
  1188.         turtle.select(1)
  1189.         if stacks == 0 then
  1190.             while suck() do end
  1191.         else
  1192.             for i = 1, stacks do -- get 6 stacks of stone from chest
  1193.                 suck()
  1194.             end
  1195.         end
  1196.         return T:getSlotContains(slot) -- use this as default building block
  1197.     end
  1198.    
  1199.     function lib.stackBuckets()
  1200.         local data = {}
  1201.         local bucketSlot = 0
  1202.         local emptySlots = 0
  1203.         local water = 0
  1204.         for i = 1, 16 do
  1205.             -- find first empty bucket
  1206.             if turtle.getItemCount(i) > 0 then
  1207.                 data = turtle.getItemDetail(i)
  1208.                 if data.name == "minecraft:bucket" then
  1209.                     if bucketSlot == 0 then
  1210.                         bucketSlot = i
  1211.                     else
  1212.                         turtle.select(i)
  1213.                         turtle.transferTo(bucketSlot)
  1214.                     end
  1215.                 elseif data.name == "minecraft:water_bucket" then
  1216.                     water = water + 1
  1217.                 end
  1218.             else
  1219.                 emptySlots = emptySlots + 1
  1220.             end
  1221.         end
  1222.         return emptySlots, water
  1223.     end
  1224.    
  1225.     function lib.countWaterBuckets()
  1226.         local data = {}
  1227.         local buckets = 0
  1228.         for i = 1, 16 do
  1229.             data = turtle.getItemDetail(i)
  1230.             if data.name == "minecraft:water_bucket" then
  1231.                 buckets = buckets + 1
  1232.             end
  1233.         end
  1234.         return buckets
  1235.     end
  1236.    
  1237.     function lib.baseRun(preferredBlock, count, turn)
  1238.         for i = 1, count do
  1239.             T:go("C2F1", false, 0, false, preferredBlock)
  1240.         end
  1241.         T:go("C2"..turn, false, 0, false, preferredBlock)
  1242.     end
  1243.    
  1244.     function lib.outsideRun(preferredBlock)
  1245.         T:place("fence", -1, "down", false)
  1246.         T:forward(1)
  1247.         T:place(preferredBlock, -1, "down", false)
  1248.         T:forward(1)
  1249.         T:place(preferredBlock, -1, "down", false)
  1250.         T:forward(2)
  1251.         T:place(preferredBlock, -1, "down", false)
  1252.     end
  1253.    
  1254.     function lib.signRun(preferredBlock ,message)
  1255.         T:place(preferredBlock, -1, "down", false)
  1256.         T:forward(4)
  1257.         T:place(preferredBlock, -1, "down", false)
  1258.         turtle.back()
  1259.         turtle.back()
  1260.         T:down(1)
  1261.         T:place("sign", -1, "forward", false, message)
  1262.         T:go("U1F2")
  1263.     end
  1264.    
  1265.     function lib.goToWater(height)
  1266.         local built = 0 -- measures completed lift height
  1267.         while turtle.down() do -- takes turtle to bottom of water source
  1268.             height = height + 1
  1269.             if turtle.detect() then
  1270.                 built = built + 1
  1271.             end
  1272.         end
  1273.         T:up(1) -- above watersource assuming it is 1-1.5 blocks deep
  1274.         height = height - 1
  1275.         -- built = built - 1 not required as next block is water source: not detected
  1276.         return built, height
  1277.     end
  1278.    
  1279.     function lib.fillBuckets(toBuild)
  1280.         local emptySlots, water = lib.stackBuckets() -- gets no of empty slots + no of water buckets
  1281.         if water < toBuild then -- no of water buckets onboard less than required quantity
  1282.             for i = 1, toBuild do -- fill required no of buckets up to max space in inventory
  1283.                 emptySlots = lib.getEmptySlots()
  1284.                 if emptySlots == 0 then -- inventory full
  1285.                     break
  1286.                 else
  1287.                     if T:place("minecraft:bucket", -1, "down", false) then
  1288.                         water = water + 1
  1289.                         sleep(0.5)
  1290.                     end
  1291.                 end
  1292.             end
  1293.         end
  1294.        
  1295.         return water
  1296.     end
  1297.    
  1298.     function lib.buildLift(preferredBlock)
  1299.         local built = 0 -- measures completed lift height
  1300.         local height = 0 -- measures total height from starting position
  1301.         built, height = lib.goToWater(height) -- returns lift blocks already placed, total height of drop from starting point
  1302.         local toBuild = height - built -- no of blocks to increase lift size
  1303.         while toBuild > 0 do -- at least 1 block height remaining
  1304.             local water = lib.fillBuckets(toBuild) -- no of water buckets onboard (could be more than required)
  1305.             if water > toBuild then
  1306.                 water = toBuild
  1307.             end
  1308.             while turtle.detect() do -- climb to top of existing lift
  1309.                 turtle.up()
  1310.                 height = height - 1
  1311.             end
  1312.             T:forward(1)
  1313.             for i = 1, water do -- build lift by no of water buckets
  1314.                 if T:place("minecraft:water_bucket", -1, "forward", false) then
  1315.                     T:up(1)
  1316.                     height = height - 1
  1317.                     toBuild = toBuild - 1
  1318.                     T:place(preferredBlock, -1, "down", false)
  1319.                 end
  1320.             end
  1321.             turtle.back()
  1322.             -- may still be some height to complete, but needs refill
  1323.             if toBuild > 0 then
  1324.                 lib.goToWater(0) --return to source
  1325.                 lib.fillBuckets(toBuild)
  1326.             end
  1327.         end
  1328.         if height > 0 then -- if any remaining distance
  1329.             T:up(height)
  1330.         end
  1331.        
  1332.     end
  1333.    
  1334.     function lib.buildSection(preferredBlock, solid) -- builds a section without any blocks in the centre
  1335.         if solid then
  1336.             T:go("C2F1 C2F1 C2F1 C2F1 C2R1", false, 0, false, preferredBlock) -- first side
  1337.             T:go("F1C2 F1R1", false, 0, false, preferredBlock) -- top side
  1338.             T:go("C2F1 C2F1 C2F1 C2F1 C2R1", false, 0, false, preferredBlock) -- far side
  1339.             T:go("F1C2 F1R1U1", false, 0, false, preferredBlock) -- top side
  1340.         else
  1341.             T:go("C2F1", false, 0, false, preferredBlock) -- first side
  1342.             if not T:place("fence", -1, "down", false) then-- first side
  1343.                 T:place(preferredBlock, -1, "down", false)
  1344.             end
  1345.             T:go("F1C2 F2C2 R1", false, 0, false, preferredBlock) -- first side
  1346.             T:go("F2C2 R1", false, 0, false, preferredBlock) -- top side
  1347.             T:go("F2C2 F1", false, 0, false, preferredBlock) -- far side
  1348.             if not T:place("fence", -1, "down", false) then-- first side
  1349.                 T:place(preferredBlock, -1, "down", false)
  1350.             end
  1351.             T:go("F1C2 R1", false, 0, false, preferredBlock) -- far side
  1352.             T:go("F1C2 F1R1U1", false, 0, false, preferredBlock) -- far side
  1353.         end
  1354.     end
  1355.    
  1356.     function lib.decorate()
  1357.         lib.placeFence(1) -- move up 1 and place fence
  1358.         lib.placeFence(1) -- move up 1 and place fence
  1359.         for i = 1, 7 do
  1360.             lib.placeFence(2) -- move up 2 and place fence
  1361.         end
  1362.         -- under main platform
  1363.         lib.placeFence(6)
  1364.         lib.placeFence(3)
  1365.         while lib.placeFence(2) do end-- move up 2 and place fence until top reached
  1366.     end
  1367.    
  1368.     function lib.placeFence(up)
  1369.         -- starting from chest level 0
  1370.         local success = true
  1371.         for i = 1, up do
  1372.             if turtle.detect() then
  1373.                 T:up(1)
  1374.             else
  1375.                 success = false -- reached the top
  1376.                 break
  1377.             end
  1378.         end
  1379.         if success then
  1380.             T:place("fence", -1, "forward", false) -- level 1
  1381.         end
  1382.         return success
  1383.     end
  1384.    
  1385.     --[[
  1386.         clsTurtle methods:
  1387.         clsTurtle.place(self, blockType, damageNo, direction, leaveExisting)
  1388.         clsTurtle.go(self, path, useTorch, torchInterval, leaveExisting, preferredBlock)
  1389.     ]]
  1390.     -- remove 1 stack stone from chest
  1391.     local preferredBlock = lib.getStone("down", 1) -- use this as default building block
  1392.     -- build base floor
  1393.     T:go("R2F2R1F3R1", false, 0, false, preferredBlock)
  1394.     for i = 1, 2 do
  1395.         lib.baseRun(preferredBlock, 8, "R1F1R1")
  1396.         lib.baseRun(preferredBlock, 8, "L1F1L1")
  1397.         lib.baseRun(preferredBlock, 8, "R1F4R1")
  1398.     end
  1399.     -- move back to centre, build water source, with soul sand at base of first source
  1400.     T:go("R1F3L1C2F1C2F2D1", false, 0, false, preferredBlock) --just behind chest, 1 below ground level
  1401.     T:place("minecraft:soul_sand", -1, "down", false) -- over block 1 of water source
  1402.     T:go("F1C2F1C2", false, 0, false, preferredBlock) -- over block 2 of water source
  1403.     T:go("F1C2U1C2", false, 0, false, preferredBlock) -- over block 4 of water source
  1404.     T:go("F1C2F1C2R2F5R2", false, 0, false, preferredBlock) -- over block 1 of water source
  1405.     T:place("minecraft:water_bucket", -1, "down", false)
  1406.     T:forward(2) -- over block 3 of water source
  1407.     T:place("minecraft:water_bucket", -1, "down", false)
  1408.     turtle.back() -- over block 2 of water source
  1409.     T:place("minecraft:bucket", -1, "down", false)
  1410.     T:go("F2D1R2C2") -- over block 4 of water source
  1411.     T:go("U1", false, 0, false, preferredBlock)
  1412.     T:place("minecraft:water_bucket", -1, "down", false)
  1413.     T:forward(4)
  1414.     lib.stackBuckets() -- put all buckets in same slot
  1415.     T:dropItem("minecraft:dirt", 0, "up") -- drop dirt up:  clsTurtle.dropItem(self, item, keepAmount, direction)
  1416.     preferredBlock = lib.getStone("down", 6)
  1417.     T:go("R1F2R1U1") -- move to start position
  1418.     for i = 1, 2 do
  1419.         -- build first level of tower: 2 x outside run, 2 x sign run
  1420.         lib.outsideRun(preferredBlock)
  1421.         T:go("R1F1R1")
  1422.         lib.signRun(preferredBlock, "Pint size\nzombies\nProhibited")
  1423.         T:go("L1F1L1C2", false, 0, false, preferredBlock)
  1424.         T:forward(4) -- miss out centre block
  1425.         T:place(preferredBlock, -1, "down", false)
  1426.         T:go("R1F1R1")
  1427.         lib.signRun(preferredBlock, "Pint size\nzombies\nProhibited")
  1428.         T:go("L1F1L1")
  1429.         lib.outsideRun(preferredBlock)
  1430.         if i == 1 then -- layer 1
  1431.             T:go("L1F4L1F4R2U1")
  1432.         else -- layer 2
  1433.             T:go("L1F5L1F6R2U1") -- over corner of lower platform
  1434.         end
  1435.     end
  1436.     for i = 1, 2 do -- build both sides of platform, leave centre missing
  1437.         lib.baseRun(preferredBlock, 8, "R1F1R1")
  1438.         lib.baseRun(preferredBlock, 8, "L1F1L1")
  1439.         lib.baseRun(preferredBlock, 8, "R1F4R1")
  1440.     end
  1441.     T:go("R1F3L1C2F1C2F1C2F4C2F1C2F1C2", false, 0, false, preferredBlock) --fill in centre row
  1442.     T:go("R2F6R1F1R1U1") -- go to start of tower base
  1443.     for i = 1, 7 do -- build 14 block high tower
  1444.         lib.buildSection(preferredBlock, false)
  1445.         lib.buildSection(preferredBlock, true)
  1446.     end
  1447.    
  1448.     T:go("R2F4R1F4R1", false, 0, false, preferredBlock) -- build upper platform (154 blocks remaining)
  1449.     for i = 1, 2 do -- build both sides of upper platform, leave centre missing
  1450.         lib.baseRun(preferredBlock, 12, "R1F1R1")
  1451.         lib.baseRun(preferredBlock, 12, "L1F1L1")
  1452.         lib.baseRun(preferredBlock, 12, "R1F1R1")
  1453.         lib.baseRun(preferredBlock, 12, "L1F1L1")
  1454.         lib.baseRun(preferredBlock, 12, "R1F6R1")
  1455.     end
  1456.     T:go("R1F5 L1C2 F1C2 F1C2 F1C2 F1C2 F4C2 F1C2 F1C2 F1C2 F1C2 ", false, 0, false, preferredBlock) --fill in centre row
  1457.     T:go("R2F5") -- return to drop area
  1458.     lib.buildLift(preferredBlock) -- build bubble lift
  1459.     T:go("F4D19R2") -- go down to chest: facing chest
  1460.     preferredBlock = lib.getStone("forward", 6)
  1461.     T:up(20)
  1462.     T:go("L1F1R1F1") -- go to start of tower base
  1463.     T:go("C2F4 C2R1F1R1", false, 0, false, preferredBlock) -- left side
  1464.     T:go("F2C2 F2C2 L1F1L1", false, 0, false, preferredBlock)
  1465.     T:go("C2F4 C2R2U1", false, 0, false, preferredBlock)
  1466.     T:go("C2F4 C2R1F1R1", false, 0, false, preferredBlock)
  1467.     T:place("fence", -1, "down", false)
  1468.     T:go("F2C2 F2L1F1L1", false, 0, false, preferredBlock)
  1469.     T:go("C2F4 C2R2F2L1F1R2D2", false, 0, false, preferredBlock) --ready to place ladder
  1470.     T:place("ladder", -1, "forward", false)
  1471.     T:up(1)
  1472.     T:place("ladder", -1, "forward", false)
  1473.     T:go("U2R1F4R1F1R1") -- ready to make upper tower base
  1474.    
  1475.     for i = 1, 2 do -- build both sides of platform, leave centre missing
  1476.         lib.baseRun(preferredBlock, 6, "R1F1R1")
  1477.         lib.baseRun(preferredBlock, 6, "L1F1L1")
  1478.         lib.baseRun(preferredBlock, 6, "R1F2R1")
  1479.     end
  1480.    
  1481.     T:go("R1F1 L1C2 F1C2 F1", false, 0, false, preferredBlock) --fill in centre row
  1482.     T:place("minecraft:soul_sand", -1, "down", false)
  1483.     T:go("F1C2 F2C2 F1C2", false, 0, false, preferredBlock)
  1484.     T:go("R2F5R1F1R1U1") -- go to start of tower base
  1485.     -- build 2 levels, finish signs and ladders
  1486.     T:go("C2F2 R1D2 U1", false, 0, false, preferredBlock)
  1487.     T:place("ladder", -1, "down", false)
  1488.     T:turnRight(1)
  1489.     T:place("sign", -1, "forward", false, "UP\n^\n|\n|")
  1490.     T:go("U1R2F2 R1F1C2 F2C2R1", false, 0, false, preferredBlock) --top right corner
  1491.     T:go("F4C2B2D1", false, 0, false, preferredBlock)
  1492.     T:place("sign", -1, "forward", false, "UP\n^\n|\n|")
  1493.     T:go("U1F2R1F1C2F1R1U1", false, 0, false, preferredBlock) --ready for second level
  1494.     T:go("C2F2 R2D1", false, 0, false, preferredBlock)
  1495.     T:place("sign", -1, "forward", false, "UP\n^\n|\n|")
  1496.     T:go("U1R2F2C2R1", false, 0, false, preferredBlock) --top left corner
  1497.     T:go("F1R1C2F4C2", false, 0, false, preferredBlock) --mid bottom row
  1498.     T:go("L1F1L1C2", false, 0, false, preferredBlock) -- bottom right corner
  1499.     T:go("F2R2D1", false, 0, false, preferredBlock)
  1500.     T:place("sign", -1, "forward", false, "UP\n^\n|\n|")
  1501.     T:go("U1R2F2C2", false, 0, false, preferredBlock) -- top right corner
  1502.     -- return to chest
  1503.     T:go("L1F1L1 F5D24R2", false, 0, false, preferredBlock) -- return to chest
  1504.     preferredBlock = lib.getStone("forward", 0)
  1505.     T:go("U25L1F1R1F1", false, 0, false, preferredBlock) -- return to finish tower
  1506.     -- tower 120 blocks high: first 72 layers
  1507.     for i = 1, 36 do -- build 72 block high tower 19 blocks/section = 720 (9 stacks)
  1508.         lib.buildSection(preferredBlock, true)
  1509.         lib.buildSection(preferredBlock, false)
  1510.     end
  1511.     T:go("D1F3R1F1R1", false, 0, false, preferredBlock) -- return to drop
  1512.     lib.buildLift(preferredBlock) -- build bubble lift
  1513.     T:go("F4R2", false, 0, false, preferredBlock) -- return to chest
  1514.     while turtle.down() do end
  1515.     preferredBlock = lib.getStone("forward", 0)
  1516.     turtle.select(16)
  1517.     turtle.drop() -- empty slot 16
  1518.     lib.decorate()-- replace  blocks with fence
  1519.     T:go("L1F1R1F1U1", false, 0, false, preferredBlock) -- return to finish tower
  1520.     -- continue tower
  1521.     for i = 1, 19 do -- build 38 block high tower 19 blocks/section = 570 (9 stacks)
  1522.         lib.buildSection(preferredBlock, true)
  1523.         lib.buildSection(preferredBlock, false)
  1524.     end
  1525.     -- add small platform at the top
  1526.     T:go("L1F2L1F2R2", false, 0, false, preferredBlock)
  1527.     for i = 1, 2 do
  1528.         lib.baseRun(preferredBlock, 8, "R1F1R1")
  1529.         lib.baseRun(preferredBlock, 8, "L1F1L1")
  1530.         lib.baseRun(preferredBlock, 8, "R1F4R1")
  1531.     end
  1532.     T:go("R1F3 L1C2 F1C2 F1C2 F4C2 F1C2 F1C2 R2F3", false, 0, false, preferredBlock) --fill in centre row
  1533.     lib.buildLift(preferredBlock) -- build bubble lift
  1534.     -- go down outside and repair holes
  1535.     T:go("F4R2D2C0", false, 0, false, preferredBlock) -- 1 repair top platform
  1536.     -- 19 fences left
  1537.     for i = 1, 19 do
  1538.         T:place("fence", -1, "forward", false) -- level 1
  1539.         T:down(2)
  1540.     end
  1541.     T:turnRight(2)
  1542.     while not turtle.detect() do
  1543.         turtle.down()
  1544.     end
  1545.     T:go("D1C0", false, 0, false, preferredBlock) -- 2 repair main platform roof
  1546.     while not turtle.detect() do
  1547.         turtle.down()
  1548.     end
  1549.     T:go("D1C0", false, 0, false, preferredBlock) -- 3 repair main platform
  1550.     while not turtle.detect() do
  1551.         turtle.down()
  1552.     end
  1553.     T:go("D1C0", false, 0, false, preferredBlock) -- 4 repair base platform
  1554.     while turtle.down() do end -- go to bottom
  1555.     T:turnRight(2) -- face chest
  1556.     local slot = T:getItemSlot(preferredBlock)
  1557.     for i = 1, 16 do
  1558.         if i ~= slot then
  1559.             turtle.select(i)
  1560.             turtle.drop()
  1561.         end
  1562.     end
  1563.     turtle.select(slot)
  1564.     turtle.transferTo(16)
  1565.     turtle.select(16)
  1566.     turtle.transferTo(1, 1)
  1567.     turtle.transferTo(2, 1)
  1568.     turtle.transferTo(3, 1)
  1569.     turtle.drop()
  1570.     turtle.craft()
  1571.     while turtle.suck() do end
  1572.     turtle.dig()
  1573.     T:place(preferredBlock, -1, "forward", false)
  1574.     T:go("U1C2", false, 0, false, preferredBlock) -- repair ground
  1575.     -- go to upper platform to fix water drop
  1576.     T:go("R2F4R2 U21F4 L1F2 R1F4 R1F2", false, 0, false, preferredBlock) -- fill in drop hole
  1577.     T:place("slab", -1, "forward", false)
  1578.     T:turnRight(2)
  1579.     T:place("slab", -1, "forward", false)
  1580.     local drop = 0
  1581.     while turtle.down() do
  1582.         drop = drop + 1
  1583.     end
  1584.     T:up(1)
  1585.     T:place("minecraft:bucket", -1, "down", false)
  1586.     T:up(drop - 1)
  1587.     T:place(preferredBlock, -1, "down", false)
  1588.     T:up(1)
  1589.     T:place("minecraft:water_bucket", -1, "down", false)   
  1590.     T:go("F1U2")
  1591.     T:place("slab", -1, "down", false)
  1592.     T:go("R2F2")
  1593.     T:place("slab", -1, "down", false)
  1594. end
  1595.  
  1596. function createFarm(extend)
  1597.     lib = {}
  1598.     function lib.addWaterSource(pattern)
  1599.         -- pattern = {"d","c","c","d"}
  1600.         T:go("D1x2C2")
  1601.         for i = 1, 4 do
  1602.             T:dig("forward")
  1603.             if pattern[i] == "d" then
  1604.                 T:place("minecraft:dirt", -1, "forward", false)
  1605.             elseif pattern[i] == "c" then
  1606.                 T:place("minecraft:cobblestone", -1, "forward", false)
  1607.             end
  1608.             T:turnRight(1)
  1609.         end
  1610.         T:up(1)
  1611.         T:place("minecraft:water_bucket", -1, "down")
  1612.     end
  1613.    
  1614.     function lib.placeDirt(count, atCurrent)
  1615.         if atCurrent then
  1616.             local blockType = T:getBlockType("down")
  1617.             if blockType ~= "minecraft:dirt" and blockType ~= "minecraft:grass_block" then
  1618.                 T:place("minecraft:dirt", -1, "down", false)
  1619.             end
  1620.         end
  1621.         for  i = 1, count do
  1622.             T:forward(1)
  1623.             T:dig("up")
  1624.             local blockType = T:getBlockType("down")
  1625.             if blockType ~= "minecraft:dirt" and blockType ~= "minecraft:grass_block" then
  1626.                 T:place("minecraft:dirt", -1, "down", false)
  1627.             end
  1628.         end
  1629.     end
  1630.    
  1631.     -- extend "", "right" or "forward". only adds a single new farm.
  1632.     -- right adds farm and checks for existing front extensions, dealt with separately
  1633.     -- clsTurtle.place(blockType, damageNo, direction, leaveExisting)
  1634.     if extend == nil then
  1635.         extend = ""
  1636.     end
  1637.     local blockType = ""
  1638.     -- extend = "right": placed on cobble corner of existing farm facing right side
  1639.     -- extend = "front": placed on cobble corner of existing farm facing front
  1640.     -- else placed on ground at corner of potential new farm facing front
  1641.    
  1642.     -- step 1 dig ditch round perimeter wall
  1643.     if extend == "right" then
  1644.         -- move to front corner
  1645.         T:forward(12) -- over wall of existing farm, will be empty below if not extended
  1646.         blockType = T:getBlockType("down")
  1647.         if blockType == "minecraft:cobblestone" then -- already a farm extension on left side
  1648.             T:go("R1F1D1")
  1649.         else
  1650.             T:go("D1R1F1x0")
  1651.         end
  1652.         -- cut ditch round new farm extension
  1653.         for i = 1, 11 do
  1654.             T:go("x0F1")
  1655.         end
  1656.         T:go("R1x0")
  1657.         for i = 1, 13 do
  1658.             T:go("x0F1")
  1659.         end
  1660.         T:go("R1x0")
  1661.         -- now at lower right corner. if extension below, do not cut ditch
  1662.         blockType = T:getBlockType("forward")
  1663.         if blockType == "minecraft:cobblestone" then -- already a farm extension below
  1664.             -- return to start for adding chests and walls
  1665.             T:go("U1R1F1L1F12R1")
  1666.         else -- finish ditch
  1667.             for i = 1, 12 do
  1668.                 T:go("x0F1")
  1669.             end
  1670.             T:go("R1U1F1") -- on corner of new extension
  1671.         end
  1672.     elseif extend == "forward" then
  1673.         -- cut ditch round new farm extension
  1674.         T:go("L1F1x0R1D1")
  1675.         for i = 1, 12 do
  1676.             T:go("x0F1")
  1677.         end
  1678.         T:go("R1x0")
  1679.         for i = 1, 13 do
  1680.             T:go("x0F1")
  1681.         end
  1682.         T:go("R1x0")
  1683.         for i = 1, 11 do
  1684.             T:go("x0F1")
  1685.         end
  1686.         T:go("U1x0F1R1F12R1") -- on corner of new extension
  1687.     else -- new farm. cut a groove round the entire farm base
  1688.         -- move to left side of intended wall
  1689.         T:go("L1F1x0R1")
  1690.         for j = 1, 4 do
  1691.             for i = 1, 12 do
  1692.                 T:go("x0F1")
  1693.             end
  1694.             T:go("R1x0F1")
  1695.         end
  1696.         T:go("R1F1L1U1")
  1697.     end
  1698.     -- stage 2 place sapling and double chest
  1699.     T:dig("down") --remove cobble if present
  1700.     T:place("minecraft:dirt", -1, "down", false)
  1701.     T:go("F1R2")
  1702.     T:place("sapling", -1, "forward", false) -- plant sapling
  1703.     T:go("L1")
  1704.     T:dig("down")
  1705.     T:place("minecraft:chest", -1, "down", false)-- place chest below
  1706.     T:go("L1F1R1")
  1707.     T:dig("down")
  1708.     T:place("minecraft:chest", -1, "down", false) -- place chest 2 below
  1709.     T:turnLeft(1)
  1710.     if extend == "right" then -- cobble wall exists so go forward to its end
  1711.         T:forward(9)
  1712.     else -- new farm or extend forward
  1713.         for i = 1, 9 do -- complete left wall to end of farm
  1714.             T:go("F1x0x2C2")
  1715.         end
  1716.     end
  1717.     T:go("R1F1R1x0x2C2F1D1")-- turn round ready for first dirt col
  1718.     lib.addWaterSource({"d","c","c","d"}) -- water at top of farm
  1719.     lib.placeDirt(9, false) -- place dirt back to start
  1720.     lib.addWaterSource({"c","c","d","d"}) -- water source next to chests
  1721.     T:go("U1F1R2")
  1722.     if T:getBlockType("down") ~= "minecraft:chest" then
  1723.         T:dig("down")
  1724.         T:place("minecraft:chest", -1, "down", false)
  1725.     end
  1726.     T:go("R1F1L1")
  1727.     if T:getBlockType("down") ~= "minecraft:chest" then
  1728.         T:dig("down")
  1729.         T:place("minecraft:chest", -1, "down", false)
  1730.     end
  1731.     T:go("F1D1")
  1732.     lib.placeDirt(9, true)
  1733.     local turn = "R"
  1734.     for i = 1, 7 do
  1735.         T:go("F1U1x0C2"..turn.."1F1"..turn.."1x0x2C2F1D1")
  1736.         lib.placeDirt(9, true)
  1737.         if turn == "R" then
  1738.             turn = "L"
  1739.         else
  1740.             turn = "R"
  1741.         end
  1742.     end
  1743.     T:go("F1U1x0C2"..turn.."1F1"..turn.."1x0x2C2F1D1")
  1744.     lib.addWaterSource({"d","c","c","d"})
  1745.     lib.placeDirt(9, false)
  1746.     lib.addWaterSource({"c","c","d","d"})
  1747.     T:go("F1U1R1C2x0F1x0x2C2R1")
  1748.     for i = 1, 11 do
  1749.         T:go("F1x0x2C2")
  1750.     end
  1751.     -- add chest to any existing farm extension to the right
  1752.     T:go("L1F1L1")
  1753.     if T:getBlockType("down") ~= "minecraft:cobblestone" then -- farm extension already exists to right
  1754.         T:place("minecraft:chest", -1, "down", false) --single chest marks this as an extension
  1755.     end
  1756.     T:go("L1F11")
  1757. end
  1758.  
  1759. function createFarmExtension()
  1760.     -- assume inventory contains 4 chests, 64 cobble, 128 dirt, 4 water, 1 sapling
  1761.     -- check position by rotating to face tree/sapling
  1762.     local doContinue = true
  1763.     local treePresent = false
  1764.     local blockType = T:getBlockType("down")
  1765.     local extend = "right" -- default
  1766.     if blockType ~= "minecraft:chest" then
  1767.         T:clear()
  1768.         print("Chest not present below\n")
  1769.         print("Unable to calculate position")
  1770.         print("Move me next to/front of the tree / sapling")
  1771.         print("lower left corner of the existing farm.")
  1772.         doContinue = false
  1773.     else
  1774.         for i = 1, 4 do
  1775.             blockType = T:getBlockType("forward")
  1776.             if blockType:find("log") ~= nil or blockType:find("sapling") ~= nil then
  1777.                 treePresent = true
  1778.                 break
  1779.             end
  1780.             T:turnRight()
  1781.         end
  1782.         if not treePresent then
  1783.             T:clear()
  1784.             print("Unable to locate tree or sapling")
  1785.             print("Plant a sapling on the lower left")
  1786.             print("corner of the farm, or move me there")
  1787.             doContinue = false
  1788.         end
  1789.     end
  1790.     if doContinue then -- facing tree. check if on front or l side of farm
  1791.         T:go("R1F1D1") -- will now be over water if at front
  1792.         if T:getBlockType("down"):find("water") == nil then
  1793.             extend = "forward"
  1794.         end
  1795.         T:go("R2U1F1L1") -- facing away from tree, either to front or right
  1796.         T:forward(9)
  1797.         -- if tree or sapling in front warn and stop
  1798.         blockType = T:getBlockType("forward")
  1799.         if blockType:find("log") ~= nil or blockType:find("sapling") ~= nil then
  1800.             doContinue = false
  1801.         else
  1802.             T:forward(1) -- on corner ? cobble
  1803.             blockType = T:getBlockType("down")
  1804.             if blockType ~= "minecraft:cobblestone" then
  1805.                 doContinue = false
  1806.             end
  1807.         end
  1808.         if doContinue then -- extend farm.
  1809.             if extend == "right" then
  1810.                 T:turnLeft(1)
  1811.             end
  1812.             createFarm(extend)
  1813.         else
  1814.             T:clear()
  1815.             print("This farm has already been extended")
  1816.             print("Move me next to/front of the tree / sapling")
  1817.             print("of the last extension in this direction.")
  1818.         end
  1819.     end
  1820. end
  1821.  
  1822. function createHollow(width, length, height)
  1823.     -- this function currently not used
  1824.     --should be in bottom left corner at top of structure
  1825.     -- dig out blocks in front and place to the left side
  1826.     --go(path, useTorch, torchInterval, leaveExisting)
  1827.     -- go @# = place any block up/forward/down # = 0/1/2
  1828.     for h = 1, height do
  1829.         for i = 1, length - 1 do
  1830.             T:go("L1@1R1F1", false, 0, true)
  1831.         end
  1832.         T:go("L1@1R2", false, 0, true, false)
  1833.         for i = 1, width - 1 do
  1834.             T:go("L1@1R1F1", false, 0, true)
  1835.         end
  1836.         T:go("L1@1R2", false, 0, true, false)
  1837.         for i = 1, length - 1 do
  1838.             T:go("L1@1R1F1", false, 0, true)
  1839.         end
  1840.         T:go("L1@1R2", false, 0, true, false)
  1841.         for i = 1, width - 1 do
  1842.             T:go("L1@1R1F1", false, 0, true)
  1843.         end
  1844.         T:go("L1@1R2", false, 0, true, false)
  1845.         -- hollowed out, now clear water/ blocks still present
  1846.         clearRectangle(width, length)
  1847.         if h < height then
  1848.             T:down(1)
  1849.         end
  1850.     end
  1851. end
  1852.  
  1853. function createLadder(destination, level, destLevel)
  1854.     -- go(path, useTorch, torchInterval, leaveExisting)
  1855.     -- place(blockType, damageNo, direction, leaveExisting)
  1856.    
  1857.     local ledge = 0
  1858.     if destLevel == nil then destLevel = 1 end
  1859.     if destination == "surface" then -- create ladder from current level to height specified
  1860.         -- check if extending an existing ladder
  1861.         local top = destLevel - level --height of ladder
  1862.         local height = 1
  1863.         local extend = true
  1864.         if T:getBlockType("down") ~= "minecraft:ladder" then -- no ladder below, not extension
  1865.             T:go("C1U1C1U1", false, 0, true)-- place lower 2 blocks
  1866.             height = 2
  1867.             top = top - 2
  1868.             extend = false -- not extending existing ladder
  1869.         end
  1870.         for i = 1, top do
  1871.             for i = 1, 4 do
  1872.                 if i ~= 3 then
  1873.                     T:go("C1R1", false, 0, true)
  1874.                 else
  1875.                     T:turnRight(1)
  1876.                 end
  1877.             end
  1878.             if i < top then
  1879.                 T:up(1)
  1880.                 height = height + 1
  1881.             end
  1882.         end
  1883.         T:go("R2F1L2", false, 0, true) -- face wall previously built
  1884.         for i = top, 1, -1 do
  1885.             ledge = ledge + 1
  1886.             if ledge >= 3 then
  1887.                 ledge = 0
  1888.                 T:fillVoid("up", "", false)
  1889.             end
  1890.             -- Place cobble on 3 sides (if required)
  1891.             for j = 1, 4 do
  1892.                 if j == 1 then -- place ladder on first side
  1893.                     T:place("minecraft:ladder", -1, "forward", false)
  1894.                 else
  1895.                     T:fillVoid("forward", "", false)
  1896.                 end
  1897.                 T:turnLeft(1)
  1898.             end
  1899.             if i > 1 then
  1900.                 T:down(1)
  1901.             end
  1902.         end
  1903.         if not extend then
  1904.             for i = 1, 2 do
  1905.                 T:down(1)
  1906.                 T:place("minecraft:ladder", -1, "forward", false)
  1907.             end
  1908.         end
  1909.        
  1910.     else -- ladder to bedrock
  1911.         -- dig shaft to bedrock and close all sides except facing
  1912.         -- create a working area at the base
  1913.         -- Return to surface facing towards player placing ladders
  1914.         local height = 0
  1915.         local success = true
  1916.         local numBlocks, errorMsg
  1917.         while success do --success = false when hits bedrock
  1918.             height = height + 1
  1919.             for i = 1, 4 do
  1920.                 if i ~= 1 then
  1921.                     T:fillVoid("forward", "", false)
  1922.                 end
  1923.                 T:turnRight(1)
  1924.             end
  1925.             success, numBlocks, errorMsg = T:down(1)
  1926.             -- if turtle does not delete source blocks place and dig a block above
  1927.             if not T:place("minecraft:netherrack", -1, "up", true) then
  1928.                 T:place("minecraft:cobblestone", -1, "up", true)
  1929.             end
  1930.             T:dig("up")
  1931.         end
  1932.         -- test to check if on safe level immediately above tallest bedrock
  1933.         height = T:findBedrockTop(height)
  1934.         -- In shaft, facing start direction, on lowest safe level
  1935.         -- create a square space round shaft base, end facing original shaft, 1 space back
  1936.         -- place ladder on back of column for mining marker
  1937.         T:go("F1R1m1R1m2R1m2R1m2R1F1R1F1C1U1C1D1R2F1R2", false, 0, true)
  1938.         T:go("R1F1L1F3L1F1R1F1C1R2", false, 0, true)
  1939.         T:place("minecraft:ladder", -1, "forward", true)
  1940.         T:go("U1C0F1C0L1F1R1F3R1F1R1D1", false, 0, true)
  1941.         ledge = 0
  1942.         --local atBedrock = true
  1943.         for i = height, 0, -1 do
  1944.             if ledge >= 3 then
  1945.                 ledge = 0
  1946.                 T:fillVoid("down", "", false)
  1947.             elseif ledge == 1 then
  1948.                 T:place("minecraft:torch", -1, "down")
  1949.             end
  1950.             -- Place cobble on 3 sides (if required)
  1951.             for j = 1, 4 do
  1952.                 if j == 1 then -- place ladder on first side
  1953.                     T:place("minecraft:ladder", -1, "forward", false)
  1954.                 else
  1955.                     T:fillVoid("forward", "", false)
  1956.                 end
  1957.                 T:turnLeft(1)
  1958.             end
  1959.             T:up(1)
  1960.             ledge = ledge + 1
  1961.         end
  1962.     end
  1963. end
  1964.  
  1965. function createLadderToWater()
  1966.     -- go down to water/lava with alternaate solid/open layers
  1967.     -- create a working area at the base
  1968.     -- Return to surface facing towards player placing ladders
  1969.     local inAir = true
  1970.     local numBlocks, errorMsg
  1971.     local block, blockType
  1972.     local height = 2
  1973.     T:go("R2D2", false, 0, true) -- face player, go down 2
  1974.     while inAir do --success = false when hits water/lava
  1975.         T:go("C1R1C1R2C1R1", false, 0, true)
  1976.         T:go("D1C1", false, 0, true)
  1977.         height = height + 1
  1978.         block, blockType = T:isWaterOrLava("down")
  1979.         if string.find(block, "water") ~= nil or string.find(block, "lava") ~= nil then
  1980.             inAir = false
  1981.         else
  1982.             T:down(1)
  1983.             height = height + 1
  1984.         end
  1985.     end
  1986.     -- In shaft, facing opposite start direction, on water/lava
  1987.     -- create a square space round shaft base, end facing original shaft, 1 space back
  1988.     T:go("R2C2F1C2F1C2R1", false, 0, true)
  1989.     T:go("F1C2F1C2R1", false, 0, true)
  1990.     T:go("F1C2F1C2F1C2F1C2R1", false, 0, true)
  1991.     T:go("F1C2F1C2F1C2F1C2R1", false, 0, true)
  1992.     T:go("F1C2F1C2F1C2F1C2R1", false, 0, true)
  1993.     T:go("F2R1F1", false, 0, true) -- under the upward pillar
  1994.  
  1995.     for i = height, 0, -1 do
  1996.         T:go("C2e1U1")
  1997.     end
  1998.     T:down(1)
  1999. end
  2000.  
  2001. function createMine()
  2002.     T:clear()  
  2003.     T:go("m32U1R2M16", true, 8) -- mine ground level, go up, reverse and mine ceiling to mid-point
  2004.     T:go("U2D2") -- create space for chest
  2005.     T:place("minecraft:chest", -1, "up", false)
  2006.     T:emptyTrash("up")
  2007.     T:go("D1R1m16U1R2M16", true, 8) -- mine floor/ceiling of right side branch
  2008.     T:emptyTrash("up")
  2009.     T:go("D1m16U1R2M16", true, 8) -- mine floor/ceiling of left side branch
  2010.     T:emptyTrash("up")
  2011.     T:go("L1M15F1R1D1", true, 8) -- mine ceiling of entry coridoor, turn right
  2012.     T:go("F1x0F1x0n14R1n32R1n32R1n32R1n14F1x0F1U1", true, 8)-- mine floor of 36 x 36 square coridoor
  2013.     T:go("R1F16R2") --return to centre
  2014.     T:emptyTrash("up")
  2015.     T:go("F16R1") --return to entry shaft
  2016.     T:go("F2Q14R1Q32R1Q32R1Q32R1Q14F2R1", true, 8) --mine ceiling of 36x36 square coridoor. return to entry shaft + 1
  2017.     T:go("F16R2") --return to centre
  2018.     T:emptyTrash("up")
  2019.     -- get rid of any remaining torches
  2020.     while T:getItemSlot("minecraft:torch", -1) > 0 do
  2021.         turtle.select(T:getItemSlot("minecraft:torch", -1))
  2022.         turtle.dropUp()
  2023.     end
  2024.     T:go("F16R1F1R1") --return to shaft + 1
  2025.     for i = 1, 8 do
  2026.         T:go("N32L1F1L1", true)
  2027.         T:go("N16L1F"..(i * 2).."R2", true)
  2028.         T:emptyTrash("up")
  2029.         if i < 8 then
  2030.             T:go("F"..(i * 2).."L1N16R1F1R1", true)
  2031.         else
  2032.             T:go("F"..(i * 2).."L1N16L1", true)
  2033.         end
  2034.     end
  2035.     T:go("F17L1") -- close gap in wall, return to ladder + 1
  2036.     for i = 1, 8 do
  2037.         T:go("N32R1F1R1", true)
  2038.         T:go("N16R1F"..(i * 2).."R2", true)
  2039.         T:emptyTrash("up")
  2040.         if i < 8 then
  2041.             T:go("F"..(i * 2).."R1N16L1F1L1", true)
  2042.         else
  2043.             T:go("F"..(i * 2).."R1N16R1", true)
  2044.         end
  2045.     end
  2046.     T:go("F16R1")
  2047.     T:clear()
  2048.     print("Mining operation complete")
  2049. end
  2050.  
  2051. function createMineBase()
  2052.     T:clear()
  2053.     -- check ladder:
  2054.     T:turnRight(2)
  2055.     local blockType, modifier = T:getBlockType("forward")
  2056.     while blockType == "" do
  2057.         T:forward(1)
  2058.         blockType, modifier = T:getBlockType("forward")
  2059.     end
  2060.     if blockType ~= "minecraft:ladder" then -- in correct position
  2061.         -- no ladder, move back 1
  2062.         T:back(1)
  2063.     end
  2064.     -- build pond:
  2065.     T:go("R1F1x0L1F1x0F1x0R1") -- at side wall
  2066.     T:go("F1n4R2n4U1R2Q4R2Q4R2") -- cut pond 3x1
  2067.     T:go("C2F4C2R2F1")
  2068.     T:place("minecraft:water_bucket", 0, "down", false)
  2069.     T:forward(2)
  2070.     T:place("minecraft:water_bucket", 0, "down", false)
  2071.     T:go("F2L1F2R1F1L1") -- at start position
  2072.     --[[
  2073.     T:go("m32U1R2M16D1", true, 8) -- mine ground level, go up, reverse and mine ceiling to mid-point, drop to ground
  2074.     T:go("U1R1A15D1R2m15", false, 0) -- Create roof of coridoor, turn and create lower wall + floor
  2075.     T:go("U1A15D1R2m15U1x0", false, 0) -- Create roof of coridoor, turn and create lower wall + floor
  2076.     T:place("minecraft:chest", -1, "up", false) --place chest in ceiling
  2077.     T:emptyTrash("up")
  2078.     T:go("L1M15F1R1D1", true, 8) -- mine ceiling of entry coridoor, turn right, drop down
  2079.     T:go("F2n14R1n15", true, 8)-- mine floor of first quarter of square
  2080.     T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
  2081.     T:go("F1x0n14R1n32R1n15", true, 8)
  2082.     T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
  2083.     T:go("F1x0n14R1n14F2", true, 8)-- mine floor of last quarter of square
  2084.    
  2085.     T:go("U1R1F16R2D1") --return to centre
  2086.     T:emptyTrash("up")
  2087.     T:go("U1F16R1") --return to entry shaft
  2088.     T:go("F2Q14R1Q15", true, 8) -- mine ceiling of first quarter
  2089.     T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
  2090.     T:go("C0F1Q14R1Q32R1Q15", true, 8) --mine ceiling of second half
  2091.     T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
  2092.     T:go("C0F1Q14R1Q14F2R1", true, 8) -- mine ceiling of last quarter
  2093.     T:go("F16D1") --return to centre
  2094.     T:emptyTrash("up")
  2095.     -- get rid of any remaining torches
  2096.     while T:getItemSlot("minecraft:torch", -1) > 0 do
  2097.         turtle.select(T:getItemSlot("minecraft:torch", -1))
  2098.         turtle.dropUp()
  2099.     end
  2100.    
  2101.     for i = 1, 8 do
  2102.         T:go("N32L1F1L1", true)
  2103.         T:go("N16L1F"..(i * 2).."R2", true)
  2104.         T:emptyTrash("up")
  2105.         T:go("F"..(i * 2).."L1N16R1F1R1", true)
  2106.     end
  2107.     T:go("L1F17L1") -- close gap in wall, return to ladder + 1
  2108.     for i = 1, 8 do
  2109.         T:go("N32R1F1R1", true)
  2110.         T:go("N16R1F"..(i * 2).."R2", true)
  2111.         T:emptyTrash("up")
  2112.         T:go("F"..(i * 2).."R1N16L1F1L1", true)
  2113.     end
  2114.     -- fill water buckets
  2115.     -- return to centre
  2116.     T:go("R1F16R1")]]
  2117.    
  2118.     T:clear()
  2119.     print("Mining operation complete")
  2120. end
  2121.  
  2122. function createMineEnhanced()
  2123.     T:clear()  
  2124.     T:go("m32U1R2M16D1x2", true, 8) -- mine ground level, go up, reverse and mine ceiling to mid-point, drop to ground, excavate
  2125.     T:emptyTrash("down")
  2126.     T:go("U1R1A15D1R2E13m2x2", false, 0) -- Create roof of coridoor, turn and create lower wall + remove floor
  2127.     T:emptyTrash("down")
  2128.     T:go("U1A15D1R2E13m2x2", false, 0) -- Create roof of coridoor, turn and create lower wall + remove floor
  2129.     T:emptyTrash("down")
  2130.     T:go("U1L1M15F1R1D1", true, 8) -- mine ceiling of entry coridoor, turn right, drop down
  2131.     T:go("F2n14R1n15", true, 8)-- mine floor of first quarter of square
  2132.    
  2133.     T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
  2134.     T:go("F1x0n14R1n32R1n15", true, 8)
  2135.     T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
  2136.     T:go("F1x0n14R1n14F2", true, 8)-- mine floor of last quarter of square
  2137.     T:go("U1R1F16R2D1") --return to centre
  2138.     T:emptyTrash("down")
  2139.     T:go("U1F16R1") --return to entry shaft
  2140.     T:go("F2Q14R1Q15", true, 8) -- mine ceiling of first quarter
  2141.     T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
  2142.     T:go("C0F1Q14R1Q32R1Q15", true, 8) --mine ceiling of second half
  2143.     T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
  2144.     T:go("C0F1Q14R1Q14F2R1", true, 8) -- mine ceiling of last quarter
  2145.     T:go("F16D1") --return to centre
  2146.     T:emptyTrash("down")
  2147.     -- get rid of any remaining torches
  2148.     while T:getItemSlot("minecraft:torch", -1) > 0 do
  2149.         turtle.select(T:getItemSlot("minecraft:torch", -1))
  2150.         turtle.dropDown()
  2151.     end
  2152.     --cut access coridoors
  2153.     T:go("U1F2R1F1Q14F1 R1F1L1F1R1F2R1F1L1F1R1 F1Q14F2Q14F1 R1F1L1F1R1F2R1F1L1F1R1F1 Q14F1D1") --ceiling
  2154.     T:go("F1n14F1 R1F1L1F1R1F2R1F1L1F1R1 F1n14F2n14F1 R1F1L1F1R1F2R1F1L1F1R1F1 n14F1U1") --floor, then up
  2155.     T:go("R1F2D1")
  2156.     T:go("R1F1C1B1C1L1C1L1F1C1B1C1L1C1L2")
  2157.     T:emptyTrash("down")
  2158.     T:go("U1F16R1F1R1") --return to entry shaft + 1
  2159.  
  2160.     for i = 1, 8 do
  2161.         T:go("N32L1F1L1", true)
  2162.         if i == 1 then
  2163.             T:go("N16L1F2R2", true)
  2164.             T:emptyTrash("down")
  2165.             T:go("F2L1N16R1F1R1", true)
  2166.         elseif i == 8 then
  2167.             T:go("L1F1R1N16", true)
  2168.             T:emptyTrash("down")
  2169.             T:go("N16R1F1R1", true)
  2170.         else
  2171.             T:go("N16", true)
  2172.             T:emptyTrash("down")
  2173.             T:go("N16R1F1R1", true)
  2174.         end
  2175.     end
  2176.     T:go("L1F16L1") -- return to shaft + 1
  2177.     for i = 1, 8 do
  2178.         T:go("N32R1F1R1", true)
  2179.         if i == 1 then
  2180.             T:go("N16R1F2R2", true)
  2181.             T:emptyTrash("down")
  2182.             T:go("F2R1N16L1F1L1", true)
  2183.         elseif i == 8 then
  2184.             T:go("R1F1L1N16", true)
  2185.             T:emptyTrash("down")
  2186.             T:go("N16R1F1R1", true)
  2187.         else
  2188.             T:go("N16", true)
  2189.             T:emptyTrash("down")
  2190.             T:go("N16L1F1L1", true)
  2191.         end
  2192.     end
  2193.     T:go("L1F15R1") -- return
  2194.     T:clear()
  2195.     print("Mining operation complete")
  2196. end
  2197.  
  2198. function createMobBubbleLift(size)
  2199.     -- size = 0 or 1 (left/right)
  2200.     local lib = {}
  2201.        
  2202.     function lib.down()
  2203.         local moves = 0
  2204.         while turtle.down() do
  2205.             moves = moves + 1
  2206.         end
  2207.         return moves
  2208.     end
  2209.    
  2210.     function lib.up()
  2211.         local moves = 0
  2212.         while turtle.up() do
  2213.             moves = moves + 1
  2214.         end
  2215.         return moves
  2216.     end
  2217.     -- check if dirt or soulsand below
  2218.     local turn = "R"
  2219.     if size == 1 then
  2220.         turn = "L"
  2221.     end
  2222.     local onSand = false
  2223.     local blockType = T:getBlockType("down")
  2224.     if blockType == "minecraft:soul_sand" then
  2225.         onSand = true
  2226.     elseif blockType == "minecraft:dirt" then
  2227.         T:dig("down")
  2228.         if T:place("minecraft:soul_sand", -1, "down", false) then
  2229.             onSand = true
  2230.         end
  2231.     end
  2232.     if onSand then
  2233.         -- check facing sign, rotate if not
  2234.         blockType = T:getBlockType("forward")
  2235.         while blockType:find("sign") == nil do
  2236.             T:turnRight(1)
  2237.             blockType = T:getBlockType("forward")
  2238.         end
  2239.         for i = 1, 3 do
  2240.             -- fill in back and one side, go up
  2241.             if turn == "R" then
  2242.                 T:go("R1C1R1C1R1x1R1U1", false, 0, true)
  2243.             else
  2244.                 T:go("L1C1L1C1L1x1L1U1", false, 0, true)
  2245.             end
  2246.         end
  2247.         for i = 1, 17 do
  2248.             -- tunnel up, filling 3 sides
  2249.             if turn == "R" then
  2250.                 T:go("R1C1R1C1R1x1R1C1U1", false, 0, true)
  2251.             else
  2252.                 T:go("L1C1L1C1L1x1L1C1U1", false, 0, true)
  2253.             end
  2254.         end
  2255.         -- move either left/right 8 blocks, repairing ceiling and sides
  2256.         if turn == "R" then
  2257.             T:go("C0R2C1R1F1C0C1R1C1R2C1L1F1A8", false, 0, true) -- fill top of column
  2258.         else
  2259.             T:go("C0L2C1L1F1C0C1L1C1L2C1R1F1A8", false, 0, true) -- fill top of column
  2260.         end
  2261.         -- turn round, go down 1, forward 7 blocks repairing bottom and sides
  2262.         T:go("D1C1R2X7", false, 0, true)
  2263.         -- turn round, go up, place cobble, forward 4, place cobble
  2264.         T:go("R2U1C2F4C2", false, 0, true)
  2265.         -- turn round forward 1 place water, forward 2, place water
  2266.         T:go("R2F1", false, 0, true)
  2267.         T:place("minecraft:water_bucket", -1, "down", false)
  2268.         T:forward(2)
  2269.         T:place("minecraft:water_bucket", -1, "down", false)
  2270.         T:go("R2F1")
  2271.         repeat
  2272.             -- refill both buckets
  2273.             T:place("minecraft:bucket", -1, "down", false)
  2274.             sleep(0.5)
  2275.             T:place("minecraft:bucket", -1, "down", false)
  2276.             -- back 4, down to solid, place water,
  2277.             for i = 1, 4 do
  2278.                 turtle.back()
  2279.             end
  2280.             local moves = lib.down() -- returns no of blocks descent 0 to 19
  2281.             if moves > 0 then
  2282.                 T:place("minecraft:water_bucket", -1, "forward", false)
  2283.                 T:go("U1C2")
  2284.                 if moves > 1 then
  2285.                     T:place("minecraft:water_bucket", -1, "forward", false)
  2286.                     T:go("U1C2")
  2287.                 end
  2288.             end
  2289.             lib.up() -- 0 - 19
  2290.             T:forward(4)
  2291.         until moves <= 1
  2292.         -- delete water sources and remove cobble
  2293.         T:go("R2F3C1R2F1")
  2294.         for i = 1, 7 do -- go to end of run placing cobble
  2295.             T:go("C2F1")
  2296.         end
  2297.         T:turnRight(2)
  2298.         for i = 1, 7 do -- go to end of run, down 2
  2299.             T:go("x2F1x2")
  2300.         end
  2301.         T:go("R2F7D2")
  2302.         for i = 1, 18 do
  2303.             -- tunnel down, filling all 4 sides
  2304.             T:go("R1C1R1C1R1C1R1C1D1", false, 0, true)
  2305.         end
  2306.         -- turn round, tunnel forward 6 blocks
  2307.         T:go("R2U1F1M5D1R2F1X5")-- end up under drop column
  2308.     else
  2309.         print("Unable to find or place soulsand.\nEnter to continue")
  2310.         read()
  2311.     end
  2312. end
  2313.  
  2314. function createMobFarmCube(blaze)
  2315.     if blaze == nil then blaze = false end
  2316.     local lib = {}
  2317.     function lib.rail(move, isPowered, count)
  2318.         if move ~= "" then
  2319.             T:go(move)
  2320.         end
  2321.         for i = 1, count do
  2322.             if isPowered then
  2323.                 if not T:place("minecraft:powered_rail", -1, "down", false) then
  2324.                     T:place("minecraft:golden_rail", -1, "down", false)
  2325.                 end
  2326.             else
  2327.                 T:place("minecraft:rail", -1, "down", false)
  2328.             end
  2329.             if i < count then
  2330.                 T:forward(1)
  2331.             end
  2332.         end
  2333.     end
  2334.    
  2335.     -- clsTurtle.go(self, path, useTorch, torchInterval, leaveExisting, preferredBlock)
  2336.     -- determine spawner position level 4, move to top of spawner (level 6)
  2337.     local onTop = false
  2338.     local blockType = T:getBlockType("down")
  2339.     if blockType:find("spawner") ~= nil then
  2340.         onTop = true
  2341.     end
  2342.     if not onTop then
  2343.         blockType = T:getBlockType("up")
  2344.         if blockType:find("spawner") ~= nil then
  2345.             T:go("B1U2F1")
  2346.             onTop = true
  2347.         end
  2348.     end
  2349.     if not onTop then
  2350.         blockType = T:getBlockType("forward")
  2351.         if blockType:find("spawner") ~= nil then
  2352.             T:go("U1F1")
  2353.             onTop = true
  2354.         end
  2355.     end
  2356.     if onTop then
  2357.         -- place slab on top T:place(blockType, damageNo, direction, leaveExisting)
  2358.         T:up(1)
  2359.         T:place("slab", -1, "down", true)
  2360.         -- go up 2 blocks, forward 4, right, forward 4, right
  2361.         T:go("U2F4R1F4R1")
  2362.         -- clear 9x9 and plug ceiling (level 9)
  2363.         --"Q": mine block above and/or fill void + mine block below if valuable + left side
  2364.         T:go("R2C1R2Q8R1Q8R1Q8R1Q7R1F1", false, 0, false)
  2365.         -- 7x7 rectangle filling above
  2366.         for i = 1, 3 do
  2367.             T:go("M7R1F1R1M7L1F1L1", false, 0, false)
  2368.         end
  2369.         T:go("M7R2F8R1F7R1", false, 0, false) --back to corner
  2370.         -- mine wall:     q# mine # blocks forward, check left side and patch
  2371.         for i = 1, 2 do
  2372.             -- down 1, clear 9x9 border, checking walls (level 8, 7)
  2373.             T:go("D1R2C1R2q8R1q8R1q8R1q7R1F1",  false, 0, false)
  2374.             -- clear remaining 7x7 area
  2375.             clearRectangle(7, 7, false)
  2376.             T:go("R2F1R1F1R1",  false, 0, false) --back to corner
  2377.         end
  2378.         for i = 1, 2 do
  2379.             -- down 1, clear 9x9 border (level 6, 5)
  2380.             T:go("D1R2C1R2q8R1q8R1q8R1q7R1",  false, 0, false)
  2381.             T:go("F7R1F6R1F6R1F5R1",  false, 0, false)
  2382.             T:go("F5R1F4R1F4R1F6L1F2R2",  false, 0, false)
  2383.         end
  2384.         local count = 3
  2385.         if blaze then
  2386.             count = 2
  2387.         end
  2388.         for i = 1, count do
  2389.             -- down 1, clear 9x9 border, checking walls (level 4, 3, (2))
  2390.             T:go("D1R2C1R2q8R1q8R1q8R1q7R1F1")
  2391.             -- clear remaining 7x7 area
  2392.             clearRectangle(7, 7, false)
  2393.             T:go("R2F1R1F1R1", false, 0, false) --back to corner
  2394.         end
  2395.         if blaze then
  2396.             -- strart in top right corner. border is made of slabs placed up
  2397.             T:go("D1R2F1R1F1R1")
  2398.             for i = 1, 3 do
  2399.                 clearRectangle(11, 11, false) --layer 2, 1, 0
  2400.                 T:down(1)
  2401.             end
  2402.            
  2403.             T:go("R2F1R1F1R1")
  2404.             -- ready to lay floor and border
  2405.             -- q# mine # blocks forward, check left side and patch
  2406.             T:go("R2C1R2 n12R1 n12R1 n12R1 n11R1F1", false, 0, false)
  2407.             --  fill in floor 11x11 rectangle below        
  2408.             local brick = "minecraft:nether_bricks" -- 1.16+ name
  2409.             local a, b, numBricks = T:getItemSlot(brick)
  2410.             if numBricks == 0 then
  2411.                 a, b, numBricks = T:getItemSlot("minecraft:nether_brick") -- pre 1.16+
  2412.                 if numBricks == 0 then
  2413.                     brick = "minecraft:nether_brick"
  2414.                 end
  2415.             end
  2416.             for i = 2, 12 do -- 11 iterations (rows)
  2417.                 T:go("m10", false, 0, false, brick)
  2418.                 if i % 2 == 0 then -- 2, 4, 6, 8, 10
  2419.                     if i < 12 then
  2420.                         T:go("R1F1R1", false, 0, false, brick)
  2421.                     end
  2422.                 else -- 3,5,7,9,11
  2423.                     T:go("L1F1L1", false, 0, false, brick)
  2424.                 end
  2425.             end
  2426.             -- turn 180 and ask for supplies
  2427.             T:go("L1F1L1F1U1") -- lower left corner start
  2428.             T:sortInventory()
  2429.             T:emptyTrashItem("forward", "minecraft:netherrack", 0)
  2430.             T:emptyTrashItem("forward", brick, 128)
  2431.             T:emptyTrashItem("forward", "fence", 0)
  2432.             --clsTurtle.getItemSlot(self, item, useDamage): return slotData.lastSlot, slotData.leastModifier, total, slotData
  2433.             a, b, numBricks = T:getItemSlot(brick)
  2434.             if numBricks > 81 then -- enough for floor
  2435.                 T:checkInventoryForItem({"minecraft:cobblestone"}, {339})
  2436.             else
  2437.                 T:checkInventoryForItem({"minecraft:cobblestone", brick}, {420, 420})
  2438.             end
  2439.             T:checkInventoryForItem({"slab"}, {36})
  2440.             T:checkInventoryForItem({"minecraft:powered_rail", "minecraft:golden_rail"}, {8, 8})
  2441.             T:checkInventoryForItem({"minecraft:rail"}, {64})
  2442.             T:checkInventoryForItem({"minecraft:redstone_torch"}, {2})
  2443.             T:checkInventoryForItem({"minecraft:hopper_minecart"}, {1})
  2444.             T:checkInventoryForItem({"minecraft:stone_button"}, {1})
  2445.             print("Stand clear. Starting in 2 secs")
  2446.             os.sleep(2)    -- pause for 2 secs to allow time to press esc
  2447.             lib.rail("", true, 2) -- lay 2 plain rail at start
  2448.             lib.rail("F1", false, 1) -- lay 1 plain rail
  2449.             lib.rail("F1", true, 3) -- lay 3 powered rail
  2450.             T:go("L1F1")
  2451.             T:place("minecraft:redstone_torch", -1, "down", false) --place redstone torch
  2452.             lib.rail("R2F1L1F1", false, 3)
  2453.             lib.rail("R1F1R1", false, 8)
  2454.             lib.rail("L1F1L1", false, 7)
  2455.             lib.rail("R1F1R1", false, 8)
  2456.             lib.rail("L1F1L1", false, 9)
  2457.             lib.rail("R1F1R1", false, 8)
  2458.             lib.rail("L1F1L1", false, 7)
  2459.             lib.rail("R1F1R1", false, 8)
  2460.             lib.rail("L1F1L1", false, 5) -- final strip
  2461.             lib.rail("F1", true, 3)
  2462.             T:go("F1C2R1F1R1F1")
  2463.             T:place("minecraft:redstone_torch", -1, "down", false)
  2464.             T:go("R2F1L1F1L1U1")
  2465.             -- lay floor 9 x 9 rectangle filling below
  2466.             for i = 2, 10 do -- repeat 9x
  2467.                 T:go("m8", false, 0, false, brick)
  2468.                 if i < 10 then
  2469.                     if i % 2 == 0 then
  2470.                         T:go("R1F1R1", false, 0, false, brick)
  2471.                     else
  2472.                         T:go("L1F1L1", false, 0, false, brick)
  2473.                     end
  2474.                 end
  2475.             end
  2476.             -- replace first rail with cobble and button
  2477.             T:go("R1F1R2D2x1C1B1", false, 0, false)
  2478.             T:place("minecraft:stone_button", -1, "forward", false)
  2479.             T:go("U2F2L1F1x2")
  2480.             T:place("minecraft:hopper_minecart", -1, "down", false)
  2481.             T:go("L1F1D1R2C1", false, 0, false, brick) -- cover minecart
  2482.             T:go("U1R1F2L1C0F1",false, 0, false)
  2483.             -- place slabs
  2484.             for j = 1, 4 do
  2485.                 for i = 1, 9 do
  2486.                     T:place("slab", -1, "up", false)
  2487.                     T:forward(1)
  2488.                 end
  2489.                 if j < 4 then
  2490.                     T:go("L1C0F1")
  2491.                 end
  2492.             end
  2493.             T:go("L1F1L2") -- get in position
  2494.             -- build outer edge
  2495.             for j = 1, 4 do
  2496.                 for i = 1, 9 do
  2497.                     turtle.back()
  2498.                     T:place("minecraft:cobblestone", -1, "forward", false)
  2499.                 end
  2500.                 if j < 4 then
  2501.                     T:turnLeft(1)
  2502.                     turtle.back()
  2503.                     T:place("minecraft:cobblestone", -1, "forward", false)
  2504.                 end
  2505.             end
  2506.             T:go("L1F1R2C1L1U1")
  2507.             for j = 1, 4 do
  2508.                 for i = 1, 11 do
  2509.                     T:go("C0x2F1")
  2510.                 end
  2511.                 T:go("C0x2R1F1")
  2512.             end
  2513.             T:go("R2F2R1F1R1")
  2514.             T:go("R2C1R2Q14R1Q14R1Q14R1Q13R1D1", false, 0, false)
  2515.             T:go("L1F1R1")
  2516.             T:go("R2C1R2n14R1n14R1n14R1n13R1", false, 0, false)
  2517.         else
  2518.             -- clear floor and plug holes
  2519.             -- n# mine block below and/or fill void + check left side
  2520.             T:down(2)
  2521.             for j = 1, 2 do
  2522.                 T:go("R2C1R2n8R1n8R1n8R1n7R1F1",  false, 0, true)
  2523.                 -- 7x7 rectangle filling below
  2524.                 for i = 1, 4 do
  2525.                     if i < 4 then
  2526.                         T:go("m6R1F1R1m6L1F1L1", false, 0, true)
  2527.                     else
  2528.                         T:go("m6R1F1R1m6", false, 0, true)
  2529.                     end
  2530.                 end
  2531.                 if j == 1 then
  2532.                     T:go("U1F1R1F8R1")
  2533.                 end
  2534.             end
  2535.         end
  2536.     else
  2537.         T:clear()
  2538.         print("Spawner not found. Place me on top,")
  2539.         print("immediately below, or facing it.")
  2540.         print("\nEnter to quit")
  2541.         read()
  2542.     end
  2543. end
  2544.  
  2545. function createMobSpawnerBase(pathLength)
  2546.     if pathLength > 0 then
  2547.         print("Building path to mob spawner base")
  2548.         createPath(pathLength)
  2549.         T:back(1)
  2550.     end
  2551.     T:place("stone", -1, "down", true)
  2552.     T:go("R1F1L1", false, 0, true)
  2553.     createPath(8)
  2554.     T:go("L1F1L1F1", false, 0, true)
  2555.     createPath(8)
  2556.     T:go("R1F1R1F1", false, 0, true)
  2557.     createPath(8)
  2558.     T:go("L1F1L1F1", false, 0, true)
  2559.     createPath(8)
  2560.     T:go("L1F2L1F1", false, 0, true)
  2561. end
  2562.  
  2563. function createMobSpawnerTower(height) 
  2564.     height = height or 2
  2565.     print("Building mob spawner base")
  2566.     -- assume placed at sea level on stone block (andesite / granite / diorite)
  2567.     --layers 2, 3 (layer 1 done at base construction)
  2568.     T:go("U1F7H2L1F1H2R1F2D1R2P1L1F1R1P1R2U1", false, 0, true)
  2569.     for i = 1, 8 do
  2570.         T:go("C2R1C1L1F1", false, 0, true)
  2571.     end
  2572.     T:go("L1F1L2C1R1F1R2C1R2", false, 0, true)
  2573.     for i = 1, 8 do
  2574.         T:go("C2R1C1L1F1", false, 0, true)
  2575.     end
  2576.     T:go("U1R2F8R1", false, 0, true)
  2577.     T:place("minecraft:water_bucket", -1, "down", false)
  2578.     T:go("F1R1", false, 0, true)
  2579.     T:place("minecraft:water_bucket", -1, "down", false)
  2580.     T:forward(16)
  2581.     T:go("R1F1D2", false, 0, true)
  2582.     for i = 1, 2 do
  2583.         sleep(0.5)
  2584.         T:place("minecraft:bucket", -1, "down", false)
  2585.     end
  2586.     T:go("R1F2", false, 0, true)
  2587.     for i = 1, 2 do
  2588.         T:go("C1R1C1R2C1R1U1")
  2589.     end
  2590.     -- height of tower
  2591.     height = math.ceil(height / 2)
  2592.     for i = 1, height do
  2593.         T:go("C1U1C1R1C1R1C1R1C1R1U1")
  2594.     end
  2595.     -- create platform for player
  2596.     T:go("R2F1L1C1R1C1R1C1U1C1L1C1L1C1L1F1L1C!R2C1L1U1F1", false, 0, true)
  2597.     -- place stone marker
  2598.     T:place("stone", -1, "down")
  2599.     -- will need to move back before completing
  2600. end
  2601.  
  2602. function createMobSpawnerTank()
  2603.     --layer 1 of tower + walkway
  2604.     -- move back 1 block before continuing with tower top and walkway
  2605.     T:go("R2F1R2")
  2606.     T:go("C1U2R1F1L1") -- now dropping cobble from above
  2607.     T:go("m10L1F1L1")
  2608.     T:go("m9R1F1L1F1C2F1L1F1C2L1F1")
  2609.     --layer 2
  2610.     T:go("U1F1C2R1F1C2F1L1F1m8L1F3L1m8F2L1F1L1")
  2611.     --layer 3
  2612.     T:go("U1R1F1C2L1F1C2")
  2613.     T:go("F1R1F1L1C2F1C2F1L1F1C2")
  2614.     T:go("F1C2F1L1F1C2F1C2F2C2F1")
  2615.     T:go("L1F1C2L1F2C2B1")
  2616.     --layer 4
  2617.     T:go("U1F1L1F1R2")
  2618.     for i = 1, 4 do
  2619.         T:go("F1C2F1C2F1L1")
  2620.     end
  2621.     T:go("F1R1F1R2")
  2622.     --layer 5
  2623.     T:go("U1R2F1m7L1F1L1C2F1C2F7C2F1C2")
  2624.     T:go("F1R1F1L1C2F1C2F1L1F1C2F1C2F1")
  2625.     T:go("L1F1C2F1C2F2C2L1F1L1F1C2R2F1R2")
  2626.     -- layer 6
  2627.     T:go("U1R2F9C2L1F1C2F1L1F1C2F1L1F1C2R1F8L1F2R2")
  2628.     for i = 1, 4 do
  2629.         T:go("F1C2F1C2F1L1")
  2630.     end
  2631.     T:go("F1L1F1")
  2632.     T:place("minecraft:water_bucket", -1, "down")
  2633.     T:go("R1F1L1")
  2634.     T:place("minecraft:water_bucket", -1, "down")
  2635.     T:go("R2F2R1F1R1")
  2636.     -- layer 7
  2637.     T:go("U1R2F8L1F2C2L1F1L1F1C2R1F7C2L1F2R1C2F1R1")
  2638.     for i = 1, 4 do
  2639.         T:go("F1C2F1C2F1L1")
  2640.     end
  2641.     T:go("F1R1F1R2")
  2642.     T:go("F2")
  2643.     -- place stone inside column, ready for temp water source
  2644.     T:place("stone", -1, "down", false)
  2645.    
  2646.     -- layer 8
  2647.     -- make temp water source in centre. destroy in createMobSpawnerRoof()
  2648.     T:go("F1C2R1F1C2R1F1C2F1R1F2U1R2")
  2649.     -- spiral construction
  2650.     for j = 3, 9, 2 do
  2651.         for i = 1, 4 do
  2652.             if i < 4 then
  2653.                 T:go("m"..j.."L1")
  2654.             else
  2655.                 T:go("m"..j.."F1R1F1L2")
  2656.             end
  2657.         end
  2658.     end
  2659.     -- fill water source
  2660.     T:go("F5L1F5")
  2661.     T:place("minecraft:water_bucket", -1, "down", false)
  2662.     T:go("F1R1F1R1")
  2663.     T:place("minecraft:water_bucket", -1, "down", false)
  2664.     T:go("F5m4F2C2F1R1F1C2F1R1F1C2F1R1F1L1C2F1m4")
  2665.     T:go("F8F2m3R1F1R1m3")
  2666.     T:go("F5L1F5m3R1F1R1m3")
  2667.     T:go("F9F2m3R1F1R1m3")
  2668.     -- layer 9
  2669.     T:up(1)
  2670.     for i = 1, 4 do
  2671.         T:go("L1F1L1m3R1F1R1m3L1F1L1m3R1F1R1m3F4")
  2672.         T:go("L1F1L1m7R1F1R1m7L1F1L1m7R1F1R1m7F1L1F1R1C2F1C2R1F4")
  2673.     end
  2674.     -- now add water
  2675.     T:go("F6")
  2676.     for i = 1, 4 do
  2677.         T:down(1)
  2678.         T:place("minecraft:bucket", -1, "down", false)
  2679.         sleep(0.5)
  2680.         T:place("minecraft:bucket", -1, "down")
  2681.         T:go("U1F8R1")
  2682.         T:place("minecraft:water_bucket", -1, "down", false)
  2683.         T:go("F1R1")
  2684.         T:place("minecraft:water_bucket", -1, "down", false)
  2685.         T:go("F8L1")
  2686.     end
  2687.     for i = 1, 2 do
  2688.         T:down(1)
  2689.         T:place("minecraft:bucket", -1, "down", false)
  2690.         sleep(0.5)
  2691.         T:place("minecraft:bucket", -1, "down", false)
  2692.         T:go("U1F4L1F4L1")
  2693.         T:place("minecraft:water_bucket", -1, "down", false)
  2694.         T:go("F9")
  2695.         T:place("minecraft:water_bucket", -1, "down", false)
  2696.         T:go("L1F5L1F4L2")
  2697.     end
  2698.     T:go("F9R1F10R1")
  2699.     -- layer 10 / 11
  2700.     for j = 1, 2 do
  2701.         T:go("U1F1m8L1F1C2F1R1F1C2F1R1F1C2F1R1F1R2m8F1R1")
  2702.         for i = 1, 3 do
  2703.             T:go("F1m17F1R1")
  2704.         end
  2705.     end
  2706.     T:go("F10R1F9D4")
  2707. end
  2708.  
  2709. function createMobSpawnerRoof()
  2710.     -- destroy water source first
  2711.     T:go("x2C1R1F1x2L1F1x2L1F1x2L1F1x2L2")
  2712.     T:go("U5L1F8L1F8L2") -- top left corner facing e
  2713.     T:go("m17R1m17R1m17R1m17") -- outer ring. ends facing n
  2714.     T:go("R1F2R1F1L1") -- facing e
  2715.     for i = 1, 4 do -- outer ring - 1 (with torches) ends facing e
  2716.         T:go("m6t1m3t1m5R1F1t1")
  2717.     end
  2718.     T:go("R1F1L1") -- facing e
  2719.     for i = 1, 4 do -- outer ring - 2 ends facing e
  2720.         T:go("m13R1m13R1m13R1m13")
  2721.     end
  2722.     T:go("R1F1L1") -- ends facing e
  2723.     T:go("m11R1m11R1m11R1m11") -- ends facing e
  2724.     T:go("R1F1R1F1L1F1")
  2725.     for i = 1, 4 do
  2726.         T:go("m8R1F1t1")
  2727.     end
  2728.     T:go("R1F1L1")
  2729.     T:go("m7R1m7R1m7R1m7")
  2730.     T:go("R1F1R1F1L1")
  2731.     T:go("m5R1m5R1m5R1m5")
  2732.     T:go("R1F1R1F1L1F1")
  2733.     for i = 1, 4 do
  2734.         T:go("m2R1F1t1")
  2735.     end
  2736.     T:go("R1F1L1")
  2737.     T:go("m1R1m1R1m1R1m1")
  2738. end
  2739.  
  2740. function createPath(length, isCanal)
  2741.     length = length or 0 --allow for choice of path length
  2742.     if isCanal == nil then
  2743.         isCanal = false
  2744.     end
  2745.     local numBlocks = 1
  2746.     local path = 0
  2747.     local distance = 0
  2748.     local torch = 0
  2749.     local continue = true
  2750.     local slot = 0
  2751.     local place = clearVegetation("down") --true if water, lava, or air below
  2752.     if place then
  2753.         T:fillVoid("down", "", false)
  2754.     end
  2755.     T:forward(1)
  2756.     place = clearVegetation("down")
  2757.     --while string.find(blockType, "water") ~= nil or string.find(blockType, "lava") ~= nil or blockType == "" do
  2758.     while place do -- while air, water or lava below
  2759.         continue = T:fillVoid("down", "", false)
  2760.         if continue then -- false if out of blocks
  2761.             T:forward(1)
  2762.             numBlocks = numBlocks + 1
  2763.             distance = distance + 1
  2764.             torch = torch + 1
  2765.             slot = T:getItemSlot("minecraft:torch", -1)
  2766.             if torch == 8 and slot > 0 then
  2767.                 torch = 0
  2768.                 T:turnRight(2)
  2769.                 T:place("minecraft:torch", -1, "forward", false)
  2770.                 T:turnRight(2)
  2771.             end
  2772.         else
  2773.             break
  2774.         end
  2775.         path = path + 1
  2776.         if length > 0 and path >= length then
  2777.             break
  2778.         end
  2779.         place = clearVegetation("down")
  2780.     end
  2781.     if continue and not isCanal then
  2782.         T:forward(1)
  2783.     end
  2784.     return numBlocks
  2785. end
  2786.  
  2787. function createPortal()
  2788.     T:go("D1x1", false, 0, true)
  2789.     T:place("minecraft:cobblestone", 0, "forward", true)
  2790.     for i = 1, 3 do
  2791.         T:go("U1x1", false, 0, true)
  2792.         T:place("minecraft:obsidian", 0, "forward", true)
  2793.     end
  2794.     T:go("U1x1", false, 0, true)
  2795.     T:place("minecraft:cobblestone", 0, "forward", true)
  2796.     for i = 1, 2 do
  2797.         T:go("R1F1L1x1")
  2798.         T:place("minecraft:obsidian", 0, "forward", true)
  2799.     end
  2800.     T:go("R1F1L1x1", false, 0, true)
  2801.     T:place("minecraft:cobblestone", 0, "forward", true)
  2802.     for i = 1, 3 do
  2803.         T:go("D1x1")
  2804.         T:place("minecraft:obsidian", 0, "forward", true)
  2805.     end
  2806.     T:go("D1x1", false, 0, true)
  2807.     T:place("minecraft:cobblestone", 0, "forward", true)
  2808.     for i = 1, 2 do
  2809.         T:go("L1F1R1x1")
  2810.         T:place("minecraft:obsidian", 0, "forward", true)
  2811.     end
  2812.     T:go("U1L1F1R1", false, 0, true)
  2813. end
  2814.  
  2815. function createRailwayDown(userChoice, drop)
  2816.     --make sure torch placed on lowest level
  2817.     -- 1 block not required
  2818.     -- 2 - 3 blocks 1 torch at base
  2819.     -- 4 - 6 blocks 2 torch
  2820.     --
  2821.     for i = 1, drop - 1 do
  2822.         T:go("F1D1", false, 0, true)
  2823.         T:place(userChoice, -1, "down", false)
  2824.     end
  2825. end
  2826.  
  2827. function createRailwayUp(userChoice, up)
  2828.     for i = 1, up do
  2829.         T:place(userChoice, -1, "forward", false)
  2830.         T:go("U1F1", false, 0, true)
  2831.     end
  2832. end
  2833.  
  2834. function createRetainingWall(length, height)
  2835.     local place = false
  2836.     if height <= 0 then
  2837.         height = 30
  2838.     end
  2839.     local inWater = false
  2840.     for i = 1, 4 do
  2841.         if string.find(T:getBlockType("forward"), "water") ~= nil then
  2842.             inWater = true
  2843.         end
  2844.         T:turnRight(1)
  2845.     end
  2846.    
  2847.     local y = 1
  2848.     -- go(path, useTorch, torchInterval, leaveExisting)
  2849.     -- start at surface, move back 1 block
  2850.     -- each iteration completes 3 columns
  2851.     local numBlocks = T:getSolidBlockCount()
  2852.    
  2853.     if not inWater then
  2854.         T:down(1)
  2855.     end
  2856.     place = clearVegetation("down") -- returns true if air, water or lava below
  2857.     if length == 1 then --single column
  2858.         local place = clearVegetation("down")
  2859.         while place do -- loop will be entered at least once
  2860.             T:down(1)
  2861.             y = y + 1
  2862.             place = clearVegetation("down")
  2863.         end
  2864.         for i = 1, y - 1  do
  2865.             T:go("U1C2", false, 0, true, false)
  2866.         end
  2867.     elseif length == 2 then--down then up
  2868.         T:back(1) -- move 1 block away from wall edge
  2869.         local place = clearVegetation("down")
  2870.         while place do -- loop will be entered at least once
  2871.             T:go("C1D1", false, 0, true, false)
  2872.             y = y + 1
  2873.             place = clearVegetation("down")
  2874.         end
  2875.         T:forward(1) -- in case col in front is deeper
  2876.         place = clearVegetation("down")
  2877.         while place do -- loop will be entered at least once
  2878.             T:down(1)
  2879.             y = y + 1
  2880.             place = clearVegetation("down")
  2881.         end
  2882.         T:go("B1C1", false, 0, true)
  2883.         for i = 1, y - 1 do
  2884.             T:go("U1C2", false, 0, true)
  2885.         end
  2886.         T:go("C1", false, 0, true, false)
  2887.     else -- length 3 or more eg 3,22; 11
  2888.         local remain = length % 3 -- 0; 1; 2 only possible results
  2889.         length = length - remain -- 3-0=3; 4-1=3; 5-2=3; 6-0=6
  2890.         for i = 3, length, 3 do -- 3, 6, 9, 12 etc
  2891.             numBlocks = T:getSolidBlockCount()
  2892.             if numBlocks < height * 3 then
  2893.                 --ask player for more
  2894.                 T:checkInventoryForItem({"minecraft:cobblestone",  "minecraft:dirt"}, {height * 3, height * 3}, false)
  2895.             end
  2896.             T:go("B1C1", false, 0, true)
  2897.             if i > 3 then -- second iteration
  2898.                 T:go("B1C1")
  2899.             end
  2900.             -- place blocks forward while descending
  2901.             place = clearVegetation("down")
  2902.             while place do -- loop will be entered at least once
  2903.                 T:go("C1D1", false, 0, true)
  2904.                 y = y + 1
  2905.                 place = clearVegetation("down")
  2906.             end
  2907.             T:forward(1) -- in case col in front is deeper
  2908.             place = clearVegetation("down")
  2909.             while place do -- loop will be entered at least once
  2910.                 T:down(1)
  2911.                 y = y + 1
  2912.                 place = clearVegetation("down")
  2913.             end
  2914.             while not turtle.detectUp() do  -- go up until column base is met
  2915.                 T:go("U1C2")
  2916.                 y = y - 1
  2917.                 if y < 0 then
  2918.                     break
  2919.                 end
  2920.             end
  2921.             T:go("B1C1B1", false, 0, true)
  2922.             -- return to surface, placing forward and below
  2923.             for i = 1, y - 1 do
  2924.                 T:go("C1U1C2", false, 0, true)
  2925.             end
  2926.             -- put missing block down
  2927.             T:go("C1", false, 0, true)
  2928.             y = 1 -- reset counter
  2929.         end
  2930.         if remain == 1 then -- 1 more column
  2931.             y = 1
  2932.             T:back(1)
  2933.             place = clearVegetation("down")        
  2934.             while place do -- loop will be entered at least once
  2935.                 T:down(1)
  2936.                 y = y + 1
  2937.                 place = clearVegetation("down")
  2938.             end
  2939.             for i = 1, y - 1 do
  2940.                 T:go("U1C2", false, 0, true)
  2941.             end
  2942.             -- put missing block down
  2943.             T:go("C1", false, 0, true)
  2944.         elseif remain == 2 then -- 2 cols
  2945.             y = 1
  2946.             T:back(1)
  2947.             place = clearVegetation("down")
  2948.             while place do -- loop will be entered at least once
  2949.                 T:go("C1D1", false, 0, true)
  2950.                 y = y + 1
  2951.                 place = clearVegetation("down")
  2952.             end
  2953.             T:forward(1)
  2954.             place = clearVegetation("down")
  2955.             while place do
  2956.                 T:down(1)
  2957.                 y = y + 1
  2958.                 place = clearVegetation("down")
  2959.             end
  2960.             T:go("B1C1", false, 0, true)
  2961.             for i = 1, y - 1 do
  2962.                 T:go("U1C2", false, 0, true)
  2963.             end
  2964.             -- put missing block down
  2965.             T:go("C1", false, 0, true)
  2966.         end
  2967.     end
  2968. end
  2969.  
  2970. function createSandWall(length)
  2971.     length = length or 0
  2972.     local success = true
  2973.     --move above water
  2974.     local maxMove = 2
  2975.     while turtle.detectDown() and maxMove > 0 do
  2976.         T:forward(1)
  2977.         maxMove = maxMove - 1
  2978.     end
  2979.     if length > 0 then
  2980.         for i = 1, length - 1 do
  2981.             success = dropSand()
  2982.             T:forward(1, false)
  2983.         end
  2984.         success = dropSand()
  2985.     else
  2986.         while not turtle.detectDown() do -- over water
  2987.             while not turtle.detectDown() do -- nested to allow forward movement
  2988.                 success = dropSand() -- drops sand and checks supplies
  2989.             end
  2990.             if success then
  2991.                 T:forward(1, false)
  2992.             else -- out of sand
  2993.                 break
  2994.             end
  2995.         end
  2996.     end
  2997. end
  2998.  
  2999. function createSolid(width, length, height)
  3000.     -- this function currently not used
  3001.     for i = 1, width do --width could be 1, 2, 3 etc
  3002.         createRetainingWall(length, height)
  3003.         if i < width then --width = 2 or more
  3004.             if i == 1 or i % 2 == 1 then -- iteration 1, 3, 5
  3005.                 T:go("L1F1L2C1R1", false, 0, true)
  3006.             else
  3007.                 T:go("R1F1R2C1L1", false, 0, true)
  3008.             end
  3009.         end
  3010.     end
  3011. end
  3012.  
  3013. function createStaircase(destination, level)
  3014.     -- R# L# F# B# U# D# +0 -0 = Right, Left, Forward, Back, Up, Down, up while detect and return, down while not detect
  3015.     -- dig:           x0,x1,x2 (up/fwd/down)
  3016.     -- suck:          s0,s1,s2
  3017.     -- place chest:   H0,H1,H2
  3018.     -- place sapling: S0,S1,S2
  3019.     -- place Torch:   T0,T1,T2
  3020.     -- place Hopper:  P0,P1,P2
  3021.     -- mine floor:    m# = mine # blocks above and below, checking for valuable items below, and filling space with cobble or dirt
  3022.     -- mine ceiling:  M# = mine # blocks, checking for valuable items above, and filling space with cobble or dirt
  3023.     -- mine ceiling:  N# same as M but not mining block below unless valuable
  3024.     -- 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
  3025.    
  3026.     -- 3| |B| |
  3027.     --   - - -
  3028.     -- 2|A| |C|
  3029.     --   - - -
  3030.     -- 1|^|D| |
  3031.     --   - - -
  3032.     --   1 2 3
  3033.  
  3034.     local height = level -- eg 64 at top or 5 at bedrock
  3035.     local data = T:getStock("stone_stairs")
  3036.     --{rt.total, rt.mostSlot, rt.leastSlot, rt.mostCount, rt.leastCount}
  3037.     local numStairs = data.total
  3038.     local numStairsNeeded = 0
  3039.     if destination == "bedrock" then
  3040.         numStairsNeeded = math.ceil(level / 4) * 4
  3041.     else
  3042.         numStairsNeeded = math.ceil((64 - level) / 4) * 4
  3043.     end
  3044.     numStairsNeeded = numStairsNeeded - numStairs
  3045.     print('crafting '..numStairsNeeded..'  '..numStairs.. ' in stock')
  3046.     if numStairsNeeded >  40 then
  3047.         T:craft('stone_stairs', 40) -- max 40 so repeat
  3048.         data = T:getStock("stone_stairs")
  3049.         if data.total == 0 then
  3050.             data = T:getStock("stone_stairs")
  3051.         end
  3052.         numStairs = data.total
  3053.         numStairsNeeded = numStairsNeeded - numStairs
  3054.     end
  3055.     if numStairsNeeded >  0 then
  3056.         T:craft('stone_stairs', numStairsNeeded)
  3057.     end
  3058.     if destination == "bedrock" then -- go down to bedrock
  3059.         while T:down() do
  3060.             height = height - 1
  3061.         end
  3062.         height = T:findBedrockTop(height) -- usually around 5
  3063.         T:go("R1F1R1", false, 0, true)
  3064.     end
  3065.     local onGround = true
  3066.     local top = (math.ceil((64 - height) / 4) * 4) + 4 + height
  3067.  
  3068.     for i = height, top, 4 do
  3069.         for x = 1, 4 do
  3070.             onGround = createStaircaseSection(onGround)
  3071.         end
  3072.     end
  3073.     -- continue while block found above
  3074.     while T:getBlockType('up') ~= "" do
  3075.         onGround = createStaircaseSection(onGround)
  3076.     end
  3077. end
  3078.  
  3079. function createStaircaseSection(onGround)
  3080.     -- start 1,1,1, n
  3081.     -- stage A
  3082.     local data = T:getStock("stone_stairs")
  3083.     if data.total == 0 then
  3084.         T:craft('stone_stairs', 4)
  3085.     end
  3086.     T:go("L1C1R1F1L1C1R1C1R1C1L1B1^1", false, 0, true) --start:1,1,1,n stairs A on level 1, going back to 1,1,1,n
  3087.     if not onGround then
  3088.         -- stage A1
  3089.         T:go("L2C1L2", false, 0, true) -- start 1,1,1,n fix corner on level 1 end: 1,1,1,n
  3090.     end
  3091.     -- stage B
  3092.     T:go("U1L1C1", false, 0, true) -- end  1,1,1,w layer 2
  3093.     if not onGround then
  3094.         T:go("L1C1R1", false, 0, true) -- end  1,1,1,w layer 2
  3095.     end
  3096.     -- stage C1
  3097.     T:go("R1F1L1C1R2C1L1B1", false, 0, true)
  3098.     -- stage C2
  3099.     T:go("U1L1C1L1C1L2F1L1C1R2C1L1B1D1", false, 0, true) -- end 1,1,2,n
  3100.     onGround = false
  3101.     -- stage D
  3102.     T:go("F2L1C1R1C1R1", false, 0, true) -- 3,1,2,e
  3103.    
  3104.     return onGround
  3105. end
  3106.  
  3107. function createTreefarm(size)
  3108.     local blockType
  3109.     local blockModifier
  3110.     local length
  3111.     local width
  3112.    
  3113.     if size == 1 then
  3114.         length = 11
  3115.         width = 6
  3116.         clearArea(11, 11)
  3117.     else
  3118.         length = 19
  3119.         width = 10
  3120.         clearArea(19, 19)
  3121.     end
  3122.     -- now place dirt blocks and torches
  3123.     T:go("F2R1F2L1U1", false, 0, true)
  3124.     for x = 1, (width - 2) / 2 do
  3125.         for y = 1, (length - 3) / 2 do
  3126.             T:place("minecraft:dirt", -1, "down", false)
  3127.             if y < (length - 3) / 2 then
  3128.                 T:forward(1)
  3129.                 T:place("minecraft:torch", -1, "down", false)
  3130.                 T:forward(1)
  3131.             end
  3132.         end
  3133.         T:go("R1F2R1", false, 0, true)
  3134.         for y = 1, (length - 3) / 2 do
  3135.             T:place("minecraft:dirt", -1, "down", false)
  3136.             if y < (length - 3) / 2 then
  3137.                 T:forward(1)
  3138.                 T:place("minecraft:torch", -1, "down", false)
  3139.                 T:forward(1)
  3140.             end
  3141.         end
  3142.         if x < (width - 2) / 2 then
  3143.             T:go("L1F2L1", false, 0, true)
  3144.         else
  3145.             T:go("R1F6", false, 0, true)
  3146.             if size == 2 then
  3147.                 T:go("F8", false, 0, true)
  3148.             end
  3149.             T:go("R1B1", false, 0, true)
  3150.         end
  3151.     end
  3152. end
  3153.  
  3154. function createWalkway(length)
  3155.     local lengthParts = math.floor(length / 8) -- eg 12/8 = 1
  3156.     local lastPart = length - (lengthParts * 8) -- eg 12 - (1 * 8) = 4
  3157.     T:up(1)
  3158.     for j = 1, lengthParts do
  3159.         T:go("M8", false, 0, true)
  3160.     end
  3161.     if lastPart > 0 then
  3162.         T:go("M"..tostring(lastPart)) -- eg m4
  3163.     end
  3164.     T:go("R2D1", false, 0, true)
  3165.     T:place("minecraft:torch", 0, "up", false)
  3166.     for j = 1, lengthParts do
  3167.         T:go("m8", true)
  3168.         T:place("minecraft:torch", 0, "up", false)
  3169.     end
  3170.     if lastPart > 0 then
  3171.         T:go("m"..tostring(lastPart), true) -- eg m4
  3172.     end
  3173.     T:go("R2", false, 0, true)
  3174. end
  3175.  
  3176. function createWaterSource(level)
  3177.     if level == nil then
  3178.         level = 0
  3179.     end
  3180.     if level > 0 then
  3181.         T:up(level)
  3182.     elseif level < 0 then
  3183.         T:down(math.abs(level))
  3184.     end
  3185.     -- assume on flat surface, but allow for blocks above
  3186.     T:go("x0C2F1 x0C2F1 x0C2F1 x0C2R1 F1 x0C2F1 x0C2F1 x0C2R1 F1 x0C2F1 x0C2F1 x0C2R1 F1 x0C2F1 x0C2", false, 0, false)
  3187.     T:go("R1F1D1", false, 0, false) --move to corner and drop down
  3188.     T:go("C2F1R1 C2F1R1 C2F1R1 C2F1R1", false, 0, false)
  3189.     T:go("U1")
  3190.     for i = 1, 2 do
  3191.         T:place("minecraft:water_bucket", -1, "down", false)
  3192.         T:go("F1R1F1R1", false, 0, false)
  3193.     end
  3194.     -- refill water buckets
  3195.     for i = 1, 2 do
  3196.         sleep(0.5)
  3197.         T:place("minecraft:bucket", -1, "down", false)
  3198.     end
  3199.     T:go("R2F1R1F1R1")
  3200.     -- end above lower left of pond (starting point)
  3201. end
  3202.  
  3203. function decapitateBuilding(width, length)
  3204.     --clearRectangle with sand drop
  3205.     -- could be 1 wide x xx length (trench) up and return
  3206.     -- could be 2+ x 2+
  3207.     -- even no of runs return after last run
  3208.     -- odd no of runs forward, back, forward, reverse and return
  3209.     local success
  3210.     local directReturn = true
  3211.     if width % 2 == 1 then
  3212.         directReturn = false
  3213.     end
  3214.     if width == 1 then -- trench ahead, so fill then return
  3215.         for i = 1, length - 1 do
  3216.             success = dropSand()
  3217.             T:forward(1, false)
  3218.         end
  3219.         success = dropSand()
  3220.         T:go("R2F"..(length - 1).."R2", false, 0, false)
  3221.     else --2 or more columns
  3222.         if directReturn then -- width = 2,4,6,8 etc
  3223.             for i = 1, width, 2 do -- i = 1,3,5,7 etc
  3224.                 -- move along length, dropping sand
  3225.                 for j = 1, length - 1 do
  3226.                     success = dropSand()
  3227.                     T:forward(1, false)
  3228.                 end
  3229.                 success = dropSand()
  3230.                 T:go("R1F1R1") --turn right and return on next column
  3231.                 for j = 1, length - 1 do
  3232.                     success = dropSand()
  3233.                     T:forward(1, false)
  3234.                 end
  3235.                 success = dropSand()
  3236.                 if i < width - 2 then -- eg width = 8, i compares with 6: 1, 3, 5, 7
  3237.                     T:go("L1F1L1")
  3238.                 end
  3239.             end
  3240.             T:go("R1F"..width - 1 .."R1") --return home
  3241.         else
  3242.             for i = 1, width, 2 do -- i = 1,3,5,7 etc
  3243.                 -- move along length, dropping sand
  3244.                 for j = 1, length - 1 do
  3245.                     success = dropSand()
  3246.                     T:forward(1, false)
  3247.                 end
  3248.                 success = dropSand()
  3249.                 T:go("R1F1R1") --turn right and return on next column
  3250.                 for j = 1, length - 1 do
  3251.                     success = dropSand()
  3252.                     T:forward(1, false)
  3253.                 end
  3254.                 success = dropSand()
  3255.                 T:go("L1F1L1")
  3256.             end
  3257.             -- one more run then return
  3258.             for j = 1, length - 1 do
  3259.                 success = dropSand()
  3260.                 T:forward(1, false)
  3261.             end
  3262.             success = dropSand()
  3263.             T:go("R2F"..length.."R1F"..width - 1 .."R1")
  3264.         end
  3265.     end
  3266. end
  3267.  
  3268. function demolishBuilding(width, length)
  3269.     -- start bottom left
  3270.     clearBuilding(width, length, 0, false)
  3271. end
  3272.  
  3273. function demolishPortal()
  3274.     if T:getBlockType("forward") == "minecraft:obsidian" then
  3275.         T:down(1)
  3276.     end
  3277.     T:go("x1U1x1U1x1U1x1U1x1")
  3278.     for i = 1, 3 do
  3279.         T:go("R1F1L1x1")
  3280.     end
  3281.     T:go("D1x1D1x1D1x1D1x1")
  3282.     T:go("L1F1R1x1L1F1R1x1")
  3283. end
  3284.  
  3285. function digMobTrench(height, length)
  3286.     local blockType
  3287.     -- go down 1 layer at a time height x, move forward length, fill voids
  3288.     if length == 0 then
  3289.         length = 8 --common length
  3290.     end
  3291.     for i = 1, height do
  3292.         T:down(1)
  3293.         -- tunnel bottom: E# fill voids both sides, remove floor
  3294.         T:go("E"..length - 1 .."R2", false, 0 , true)
  3295.     end
  3296.     T:up(height)
  3297.     if height % 2 == 1 then
  3298.         T:forward(length - 1)
  3299.     end
  3300. end
  3301.  
  3302. function digTrench(height, length)
  3303.     local blockType
  3304.     -- go down height, move forward
  3305.     if length == 0 then
  3306.         length = 4096 -- will go out of loaded chunks and stop or max 4096 on a server
  3307.     end
  3308.     for i = 1, length, 2 do
  3309.         local count = 0
  3310.         for down = 1, height do
  3311.             blockType = T:isWaterOrLava("down")
  3312.             -- go down only if no water or lava below
  3313.             if string.find(blockType, "water") == nil and string.find(blockType, "lava") == nil then
  3314.                 T:down(1)
  3315.                 count = count + 1
  3316.             end
  3317.         end
  3318.         -- return to surface, continue if block above
  3319.         T:go("U"..count)
  3320.         -- go up while block in front
  3321.         while turtle.detect() do
  3322.             blockType = T:getBlockType("forward")
  3323.             --print("Ahead: "..blockType)
  3324.             if T:isVegetation(blockType) then
  3325.                 T:dig("forward")
  3326.                 break
  3327.             elseif blockType:find("log") ~= nil then
  3328.                 T:harvestTree("forward", false)
  3329.             else
  3330.                 T:up(1)
  3331.             end
  3332.         end
  3333.         -- move forward
  3334.         T:forward(1)
  3335.         -- go down until block detected
  3336.         while not turtle.detectDown() do
  3337.             blockType = T:isWaterOrLava("down")
  3338.             if string.find(blockType, "water") == nil and string.find(blockType, "lava") == nil then
  3339.                 T:down(1)
  3340.             else
  3341.                 break
  3342.             end
  3343.         end
  3344.     -- repeat
  3345.     end
  3346. end
  3347.  
  3348. function drainLiquid(width, length, size)
  3349.     if size == 1 then --turtle replaces source so use clearSolid()
  3350.         --top-bottom =1
  3351.         clearSolid(width, length, 1, size)
  3352.     else -- mc 1.12.15+ turtle does NOT replace source blocks
  3353.         if width == 0 then
  3354.             width = 64
  3355.         end
  3356.         if length == 0 then
  3357.             length = 64
  3358.         end
  3359.         local drop = 0
  3360.         local calcLength = 1
  3361.         local calcWidth = 0
  3362.  
  3363.         -- start above water
  3364.         if T:detect("down") then -- in case not over wall
  3365.             T:forward(1)
  3366.         end
  3367.         -- go down until water detected
  3368.         while not turtle.detectDown() do
  3369.             block, blockType = T:isWaterOrLava("down")
  3370.             if string.find(block, "water") == nil and string.find(block, "lava") == nil then
  3371.                 T:down(1)
  3372.                 drop = drop + 1
  3373.             else
  3374.                 break
  3375.             end
  3376.         end
  3377.        
  3378.         local place = true
  3379.         local block, blockType
  3380.         -- place first cobble along the length of water and measure length
  3381.         for l = 1, length do
  3382.             -- check for water/kelp below
  3383.             place = clearVegetation("down") -- returns true if water or removed kelp below
  3384.             if place then
  3385.                 T:go("C2")
  3386.             end
  3387.             if T:getBlockType("forward") == "minecraft:cobblestone" then
  3388.                 break
  3389.             end
  3390.             if l < length then
  3391.                 if T:getBlockType("forward") == "minecraft:cobblestone" then
  3392.                     break
  3393.                 else
  3394.                     T:forward(1)
  3395.                     calcLength = calcLength + 1
  3396.                     if T:getBlockType("down") == "minecraft:cobblestone" then
  3397.                         turtle.back()
  3398.                         calcLength = calcLength - 1
  3399.                         break
  3400.                     end
  3401.                 end
  3402.             end
  3403.         end
  3404.         length = calcLength
  3405.         T:go("R1F1R1")
  3406.         print("calcLength = "..length)
  3407.         for w = 1, width- 2, 2 do
  3408.             -- place cobble along the length of water return journey
  3409.             for l = 1, length do
  3410.                 -- check for water/kelp below
  3411.                 place = clearVegetation("down") -- returns true if water or removed kelp below
  3412.                 if place then
  3413.                     T:go("C2")
  3414.                 end
  3415.                 if l < length then
  3416.                     T:forward(1)
  3417.                     T:go("C2")
  3418.                 end
  3419.             end
  3420.             -- go to starting point
  3421.             T:go("R1F1R1")
  3422.             -- remove cobble along the length of water
  3423.             for d = 1, length do
  3424.                 T:dig("down")
  3425.                 if d < length then
  3426.                     T:forward(1)
  3427.                 end
  3428.             end
  3429.             -- turn right
  3430.             T:turnRight(1)
  3431.             -- move across to next col
  3432.             for i = 1, 2 do
  3433.                 if not turtle.detect() then
  3434.                     T:forward(1)
  3435.                     calcWidth = calcWidth + 1
  3436.                 end
  3437.             end
  3438.             T:turnRight(1)
  3439.             --check if now cobble below. If so run has finished
  3440.             if T:getBlockType("down") == "minecraft:cobblestone" then
  3441.                 T:go("R1F1L1")
  3442.                 calcWidth = calcWidth - 1
  3443.                 break
  3444.             elseif turtle.detect() then
  3445.                 -- end of line reached
  3446.                 break
  3447.             end
  3448.         end
  3449.         -- now on retaining wall, return to last cobble strip
  3450.        
  3451.         -- dig it out
  3452.         for d = 1, length do
  3453.             T:dig("down")
  3454.             if d < length then
  3455.                 T:forward(1)
  3456.             end
  3457.         end
  3458.  
  3459.         T:go("R1F"..calcWidth - 1 .."R1U"..drop)
  3460.        
  3461.     end
  3462. end
  3463.  
  3464. function dropSand()
  3465.     local success, slot
  3466.     while not turtle.detectDown() do -- over water. will be infinite loop if out of sand
  3467.         success, slot = T:place("minecraft:sand", -1, "down", false)
  3468.         if not success then
  3469.             print("Out of sand. Add more to continue...")
  3470.             sleep(2)
  3471.         end
  3472.     end
  3473.     return true --will only get to this point if turtle.detectDown() = true
  3474. end
  3475.  
  3476. function floodMobFarm()
  3477.     -- turtle on floor, pointing towards water source wall
  3478.     -- move forward until hit wall
  3479.     while turtle.forward() do end
  3480.     -- turn left, move forward until hit wall
  3481.     T:turnLeft(1)
  3482.     while turtle.forward() do end
  3483.     -- back 1, place water
  3484.     turtle.back()
  3485.     T:place("minecraft:water_bucket", -1, "forward", true)
  3486.     -- turn round go forward 7, place water
  3487.     T:turnLeft(2)
  3488.     while turtle.forward() do end
  3489.     -- back 1, place water
  3490.     turtle.back()
  3491.     T:place("minecraft:water_bucket", -1, "forward", true)
  3492.    
  3493.     -- turn round, go forward 3 (centre of wall), turn left, forward 4 (centre of chamber)
  3494.     T:go("L2F3L1F4")
  3495.     -- go down, left, forward, turn round
  3496.     T:go("D1L1F1R2")
  3497.     for i = 3, 9, 2 do
  3498.         -- check down, dig forward, go forward, check down (i blocks)
  3499.         T:go("m"..i-1, false, 0, true)
  3500.         if i == 3 or i == 7 then
  3501.             -- left, forward, right, forward, turn round
  3502.             T:go("L1F1R1F1R2")
  3503.         elseif i < 9 then
  3504.             T:go("R1F1L1F1R2")
  3505.             -- right, forward, left, forward, turn round
  3506.         end
  3507.     end
  3508.     -- right, forward, right, check down / forward 9 x
  3509.     T:go("R1F1R1m8R2F4R1") -- now facing bubble lift, next to wall
  3510.     -- go down 2, check floor, up 1, place fence
  3511.     T:go("D2C2U1", false, 0, true)
  3512.     T:place("fence", -1, "down", false)
  3513.     T:go("F1D1C2U1", false, 0, true)
  3514.     T:place("fence", -1, "down", false)
  3515.     T:go("F1U1R2", false, 0, true)
  3516.     if not T:place("minecraft:soul_sand", -1, "down", false) then
  3517.         T:place("minecraft:dirt", -1, "down", false)
  3518.     end
  3519.     T:go("F1R1U1")
  3520.     T:place("sign", -1, "down", false)
  3521.     T:go("U1C0D1")
  3522.     T:place("slab", -1, "up", false)
  3523.     T:go("R2F1R2")
  3524.     T:place("sign", -1, "forward", false)
  3525.     T:go("R1F1R2C1R1F1D1L1") --sitting on soul sand/dirt facing spawner
  3526. end
  3527.  
  3528. function getDecision(choice)
  3529.     local decision = read()
  3530.     local retValue = 0
  3531.     if decision == "" or decision == "y" then -- allow for enter only
  3532.         retValue = choice
  3533.     end
  3534.     return tonumber(retValue)
  3535. end
  3536.  
  3537. function getSize(clear, prompt, lowerLimit, upperLimit)
  3538.     local retValue = -1
  3539.     while tonumber(retValue) < lowerLimit or  tonumber(retValue) > upperLimit do
  3540.         if clear then
  3541.             T:clear()
  3542.         end
  3543.         print(prompt)
  3544.         --term.write(prompt)
  3545.         --io.write(prompt.."_")
  3546.         retValue = read()
  3547.         if tonumber(retValue) == nil then
  3548.             retValue = 0
  3549.         end
  3550.     end
  3551.     return tonumber(retValue)
  3552. end
  3553.  
  3554. function getTask()
  3555.     local lib = {}
  3556.    
  3557.     function lib.waterWarning()
  3558.         T:clear()
  3559.         print("           IMPORTANT!\n")
  3560.         print("1.14+ turtles do NOT delete source\n")
  3561.         print("0 if I do NOT replace source blocks")
  3562.         print("1 if I do delete. (pre 1.14)")
  3563.         return getSize(false, "Option? (0 or 1)\n", 0, 1)
  3564.     end
  3565.    
  3566.     local choice = nil
  3567.     local mainChoice = nil
  3568.     local size = 0
  3569.     local width = 0
  3570.     local length = 0
  3571.     local height = 0
  3572.     local prompt = "Choose your option:"
  3573.     local options = getTaskOptions()
  3574.     local text = getTaskText()
  3575.    
  3576.    
  3577.     while choice == nil do
  3578.         mainChoice = menu.new(prompt, options.main)
  3579.         if mainChoice == nil then
  3580.             break
  3581.         else
  3582.             choice = menu.new(prompt, options[mainChoice])
  3583.         end
  3584.         if choice ~= nil then
  3585.             if choice > 9 then
  3586.                 choice = choice + (mainChoice * 100)
  3587.             else
  3588.                 choice = choice + (mainChoice * 10)
  3589.             end
  3590.         end
  3591.     end
  3592.     T:clear()
  3593.     local instructions = "Enter to continue\nany other key to quit"
  3594.     if choice == nil then
  3595.         print("You chose quit from the main menu")
  3596.     else
  3597.         print(text[choice])
  3598.     end
  3599.     -- MINING
  3600.     if choice == 11 then -- Create Mine at this level
  3601.         choice = getDecision(choice)
  3602.     elseif choice == 12 then -- Ladder to bedrock
  3603.         choice = getDecision(choice)
  3604.     elseif choice == 13 then -- Ladder to surface
  3605.         choice = getDecision(choice)
  3606.     elseif choice == 14 then -- Stairs to bedrock
  3607.         choice = getDecision(choice)
  3608.     elseif choice == 15 then -- Stairs to surface
  3609.         choice = getDecision(choice)
  3610.     -- FORESTRY
  3611.     elseif choice == 21 then    -- Fell Tree
  3612.         choice = getDecision(choice)
  3613.     elseif choice == 22 then --Create treefarm
  3614.         choice = getDecision(choice)
  3615.         if choice > 0 then
  3616.             options =   {"4 x 4 trees(16)","8 x 8 trees(64)"}
  3617.             size = menu.new(prompt, options)
  3618.         end
  3619.     elseif choice == 23 then -- plant treefarm
  3620.         choice = getDecision(choice)
  3621.         if choice > 0 then
  3622.             options = {"4 x 4 trees(16)","8 x 8 trees(64)"}
  3623.             size = menu.new(prompt, options)
  3624.         end
  3625.     elseif choice == 24 then -- Harvest treefarm
  3626.         choice = getDecision(choice)
  3627.         if choice > 0 then
  3628.             options = {"4 x 4 trees(16)","8 x 8 trees(64)"}
  3629.             size = menu.new(prompt, options)
  3630.         end
  3631.     elseif choice == 25 then    -- Create Auto-TreeFarm
  3632.         choice = getDecision(choice)
  3633.     elseif choice == 26 then    -- Manage Auto-TreeFarm
  3634.         choice = getDecision(choice)
  3635.        
  3636.     -- FARMING
  3637.     elseif choice == 31 then    -- Create crop farm
  3638.         choice = getDecision(choice)
  3639.     elseif choice == 32 then    -- Extend crop farm
  3640.         choice = getDecision(choice)
  3641.     elseif choice == 33 then    -- Manage crop farm
  3642.         choice = getDecision(choice)
  3643.        
  3644.     -- OBSIDIAN
  3645.     elseif choice == 41 then    -- Harvest obsidian
  3646.         width = getSize(false, "Width of the area (1-64)\n", 1, 64)
  3647.         length  = getSize(false, "Length of the area (1-64)\n", 1, 64)
  3648.     elseif choice == 42 then -- build Nether portal
  3649.         choice = getDecision(choice)
  3650.     elseif choice == 43 then -- demolish Nether portal
  3651.         choice = getDecision(choice)
  3652.    
  3653.     -- CANAL BRIDGE
  3654.     elseif choice == 51 then    --single path
  3655.         choice = getDecision(choice)
  3656.     elseif choice == 52 then    --2 block coridoor
  3657.         length = getSize(false, "Coridoor length? 0 = continuous\n", 0, 1024)
  3658.     elseif choice == 53 then    --return Path over void/water/lava
  3659.         size = getSize(false, "Length of the area (1-128)\n", 1, 128)
  3660.     elseif choice == 54 then    --Covered walkway
  3661.         size = getSize(false, "Length of the walk (1-64)\n", 1, 64)
  3662.     elseif choice == 55 then    --left/right side of new/existing canal
  3663.         width = lib.waterWarning()
  3664.         length = getSize(false, "Canal length? 0 = continuous\n", 0, 1024)
  3665.         height = getSize(false, "Am I on the floor(0) or wall(1)?\n", 0, 1)
  3666.     elseif choice == 56 then    --left/right side of new/existing canal
  3667.         width = lib.waterWarning()
  3668.         length = getSize(false, "Canal length? 0 = continuous\n", 0, 1024)
  3669.         height = getSize(false, "Am I on the floor(0) or wall(1)?\n", 0, 1)
  3670.    
  3671.        
  3672.     -- MOB SPAWNER TOOLS
  3673.     elseif choice == 61 then -- Mob spawner cube
  3674.         choice = getDecision(choice)
  3675.     elseif choice == 62 then -- Mob trench
  3676.         length = getSize(false, "Length of trench (1-256)\n", 1, 256)
  3677.         height = getSize(false, "Depth of trench (1-50)\n", 1, 50)
  3678.     elseif choice == 63 then -- flood mobspawner cube
  3679.         choice = getDecision(choice)
  3680.     elseif choice == 64 then -- create bubble lift at mob spawner
  3681.         size = getSize(false, "Standing inside the cube:\n"..
  3682.                               "Killzone on left(0)?\n"..
  3683.                               "Killzone on right(1)?\n\n"..
  3684.                               "Standing outside the cube:\n"..
  3685.                               "Killzone on left(1)?\n"..
  3686.                               "Killzone on right(0)?", 0, 1)                         
  3687.     elseif choice == 65 then -- Blaze spawner
  3688.         choice = getDecision(choice)
  3689.     elseif choice == 66 then -- Enderman tower
  3690.         choice = getDecision(choice)
  3691.        
  3692.     --[[
  3693.     elseif choice == 66 then -- Path to ocean base
  3694.         size = getSize(false, "Path length (0-128)?\n", 0, 128)
  3695.     elseif choice == 67 then -- Ocean base complete. Place on polished block to start
  3696.         size = getSize(false, "Tower Height (32-128)?\n", 32, 128)
  3697.     elseif choice == 68 then -- Mob tower complete Place on polished block to start
  3698.         choice = getDecision(choice)
  3699.     elseif choice == 69 then -- Mob tower roof Place on polished block to start
  3700.         choice = getDecision(choice)]]
  3701.        
  3702.     -- AREA CARVING
  3703.     elseif choice == 71 then --Clear field
  3704.         width = getSize(false, "Width of the area (1-64)\n", 1, 64)
  3705.         length  = getSize(false, "Length of the area (1-64)\n", 1, 64)
  3706.     elseif choice == 72 then -- Clear solid rectangle width, length
  3707.         width = getSize(false, "Width of the area (1-256)\n", 1, 256)
  3708.         length  = getSize(false, "Length of the area (1-256)\n", 1, 256)
  3709.     elseif choice == 73 then -- Clear wall height, length, direction
  3710.         size = getSize(false, "Bottom->Top (0), Top->bottom(1)",0, 1)
  3711.         width = 1
  3712.         length = getSize(false, "Length of wall (1-256)\n", 1, 256)
  3713.         height = getSize(false, "Height of wall (1-50)\n", 1, 50)
  3714.     elseif choice == 74 then -- Clear rectangle perimeter only width, length
  3715.         width = getSize(false, "Width of walled area (1-256)\n", 1, 256)
  3716.         length  = getSize(false, "Length of walled area (1-256)\n", 1, 256)
  3717.         height = 1
  3718.     elseif choice == 75 then -- Clear sructure floor/walls/ceiling
  3719.         size = getSize(false, "Bottom->Top (0), Top->bottom(1)",0, 1)
  3720.         width = getSize(false, "Hollow structure width (1-256)", 1, 256)
  3721.         length  = getSize(false, "Hollow structure length (1-256)", 1, 256)
  3722.         if size == 0 then
  3723.             height  = getSize(false, "Height (1-256)", 1, 256)
  3724.         else
  3725.             height  = getSize(false, "Depth/Height (1-256)", 1, 256)
  3726.         end
  3727.     elseif choice == 76 then -- clear solid structure
  3728.         size = getSize(false, "Bottom->Top (0), Top->bottom(1)",0, 1)
  3729.         width = getSize(false, "Solid structure width (1-60)", 1, 60)
  3730.         length  = getSize(false, "Solid structure length (1-60)", 1, 60)
  3731.         if size == 0 then
  3732.             height  = getSize(false, "Height (1-256)", 1, 256)
  3733.         else
  3734.             height  = getSize(false, "Depth/Height (1-256)", 1, 256)
  3735.         end
  3736.     elseif choice == 77 then    -- Dig a trench
  3737.         height = getSize(false, "Depth of the trench (1-64)", 1, 64)
  3738.         length = getSize(false, "Trench length? 0 = continuous\n", 0, 1024)
  3739.     elseif choice == 78 then    -- Carve side of mountain
  3740.         size = getSize(false, "Left <- Right (0), Left -> Right(1)",0, 1)
  3741.         width = getSize(false, "Width of area to remove?", 1, 1024)
  3742.         length = getSize(false, "Length of area to remove?", 0, 1024)
  3743.        
  3744.     -- WATER LAVA
  3745.     elseif choice == 81 then -- build wall from water or lava surface downwards
  3746.         width = 1
  3747.         length = getSize(false, "Length of the wall (1-60)\n", 1, 60)
  3748.         height = getSize(false, "Estimated depth (1-60) 0=default\n", 0, 60)
  3749.     elseif choice == 82 then -- drop sand into water or lava surface until solid grond reached
  3750.         width = 1
  3751.         length = getSize(false, "Length of dam (0=to solid block)\n", 0, 60)
  3752.     elseif choice == 83 then -- clear rectangle on top of building and fill with sand
  3753.         width = getSize(false, "Width of roof (<=30)\n", 1, 30)
  3754.         length = getSize(false, "Length of of roof (<=30)\n", 1, 30)
  3755.     elseif choice == 84 then -- clear sand wall or harvest sand
  3756.         width = 1
  3757.         length = getSize(false, "Length of sand \n", 1, 250)
  3758.     elseif choice == 85 then -- remove sand from cube. start at top
  3759.         width = getSize(false, "Width of sand (<=30)\n", 1, 30)
  3760.         length = getSize(false, "Length of of sand (<=30)\n", 1, 30)
  3761.     elseif choice == 86 then -- remove floor, walls (and sand) from building. start at base
  3762.         width = getSize(false, "Width of floor (<=30)\n", 1, 30)
  3763.         length = getSize(false, "Length of of floor (<=30)\n", 1, 30)
  3764.     elseif choice == 87 then -- Clear all blocks top of water
  3765.         T:clear()
  3766.         print("           IMPORTANT!\n")
  3767.         print("1.14+ turtles do NOT delete source\n")
  3768.         print("0 if I do NOT replace source blocks")
  3769.         print("1 to recover blocks, leaving water")
  3770.         size  = getSize(false, "Option? (0 or 1)\n", 0, 1)
  3771.     elseif choice == 88 then -- clear monument layer
  3772.         width = getSize(false, "Width of monument area (1 to 64)\n", 1, 64)
  3773.         length = getSize(false, "Length of monument area (1 to 64)", 1, 64)
  3774.         size = getSize(false, "Clear above and below? 0:no 1:yes", 0, 1)
  3775.     elseif choice == 89 then -- Ladder to water/lava   
  3776.         choice = getDecision(choice)
  3777.         if choice > 0 then
  3778.             height = getSize(false, "Est. height above (?F3)\n", 1, 256)
  3779.         end
  3780.     elseif choice == 810 then -- Clear seaweed from enclosed area
  3781.         width = getSize(false, "water width (1-64)\n", 1, 64)
  3782.         length  = getSize(false, "water length (1-64)\n", 1, 64)
  3783.        
  3784.     -- RAILWAY
  3785.     elseif choice == 91 then -- place redstone torch under current block
  3786.  
  3787.     elseif choice == 92 then -- place redstone torch on upward slope
  3788.  
  3789.     elseif choice == 93 then -- build downward slope
  3790.         height  = getSize(false, "Drop down by how many blocks?\n", 1, 64)
  3791.     elseif choice == 94 then -- build upward slope
  3792.         height  = getSize(false, "Go up by how many blocks?\n", 1, 64)
  3793.     end
  3794.    
  3795.     return choice, size, width, length, height -- eg 86, 0, 8, 8, 4
  3796. end
  3797.  
  3798. function getTaskOptions()
  3799.     local o = {}
  3800.     o.main =
  3801.     {
  3802.         "Mining (includes Nether)",
  3803.         "Forestry",
  3804.         "Farming",
  3805.         "Obsidian and Nether Portal",
  3806.         "Canal, bridge and walkway",
  3807.         "Mob farm tools",
  3808.         "Area shaping and clearing",
  3809.         "Lava and Water",
  3810.         "Railway"
  3811.     }
  3812.     table.insert(o,
  3813.     {
  3814.         "Create mine at this level",
  3815.         "Ladder down (to bedrock)",
  3816.         "Ladder up (to surface)",
  3817.         "Stairs down (to bedrock)",
  3818.         "Stairs up (to surface)"
  3819.     })
  3820.     table.insert(o,
  3821.     {
  3822.         "Fell Tree",
  3823.         "Create tree farm",
  3824.         "Plant tree farm",
  3825.         "Harvest tree farm",
  3826.         "Create Auto-treeFarm",
  3827.         "Manage Auto-treeFarm"
  3828.     })
  3829.     table.insert(o,
  3830.     {
  3831.         "Create modular crop farm",
  3832.         "Extend modular crop farm",
  3833.         "Manage modular crop farm"
  3834.     }) 
  3835.     table.insert(o,                
  3836.     {
  3837.         "Dig obsidian field",
  3838.         "Build Nether Portal",
  3839.         "Demolish Nether Portal"
  3840.     })
  3841.     table.insert(o,
  3842.     {
  3843.         "Continuous path",
  3844.         "2 block high tunnel",
  3845.         "2 block wide over air/water/lava",
  3846.         "Covered walkway",
  3847.         "Left side of canal",
  3848.         "Right side of canal",
  3849.        
  3850.     })
  3851.     table.insert(o,
  3852.     {
  3853.         "Create 9x9 cube around spawner",
  3854.         "Dig mob drop trench",
  3855.         "Flood mob farm floor",
  3856.         "Create mob bubble lift",
  3857.         "Create Blaze farm around spawner",
  3858.         "Create Endermen observation tower",
  3859.         --[[
  3860.         "Mob spawner base & ocean path",
  3861.         "Mob spawner tower",
  3862.         "Mob spawner chamber",
  3863.         "Mob spawner roof"]]
  3864.     })
  3865.     table.insert(o,
  3866.     {
  3867.         "Clear field (inc trees)",
  3868.         "Clear a rectangle",
  3869.         "Clear single wall up/down",
  3870.         "Clear rectangular wall section",
  3871.         "Clear hollow structure up/down",
  3872.         "Clear solid structure up/down",
  3873.         "Dig a trench",
  3874.         "Carve mountain side"
  3875.     })
  3876.     table.insert(o,
  3877.     {
  3878.         "Vertical wall from surface",
  3879.         "Drop sand or gravel wall",
  3880.         "Decapitate and fill with sand",
  3881.         "Clear sand wall",
  3882.         "Clear sand filled building",
  3883.         "Demolish sand filled structure",
  3884.         "Clear top layer of water",
  3885.         "Clear monument layer",
  3886.         "Ladder down to water/lava",
  3887.         "Clear water plants"
  3888.     })
  3889.     table.insert(o,
  3890.     {
  3891.         "Place Redstone:torch level track",
  3892.         "Place Redstone:torch upward track",
  3893.         "Build downward track",
  3894.         "Build upward track"
  3895.     })
  3896.    
  3897.     return o
  3898. end
  3899.  
  3900. function getTaskText()
  3901.     local text = {}
  3902.     local instructions = "Enter to continue\nany other key to quit"
  3903.     --MINING
  3904.     text[11] =  "Press F3 to check level. Look for 'Y'\n"..
  3905.                 "Place at level 5, 8, 12 (11 nether)\n\n"..instructions --mine this level
  3906.     text[12] =  "Place me on the ground\n"..
  3907.                 "The ladder will start at this level\n"..
  3908.                 "and drop to bedrock\n\n"..instructions -- ladder to bedrock
  3909.     text[13] =  "Place me on the ground\n"..
  3910.                 "The ladder will start at this level\n"..
  3911.                 "and rise to chosen level/surface\n\n"..instructions -- ladder to surface
  3912.     text[14] =  "Place me on the ground\n"..
  3913.                 "The stairs will start at this level\n"..
  3914.                 "and drop to bedrock in a 5x5 block\n\n"..instructions -- Stairs to bedrock
  3915.     text[15]  =     "Place me on the ground\n"..
  3916.                 "The stairs will start at this level\n"..
  3917.                 "and rise to level 64 in a 5x5 block\n\n"..instructions-- Stairs to surface
  3918.  
  3919.     -- FORESTRY
  3920.     text[21] =  "Place me in front of the tree\n"..
  3921.                 "you want to fell\n\n"..
  3922.                 "Fuel not required as logs will be used.\n\n"..instructions -- Fell Tree
  3923.     text[22] =  "Place me on grass, lower left corner\n"..
  3924.                 "of a 11x11 OR 19x19 square\n"..
  3925.                 "Trees to be grown on alternate blocks\n"..
  3926.                 "in a square 4x4 or 8x8 trees\n"..
  3927.                 "with a 2 block wide margin\n"..instructions --Create treefarm
  3928.     text[23] =  "Place me in front of first tree base\n"..
  3929.                 "or dirt on the lower left corner\n"..
  3930.                 "of a 4x4 trees OR 8x8 trees square\n\n"..
  3931.                 "Provide 2 types of saplings for a\n"..
  3932.                 "mixed tree farm\n\n"..instructions --plant treefarm
  3933.     text[24] =  "Place me in front of first tree\n"..
  3934.                 "on the lower left corner\n"..
  3935.                 "of a 4x4 trees OR 8x8 trees square\n\n"..
  3936.                 "Fuel not required as logs will be used.\n\n"..instructions-- Harvest treefarm
  3937.     text[25] =  "For a new Auto-TreeFarm:\n"..
  3938.                 "Place me on left side of a 19x14 area\n\n"..instructions   -- Create Auto-TreeFarm
  3939.     text[26] =  "Place me in front of sapling\n"..
  3940.                 "or tree with the chest behind me\n\n"..instructions    -- Manage Auto-TreeFarm
  3941.                
  3942.     -- FARMING         
  3943.     text[31] =  "Place me on the ground lower left\n"..
  3944.                 "of an area 14 x 14. A crop farm\n"..
  3945.                 "12 x 12 with cobble wall will be \n"..
  3946.                 "built forward and to the right\n\n"..instructions -- Create modular crop farm
  3947.     text[32] =  "Place me next to the tree on\n"..
  3948.                 "a chest, either left side of farm\n"..
  3949.                 "or facing front wall to add a farm\n"..
  3950.                 "in that direction.\n\n"..instructions-- extend farm
  3951.     text[33] =  "Place me over the water on the\n"..
  3952.                 "left corner. There should be\n"..
  3953.                 "chests on 2 sides\n\n"..instructions -- Manual harvest and auto setup
  3954.  
  3955.     -- OBSIDIAN
  3956.     text[41] =  "Place me on any block\n"..
  3957.                 "on the left side facing the\n"..
  3958.                 "obsidian field.\n\n"..instructions -- Harvest obsidian
  3959.     text[42] =  "Place me on the ground\n"..
  3960.                 "on the left side\n"..
  3961.                 " of the portal base\n\n"..instructions -- build Nether portal
  3962.     text[43] =  "Place me on the ground\n"..
  3963.                 "on the left side\n"..
  3964.                 " of the portal base\n\n"..instructions -- demolish Nether portal
  3965.                
  3966.     --CANALS BRIDGES WALKWAYS
  3967.     text[51] =  "Place me on the ground in front\n"..
  3968.                 "of water, lava or air.\n"..
  3969.                 "Follow and supply blocks for a path\n\n"..instructions --single path
  3970.     text[52] =  "Place me on the ground at start\n"..
  3971.                 "of coridoor.\n\n"..instructions    --2 block coridoor
  3972.     text[53] =  "Place me on the ground\n"..
  3973.                 "The bridge will start in front,\n"..
  3974.                 "continue for your chosen length\n"..
  3975.                 "and return\n"  --Bridge over void/water/lava
  3976.     text[54] =  "Place me on the ground\n"..
  3977.                 "The covered walkway will start in front,\n"..
  3978.                 "continue for your chosen length\n"..
  3979.                 "and return\n"  --Covered walkway
  3980.    
  3981.     text[55] =  "I should be on either an existing canal\n"..
  3982.                 "on the left side\n"..
  3983.                 "or ready to start a new canal\n\n"..
  3984.                 "If crossing water I should be on top\n"..
  3985.                 "of a solid block making up the left wall\n"    -- left side of new/existing canal
  3986.     text[56] =  "I should be on either an existing canal\n"..
  3987.                 "on the right side\n"..
  3988.                 "or ready to start a new canal\n\n"..
  3989.                 "If crossing water I should be on top\n"..
  3990.                 "of a solid block making up the right wall\n"   -- right side of new/existing canal
  3991.    
  3992.     -- MOB FARM
  3993.     text[61] =  "Place me in contact with spawner\n"..
  3994.                 "above/below/facing spawner block\n"..
  3995.                 "to create a 9 x 9 hollow cube\n\n"..
  3996.                 instructions -- 9x9 cube round spawner
  3997.     text[62] =  "Place me at start of trench\n"..
  3998.                 "facing required direction\n"
  3999.     text[63] =  "Place me on the floor facing the wall\n"..
  4000.                 "where the water sources will start\n\n"..
  4001.                 "If you do not have soul sand, add dirt\n"..
  4002.                 "as a temporary place marker\n\n"..
  4003.                 "Make sure you have an escape route!\n\n"..
  4004.                 instructions -- flood spawner chamber  
  4005.     text[64] =  "Place me on the soul sand/dirt block\n"..
  4006.                 "facing any direction\n"
  4007.                
  4008.     text[65] =  "Place me in contact with Blaze spawner\n"..
  4009.                 "above/facing spawner block\n"..
  4010.                 "to create a safe killzone\n\n"..
  4011.                 instructions -- 9x9 cube round spawner
  4012.     text[66] =  "Find an open plains area.\n"..
  4013.                 "Bury a chest in the ground.\n"..
  4014.                 "I will need 29 stacks of cobble,\n"..
  4015.                 "andesite, diorite or granite in total\n"..
  4016.                 "(can be polished) in the chest.\n\n"..
  4017.                 instructions -- build endermen observation tower
  4018.     --[[
  4019.     text[66] =  "Place me on the ground in front\n"..
  4020.                 "of the ocean.\n"..
  4021.                 "Follow me as I create a path\n" -- Path to mob spawner ocean base
  4022.     text[67] =  "Place me on the stone block\n"..
  4023.                 "(granite / andesite / diorite)\n"..
  4024.                 "in the ocean base.\n"..
  4025.                 "Facing the sea\n" -- Ocean base complete. Place on polished block to start
  4026.     text[68] =  "Place me on the stone block\n"..
  4027.                 "(granite / andesite / diorite)\n"..
  4028.                 "at the top of the tower.\n"..
  4029.                 "Facing the sea\n\n"..
  4030.                 instructions -- Mob tower complete Place on polished block to start
  4031.     text[69] =  "Place me on the stone block\n"..
  4032.                 "(granite / andesite / diorite)\n"..
  4033.                 "at the top of the tower.\n"..
  4034.                 "Facing the sea\n\n"..
  4035.                 instructions-- Mob tower roof Place on polished block to start
  4036.     ]]
  4037.                
  4038.     -- AREA CARVING
  4039.     text[71] =  "Place me on grass, lower left corner\n"..
  4040.                 "of the area\n"..
  4041.                 "To be levelled and cleared\n\n"..
  4042.                 "Provide dirt to plug voids in the floor\n" --Clear field
  4043.     text[72] =  "Place me inside the left corner\n"..
  4044.                 "of the rectangle to be cleared.\n"..
  4045.                 "At the level to be worked on\n"..
  4046.                 "I will include this corner in\n"..
  4047.                 "the area to be cleared\n"-- Clear rectangle width, length
  4048.     text[73] =  "Place me inside top/bottom corner\n"..
  4049.                 "of the wall to be cleared.\n"-- Clear wall height, length
  4050.     text[74] =  "Place me inside top/bottom left corner\n"..
  4051.                 "of the rectangular wall to be cleared.\n"..
  4052.                 "At the level to be worked on\n"..
  4053.                 "I will include this corner in\n"..
  4054.                 "the area to be cleared\n"-- Clear rectangle perimeter only width, length
  4055.     text[75] =  "Place me INSIDE top/bottom left corner\n"..
  4056.                 "in the floor/ceiling.\n"..
  4057.                 "I will include this corner in\n"..
  4058.                 "the area to be cleared\n" -- Clear structure floor/walls/ceiling
  4059.     text[76] =  text[75]
  4060.     text[77] =  "Place me on the ground\n"..
  4061.                 "facing the trench direction\n" -- Dig a trench
  4062.     text[78] =  "Place me on the ground\n"..
  4063.                 "facing the mountain side\n"    -- carve mountain
  4064.                
  4065.     --LAVA WATER
  4066.     text[81] =  "Place me on the surface facing wall END\n"..
  4067.                 "(Any block below will be removed)\n"..
  4068.                 "Wall will be built DOWN and BACKWARDS\n"-- build wall from water or lava surface downwards
  4069.     text[82] =  "Place me on the surface of water or lava\n"..
  4070.                 "Sand  will be dropped DOWN and Forwards\n"-- drop sand into water or lava surface until solid grond reached
  4071.     text[83] =  "Place me on top left corner of roof\n"..
  4072.                 "Sand  will be dropped into the hollow\n"-- clear rectangle on top of building and fill with sand
  4073.     text[84] =  "Place me on the surface of sand\n"..
  4074.                 "Sand  will be mined DOWN then forwards\n"-- clear sand wall or harvest sand
  4075.     text[85] =  "Place me on top left corner of sand\n"..
  4076.                 "Sand cleared down, then left to right\n"-- remove sand from cube. start at top
  4077.     text[86] =  "Place me on lower left corner of floor\n"..
  4078.                 "Floor + walls removed + sand cleared\n" -- remove floor, walls (and sand) from building. start at base
  4079.     text[87] =  "Place me on the left corner of the top\n"..
  4080.                 "of retaining wall facing water/lava\n"-- Clear all blocks top of water
  4081.     text[88] =  "Place me on lower left corner of area\n"..
  4082.                 "on wall or over air\n" -- clear monument layer
  4083.     text[89] =  "Place me on the ground\n"..
  4084.                 "The ladder will start here\n"..
  4085.                 "and drop to water/lava\n\n"..instructions -- Ladder to water/lava
  4086.     text[810] = "Place me on the left corner of the top\n"..
  4087.                 "of retaining wall facing water\n"-- Clear seaweed from enclosed area
  4088.                
  4089.     -- RAILWAY
  4090.     text[91] =  "Place me on suspended railway stone\n"..
  4091.                 "Redstone torch will go below me\n"-- place redstone torch under current block
  4092.     text[92] =  "Place me on railway stone going up\n"..
  4093.                 "Redstone torch will go below me\n"-- place redstone torch on upward slope
  4094.     text[93] =  "Place me on last stone\n"..
  4095.                 "Track will go down from this point\n"-- build downward slope
  4096.     text[94] =  "Place me on last stone\n"..
  4097.                 "Track will go up from this point\n"-- build upward slope
  4098.     return text
  4099. end
  4100.  
  4101. function getTaskInventory(choice, size, width, length, height)
  4102.     -- run this loop 2x per second to check if player has put anything in the inventory
  4103.     -- fuel 1 coal = 60 = 4 planks. 64 planks = 16 coal = 960 units
  4104.     local retValue = ""
  4105.     local gotBirchSaplings = 0
  4106.     local gotCoal = 0
  4107.     local gotCobble = 0
  4108.     local gotDirt = 0
  4109.     local gotOakSaplings = 0
  4110.     local gotPlanks = 0
  4111.     local gotTorches = 0
  4112.     local thanks = "Thank you.\n\nPress the ESC key\n\nStand Back..\n"
  4113.    
  4114.     T:clear()
  4115.     if choice == 0 then --Missing pickaxe
  4116.         T:checkInventoryForItem({"minecraft:diamond_pickaxe"}, {1})
  4117.         print("Diamond Pickaxe being tested...")
  4118.         T:setEquipment()
  4119.     elseif choice == 1 then --Missing crafting table
  4120.         T:checkInventoryForItem({"minecraft:crafting_table", ""}, {1, 0}) -- 0 if not present
  4121.         print("Crafting table being tested...")
  4122.         T:setEquipment()
  4123.     elseif choice == 2 then --Missing chest
  4124.         retValue = T:checkInventoryForItem({"minecraft:chest"}, {1}) -- 0 if not present
  4125.         sleep(1.5)
  4126.        
  4127.     -- MINING
  4128.     elseif choice == 11 then --Create Mine at this level
  4129.         checkFuelNeeded(960)
  4130.         T:checkInventoryForItem({"minecraft:torch"}, {24}, false)
  4131.         T:checkInventoryForItem({"minecraft:bucket"}, {1}, false)
  4132.         T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:netherrack"}, {64, 128})
  4133.         T:checkInventoryForItem({"minecraft:chest"}, {1})
  4134.         sleep(2)
  4135.         print("CreateMine starting")
  4136.         createMine()
  4137.     elseif choice == 12 then    -- ladder to bedrock
  4138.         local level = T:getY()
  4139.         print("Current saved y level = "..level)
  4140.         print("\nIs this correct? (y/n + Enter)")
  4141.         if read() ~= "y" then
  4142.             level = getSize(true, "Current level (F3->Y coord)?_", 4, 300)
  4143.         end
  4144.         checkFuelNeeded(level * 2)
  4145.         T:checkInventoryForItem({"minecraft:ladder"}, {level})
  4146.         T:checkInventoryForItem({"minecraft:torch"}, {16}, false)
  4147.         T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt", "minecraft:netherrack"}, {64, 64, 128})
  4148.         print(thanks)
  4149.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4150.         print("Creating ladder to bedrock")
  4151.         createLadder("bedrock", level)
  4152.     elseif choice == 13 then    -- ladder to surface
  4153.         local currentLevel = getSize(true,"Current level (F3->Y coord)?_", 4, 300)
  4154.         local destLevel = getSize(true, "Go up to level? "..currentLevel + 2 .."-"..currentLevel + 300 ..")", currentLevel + 2, currentLevel + 300)
  4155.         local inAir = getSize(true, "Is this ladder in open air? (n:0 y:1)", 0, 1)
  4156.         local range = destLevel - currentLevel
  4157.         checkFuelNeeded(range * 2)
  4158.         T:checkInventoryForItem({"minecraft:ladder"}, {range})
  4159.         if inAir then
  4160.             range = range * 6
  4161.         else
  4162.             range = range * 3
  4163.         end
  4164.         range = range + math.ceil(((destLevel - currentLevel) / 2)) -- allow for shelves
  4165.         --T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt", "minecraft:netherrack"}, {range, range, range})
  4166.         T:checkInventoryForItem({"common blocks"}, {range})
  4167.         print(thanks)
  4168.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4169.         print("Creating ladder going up")
  4170.         createLadder("surface", currentLevel, destLevel)
  4171.     elseif choice == 14 or choice == 15 then    -- stairs to bedrock or surface
  4172.         local level = getSize(true,"Current level (F3->Y coord)?_", 4, 300)
  4173.         if level >= 64 then --assume going down
  4174.             checkFuelNeeded(level * 10)
  4175.         else -- assume going up
  4176.             checkFuelNeeded((64 - level) * 10)
  4177.         end
  4178.         local numStairsNeeded = 0
  4179.         if choice == 14 then -- to bedrock
  4180.             numStairsNeeded = math.ceil(level / 4)
  4181.         else
  4182.             numStairsNeeded = math.ceil((64 - level) / 4)
  4183.         end
  4184.         local data = T:getStock("stairs")
  4185.         --{rt.total, rt.mostSlot, rt.leastSlot, rt.mostCount, rt.leastCount}
  4186.         local numStairs = data.total
  4187.         --print(numStairs..' stairs onboard')
  4188.         local cobbleNeeded = 256 - (level * 2)
  4189.         if numStairs > 0 then
  4190.             cobbleNeeded = 192 - (math.floor((2 * numStairs) / 3))
  4191.             if cobbleNeeded < 64 then
  4192.                 cobbleNeeded = 64
  4193.             end
  4194.         end
  4195.         T:checkInventoryForItem({"stairs"}, {numStairsNeeded}, false)
  4196.         T:checkInventoryForItem({"minecraft:cobblestone"}, {cobbleNeeded})
  4197.         T:checkInventoryForItem({"minecraft:chest"}, {1})   -- needed for crafting
  4198.         print(thanks)
  4199.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4200.         if choice == 14 then
  4201.             print("Creating stairs to bedrock")
  4202.             createStaircase("bedrock", level)
  4203.         else
  4204.             print("Creating stairs to surface")
  4205.             createStaircase("surface", level)
  4206.         end
  4207.        
  4208.     -- FORESTRY
  4209.     elseif choice == 21 then    -- Fell tree
  4210.         if T:isLog("forward") then
  4211.             T:checkInventoryForItem({"minecraft:chest"}, {1}, false)
  4212.             T:forward(1)
  4213.             T:harvestWholeTree("up")
  4214.             print("Press esc within 2 seconds!")
  4215.             os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4216.             print("Felling tree")
  4217.         else
  4218.             print("No log in front..")
  4219.             print("Move me in front of a tree!")
  4220.             os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4221.             retValue = ""
  4222.         end
  4223.     elseif choice == 22 then --Create treefarm
  4224.         if size == 1 then
  4225.             checkFuelNeeded(300)
  4226.         else
  4227.             checkFuelNeeded(900)
  4228.         end
  4229.         T:checkInventoryForItem({"minecraft:dirt"}, {64})
  4230.         if size == 1 then
  4231.             T:checkInventoryForItem({"minecraft:torch"}, {16}, false)
  4232.         else
  4233.             T:checkInventoryForItem({"minecraft:torch"}, {64}, false)
  4234.         end
  4235.         print(thanks)
  4236.         sleep(2)
  4237.         print("CreateTreefarm starting: size "..size)
  4238.         createTreefarm(size)
  4239.     elseif choice == 23 then -- Plant treefarm
  4240.         if size == 1 then
  4241.             checkFuelNeeded(180)
  4242.         else
  4243.             checkFuelNeeded(480)
  4244.         end
  4245.         T:checkInventoryForItem({"sapling"}, {4})
  4246.         print(thanks)
  4247.         print("plantTreefarm starting: size "..size)
  4248.         plantTreefarm(size)
  4249.     elseif choice == 24 then    -- Harvest treefarm
  4250.         print(thanks)
  4251.         os.sleep(2)
  4252.         print("Harvesting treefarm starting: size "..size)
  4253.         harvestTreeFarm(size)
  4254.     elseif choice == 25 then -- create auto tree farm
  4255.         checkFuelNeeded(1000)
  4256.         T:checkInventoryForItem({"minecraft:chest"}, {3})
  4257.         T:checkInventoryForItem({"minecraft:dirt"}, {128})
  4258.         T:checkInventoryForItem({"minecraft:cobblestone"}, {128})
  4259.         T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
  4260.         T:checkInventoryForItem({"minecraft:hopper"}, {1})
  4261.         T:checkInventoryForItem({"minecraft:torch"}, {21})
  4262.         T:checkInventoryForItem({"sapling"}, {21}, false)
  4263.         print(thanks)
  4264.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4265.         print("Creating automatic tree farm...")
  4266.         createAutoTreeFarm()
  4267.     elseif choice == 26 then    -- Manage auto-treefarm
  4268.         manageFarmSetup("tree")
  4269.        
  4270.     -- FARMING
  4271.     elseif choice == 31 then    -- Create modular farm
  4272.         checkFuelNeeded(300)
  4273.         T:checkInventoryForItem({"minecraft:cobblestone"}, {64})
  4274.         T:checkInventoryForItem({"minecraft:dirt"}, {128}, false)
  4275.         T:checkInventoryForItem({"minecraft:water_bucket"}, {4})
  4276.         T:checkInventoryForItem({"minecraft:chest"}, {4})
  4277.         T:checkInventoryForItem({"sapling"}, {1})
  4278.         print(thanks)
  4279.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4280.         print("Creating modular wheat farm")
  4281.         createFarm()
  4282.     elseif choice == 32 then    -- Extend modular farm
  4283.         checkFuelNeeded(300)
  4284.         T:checkInventoryForItem({"minecraft:cobblestone"}, {64})
  4285.         T:checkInventoryForItem({"minecraft:dirt"}, {128}, false)
  4286.         T:checkInventoryForItem({"minecraft:water_bucket"}, {4})
  4287.         T:checkInventoryForItem({"minecraft:chest"}, {5})
  4288.         T:checkInventoryForItem({"sapling"}, {1})
  4289.         print("Checking position...\n")
  4290.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4291.         createFarmExtension()
  4292.     elseif choice == 33 then    -- manage modular farm
  4293.         manageFarmSetup("farm")
  4294.    
  4295.     -- OBSIDIAN
  4296.     elseif choice == 41 then --harvest obsidian
  4297.         checkFuelNeeded(width * length * 3)
  4298.         T:checkInventoryForItem({"minecraft:cobblestone"}, {width * length})
  4299.         print(thanks)
  4300.         sleep(2)
  4301.         print("Harvesting obsidian area: size "..width.. " x "..length)
  4302.         harvestObsidian(width, length)
  4303.     elseif choice == 42 then --build nether portal
  4304.         checkFuelNeeded(20)
  4305.         T:checkInventoryForItem({"minecraft:obsidian"}, {10})
  4306.         T:checkInventoryForItem({"minecraft:cobblestone"}, {8})
  4307.         print(thanks)
  4308.         sleep(2)
  4309.         print("Building Nether portal")
  4310.         createPortal()
  4311.     elseif choice == 43 then --demolish nether portal
  4312.         checkFuelNeeded(20)
  4313.         print("Demolishing Nether portal")
  4314.         demolishPortal()
  4315.        
  4316.     -- CANAL BRIDGE
  4317.     elseif choice == 51 then    -- continuous path over void/water/lava
  4318.         checkFuelNeeded(512) -- allow for 512 length
  4319.         T:checkInventoryForItem({"common blocks"}, {64}, false)
  4320.         --T:checkInventoryForItem({"minecraft:cobblestone",  "minecraft:dirt"}, {64, 64}, false)
  4321.         T:checkInventoryForItem({"minecraft:torch"}, {64}, false)
  4322.         print(thanks)
  4323.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4324.         print("Building continuous path")
  4325.         createPath()
  4326.     elseif choice == 52 then    -- simple 2 block coridoor
  4327.         checkFuelNeeded(length)
  4328.         T:checkInventoryForItem({"minecraft:cobblestone",  "minecraft:dirt"}, {64, 64}, false)
  4329.         T:checkInventoryForItem({"minecraft:torch"}, {64}, false)
  4330.         print(thanks)
  4331.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4332.         print("Building simple coridoor")
  4333.         createCoridoor(length)
  4334.     elseif choice == 53 then    -- bridge over void/water/lava
  4335.         checkFuelNeeded((size + 1) * 2)
  4336.         T:checkInventoryForItem({"minecraft:cobblestone",  "minecraft:dirt"}, {size * 2, size * 2})
  4337.         print(thanks)
  4338.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4339.         print("Building bridge ".. size.." blocks")
  4340.         createBridge(size)
  4341.     elseif choice == 54 then    -- covered walkway
  4342.         checkFuelNeeded((size + 1) * 2)
  4343.         T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {size * 2, size * 2})
  4344.         T:checkInventoryForItem({"minecraft:torch"}, {math.ceil(size / 8)})
  4345.         print(thanks)
  4346.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4347.         print("Building bridge ".. size.." blocks")
  4348.         createWalkway(size)
  4349.     elseif choice == 55 or choice == 56 then    -- canal management
  4350.         checkFuelNeeded(2048) -- allow for 1024 length
  4351.         T:checkInventoryForItem({"minecraft:cobblestone",  "minecraft:dirt"}, {256, 256})
  4352.         T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
  4353.         T:checkInventoryForItem({"minecraft:torch"}, {64}, false)
  4354.         print(thanks)
  4355.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4356.         print("Building canal")
  4357.         createCanal(choice, length, height, width) -- eg 55, 312, 1 = complete a canal 312 blocks long on top of the wall
  4358.    
  4359.     -- MOB SPAWNER
  4360.     elseif choice == 61 then    --  9x9 hollow cube cobble lined
  4361.         checkFuelNeeded(600) -- allow for 600 moves
  4362.         T:checkInventoryForItem({"minecraft:cobblestone"}, {256})
  4363.         T:checkInventoryForItem({"slab"}, {1})
  4364.         print(thanks)
  4365.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4366.         createMobFarmCube(false)
  4367.     elseif choice == 62 then -- dig mob trench
  4368.         checkFuelNeeded(length * height) -- allow for 600 moves
  4369.         T:checkInventoryForItem({"minecraft:cobblestone"}, {128})
  4370.         print(thanks)
  4371.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4372.         digMobTrench(height, length)
  4373.     elseif choice == 63 then    --  flood mob spawner
  4374.         checkFuelNeeded(60) -- allow for 60 moves
  4375.         T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
  4376.         T:checkInventoryForItem({"fence"}, {2})
  4377.         T:checkInventoryForItem({"sign"}, {2})
  4378.         T:checkInventoryForItem({"slab"}, {1})
  4379.         T:checkInventoryForItem({"minecraft:soul_sand", "minecraft:dirt"}, {1, 1}, true)
  4380.         print(thanks)
  4381.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4382.         floodMobFarm()
  4383.     elseif choice == 64 then -- build bubble lift on top of soul sand
  4384.         checkFuelNeeded(200) -- allow for 200 moves
  4385.         T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
  4386.         T:checkInventoryForItem({"minecraft:cobblestone"}, {128})
  4387.         if T:getBlockType("down") ~= "minecraft:soul_sand" then
  4388.             T:checkInventoryForItem({"minecraft:soul_sand"}, {1})
  4389.         end
  4390.         print(thanks)
  4391.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4392.         createMobBubbleLift(size)
  4393.     elseif choice == 65 then    -- Blaze spawner
  4394.         checkFuelNeeded(2500) -- allow for 2500 moves
  4395.         T:checkInventoryForItem({"minecraft:cobblestone"}, {640})
  4396.         T:checkInventoryForItem({"slab"}, {1})
  4397.         print("You will be asked for more assets later\n")
  4398.         print(thanks)
  4399.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4400.         createMobFarmCube(true)
  4401.     elseif choice == 66 then -- build endermen tower
  4402.         checkFuelNeeded(5000) -- allow for 5000 moves
  4403.         if T:getBlockType("down") ~= "minecraft:chest" then
  4404.             T:checkInventoryForItem({"minecraft:chest"}, {1})
  4405.             T:place("chest", -1, "down", false)
  4406.             T:checkInventoryForItem({"stone"}, {1024}) -- 16 stacks
  4407.             for i = 1, 16 do
  4408.                 turtle.select(i)
  4409.                 turtle.dropDown()
  4410.             end
  4411.             T:checkInventoryForItem({"stone"}, {832}) -- 13 stacks
  4412.             for i = 1, 16 do
  4413.                 turtle.select(i)
  4414.                 turtle.dropDown()
  4415.             end
  4416.         end
  4417.         T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
  4418.         T:checkInventoryForItem({"minecraft:bucket"}, {10})
  4419.         T:checkInventoryForItem({"fence"}, {192})
  4420.         T:checkInventoryForItem({"sign"}, {8})
  4421.         T:checkInventoryForItem({"ladder"}, {3})
  4422.         T:checkInventoryForItem({"minecraft:soul_sand"}, {2})
  4423.         print(thanks)
  4424.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4425.         createEnderTower()
  4426.     --[[
  4427.     elseif choice == 66 then    --  block path over water
  4428.         checkFuelNeeded(size + 24) -- allow for 88 moves
  4429.         T:checkInventoryForItem({"minecraft:cobblestone"}, {88})
  4430.         T:checkInventoryForItem({"stone"}, {1})
  4431.         T:checkInventoryForItem({"minecraft:torch"}, {8}, false)
  4432.         print(thanks)
  4433.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4434.         createMobSpawnerBase(size)
  4435.     elseif choice == 67 then    -- mob spawner tower
  4436.         checkFuelNeeded(1500) -- allow for 1000 blocks +  moves
  4437.         T:checkInventoryForItem({"minecraft:chest"}, {2})
  4438.         T:checkInventoryForItem({"minecraft:hopper"}, {2})
  4439.         T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
  4440.         T:checkInventoryForItem({"minecraft:cobblestone"}, {576})
  4441.         T:checkInventoryForItem({"stone"}, {1})
  4442.         print(thanks)
  4443.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4444.         createMobSpawnerTower(size)
  4445.     elseif choice == 68 then    -- mob spawner tank
  4446.         checkFuelNeeded(1000) -- allow for 500 blocks +  moves
  4447.         T:checkInventoryForItem({"minecraft:water_bucket"}, {2})
  4448.         T:checkInventoryForItem({"minecraft:cobblestone"}, {576})
  4449.         T:checkInventoryForItem({"stone"}, {1})
  4450.         print(thanks)
  4451.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4452.         createMobSpawnerTank()
  4453.     elseif choice == 69 then    -- mob spawner roof
  4454.         checkFuelNeeded(500) -- allow for 400 blocks +  moves
  4455.         T:checkInventoryForItem({"minecraft:cobblestone"}, {384})
  4456.         T:checkInventoryForItem({"minecraft:torch"}, {20}, false)
  4457.         print(thanks)
  4458.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4459.         createMobSpawnerRoof()
  4460.     ]]
  4461.            
  4462.     -- AREA CARVING
  4463.     elseif choice == 71 then--Clear area
  4464.         checkFuelNeeded(width * length * 3)
  4465.         T:checkInventoryForItem({"minecraft:dirt"}, {64})
  4466.         print(thanks)
  4467.         sleep(2)
  4468.         print("Clearing area: size "..width.. " x "..length)
  4469.         clearArea(width, length, true)
  4470.     elseif choice == 72 then --Clear rectangle
  4471.         checkFuelNeeded(width * length)
  4472.         print("Clearing rectangle: size "..width.. " x "..length)
  4473.         clearRectangle(width, length)
  4474.     elseif choice == 73 then --Clear wall
  4475.         checkFuelNeeded(length * height)
  4476.         print("Recycling wall "..height.." blocks high")
  4477.         clearWall(1, length, height, size)
  4478.     elseif choice == 74 then --Clear single height perimeter wall
  4479.         checkFuelNeeded((width + length) * 2)
  4480.         print("Recycling wall section "..width.." x "..length)
  4481.         clearPerimeterWall(width, length, 1)
  4482.     elseif choice == 75 then --Clear hollow structure
  4483.         --size =  Bottom->Top (0), Top->bottom(1)
  4484.         local withCeiling = true
  4485.         local withFloor = true
  4486.         local r = getSize(false, "Remove ceiling? (1 (y), 0 (n))", 0, 1)
  4487.         if r == 0 then
  4488.             withCeiling = false
  4489.         end
  4490.         local r = getSize(false, "Remove floor? (1 (y), 0 (n))", 0, 1)
  4491.         if r == 0 then
  4492.             withFloor = false
  4493.         end
  4494.         checkFuelNeeded((width * length) + ((width + length) * height))
  4495.         print("Recycling hollow structure "..width.." x "..length.." height: "..height)
  4496.         clearBuilding(width, length, height, size, withCeiling, withFloor)
  4497.     elseif choice == 76 then --Clear solid structure
  4498.         --size =  Bottom->Top (0), Top->bottom(1)
  4499.         checkFuelNeeded((width * length) + ((width + length) * height))
  4500.         print("Recycling solid structure "..width.." x "..length.." height: "..height)
  4501.         clearSolid(width, length, height, size) -- size is 'up' or 'down'
  4502.     elseif choice == 77 then    -- Dig trench
  4503.         checkFuelNeeded(height * length * 2)
  4504.         print(thanks)
  4505.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4506.         if length == 0 then
  4507.             print("Digging continuous trench "..height.." blocks deep")
  4508.         else
  4509.             print("Digging trench "..length.." blocks long, "..height.." blocks deep")
  4510.         end
  4511.         digTrench(height, length)
  4512.     elseif choice == 78 then --Carve mountain
  4513.         --size =  Left <- Right (0), Left _> Right(1)
  4514.         checkFuelNeeded(length * width * 10)
  4515.         print("Carving mountain side "..width.." x "..length)
  4516.         clearMountainSide(width, length, size) -- size is 'left<-Right' or 'left->Right'
  4517.        
  4518.     -- LAVA WATER
  4519.     elseif choice == 81 then --build containing wall in water or lava
  4520.         checkFuelNeeded(length * length)
  4521.         T:checkInventoryForItem({"minecraft:cobblestone",  "minecraft:dirt"}, {1024, 1024}, false)
  4522.         print("Building retaining wall in lava/water. length"..length)
  4523.         createRetainingWall(length, height)
  4524.     elseif choice == 82 then --drop sand
  4525.         checkFuelNeeded(100)
  4526.         T:checkInventoryForItem({"minecraft:sand"}, {1024}, false)
  4527.         print("Building sand wall. length: "..length)
  4528.         createSandWall(length)
  4529.     elseif choice == 83 then --decapitate and drop sand
  4530.         checkFuelNeeded(length * width)
  4531.         T:checkInventoryForItem({"minecraft:sand"}, {768}, false)
  4532.         print("Decapiating structure. length: "..length.." width: "..width)
  4533.         decapitateBuilding(width, length)
  4534.     elseif choice == 84 then --harvest sand
  4535.         checkFuelNeeded(100)
  4536.         print("Digging sand. length: "..length)
  4537.         clearSandWall(length)
  4538.     elseif choice == 85 then --remove sand cube
  4539.         checkFuelNeeded(length * width * 4)
  4540.         print("Removing sand cube. length: "..length.." width: "..width)
  4541.         clearSandCube(width, length)
  4542.     elseif choice == 86 then --
  4543.         --[[
  4544.         checkFuelNeeded(length * width + 64)
  4545.         print("Clearing monument layer: "..length.." width: "..width)
  4546.         clearMonumentLayer(width, length, size)]]
  4547.     elseif  choice == 87 then -- Drain water/lava
  4548.         if length == 0 or width == 0 then
  4549.             checkFuelNeeded(width * length)
  4550.             T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {128, 128}, false)
  4551.             print("Draining enclosed area with auto settings")
  4552.         else
  4553.             checkFuelNeeded(width * length)
  4554.             T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt"}, {length * 2, length * 2}, false)
  4555.             print("Draining enclosed area "..width.." x "..length)
  4556.         end
  4557.         drainLiquid(width, length, size)
  4558.     elseif choice == 88 then --clear monument layer
  4559.         checkFuelNeeded(length * width + 64)
  4560.         print("Clearing monument layer: "..length.." width: "..width)
  4561.         clearMonumentLayer(width, length, size)
  4562.     elseif choice == 89 then --ladder to water/lava
  4563.         checkFuelNeeded(height * 2)
  4564.         T:checkInventoryForItem({"minecraft:ladder"}, {height})
  4565.         local cobble = height * 3 + 10
  4566.         T:checkInventoryForItem({"minecraft:cobblestone", "minecraft:dirt", "minecraft:netherrack"}, {cobble, cobble, cobble})
  4567.         print(thanks)
  4568.         os.sleep(2)    -- pause for 2 secs to allow time to press esc
  4569.         print("Creating ladder to bedrock")
  4570.         createLadderToWater()
  4571.     elseif choice == 810 then --remove plants
  4572.         checkFuelNeeded(length * width * 4)
  4573.         T:checkInventoryForItem({"minecraft:sand"}, {64})
  4574.         print("Removing seaweed. length: "..length.." width: "..width)
  4575.         clearSeaweed(width, length)
  4576.        
  4577.     -- RAILWAY
  4578.     elseif choice == 91 then --place redstone torch level or downward slope
  4579.         checkFuelNeeded(10)
  4580.         local userChoice = T:checkInventoryForItem({"userChoice"}, {1})
  4581.         T:checkInventoryForItem({"minecraft:redstone_torch"}, {1})
  4582.         print("Placing redstone torch on ".. userChoice)
  4583.         placeRedstoneTorch("level", userChoice)
  4584.     elseif choice == 92 then --place redstone torch on upward slope
  4585.         checkFuelNeeded(10)
  4586.         local userChoice = T:checkInventoryForItem({"userChoice"}, {1})
  4587.         T:checkInventoryForItem({"minecraft:redstone_torch"}, {1})
  4588.         print("Placing redstone torch and ".. userChoice)
  4589.         placeRedstoneTorch("up", userChoice)
  4590.     elseif choice == 93 then --build downward slope
  4591.         checkFuelNeeded(height * 2)
  4592.         local userChoice = T:checkInventoryForItem({"userChoice"}, {height})
  4593.         T:checkInventoryForItem({"minecraft:redstone_torch"}, {math.ceil(height / 3)}, false)
  4594.         print("Building downward slope with ".. userChoice)
  4595.         createRailwayDown(userChoice, height)
  4596.     elseif choice == 94 then --build upward slope
  4597.         checkFuelNeeded(height * 2)
  4598.         local userChoice = T:checkInventoryForItem({"userChoice"}, {height + math.ceil(height / 3)})
  4599.         T:checkInventoryForItem({"minecraft:redstone_torch"}, {math.ceil(height / 3)}, false)
  4600.         print("Building upward slope with ".. userChoice)
  4601.         createRailwayUp(userChoice, height)
  4602.     end
  4603.     return retValue
  4604. end
  4605.  
  4606. function harvestObsidian(width, length)
  4607.     local heightParts = math.floor(length / 8) -- eg 12/8 = 1
  4608.     local lastPart = length - (heightParts * 8) -- eg 12 - (1 * 8) = 4
  4609.     if width % 2 ~= 0 then
  4610.         width = width + 1
  4611.     end
  4612.     for y = 1, width do
  4613.         print("Mining column "..tostring(y).." of "..tostring(width))
  4614.         for j = 1, heightParts do
  4615.             T:go("m8")
  4616.         end
  4617.         if lastPart > 0 then
  4618.             T:go("m"..tostring(lastPart)) -- eg m4
  4619.         end
  4620.         -- width = tonumber(width)
  4621.         if y < width then
  4622.             if y % 2 == 0 then
  4623.                 T:go("L1F1L1")
  4624.             else
  4625.                 T:go("R1F1R1")
  4626.             end
  4627.         end
  4628.     end
  4629. end
  4630.  
  4631. function harvestRun(runLength)
  4632.     local blockType
  4633.     local blockModifier
  4634.  
  4635.     for i = 1, runLength do
  4636.         blockType, blockModifier = T:getBlockType("forward") -- store information about the block in front in a table
  4637.         if blockType ~= "" then
  4638.             if string.find(blockType, "log") ~= nil then
  4639.                 T:harvestTree(true, false)
  4640.             else
  4641.                 T:forward(1)           
  4642.             end
  4643.         else
  4644.             T:forward(1)
  4645.         end
  4646.     end
  4647. end
  4648.  
  4649. function harvestTreeFarm(size)
  4650.     local loopCount
  4651.     -- return blockType, blockModifier -- eg  'minecraft:log', 0 on older versions, "minecraft:oak_log" , nil on newer
  4652.     local blockType, _ = T:getBlockType("forward") -- store information about the block in front in a table
  4653.     if size == 0 then --fell single tree
  4654.         if blockType ~= "" then
  4655.             if string.find(blockType, "log") ~= nil then
  4656.                 T:harvestTree(true, false)         
  4657.             end
  4658.         end
  4659.     else
  4660.         if size == 1 then
  4661.             loopCount = 4
  4662.         else
  4663.             loopCount = 8
  4664.         end
  4665.         if blockType ~= "" then
  4666.             if string.find(blockType, "dirt") ~= nil or string.find(blockType, "grass") ~= nil then
  4667.                 T:up(1)
  4668.             end
  4669.         end
  4670.         for i = 1, loopCount do
  4671.             harvestRun(loopCount * 2)
  4672.             turtle.turnRight()
  4673.             harvestRun(1)
  4674.             turtle.turnRight() --now facing opposite direction
  4675.             harvestRun(loopCount * 2)
  4676.             if i < loopCount then -- turn left if not on last run
  4677.                 turtle.turnLeft()
  4678.                 harvestRun(1)
  4679.                 turtle.turnLeft()
  4680.             end
  4681.         end
  4682.         --return to starting position
  4683.         turtle.turnRight()
  4684.         harvestRun(loopCount * 2 - 1)
  4685.         turtle.turnRight()
  4686.     end
  4687. end
  4688.  
  4689. function manageFarm(useFile)
  4690.     local lib = {}
  4691.    
  4692.     function lib.checkPosition(currentRow)
  4693.         local atHome = false
  4694.         local blockType = T:getBlockType("down")
  4695.         print("Checking position\n"..blockType.. " below")
  4696.         if string.find(blockType, "water") ~= nil then --over water
  4697.             if T:getBlockType("forward") == "minecraft:chest" then
  4698.                 atHome = true
  4699.                 T:turnRight(1)
  4700.                 if T:getBlockType("forward") == "minecraft:chest" then
  4701.                     T:turnRight(2)
  4702.                 else
  4703.                     T:turnRight(1)
  4704.                 end
  4705.             else -- not a chest
  4706.                 T:turnRight(1)
  4707.                 if T:getBlockType("forward") == "minecraft:chest" then
  4708.                     atHome = true
  4709.                     T:turnLeft(1)
  4710.                 end
  4711.             end
  4712.         end
  4713.         if currentRow == nil and not atHome then -- no position file
  4714.             print("Unable to determine my position.\n")
  4715.             print("Place me in the lower left corner")
  4716.             print("over water, facing the crops")
  4717.             print("with chests to my right and behind")
  4718.             print("\nEnter to continue")
  4719.             read()
  4720.         end
  4721.         --[[
  4722.         --debug
  4723.         if atHome then
  4724.             print("Position ok. Enter")
  4725.         else
  4726.             print("NOt atHome?. Enter")
  4727.         end
  4728.         read()]]
  4729.         return atHome
  4730.     end
  4731.    
  4732.     function lib.crossFarm(stopAtFirst)
  4733.         local blockType = ""
  4734.         if stopAtFirst == nil then
  4735.             stopAtFirst = false
  4736.         end
  4737.         -- will go forward until chest or cobble detected below
  4738.         -- if detected within 1 move, this is ignored
  4739.         local numMoves = 0
  4740.         local endOfPath = false
  4741.         while not endOfPath do
  4742.             local success, data = turtle.inspectDown()
  4743.             if data.name == nil then --nothing below
  4744.                 turtle.forward()
  4745.             elseif data.name == "minecraft:chest" or data.name =="minecraft:cobblestone" then
  4746.                 blockType = data.name
  4747.                 if stopAtFirst then -- do not move further if first instance of cobble or chest
  4748.                     endOfPath = true
  4749.                 else
  4750.                     if numMoves <= 1 then -- has chest been detected after 0 or 1 move?
  4751.                         turtle.forward()
  4752.                     else -- chest found after >1 move
  4753.                         endOfPath = true
  4754.                     end
  4755.                 end
  4756.             else
  4757.                 turtle.forward()
  4758.             end
  4759.             numMoves = numMoves + 1
  4760.         end
  4761.         return blockType -- either "" or chest/cobble
  4762.     end
  4763.    
  4764.     function lib.emptyCropItem(direction, item, keepAmount)
  4765.         local lib2 = {}
  4766.        
  4767.         function lib2.getInventory(tbl)
  4768.             local indexes = {"carrot", "potato", "wheat_seeds",  "beetroot_seeds", "wheat", "beetroot", "sapling"} --order important wheat_seeds before wheat
  4769.             local inventory = {}
  4770.             for i = 1, #indexes do
  4771.                 inventory[indexes[i]] = {}
  4772.                 inventory[indexes[i]].leastSlot = 0
  4773.                 inventory[indexes[i]].minQ = 0
  4774.                 inventory[indexes[i]].mostSlot = 0
  4775.                 inventory[indexes[i]].maxQ = 0
  4776.             end
  4777.             -- eg inventory["sapling"].leastSlot = 0
  4778.             for i = 1, 16 do
  4779.                 --print("index :"..i)
  4780.                 if turtle.getItemCount(i) >  0 then -- only check if items in slot
  4781.                     local data = turtle.getItemDetail(i)
  4782.                     local crop = ""
  4783.                     for j = 1, #indexes do
  4784.                         if data.name:find(indexes[j]) ~= nil then
  4785.                             crop = indexes[j]
  4786.                             break
  4787.                         end
  4788.                     end
  4789.                     -- eg carrot = tbl["minecraft:carrot"], sapling = tbl["minecraft:oak_sapling"]
  4790.                     if crop ~= "" then
  4791.                         if inventory[crop].leastSlot == 0 then
  4792.                             inventory[crop].leastSlot = i
  4793.                             inventory[crop].minQ = data.count
  4794.                         else -- crop already found
  4795.                             if data.count < inventory[crop].minQ then
  4796.                                 if data.count > inventory[crop].maxQ then
  4797.                                     inventory[crop].mostSlot = i
  4798.                                     inventory[crop].maxQ = data.count
  4799.                                 end
  4800.                                 inventory[crop].leastSlot = i
  4801.                                 inventory[crop].minQ = data.count
  4802.                             else -- current quantity > minQ. check if > maxQ
  4803.                                 if data.count >= inventory[crop].maxQ then
  4804.                                     inventory[crop].mostSlot = i
  4805.                                     inventory[crop].maxQ = data.count
  4806.                                 end
  4807.                             end
  4808.                         end
  4809.                         --print("Slot "..i.."-"..crop..": minQ:"..inventory[crop].minQ)
  4810.                         --read()
  4811.                     end
  4812.                 end
  4813.             end
  4814.             -- only one slot  available == leastSlot, mostSlot = 0
  4815.             -- 2 or more slots available == smallest in leastSlot, largest in mostSlot