Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- version = 20230328.1930
- --[[
- **********Toolkit v2**********
- https://pastebin.com/UFvjc1bw
- Last edited: see version YYYYMMDD.HHMM
- if NOT online:
- Make sure you create a folder 'lib' and place menu.lua and clsTurtle.lua into it
- else
- lib folder will be created and files obtained automatically!
- end
- ]]
- args = {...} -- eg "farm", "tree"
- local menu, T
- --[[
- Computercraft started with mc version 1.7.10 and went to 1.8.9
- ccTweaked started around mc 1.12 and currently at 1.18
- mc 1.18 has new blocks and bedrock at -64, so needs to be taken into account.
- _HOST = The ComputerCraft and Minecraft version of the current computer environment.
- For example, ComputerCraft 1.93.0 (Minecraft 1.15.2).
- ]]
- local bedrock = 0
- local ceiling = 255
- local deletesWater = false
- local mcMajorVersion = tonumber(_HOST:sub(_HOST:find("Minecraft") + 10, _HOST:find("\)") -3)) -- eg 1.18
- if mcMajorVersion < 1.7 and mcMajorVersion >= 1.18 then -- 1.12 to 1.??
- bedrock = -64
- ceiling = 319
- end
- if mcMajorVersion < 1.7 and mcMajorVersion <= 1.12 then -- 1.12 to 1.??
- deletesWater = true
- end
- local function attack(onPerch)
- local totalHitsF = 0
- local totalHitsU = 0
- local totalHitsD = 0
- if onPerch then
- turtle.digUp()
- end
- while true do
- local hitF = false
- local hitU = false
- local hitD = false
- if turtle.attackUp() then
- hitU = true
- totalHitsU = totalHitsU + 1
- end
- if onPerch then
- turtle.turnRight()
- else
- if turtle.attackDown() then
- hitD = true
- totalHitsD = totalHitsD + 1
- end
- if turtle.attack() then
- hitF = true
- totalHitsF = totalHitsF + 1
- end
- end
- if hitF or hitU or hitD then
- print("hits forward: "..totalHitsF..", up: "..totalHitsU..", down: "..totalHitsD)
- end
- end
- end
- local function checkFuelNeeded(quantity)
- local fuelNeeded = quantity - turtle.getFuelLevel() -- eg 600
- if fuelNeeded > 0 then
- if T:checkInventoryForItem({"minecraft:lava_bucket"}, {1}, false) == nil then
- if T:checkInventoryForItem({"coal"}, {math.ceil(fuelNeeded / 60)}, false) == nil then
- T:checkInventoryForItem({"planks"}, {math.ceil(fuelNeeded / 15)})
- end
- end
- T:refuel(quantity, true)
- end
- end
- local function checkLabel()
- if os.getComputerLabel() == nil then
- os.setComputerLabel("toolkit")
- print("Computer label set to "..os.getComputerLabel())
- end
- end
- local function checkLibs(libDir, filename)
- local fileExists = false
- if fs.exists(libDir) then
- if not fs.isDir(libDir) then
- fs.move(libDir, libDir.."Renamed")
- fs.makeDir(libDir)
- end
- else
- fs.makeDir(libDir)
- end
- if fs.exists(fs.combine(libDir, filename)) or fs.exists(fs.combine(libDir, filename..".lua")) then
- fileExists = true
- end
- return fileExists
- end
- local function clearAndReplantTrees()
- --[[ clear all trees in a rectangle area defined by walls, fences or non-dirt blocks
- replant with same type of sapling. If original tree 2 blocks wide, replant 4 if possible. ]]
- local lib = {}
- function lib.getSaplingFromLogType(log)
- --[[ get type of sapling to plant from log type ]]
- if log:find("oak") ~= nil then
- return "minecraft:oak_sapling"
- elseif log:find("spruce") ~= nil then
- return "minecraft:spruce_sapling"
- elseif log:find("birch") ~= nil then
- return "minecraft:birch_sapling"
- elseif log:find("jungle") ~= nil then
- return "minecraft:jungle_sapling"
- elseif log:find("acacia") ~= nil then
- return "minecraft:acacia_sapling"
- elseif log:find("dark_oak") ~= nil then
- return "minecraft:dark_oak_sapling"
- end
- return "sapling"
- end
- function lib.plantSapling(sapling, double)
- --[[ plant sapling(s) ]]
- if sapling == "" or sapling == nil then sapling = "sapling" end
- T:up(1)
- lib.suck()
- if double then -- check if enough saplings
- --slotData.lastSlot, slotData.leastModifier, total, slotData = T:getItemSlot(sapling, -1)
- local a, b, total, _ = T:getItemSlot(sapling, -1)
- if total >= 4 then
- for i = 1, 4 do
- T:place(sapling, -1, "down")
- T:go("F1R1")
- end
- T:forward(1) -- above pre-planted sapling
- else
- if not T:place(sapling, -1, "down") then
- T:place("sapling", -1, "down")
- end
- end
- else
- if not T:place(sapling, -1, "down") then
- T:place("sapling", -1, "down")
- end
- end
- turtle.select(1)
- end
- function lib.suck()
- --[[ Collect saplings, sticks and apples ]]
- turtle.select(1)
- turtle.suck()
- turtle.suckUp()
- turtle.suckDown()
- end
- function lib.turn(direction)
- --[[ change direction and return new value for direction ]]
- if direction == "r" then
- T:turnRight(1)
- direction = "l"
- else
- T:turnLeft(1)
- direction = "r"
- end
- return direction -- will only change direction variable if return value is used
- end
- function lib.emptyInventory(blockTypeD)
- --[[ Empty all except 32 of each sapling and 1 chest ]]
- if blockTypeD == nil then
- blockTypeD = T:getBlockType("down")
- end
- if blockTypeD:find("chest") ~= nil or blockTypeD:find("barrel") ~= nil then
- -- empty logs, apples, sticks and all but 1 stack of each sapling type
- T:emptyInventorySelection("down", {"chest", "oak_sapling", "birch_sapling", "spruce_sapling", "acacia_sapling", "jungle_sapling","dark_oak_sapling"},{1, 32, 32, 32, 32, 32, 32})
- return true
- else
- return false
- end
- end
- function lib.moveDown(blockTypeD)
- --[[ move down until hit ground. Break leaves and continue ]]
- if blockTypeD == nil then
- blockTypeD = T:getBlockType("down")
- end
- while blockTypeD == "" or blockTypeD:find("leaves") ~= nil do -- move down, breaking leavse
- T:down(1)
- lib.suck()
- blockTypeD = T:getBlockType("down")
- end
- return blockTypeD
- end
- function lib.moveForward()
- --[[ Move forward 1 block only, go down to ground while air or leaves below ]]
- local blockTypeF = T:getBlockType("forward")
- local blockTypeD = T:getBlockType("down")
- if blockTypeF == "" or blockTypeF:find("leaves") ~= nil then -- air or leaves ahead
- T:forward(1) -- move forward, breaking leaves
- T:dig("up") -- remove leaves / low branches above to allow space for player
- lib.suck()
- blockTypeD = lib.moveDown()
- if not lib.emptyInventory(blockTypeD) then -- check if above a corner chest / barrel
- if lib.isBorder(blockTypeD) then -- not above chest so check if above border
- return false, blockTypeD -- above a border block so stop
- end
- end
- blockTypeF = T:getBlockType("forward")
- return true, blockTypeF -- moved ok, could be air or block in front
- end
- return false, blockTypeF -- did not move, obstacle in front NOT leaves or air
- end
- function lib.moveUp(blockTypeF)
- --[[ Move up until air in front (dig leaves / harvest tree) ]]
- if blockTypeF == nil then
- blockTypeF = T:getBlockType("forward")
- end
- while blockTypeF:find("dirt") ~= nil or
- blockTypeF:find("grass_block") ~= nil or
- T:isVegetation(blockTypeF) do -- go up while dirt, grass-block or any vegetation in front
- T:up(1)
- blockTypeF = T:getBlockType("forward")
- if blockTypeF:find("log") ~= nil then
- lib.harvestTree(blockTypeF)
- return T:getBlockType("forward")
- elseif blockTypeF:find("leaves") ~= nil then
- T:dig("forward")
- return ""
- end
- end
- return blockTypeF -- should be "" (air) or any border block
- end
- function lib.harvestTree(blockTypeF)
- --[[ Fell tree, returns true if double size ]]
- -- clsTurtle.harvestTree(extend, craftChest, direction)
- local saplingType = lib.getSaplingFromLogType(blockTypeF)
- local double = T:harvestTree(false, false, "forward") -- assume single tree, will auto-discover
- lib.plantSapling(saplingType, double)
- end
- function lib.safeMove()
- --[[ move forward until border reached. loop breaks at that point ]]
- local blockTypeF = ""
- local success = true
- while success do
- success, blockTypeF = lib.moveForward() -- move forward 1 block, return block type ahead
- if not success then -- did not move forwards, block in the way: either log, dirt/grass, border block or vegetation
- if blockTypeF:find("log") then -- tree found
- lib.harvestTree(blockTypeF)
- success = true -- block (log) removed, try again
- else
- success = not lib.isBorder(blockTypeF) -- Is at border?: if is at border success = false so loop stops
- if success then -- Not at border. Dirt/grass vegetation in front
- blockTypeF = lib.moveUp(blockTypeF) -- move up until leaves/log/air
- success = not lib.isBorder(blockTypeF) -- Is at border?: if is at border success = false so loop stops
- if success then -- keep moving forward
- if blockTypeF:find("log") then -- tree found
- lib.harvestTree(blockTypeF)
- end
- -- else blockTypeF is air/leaves border has been checked
- end
- end
- end
- end -- else success = true, 1 block moved so continue
- end
- end
- function lib.isBorder(blockType)
- --[[ Is the block log, dirt, grass_block, vegetation: non-border, or other:border]]
- if blockType == nil then -- not passed as parameter
- blockType = T:getBlockType("forward")
- end
- if blockType == "" then -- air ahead: not border
- return false, ""
- else -- could be border or other
- if blockType:find("dirt") ~= nil or blockType:find("grass_block") ~= nil or blockType:find("log") ~= nil then -- either dirt, grass block or log
- return false, blockType -- dirt, grass, log: not border
- end
- if T:isVegetation(blockType) then -- vegetation found: not border
- return false, blockType
- end
- end
- return true, blockType -- dirt, grass_block, log and vegetation eliminated:must be border
- end
- function lib.inPosition()
- --[[ check if in lower left corner ]]
- local inPosition = true -- assume correct
- if not turtle.detectDown() then -- hanging in mid-air
- return false
- end
- T:turnLeft(1)
- if lib.isBorder() then
- -- so far so good
- T:turnLeft(1)
- if not lib.isBorder() then -- not in correct place
- inPosition = false
- end
- T:turnRight(2) -- return to original position
- else
- inPosition = false
- T:turnRight(1) -- return to original position
- end
- return inPosition
- end
- function lib.findBorder()
- --[[ assume started after reset. if log above harvest tree else return to ground. Find starting corner]]
- local blockType = T:getBlockType("up") -- dig any logs above, return to ground
- local log = "sapling"
- if blockType:find("log") ~= nil then -- originally felling a tree so complete it
- log = lib.getSaplingFromLogType(blockType)
- local double = T:harvestTree(false, false, "up") -- assume single tree, will auto-discover
- lib.plantSapling(log, double)
- else -- no log above so go downm
- blockType = lib.moveDown() -- return to ground (or vegetation)
- end
- lib.safeMove() -- move forward until border reached
- T:turnRight(1)
- lib.safeMove() -- move forward until second border reached
- T:turnRight(1) -- should now be in correct position
- lib.emptyInventory() -- empty inventory if above a chest
- end
- local direction = "r"
- local blockTypeF = ""
- local success = false
- if not lib.inPosition() then
- lib.findBorder()
- end
- local secondBorderFound = false
- while not secondBorderFound do
- lib.safeMove() -- moves forward until reaches border forward or below
- lib.turn(direction) -- turn r or l. direction is not changed
- success, blockTypeF = lib.isBorder() -- no blockType passed as parameter so will return current block in new forward direction
- if success then
- secondBorderFound = true -- game over
- elseif blockTypeF:find("log") ~= nil then -- tree in front
- lib.harvestTree(blockTypeF)
- elseif blockTypeF == "" or blockTypeF:find("leaves") ~= nil then -- air or leaves in front
- T:forward(1) -- move forward 1 block
- lib.moveDown() -- go down if required
- elseif blockTypeF:find("dirt") ~= nil or
- blockTypeF:find("grass_block") ~= nil or
- T:isVegetation(blockTypeF) then -- dirt, grass_block or vegetation in front
- blockTypeF = lib.moveUp(blockTypeF) -- move up until air or border ahead.
- if lib.isBorder(blockTypeF) then -- border ahead
- secondBorderFound = true
- else -- air ahead
- T:forward(1) -- move forward 1 block
- end
- end
- direction = lib.turn(direction) -- turn r or l. direction is changed to opposite
- end
- lib.moveDown() -- return to ground level
- lib.emptyInventory()
- return {}
- end
- local function clearArea(width, length, useDirt)
- if useDirt == nil then
- useDirt = true
- end
- local evenWidth = false
- local evenHeight = false
- local loopWidth
- -- go(path, useTorch, torchInterval, leaveExisting)
- if width % 2 == 0 then
- evenWidth = true
- loopWidth = width / 2
- else
- loopWidth = math.ceil(width / 2)
- end
- if length % 2 == 0 then
- evenHeight = true
- end
- turtle.select(1)
- -- clear an area between 2 x 4 and 32 x 32
- -- if width is even no, then complete the up/down run
- -- if width odd no then finish at top of up run and reverse
- -- should be on flat ground, check voids below, harvest trees
- for x = 1, loopWidth do
- -- Clear first column (up)
- for y = 1, length do
- if useDirt then
- if not turtle.detectDown() then
- T:place("minecraft:dirt", -1, "down", true)
- else --if not water, dirt, grass , stone then replace with dirt
- blockType, blockModifier = T:getBlockType("down")
- if blockType ~= "" then
- if blockType ~= "minecraft:dirt" and blockType ~= "minecraft:grass_block" then
- turtle.digDown()
- T:place("minecraft:dirt", -1, "down", true)
- end
- end
- end
- end
- if y < length then
- T:go("F1+1", false,0,false)
- end
- end
- -- clear second column (down)
- if x < loopWidth or (x == loopWidth and evenWidth) then -- go down if on width 2,4,6,8 etc
- T:go("R1F1+1R1", false,0,false)
- for y = 1, length do
- if useDirt then
- if not turtle.detectDown() then
- T:place("minecraft:dirt", -1, "down", true)
- else
- blockType, blockModifier = T:getBlockType("down")
- if blockType ~= "" then
- if blockType ~= "minecraft:dirt" and blockType ~= "minecraft:grass_block" then
- turtle.digDown()
- T:place("minecraft:dirt", -1, "down", true)
- end
- end
- end
- end
- if y < length then
- T:go("F1+1", false, 0, false)
- end
- end
- if x < loopWidth then
- T:go("L1F1+1L1", false,0,false)
- else
- T:turnRight(1)
- T:forward(width - 1)
- T:turnRight(1)
- end
- else -- equals width but is 1,3,5,7 etc
- T:turnLeft(2) --turn round 180
- T:forward(length - 1)
- T:turnRight(1)
- T:forward(width - 1)
- T:turnRight(1)
- end
- end
- return {}
- end
- local function clearRectangle(R)
- --local function clearRectangle(width, length, up, down)
- -- height = 0: one level, 1 = +up, 2 = +down, 3 = +up/down
- local lib = {}
- function lib.UpDown(length)
- for l = 1, length do
- T:go("x0x2F1x0x2")
- end
- end
- function lib.Up(length)
- for l = 1, length do
- T:go("x0F1x0")
- end
- end
- function lib.Down(length)
- for l = 1, length do
- T:go("x2F1x2")
- end
- end
- function lib.Forward(length)
- T:forward(length)
- end
- -- could be 1 wide x xx R.length (trench) R.up and return
- -- could be 2+ x 2+
- -- even no of runs return after last run
- -- odd no of runs forward, back, forward, reverse and return
- turtle.select(1)
- if R.width == 1 then -- single block trench ahead only
- if R.up and R.down then -- single block wide trench dig R.up and R.down = 3 blocks deep
- T:up(1)
- lib.UpDown(R.length - 1)
- T:down(1)
- elseif R.up then -- single block wide trench dig R.up = 2 blocks deep
- lib.Up(R.length - 1)
- elseif R.down then -- single block wide trench dig R.down = 2 blocks deep
- lib.Down(R.length - 1)
- else -- single block wide = 1 block deep
- lib.Forward(R.length - 1)
- end
- T:turnRight(2) -- turn at the top of the run
- T:forward(R.length - 1) -- return to start
- T:turnRight(2) -- turn round to original position
- else -- R.width 2 or more blocks
- local iterations = 0 -- R.width = 2, 4, 6, 8 etc
- if R.width % 2 == 1 then -- R.width = 3, 5, 7, 9 eg R.width 7
- iterations = (R.width - 1) / 2 -- iterations 1, 2, 3, 4 for widths 3, 5, 7, 9
- else
- iterations = R.width / 2 -- iterations 1, 2, 3, 4 for widths 2, 4, 6, 8
- end
- for i = 1, iterations do -- eg 3 blocks wide, iterations = 1
- if R.up and R.down then -- dig R.up and R.down
- lib.UpDown(R.length - 1)
- T:go("x0x2R1F1x0x2R1x0x2") -- turn round
- lib.UpDown(R.length - 1)
- elseif R.up then -- dig R.up
- lib.Up(R.length - 1)
- T:go("x0R1F1x0R1x0")
- lib.Up(R.length - 1)
- elseif R.down then -- dig R.down
- lib.Down(R.length - 1)
- T:go("x2R1F1x2R1x2")
- lib.Down(R.length - 1)
- else -- no digging R.up or R.down
- lib.Forward(R.length - 1)
- T:go("R1F1R1")
- lib.Forward(R.length - 1)
- end
- -- if 1 less than end, reposition for next run
- if i < iterations then
- T:go("L1F1L1", false, 0, false)
- end
- end
- if R.width % 2 == 1 then -- additional run and return to base needed
- T:go("L1F1L1", false, 0, false)
- if R.up and R.down then
- lib.UpDown(R.length - 1)
- elseif R.up then
- lib.Up(R.length - 1)
- elseif R.down then
- lib.Down(R.length - 1)
- else
- lib.Forward(R.length - 1)
- end
- T:turnRight(2)
- T:forward(R.length - 1)
- end
- T:go("R1F"..R.width - 1 .."R1", false, 0, false)
- end
- return {}
- end
- local function clearPerimeter(width, length, up, down)
- local lib = {}
- function lib.UpDown(length)
- for l = 1, length do
- T:go("x0x2F1x0x2")
- end
- end
- function lib.Up(length)
- for l = 1, length do
- T:go("x0F1x0")
- end
- end
- function lib.Down(length)
- for l = 1, length do
- T:go("x2F1x2")
- end
- end
- function lib.Forward(length)
- T:forward(length)
- end
- if up and down then
- for i = 1, 2 do
- lib.UpDown(length - 1)
- T:turnRight(1)
- lib.UpDown(width - 1)
- T:turnRight(1)
- end
- elseif up then
- for i = 1, 2 do
- lib.Up(length - 1)
- T:turnRight(1)
- lib.Up(width - 1)
- T:turnRight(1)
- end
- elseif down then
- for i = 1, 2 do
- lib.Down(length - 1)
- T:turnRight(1)
- lib.Down(width - 1)
- T:turnRight(1)
- end
- else
- for i = 1, 2 do
- lib.Forward(length - 1)
- T:turnRight(1)
- lib.Forward(width - 1)
- T:turnRight(1)
- end
- end
- return {}
- end
- local function clearBuilding(R, withCeiling, withFloor)
- --clearBuilding({width, length, height, direction, withCeiling, withFloor})
- --[[ Clear the outer shell of a building, leaving inside untouched. Optional floor/ceiling removal]]
- -- clearBuilding(width, length, height, size, withCeiling, withFloor) -- eg 5, 5, 6, 0, true, true
- -- clearBuilding(R, withCeiling, withFloor) -- R.size is 'up' or 'down'
- local lib = {}
- function lib.detectPosition(direction)
- --[[
- If going up check if has block in front and above else forward 1
- If going down chech has block in front and below els go down 1
- ]]
- if direction == "u" then
- if not turtle.detectUp() then -- no block above so must be in front of area to be cleared
- local response = menu.getBoolean("Am I outside clearing area (y/n)?")
- if response then
- T:forward(1)
- end
- end
- else
- if not turtle.detect() then -- no block ahead so must be sitting on top
- local response = menu.getBoolean("Am I above clearing area (y/n)?")
- if response then
- T:down(1)
- end
- end
- end
- end
- function lib.move(direction, blocks, reverse)
- if reverse == nil then
- reverse = false
- end
- if reverse then
- if direction == "d" then -- reverse direction
- T:up(blocks)
- else
- T:down(blocks)
- end
- else
- if direction == "u" then
- T:up(blocks)
- else
- T:down(blocks)
- end
- end
- return blocks
- end
- local direction = "u"
- if R.down then
- direction = "d"
- end
- local remaining = R.height -- eg 5
- lib.detectPosition(direction)
- if R.height <= 3 then --1-3 layers only
- if R.height == 1 then --one layer only
- if withFloor or withCeiling then -- only one layer, so clearRectangle
- clearRectangle({width = R.width, length = R.length, up = false, down = false})
- else
- clearPerimeter(R.width, R.length, false, false)
- end
- elseif R.height == 2 then --2 layers only current + dig up/down
- if withFloor or withCeiling then
- clearRectangle({width = R.width, length = R.length, up = withCeiling, down = withFloor})
- else
- if direction == "u" then
- clearPerimeter(R.width, R.length, true, false) -- clear perimeter and dig up
- else
- clearPerimeter(R.width, R.length, false, true) -- clear perimeter and dig down
- end
- end
- elseif R.height == 3 then --3 layers only current + dig up/down
- lib.move(direction, 1)
- clearPerimeter(R.width, R.length, true, true)
- end
- else -- 4 or more levels
- while remaining > 3 do
- if remaining == R.height then-- first iteration
- if (direction == "u" and withFloor) or (direction == "d" and withCeiling) then
- clearRectangle({width = R.width, length = R.length, up = false, down = false})
- else -- just the perimeter
- clearPerimeter(R.width, R.length, false, false) -- clear the building perimeter only
- end
- lib.move(direction, 2)
- end
- remaining = remaining - 4 -- eg 1st of height = 5 : 1 remaining. 2nd iteration remaining = 1
- clearPerimeter(R.width, R.length, true, true) -- clear the building perimeter only
- end
- if remaining == 3 then
- lib.move(direction, 3)
- clearPerimeter(R.width, R.length, true, true)
- if (direction == "u" and withCeiling) or (direction == "d" and withFloor) then
- lib.move(direction, 1)
- clearRectangle({width = R.width, length = R.length, up = false, down = false})
- end
- elseif remaining == 2 then
- if direction == "u" then
- if withCeiling then
- lib.move(direction, 2)
- clearPerimeter(R.width, R.length, true, false)
- lib.move(direction, 1)
- clearRectangle({width = R.width, length = R.length, up = false, down = false})
- else
- lib.move(direction, 3)
- clearPerimeter(R.width, R.length, true, false)
- end
- else
- if withFloor then
- lib.move(direction, 2)
- clearPerimeter(R.width, R.length, true, false)
- lib.move(direction, 1)
- clearRectangle({width = R.width, length = R.length, up = false, down = false})
- else
- lib.move(direction, 3)
- clearPerimeter(R.width, R.length, true, false)
- end
- end
- elseif remaining == 1 then
- lib.move(direction, 2)
- if (direction == "u" and withCeiling) or (direction == "d" and withFloor) then
- clearRectangle({width = R.width, length = R.length, up = false, down = false})
- else
- clearPerimeter(R.width, R.length, false, false)
- end
- end
- end
- lib.move(direction, R.height - 1, true) -- reverse direction
- return {}
- end
- local function clearMineshaft(equippedRight, equippedLeft, inInventory)
- local lib = {}
- function lib.checkCobweb(direction, inInventory)
- if inInventory == "minecraft:diamond_sword" then -- using a sword
- local side = "left"
- local item = T:getBlockType(direction)
- if item == "minecraft:cobweb" then
- --clsTurtle.equip(self, side, useItem, useDamage)
- if equippedRight == "minecraft:diamond_pickaxe" then
- side = "right"
- end
- T:equip(side, "minecraft:diamond_sword")
- T:dig(direction)
- T:equip(side, "minecraft:diamond_pickaxe")
- else
- T:dig(direction)
- end
- else
- T:dig(direction)
- end
- end
- -- check position by rotating until facing away from wall
- length = 0
- torch = 0
- turns = 0
- while not turtle.detect() do
- T:turnRight(1)
- turns = turns + 1
- if turns > 4 then
- return {"I am not facing a wall. Unable to continue"}
- end
- end
- T:turnRight(2)
- -- move forward until obstructed, digging up/down. place torches
- while not turtle.detect() do
- lib.checkCobweb("up", inInventory) -- dig cobweb or any other block up
- lib.checkCobweb("down", inInventory) -- dig cobweb or any other block down
- length = length + 1
- torch = torch + 1
- if torch == 8 then
- torch = 0
- T:place("minecraft:torch", -1, "down", false) ---(self, blockType, damageNo, direction, leaveExisting, signText)
- end
- lib.checkCobweb("forward", inInventory) -- dig cobweb or any other block in front
- T:forward(1)
- end
- -- turn right, forward, right, return to start with up/down dig
- T:go("R1F1R1")
- for i = 1, length, 1 do
- lib.checkCobweb("up", inInventory) -- dig cobweb or any other block up
- lib.checkCobweb("down", inInventory) -- dig cobweb or any other block down
- lib.checkCobweb("forward", inInventory) -- dig cobweb or any other block in front
- T:forward(1)
- end
- -- move to other wall and repeat.
- T:go("R1F2R1")
- for i = 1, length, 1 do
- lib.checkCobweb("up", inInventory) -- dig cobweb or any other block up
- lib.checkCobweb("down", inInventory) -- dig cobweb or any other block down
- lib.checkCobweb("forward", inInventory) -- dig cobweb or any other block in front
- T:forward(1)
- end
- lib.checkCobweb("up", inInventory) -- dig cobweb or any other block up
- lib.checkCobweb("down", inInventory) -- dig cobweb or any other block down
- return {}
- end
- local function clearVegetation(direction)
- local isAirWaterLava = true
- -- blockType, blockModifier, data
- local blockType, blockModifier = T:getBlockType(direction)
- if blockType ~= "" then --not air
- if T:isVegetation(blockType) then
- T:dig(direction)
- elseif blockType:find("water") == nil
- and blockType:find("lava") == nil
- and blockType:find("bubble") == nil
- and blockType ~= "minecraft:ice" then
- -- NOT water, ice or lava
- isAirWaterLava = false -- solid block
- end
- end
- return isAirWaterLava --clears any grass or sea plants, returns true if air or water, bubble column or ice
- end
- local function clearMonumentLayer(width, length, size)
- local up = true
- local down = true
- if size == 0 then
- up = false
- down = false
- end
- -- send turtle down until it hits bottom
- -- then clear rectangle of given size
- -- start above water, usually on cobble scaffold above monument
- if T:detect("down") then -- in case not over wall
- T:forward(1)
- end
- height = 1
- -- go down until solid block detected
- while clearVegetation("down") do
- T:down(1)
- height = height + 1
- end
- T:down(1)
- height = height + 1
- clearRectangle({width = width, length = length, up = up, down = down})
- --clearRectangle(width, length, up, down)
- T:up(height - 1)
- return {}
- end
- local function clearSeaweed(width, length)
- -- move over water
- turtle.select(1)
- T:clear()
- print("Checking water length")
- while not clearVegetation("down") do
- T:forward(1)
- end
- local odd = false
- local calcLength = 0
- while clearVegetation("down") do
- T:forward(1)
- calcLength = calcLength + 1
- end
- -- now check on correct side: wall to the right
- print("Checking position")
- T:go("R2F1R1F1") -- over ? wall
- if clearVegetation("down") then -- over water, so return to start on correct side
- T:go("R2F1R1F"..calcLength - 1 .."R2")
- else
- T:go("R2F1R1") -- over water
- end
- if calcLength % 2 == 1 then
- odd = true
- end
- local forward = true
- --print("calcLength:"..calcLength.. " odd:"..tostring(odd))
- for w = 1, width do
- for l = 1, calcLength, 2 do -- 1,3,5,7 etc length 3 runs 1, 5 runs 2 etc
- local depth = 0
- if l == 1 or (l % 2 == 1 and l == calcLength) then
- if forward then
- T:turnLeft(1)
- else
- T:turnRight(1)
- end
- else
- T:turnLeft(2)
- end
- -- go down destroying vegetation until on floor, checking in front at same time
- while clearVegetation("down") do
- clearVegetation("forward")
- T:down()
- depth = depth + 1
- end
- -- if slab at bottom, cover with solid block
- if string.find(T:getBlockType("down"), "slab") then
- T:up(1)
- T:place("minecraft:sand", "down")
- depth = depth + 1
- end
- if l == 1 or (l % 2 == 1 and l == calcLength) then
- if forward then
- T:turnRight(1)
- else
- T:turnLeft(1)
- end
- else
- T:turnLeft(2)
- end
- for d = depth, 1, -1 do
- clearVegetation("forward")
- T:up(1)
- end
- -- first corner complete, back at surface above water
- if l < calcLength then
- T:forward(2)
- end
- end
- if forward then
- T:go("L1F1L1")
- else
- T:go("R1F1R1")
- end
- forward = not forward
- if not clearVegetation("down") then -- reached far wall
- break
- end
- end
- return {}
- end
- local function clearMountainSide(width, length, size)
- local lib = {}
- function lib.excavate(blocksFromOrigin, going, length, digDown)
- local firstUp = 0
- for i = 1, length do
- -- record first block dug above
- if turtle.digUp() then
- if firstUp == 0 then
- firstUp = i -- will record first successful dig up
- end
- end
- if digDown then
- turtle.digDown()
- end
- T:forward(1)
- if going then
- blocksFromOrigin = blocksFromOrigin + 1
- else
- blocksFromOrigin = blocksFromOrigin - 1
- end
- end
- return blocksFromOrigin, firstUp
- end
- function lib.cutSection(blocksFromOrigin, going, length, firstUp)
- local height = 0
- local digDown = false
- blocksFromOrigin, firstUp = lib.excavate(blocksFromOrigin, going, length, digDown)
- -- while at least 1 block dug above do
- while firstUp > 0 do
- if digDown then
- turtle.digDown()
- else
- digDown = true
- end
- T:go("R2U1x1U1x1U1x1x0") -- go up 3 turn round
- going = not going
- height = height + 3
- if firstUp > 1 then
- length = length - firstUp + 1
- end
- -- go forward length digging up/down
- blocksFromOrigin, firstUp = lib.excavate(blocksFromOrigin, going, length, true)
- end
- T:down(height)
- return blocksFromOrigin, going
- end
- local originalLength = length
- local going = true
- local firstUp = 0
- local blocksFromOrigin = 0
- --T:forward(1) -- get into position
- blocksFromOrigin, going = lib.cutSection(blocksFromOrigin, going, length, firstUp)
- if width > 1 then --move left/right and repeat
- for i = 2, width do
- if going then
- T:turnRight(2)
- end
- if blocksFromOrigin > 0 then
- T:forward(blocksFromOrigin)
- end
- T:turnRight(2)
- blocksFromOrigin = 0
- if size == 0 then --Left <- Right
- T:go("L1F1R1")
- else
- T:go("R1F1L1")
- end
- going = true
- blocksFromOrigin, going = lib.cutSection(blocksFromOrigin, going, length, firstUp)
- end
- end
- return {}
- end
- local function clearSandWall(length)
- --dig down while on top of sand/soul_sand
- local height = 0
- turtle.select(1)
- T:clear()
- print("Checking sand length")
- local search = 0
- local blockType = T:getBlockType("down")
- while blockType ~= "minecraft:sand" and blockType ~= "minecraft:soul_sand" do --move forward until sand detected or 3 moves
- T:forward(1)
- search = search + 1
- blockType = T:getBlockType("down")
- if search > 3 then
- break
- end
- end
- if search <= 3 then
- local calcLength = 0
- blockType = T:getBlockType("down")
- while blockType == "minecraft:sand" or blockType == "minecraft:soul_sand" do
- T:forward(1)
- calcLength = calcLength + 1
- blockType = T:getBlockType("down")
- end
- T:go("R2F1") -- over sand
- blockType = T:getBlockType("down")
- while blockType == "minecraft:sand" or blockType == "minecraft:soul_sand" do
- T:down(1)
- height = height + 1
- blockType = T:getBlockType("down")
- end
- -- repeat length times
- for i = 1, calcLength do
- --if sand in front, dig
- while turtle.detect() do
- blockType = T:getBlockType("forward")
- if blockType == "minecraft:sand" or blockType == "minecraft:soul_sand" then
- T:dig("forward")
- else --solid block, not sand so move up
- T:up(1)
- height = height - 1
- end
- end
- --move forward
- if i < calcLength then
- T:forward(1)
- blockType = T:getBlockType("down")
- while blockType == "minecraft:sand" or blockType == "minecraft:soul_sand" do
- T:down(1)
- height = height + 1
- blockType = T:getBlockType("down")
- end
- end
- end
- -- go up, but reverse if block above
- for i = 1, height do
- if not turtle.detectUp() then
- T:up(1)
- else
- T:back(1)
- end
- end
- T:go("R2")
- end
- return {}
- end
- local function clearSandCube(width, length)
- --go down to bottom of sand
- turtle.select(1)
- while T:getBlockType("down") == "minecraft:sand" do
- T:down(1)
- end
- clearBuilding(width, length, 0, false)
- end
- local function clearSolid(R)
- --[[ direction = Bottom->Top (0), Top->bottom(1)
- Assume if going up T is inside the area
- If going down T is on top of the area ready to go
- ex1 hollow a cube top to bottom 20 wide, 20 long, 18 deep
- ]]
- local lib = {}
- function lib.detectPosition(direction)
- --[[
- If going up check if has block in front and above else forward 1
- If going down chech has block in front and below els go down 1
- ]]
- if direction == "u" then
- if not turtle.detectUp() then -- no block above so must be in front of area to be cleared
- local response = menu.getBoolean("Am I outside clearing area (y/n)?")
- if response then
- T:forward(1)
- end
- end
- else
- if not turtle.detect() then -- no block ahead so must be sitting on top
- local response = menu.getBoolean("Am I above clearing area (y/n)?")
- if response then
- T:down(1)
- end
- end
- end
- end
- function lib.move(direction, blocks, reverse)
- --[[ Move up or down by blocks count ]]
- if reverse == nil then
- reverse = false
- end
- if reverse then
- if direction == "d" then -- reverse direction
- T:up(blocks)
- else
- T:down(blocks)
- end
- else
- if direction == "u" then
- T:up(blocks)
- else
- T:down(blocks)
- end
- end
- return blocks
- end
- function lib.level(width, length)
- clearRectangle({width = width, length = length, up = false, down = false})
- --clearRectangle(width, length, false, false)
- end
- function lib.levelUp(width, length)
- clearRectangle({width = width, length = length, up = true, down = false})
- --clearRectangle(width, length, true, false)
- end
- function lib.levelUpDown(width, length)
- clearRectangle({width = width, length = length, up = true, down = true})
- --clearRectangle(width, length, true, true)
- end
- function lib.levelDown(width, length)
- clearRectangle({width = width, length = length, up = false, down = true})
- --clearRectangle(width, length, false, true)
- end
- local direction = "u"
- if R.down then
- direction = "d"
- end
- local remaining = R.height -- eg 5
- lib.detectPosition(direction)
- if R.height <= 0 then -- user entered -1 or 0:move up until no more solid
- -- starts on level 1
- lib.move(direction, 1)
- local level = 2
- local itemsOnBoard = T:getTotalItemCount()
- repeat
- lib.levelUpDown()
- T:sortInventory()
- lib.move(direction, 3)
- R.height = R.height + 3
- until T:getFirstEmptySlot() == 0 or T:getTotalItemCount() == itemsOnBoard-- nothing collected or full inventory
- elseif R.height <= 3 then --1-3 layers only
- if R.height == 1 then --one layer only
- lib.level(R.width, R.length)
- elseif R.height == 2 then --2 layers only current + dig up
- if direction == "u" then
- lib.levelUp(R.width, R.length)
- else
- lib.levelDown(R.width, R.length)
- end
- elseif R.height == 3 then --3 layers only current + dig up/down
- lib.move(direction, 1)
- lib.levelUpDown(R.width, R.length)
- end
- else -- 4 or more levels
- while remaining > 3 do
- if remaining == R.height then-- first iteration
- lib.move(direction, 1)
- else
- lib.move(direction, 3)
- end
- remaining = remaining - 3 -- eg 1st of height = 5 : 4 remaining. 2nd iteration remaining = 1
- lib.levelUpDown(R.width, R.length)
- end
- if remaining == 3 then
- lib.move(direction, 2)
- lib.levelUpDown(R.width, R.length)
- elseif remaining == 2 then
- lib.move(direction, 2)
- if direction == "u" then -- going up
- lib.levelUp(R.width, R.length)
- else -- going down
- lib.levelDown(R.width, R.length)
- end
- elseif remaining == 1 then
- lib.move(direction, 1)
- lib.level(R.width, R.length)
- end
- end
- lib.move(direction, R.height - remaining, true) -- reverse direction
- return {}
- end
- local function clearWall(width, length, height, direction)
- -- direction = Bottom->Top (0), Top->bottom(1)
- -- width preset to 1
- if direction == nil then direction = 0 end-- bottom to top
- local atStart = true
- local offset = height - 2
- -- go(path, useTorch, torchInterval, leaveExisting)
- local evenHeight = false
- if height % 2 == 0 then
- evenHeight = true
- end
- turtle.select(1)
- -- dig along and up/down for specified length
- if evenHeight then --2, 4 , 6 etc
- for h = 2, height, 2 do
- for i = 1, length - 1 do
- T:go("x0F1", false, 0, false)
- end
- if h < height then
- if direction == 0 then --bottom to top
- T:go("R2U2", false, 0, false)
- else
- T:go("R2D2", false, 0, false)
- end
- end
- atStart = not atStart
- end
- else
- offset = height - 1
- for h = 1, height, 2 do
- if h == height then
- T:go("F"..tostring(length - 1), false, 0, false)
- else
- for i = 1, length - 1 do
- if direction == 0 then --bottom to top
- T:go("x0F1", false, 0, false)
- else
- T:go("x2F1", false, 0, false)
- end
- end
- end
- atStart = not atStart
- if h < height then
- if direction == 0 then --bottom to top
- T:go("R2U2", false, 0, false)
- else
- T:go("R2D2", false, 0, false)
- end
- end
- end
- end
- if evenHeight then
- if direction == 0 then
- T:go("x0", false, 0, false)
- else
- T:go("x2", false, 0, false)
- end
- end
- if direction == 0 then
- T:go("R2D"..offset, false, 0, false)
- else
- T:go("R2U"..offset, false, 0, false)
- end
- if not atStart then
- T:go("F"..tostring(length - 1).."R2", false, 0, false)
- end
- return {}
- end
- local function createAutoTreeFarm()
- local lib = {}
- function lib.fillWaterBuckets()
- T:place("minecraft:bucket", -1, "down", false)
- sleep(0.5)
- T:place("minecraft:bucket", -1, "down", false)
- end
- createWaterSource(1)
- -- clsTurtle.go(path, useTorch, torchInterval, leaveExisting)
- -- place chest and hopper
- T:go("x0F1x0F1x0F1x0F1R1")
- for i = 1, 4 do
- T:go("D1R1C1R1C1R1C1R1")
- end
- T:up(1)
- T:place("minecraft:chest", -1, "down", false)
- T:go("F1x0D1F1x0R2", false, 0, true)
- T:place("minecraft:hopper", -1, "forward", false)
- -- dig trench and ensure base is solid
- T:go("U1R2X7U1", false, 0, true)
- T:place("minecraft:water_bucket", -1, "down", false) -- collection stream
- T:go("F1X7U1", false, 0, true)
- T:place("minecraft:water_bucket", -1, "down", false) -- upper collection stream
- T:go("U1F1R1C2F1R1C2") --now on corner
- for i = 1, 14 do --place cobble
- T:go("F1C2", false, 0, false)
- end
- T:go("F4R1F2C2R2C1R2")
- for i = 1, 8 do --place cobble
- T:go("F1C2", false, 0, false)
- end
- T:turnRight(1)
- for i = 1, 18 do --place cobble
- T:go("F1C2", false, 0, false)
- end
- T:turnRight(1)
- for i = 1, 8 do --place cobble
- T:go("F1C2", false, 0, false)
- end
- T:go("R1F1R1D1") -- ready to clear ground inside cobble wall
- for i = 1, 17 do
- T:go("C2F1C2F1C2F1C2F1C2F1C2F1C2F1C2", false, 0, true)
- if i < 17 then
- if i % 2 == 1 then -- odd no
- T:go("L1F1L1")
- else
- T:go("R1F1R1")
- end
- end
- end
- T:go("U1R2F10R2") -- over pond
- lib.fillWaterBuckets()
- for i = 0, 16, 2 do
- T:go("F10R1")
- if i > 0 then
- T:go("F"..i)
- end
- T:place("minecraft:water_bucket", -1, "down", false)
- T:go("F1R2")
- if i < 16 then
- T:place("minecraft:water_bucket", -1, "down", false)
- end
- T:go("F"..i + 1 .."L1")
- T:go("F10R2")
- lib.fillWaterBuckets()
- end
- -- place dirt/torch/sapling
- T:go("F1U1R1F1L1")
- for i = 1, 7 do
- T:go("F6R1F1L1")
- for j = 1, 3 do
- T:place("minecraft:dirt", -1, "forward", false)
- T:up(1)
- T:place("sapling", -1, "forward", false)
- T:down(1)
- turtle.back()
- T:place("minecraft:torch", -1, "forward", false)
- turtle.back()
- end
- if i < 7 then
- T:go("R1F1L1")
- end
- end
- T:go("L1F12")
- T:place("minecraft:chest", -1, "up", false)
- T:go("R1F1L1")
- T:place("minecraft:chest", -1, "up", false)
- T:go("F1U1R1F1R1F1L1")
- T:clear()
- print("Auto TreeFarm completed")
- print("\nDO NOT PLACE ANY TORCHES OR OTHER")
- print("BLOCKS ON THE COBBLE PERIMETER!")
- print("\nUse option 5 Manage Auto Tree farm")
- print("to setup monitoring\n\nEnter to continue")
- read()
- return {}
- end
- local function createBoatLift(state, side, height) -- state:0=new, size:1=extend, side:0=left, 1=right
- --[[ Legacy version (turtle deletes water source)
- Place turtles on canal floor, with sources ahead
- facing back wall preferred, but not essential
- 1.14 + (turtle can be waterlogged)
- Place same as legacy but inside source blocks
- ]]
- local lib ={}
- function lib.checkSource()
- local isWater = false
- local isSource = false
- T:dig("forward") -- break frozen source block
- isWater, isSource = T:isWater("forward")
- return isSource
- end
- function lib.findPartner()
- local block = T:getBlockType("forward")
- while block:find("turtle") == nil do -- not found partner
- if side == 0 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- sleep(0.5)
- block = T:getBlockType("forward")
- end
- end
- function lib.returnToWork(level)
- if level > 0 then
- for i = 1, level do
- T:place("minecraft:water_bucket", -1, "down")
- sleep(0.5)
- local _, isSource = T:isWater("down")
- while not isSource do
- print("Waiting for source...")
- sleep(0.5)
- _, isSource = T:isWater("down")
- end
- T:place("minecraft:bucket", -1, "down")
- T:up(1)
- end
- end
- end
- function lib.getToWater()
- local level = 0
- local isWater, isSource, isIce = T:isWater("down")
- while not isSource and isWater do -- water but not source
- T:down(1)
- level = level + 1
- isWater, isSource, isIce = T:isWater("down")
- end
- if isIce then T:dig("down") end -- break frozen source block
- if not isWater then
- isWater, isSource, isIce = T:isWater("up")
- if isSource then
- T:place("minecraft:bucket", -1, "up")
- end
- else
- T:place("minecraft:bucket", -1, "down")
- end
- lib.returnToWork(level)
- end
- function lib.refill()
- local s1, s2, buckets = T:getItemSlot("minecraft:bucket", -1) -- slotData.lastSlot, slotData.leastModifier, total, slotData
- local level = 0
- if buckets > 0 then -- at least 1 empty bucket
- local isWater, isSource, isIce = T:isWater("down")
- if isIce then T:dig("down") end -- break frozen source block
- if T:place("minecraft:bucket", -1, "down") then -- get water from below.
- sleep(0.5)
- else
- lib.getToWater()
- end
- end
- s1, s2, buckets = T:getItemSlot("minecraft:bucket", -1)
- if buckets > 0 then -- at least 1 empty bucket
- if isIce then T:dig("down") end -- break frozen source block
- if not T:place("minecraft:bucket", -1, "down") then -- get water from below
- lib.getToWater()
- end
- end
- end
- function lib.reset()
- redstone.setAnalogueOutput("front", 0)
- redstone.setOutput("front", false)
- end
- function lib.sendSignal()
- -- wait until turtle detected in front
- -- if detected set signal to 15 and pause 0.5 secs
- -- if recieves 15 from other turtle, continue
- -- if recieves 7 from other turtle, job done
- local block = T:getBlockType("forward")
- if block:find("turtle") == nil then -- not found partner
- print("Waiting for partner turtle...")
- print("If not facing towards partner")
- print("please restart this program")
- sleep(1)
- else
- redstone.setAnalogueOutput("front", 0)
- redstone.setOutput("front", false)
- if redstone.getAnalogueInput("front") == 15 then
- redstone.setOutput("front", true)
- print("Binary sent to partner turtle...")
- sleep(0.5)
- return true
- else
- print("Signal 15 sent to partner turtle...")
- redstone.setAnalogueOutput("front", 15)
- sleep(0.5)
- end
- redstone.setAnalogueOutput("front", 0)
- if redstone.getInput("front") or redstone.getAnalogueInput("front") == 15 then
- return true
- end
- return false
- end
- return false
- end
- function lib.legacyLeft(layer)
- lib.refill()
- T:go("U1")
- T:place("minecraft:water_bucket", -1, "down") -- place below. facing partner
- T:go("L1F1") -- move to back, facing back
- T:place("minecraft:water_bucket", -1, "down") -- place water below
- T:go("C1") -- facing back, build back wall
- T:go("L1C1") -- facing side, build side
- T:go("L1F1R1C1") -- move towards front, build side wall
- if layer == 1 then -- do not replace slab on layer 1
- T:go("L2")
- else
- T:go("L1C1L1") -- build front wall, turn to face partner
- end
- end
- function lib.left(layer)
- lib.refill()
- T:go("D1")
- T:place("minecraft:water_bucket", -1, "up") -- place above. facing partner
- T:go("L1F1") -- move to back, facing back
- T:place("minecraft:water_bucket", -1, "up") -- place water above
- lib.refill()
- T:go("U2C1") -- up 2;facing back, build back wall
- T:go("L1C1") -- facing side, build side
- T:go("L1F1R1C1") -- move towards front, build side wall
- if layer == 1 then -- do not replace slab on layer 1
- T:go("L2")
- else
- T:go("L1C1L1") -- build front wall, turn to face partner
- end
- local _, isSource, isIce = T:isWater("down")
- if isIce then T:dig("down") end -- break frozen source block
- if not isSource then
- lib.getToWater()
- end
- end
- function lib.right(layer)
- lib.refill()
- T:go("D1")
- T:place("minecraft:water_bucket", -1, "up") -- place above. facing partner
- T:go("R1F1") -- move to back, facing back
- T:place("minecraft:water_bucket", -1, "up") -- place water above
- lib.refill()
- T:go("U2C1") -- up 2;facing back, build back wall
- T:go("R1C1") -- facing side, build side
- T:go("R1F1L1C1") -- move towards front, build side wall
- if layer == 1 then -- do not replace slab on layer 1
- T:go("R2")
- else
- T:go("R1C1R1") -- build front wall, turn to face partner
- end
- local _, isSource, isIce = T:isWater("down")
- if isIce then T:dig("down") end -- break frozen source block
- if not isSource then
- lib.getToWater()
- end
- end
- function lib.legacyRight(layer)
- lib.refill()
- T:go("U1")
- T:place("minecraft:water_bucket", -1, "down") -- place below. facing partner
- T:go("R1F1") -- move to back, facing back
- T:place("minecraft:water_bucket", -1, "down") -- place water below
- T:go("C1") -- facing back, build back wall
- T:go("R1C1") -- facing side, build side
- T:go("R1F1L1C1") -- move towards front, build side wall
- if layer == 1 then -- do not replace slab on layer 1
- T:go("R2")
- else
- T:go("R1C1R1") -- build front wall, turn to face partner
- end -- up 1;turn to face partner
- end
- function lib.top(height)
- if side == 0 then --left side
- T:go("x0L1F1x0L2 F2R1C1C0 D1C1") -- place side block; block above, move down; side block
- T:place("sign", -1, "up", true, "Lift Exit\n<--\n<--\nEnjoy the ride...")
- T:go("L1F1L2C1 U2x1x0 L2F1x0L2")
- else
- T:go("x0R1F1x0R2 F2L1C1C0 D1C1") -- place side block, move up
- T:place("sign", -1, "up", true, "Lift Exit\n-->\n-->\nEnjoy the ride...")
- T:go("R1F1R2C1 U2x1x0 R2F1x0R2")
- end
- for i = height, 1, -1 do
- T:go("x1D1")
- end
- end
- local A = "R"
- local B = "L"
- if side == 1 then -- right side turtle
- A = "L"
- B = "R"
- end
- lib.findPartner()
- T:go(B.."1")
- if not lib.checkSource() then
- print("No water source ahead.\nReposition or add source")
- error()
- end
- T:go(A.."1")
- lib.reset()
- while not lib.sendSignal() do end
- lib.reset()
- -- confirmed opposite and active
- if state == 0 then -- new lift
- if side == 0 then
- T:turnLeft(1) -- face back
- else
- T:turnRight(1) -- face back
- end
- T:go(B.."2F1U1"..A.."1C1") -- face front;forward 1;up 1; :face side ready for sign and slab placement
- T:place("slab", -1, "up") -- slab above
- T:go("D1") -- down 1
- T:place("sign", -1, "up", true, "Lift Entrance\nKeep pressing\nforward key!")
- T:go(A.."1F1"..A.."2") -- face back; forward 1; :face front
- T:place("slab", -1, "forward") -- slab on ground at entrance
- T:go(A.."1") -- face side
- T:place("minecraft:soul_sand", -1, "down", false) -- replace block below with soul sand
- T:go("C1"..A.."1F1C1"..B.."1C1") -- block to side; forward, block at back; block to side :face side
- T:place("minecraft:soul_sand", -1, "down", false) -- replace block below with soul sand
- T:go("U1C1"..A.."1C1"..A.."2F1"..A.."1C1"..A.."2") -- up 1; block to side; forward; block to side :face other turtle
- local isWater, isSource, isIce = T:isWater("down")
- if not isSource then -- no source below
- T:place("minecraft:water_bucket", -1, "down") -- refill source
- T:go(B.."1F1"..B.."2")
- T:place("minecraft:water_bucket", -1, "down") -- refill source
- T:go("F1"..B.."1")
- sleep(0.5)
- isWater, isSource = T:isWater("down")
- if isSource then
- if isIce then
- T:dig("down") -- break frozen source block
- end
- T:place("minecraft:bucket", -1, "down") -- refill bucket
- sleep(0.5)
- T:place("minecraft:bucket", -1, "down") -- refill bucket
- end
- end
- lib.reset()
- while not lib.sendSignal() do end
- lib.reset()
- -- on layer 1 1 x source blocks below
- for layer = 1, height do
- if side == 0 then --left side
- if deletesWater then
- lib.legacyLeft(layer)
- else
- lib.left(layer)
- end
- else
- if deletesWater then
- lib.legacyRight(layer)
- else
- lib.right(layer)
- end
- end
- lib.reset()
- while not lib.sendSignal() do end
- lib.reset()
- end
- lib.top(height)
- else -- extend lift
- -- turtles should be at front, facing back of lift
- -- signs behind them, water sources below
- -- will face each other on startup, exactly as if finished new lift
- for layer = 1, height do
- for layer = 1, height do
- if side == 0 then --left side
- if deletesWater then
- lib.legacyLeft(layer)
- else
- lib.left(layer)
- end
- else
- if deletesWater then
- lib.legacyRight(layer)
- else
- lib.right(layer)
- end
- end
- lib.reset()
- while not lib.sendSignal() do end
- lib.reset()
- end
- end
- lib.top(height + 1) -- drop to below existing lift
- while turtle.down() do end -- drop to base canal
- end
- return {}
- end
- local function createBridge(numBlocks)
- for i = 1, numBlocks do
- T:go("m1", false, 0, true)
- end
- T:go("R1F1R1", false, 0, true)
- for i = 1, numBlocks do
- T:go("m1", false, 0, true)
- end
- return {}
- end
- local function createBubbleLift(height)
- local lib = {}
- function lib.addLayer()
- T:go("F2 L1C1R1C1R1C1L1", false, 0, true)
- turtle.back()
- T:place("minecraft:water_bucket", -1, "forward")
- T:dig("up") -- clear block above so completed lift can be found
- turtle.back()
- T:dig("up") -- clear block above so completed lift can be found
- T:place("stone", -1, "forward")
- end
- function lib.addSign()
- turtle.back()
- T:place("minecraft:water_bucket", -1, "forward")
- T:go("L1B1")
- T:place("sign", -1, "forward")
- end
- function lib.buildLift(toHeight)
- local built = lib.goToWater() -- returns lift blocks already placed, total height of drop from starting point
- local toBuild = toHeight - built -- no of blocks remaining to increase lift size
- local water = 0
- while toBuild > 0 do -- at least 1 block height remaining
- water = lib.fillBuckets(toBuild, false) -- no of water buckets onboard (could be more than required)
- if water > toBuild then -- more water than required
- water = toBuild -- reduce to correct amount
- end
- while turtle.detect() do -- climb to top of existing lift
- turtle.up()
- end
- while water > 0 do
- lib.addLayer()
- water = water - 1
- T:up(1)
- toBuild = toBuild - 1
- end
- -- may still be some height to complete, but needs refill
- if toBuild > 0 then
- built = lib.goToWater() --return to source
- toBuild = toHeight - built
- --lib.fillBuckets(toBuild)
- end
- end
- end
- function lib.cleanUp(fromHeight)
- local plug = false
- T:turnRight(2)
- for i = 1, fromHeight do
- plug = false
- if turtle.detect() then
- plug = true
- end
- turtle.down()
- if plug then
- T:place("stone", -1, "up")
- end
- end
- end
- function lib.fillBuckets(toBuild, withSort)
- local emptySlots, water = lib.stackBuckets(withSort)-- gets no of empty slots + no of water buckets
- if water < toBuild then -- no of water buckets onboard less than required quantity
- for i = 1, toBuild do -- fill required no of buckets up to max space in inventory
- if emptySlots == 0 then -- inventory full
- break
- else
- if T:place("minecraft:bucket", -1, "down", false) then
- water = water + 1
- sleep(0.5)
- end
- end
- emptySlots = lib.getEmptySlots()
- end
- end
- return water
- end
- function lib.getEmptySlots()
- local empty = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then
- empty = empty + 1
- end
- end
- return empty
- end
- function lib.goToWater()
- local built = 0 -- measures completed lift height
- while turtle.down() do -- takes turtle to bottom of water source
- --height = height + 1
- if turtle.detect() then
- built = built + 1
- end
- end
- T:up(1) -- above watersource assuming it is 1-1.5 blocks deep
- -- height = height - 1
- -- built = built - 1 not required as next block is water source: not detected
- return built -- , height
- end
- function lib.stackBuckets(withSort)
- if withSort == nil then withSort = false end
- local data = {}
- local bucketSlot = 0
- local emptySlots = 0
- local water = 0
- if withSort then
- T:sortInventory()
- end
- for i = 1, 16 do
- -- find first empty bucket
- if turtle.getItemCount(i) > 0 then
- data = turtle.getItemDetail(i)
- if data.name == "minecraft:bucket" then
- if bucketSlot == 0 then
- bucketSlot = i
- else
- turtle.select(i)
- turtle.transferTo(bucketSlot)
- end
- elseif data.name == "minecraft:water_bucket" then
- water = water + 1
- end
- else
- emptySlots = emptySlots + 1
- end
- end
- return emptySlots, water
- end
- -- go(path, useTorch, torchInterval, leaveExisting, preferredBlock)
- -- create water source
- T:go("D1 R2F1 D1C2 R1C1 R1C1 R1C1 R1", false, 0, true) -- down 1, turn round 1 block away from stairs, down 1. blocks forward, down, left and right, face backwards
- T:go("F1C2 L1C1 R2C1 L1", false, 0, true) -- prepare centre of water source: blocks down , left, right
- T:go("F1C2 L1C1 R1C1 R1C1 R1F1", false, 0, true) -- prepare end of water source, move to centre, facing forward
- T:place("minecraft:water_bucket", -1, "forward")
- T:turnRight(2) -- facing backward
- T:place("minecraft:water_bucket", -1, "forward")
- T:go("R2U1F1") -- facing forward
- T:place("minecraft:soul_sand", -1, "forward", false) -- placed at end of water source
- turtle.back() -- above centre of water source
- T:place("stone", -1, "forward")
- -- fill buckets and build first 2 levels
- lib.fillBuckets(height, true) -- fill as many buckets as required or until inventory full, sort inventory as well
- T:go("U1F2 L1C1R1C1R1C1L1", false, 0, true) -- prepare layer 1
- lib.addSign()
- T:go("U1F1R1F1 L1C1R1C1R1C1L1", false, 0, true) -- prepare layer 2
- lib.addSign()
- T:go("L1F1 R1F1R1", false, 0, true) -- above source, level 2
- lib.buildLift(height)
- lib.cleanUp(height)
- return {"Bubble lift created", "Check correct operation", "Check exit before using" }
- end
- local function createDragonAttack()
- --[[
- X 0 0 0 X X = exit site (y = 63)
- X E O O O E X 0 = bedrock on layer above (y = 63)
- 0 O O O O O 0 O = bedrock on working layer (y = 62)
- 0 O O O O O 0 E = starting position (y = 62)
- 0 O O O O O 0
- X E O O O E X
- X 0 0 0 X
- ]]
- local lib = {}
- function lib.upToBedrock()
- local blockTypeU = T:getBlockType("up")
- while blockTypeU ~= "minecraft:bedrock" do
- T:up(1)
- blockTypeU = T:getBlockType("up")
- end
- end
- function lib.toEdgeOfBedrock()
- local distance = 0
- local blockTypeU = T:getBlockType("up")
- while blockTypeU == "minecraft:bedrock" do
- T:forward(1)
- distance = distance + 1
- blockTypeU = T:getBlockType("up")
- end
- return distance
- end
- function lib.findStart()
- lib.toEdgeOfBedrock() -- go outside bedrock area
- T:go("R2F1") -- turn round, forward 1, under bedrock again
- local width = lib.toEdgeOfBedrock() -- ended outside bedrock
- if width == 5 then -- origin in main section
- T:go("R2F3L1") -- now in centre of 1 axis, turned left
- width = lib.toEdgeOfBedrock() -- ended outside bedrock, width should be 1 to 4 depending on start pos
- T:go("R2F1L1") -- move back under bedrock edge (3 blocks)
- lib.toEdgeOfBedrock() -- move to corner of bedrock
- -- elseif width == 3 then -- on outer strip of 3
- end
- end
- function lib.buildWall(length)
- for i = 1, length do
- if i < length then
- T:go("C2F1", false, 0, true)
- else
- T:go("C2", false, 0, true)
- end
- end
- end
- function lib.addCeiling(length)
- for i = 1, length do
- if i < length then
- T:go("C0F1", false, 0, true)
- else
- T:go("C0", false, 0, true)
- end
- end
- end
- lib.upToBedrock() -- go up until hit bedrock
- lib.findStart() -- should be on position 'E'
- T:go("F1U2L1") -- forward to any 'X' up 2, turn left
- local blockTypeF = T:getBlockType("forward")
- if blockTypeF == "minecraft:bedrock" then -- exit not correct
- T:turnRight(2) -- face correct direction
- else
- T:turnRight(1) -- return to original direction
- end
- T:go("U2F1 L1F2L2") -- on corner outside bedrock, ready to build wall
- for i = 1, 4 do
- lib.buildWall(9)
- T:turnRight(1)
- end
- T:up(1)
- for i = 1, 4 do
- lib.buildWall(9)
- T:turnRight(1)
- end
- T:go("F1R1F1L1D1")
- -- add ceiling
- lib.addCeiling(7)
- T:go("R1F1R1")
- lib.addCeiling(7)
- T:go("L1F1L1")
- lib.addCeiling(7)
- T:go("R1F1R1")
- lib.addCeiling(3)
- T:go("L2F2")
- T:go("R1F1R1")
- lib.addCeiling(7)
- T:go("L1F1L1")
- lib.addCeiling(7)
- T:go("R1F1R1")
- lib.addCeiling(7)
- T:go("R1F3R1")
- lib.addCeiling(3)
- T:dig("up")
- attack(true)
- return {}
- end
- local function createDragonTrap()
- -- build up 145 blocks with ladders
- for i = 1, 145 do
- T:go("U1C2")
- turtle.back()
- T:place("minecraft:ladder", -1, "down")
- turtle.forward()
- end
- T:go("R2F1C1 L1C1 L2C1 R1")
- for i = 1, 100 do
- T:go("F1C2")
- end
- T:forward(1)
- T:place("minecraft:obsidian", -1, "down")
- T:go("R2F1x2R2")
- T:place("minecraft:water_bucket", -1, "forward")
- T:go("R2F6R2")
- attack(false)
- return {}
- end
- local function createPath(length, isCanal)
- if length == nil then length = 0 end
- if isCanal == nil then isCanal = false end
- local numBlocks = 0
- local continue = true
- for i = 1, 2 do
- T:fillVoid("down", {}, false)
- T:forward(1)
- numBlocks = numBlocks + 1
- end
- local place = clearVegetation("down")
- while place do -- while air, water, normal ice, bubble column or lava below
- if T:fillVoid("down", {}, false) then -- false if out of blocks
- T:forward(1)
- numBlocks = numBlocks + 1
- if numBlocks % 8 == 0 then
- if T:getItemSlot("minecraft:torch", -1) > 0 then
- T:turnRight(2)
- T:place("minecraft:torch", -1, "forward", false)
- T:turnRight(2)
- end
- end
- else
- break
- end
- if length > 0 and numBlocks >= length then -- not infinite path (length = 0)
- break
- end
- place = clearVegetation("down")
- end
- return {numBlocks}
- end
- local function createCanal(side, length, height)
- -- go(path, useTorch, torchInterval, leaveExisting)
- -- if height = 0 then already at correct height on canal floor
- -- check block below, block to left and block above, move forward tunnelling
- -- if entering water then move up, onto canal wall and continue pathway
- -- if 55 and tunnelling then flood canal
- -- else height = 1 then above water and on path across
- -- move forward, checking for water below
- -- if water finishes, move into canal, drop down and continue tunnelling
- local lib = {}
- function lib.pause()
- local waiting = true
- local isWater = false
- local isSource = false
- while waiting do -- wait until either turtle or water is in front
- --print("Waiting for other turtle")
- if turtle.detect() then --block to side, check is not turtle
- if T:getBlockType("forward"):find("turtle") ~= nil then -- turtle next door
- waiting = false
- end
- else
- isWater, isSource = T:isWater("forward")
- if isSource then --either already in water or partner turtle has placed water
- waiting = false
- end
- end
- sleep(0.2)
- end
- end
- function lib.side(side, length, maxLength, height)
- local turnA = "R"
- local turnB = "L"
- local isWater = false
- local isSource = false
- local onWater = false
- local numBlocks = 0
- local doContinue = true
- if side == 1 then -- right
- turnA = "L"
- turnB = "R"
- end
- -- if starting on wall, probably already on water
- if height == 1 then -- if on wall, move to floor, turn to face opposite canal wall
- T:forward(1)
- isWater, isSource = T:isWater("down")
- if isSource then --on river/ocean so just construct walkway
- onWater = true
- numBlocks = createPath(length - 1, true)[1]
- if numBlocks < maxLength then -- continue with canal
- T:go(turnA.."1F1D1"..turnA.."1")
- else
- doContinue = false
- end
- else
- T:go(turnA.."1F1D1")
- end
- else -- on canal floor, but could be open water
- isWater, isSource = T:isWater("forward")
- if isSource then -- water source ahead. Assume on open water
- T:go(turnB.."1U1F1"..turnA.."1")
- onWater = true
- numBlocks = createPath(length - 1, true)[1]
- if numBlocks < maxLength then -- continue with canal
- T:go(turnA.."1F1D1"..turnA.."1")
- else
- doContinue = false
- end
- else
- T:go(turnA.."1")
- end
- end
- if not onWater then
- lib.pause()
- T:go(turnA.."1")
- -- facing canal start wall
- if turtle.detect() then -- solid block behind: at start of canal
- T:go(turnB.."2C2F1"..turnB.."1C1"..turnB.."1C2x0", false, 0, true) --move forward and check base/side, face start
- T:place("minecraft:water_bucket", -1, "forward")
- else -- air or water behind
- -- check if water already present behind. if not create source
- isWater, isSource = T:isWater("forward")
- if not isSource then
- T:place("minecraft:water_bucket", -1, "forward")
- end
- end
- end
- -- could be over water, just need walls
- --print("Loop starting. Enter")
- --read()
- local blockType, modifier
- local torch = 0
- local sourceCount = 0
- --loop from here. Facing backwards over existing canal/start
- while doContinue and numBlocks < maxLength do
- isWater, isSource = T:isWater("forward")
- while not isSource do
- sleep(10)
- print("waiting for water...")
- isWater, isSource = T:isWater("forward")
- end
- T:place("minecraft:bucket", -1, "forward") -- take water from source
- -- move forward check canal wall for block, below for block
- --T:go(turnA.."2F1C2"..turnB.."1C1", false, 0, true) -- face canal wall, repair if req
- T:go(turnA.."2F1C2", false, 0, true) --move forward, close floor
- isWater, isSource = T:isWater("forward")
- --print("Source in front: "..tostring(isSource).." Enter")
- --read()
- if isSource then --now on open water. move up and continue
- sourceCount = sourceCount + 1
- if sourceCount > 3 then
- sourceCount = 0
- T:go(turnB.."1U1F1"..turnA.."1")
- numBlocks = numBlocks + createPath(length - numBlocks, true)[1] -- eg done 20/64 blocks createPath(44)
- if numBlocks < maxLength then -- continue with canal
- T:go(turnA.."1F1D1"..turnA.."1x1"..turnA.."2") --return to canal bottom, break any block behind
- else
- doContinue = false
- end
- end
- end
- T:go(turnB.."1C1", false, 0, true) -- face canal wall, repair if req
- --print("facing wall. Enter")
- --read()
- T:go("U1x1") --go up and remove any block
- torch = torch + 1
- numBlocks = numBlocks + 1
- if turtle.detectUp() then -- block above
- T:go("U1x1")
- if torch == 8 then
- torch = 0
- T:place("minecraft:torch", -1, "forward")
- end
- T:down(1)
- end
- if torch == 8 then
- torch = 0
- T:place("minecraft:torch", -1, "forward")
- end
- T:down(1) -- on canal floor facing wall
- T:go(turnB.."1", false, 0, true)
- -- place water behind if some water is present
- isWater, isSource = T:isWater("forward")
- if not isWater then --no flowing water behind so deploy both sources
- T:forward(1)
- T:place("minecraft:water_bucket", -1, "forward")
- turtle.back()
- end
- T:place("minecraft:water_bucket", -1, "forward")
- -- check opposite canal wall
- T:go(turnB.."1")
- lib.pause()
- T:go(turnA.."1")
- end
- end
- function lib.leftSideLegacy(side, length, maxLength, height)
- local doContinue = true
- local numBlocks = 0
- local doTunnel = false
- local requestTunnel = false
- local blockType, modifier
- while doContinue and numBlocks < maxLength do
- if height == 0 then -- canal floor
- blockType, modifier = T:getBlockType("down")
- if blockType == "" or blockType == "minecraft:lava" then -- air or lava below, so place block
- T:place("minecraft:cobblestone", -1, "down", false)
- end
- -- place side block
- T:go("L1C1R1", false , 0, true)
- -- check above
- blockType, modifier = T:getBlockType("up")
- --if blockType == "minecraft:log" or blockType == "minecraft:log2" then
- if blockType ~= "" then
- if string.find(blockType, "log") ~= nil then
- T:harvestTree(false, false, "up")
- elseif blockType == "minecraft:lava" or blockType == "minecraft:water" then
- T:up(1)
- T:place("minecraft:cobblestone", -1, "up", false)
- T:down(1)
- else --solid block or air above
- if blockType ~= "" then
- T:dig("up")
- end
- end
- end
- -- check if block in front is water source
- blockType, modifier = T:getBlockType("forward")
- --if block:find("water") ~= nil then
- if blockType == "minecraft:water" and modifier == 0 then -- source block in front could be lake/ocean
- -- move up, to left and continue as height = 1
- T:go("U1L1F1R1", false, 0, true)
- height = 1
- else
- T:forward(1, true)
- numBlocks = numBlocks + 1
- end
- else -- height = 1, on canal wall
- numBlocks = numBlocks + createPath(0, true)[1]
- -- if path finished, then move back to canal floor and continue tunnelling
- T:go("R1F1D1L1", false, 0, true)
- height = 0
- end
- end
- end
- function lib.rightSideLegacy(side, length, maxLength, height)
- -- assume left side already under construction
- local doContinue = true
- local numBlocks = 0
- local doTunnel = false
- local requestTunnel = false
- local blockType, modifier
- local poolCreated = false
- while doContinue and numBlocks < maxLength do
- if height == 0 then-- canal floor
- -- create first infinity pool
- if not poolCreated then
- T:up(1)
- T:place("minecraft:water_bucket", -1, "down", false)
- T:go("L1F1R1", false, 0, true)
- T:place("minecraft:water_bucket", -1, "down", false)
- T:forward(1)
- T:place("minecraft:water_bucket", -1, "down", false)
- T:back(1)
- -- refill buckets
- for j = 1, 3 do
- T:place("minecraft:bucket", -1, "down", false)
- sleep(0,5)
- end
- T:go("R1F1L1F2", false , 0, true)
- T:down(1)
- poolCreated = true
- end
- blockType, modifier = T:getBlockType("down")
- if blockType == "" or blockType == "minecraft:lava"
- or blockType == "minecraft:water" or blockType == "minecraft:flowing_water" then -- air, water or lava below, so place block
- T:place("minecraft:cobblestone", -1, "down", false)
- end
- -- place side block
- T:go("R1C1L1", false , 0, true)
- T:up(1)
- blockType, modifier = T:getBlockType("up")
- if blockType == "minecraft:log" or blockType == "minecraft:log2" then
- T:harvestTree(false, false, "up")
- elseif blockType == "minecraft:lava" or blockType == "minecraft:water" then
- T:place("minecraft:cobblestone", -1, "up", false)
- end
- T:place("minecraft:water_bucket", -1, "down", false)
- for j = 1, 2 do
- T:forward(1)
- blockType, modifier = T:getBlockType("up")
- --if blockType == "minecraft:log" or blockType == "minecraft:log2" then
- if blockType ~= "" then
- if string.find(blockType, "log") ~= nil then
- T:harvestTree(false, false, "up")
- elseif blockType == "minecraft:lava" or blockType == "minecraft:water" then
- T:place("minecraft:cobblestone", -1, "up", false)
- end
- end
- -- at ceiling level
- T:go("D1R1C1L1", false, 0, true)
- blockType, modifier = T:getBlockType("down")
- if blockType == "" or blockType == "minecraft:lava"
- or blockType == "minecraft:water" or blockType == "minecraft:flowing_water" then -- air, water or lava below, so place block
- T:place("minecraft:cobblestone", -1, "down", false)
- end
- -- check if block in front is water source
- blockType, modifier = T:getBlockType("forward")
- T:up(1)
- T:place("minecraft:water_bucket", -1, "down", false)
- if blockType == "minecraft:water" and modifier == 0 then -- source block in front could be lake/ocean
- -- move to right and continue as height = 1
- T:go("R1F1L1", false, 0, true)
- height = 1
- break
- end
- end
- if height == 0 then
- T:back(2)
- for j = 1, 3 do
- T:place("minecraft:bucket", -1, "down", false)
- sleep(0,5)
- end
- T:go("F3D1", false, 0, true)
- end
- else -- height = 1: on wall
- numBlocks = numBlocks + createPath(0, true)[1]
- -- if path finished, then move back to canal floor and continue tunnelling
- T:go("L1F1L1F1", false, 0, true) -- facing backwards, collect water
- for j = 1, 3 do
- T:place("minecraft:bucket", -1, "down", false)
- sleep(0,5)
- end
- T:go("R2F1D1", false, 0, true) --canal floor
- height = 0
- end
- end
- end
- -- side = 0/1: left/right side
- -- length = 0-1024 0 = continuous
- -- height = 0/1 0 = floor, 1 = wall
- -- T:place(blockType, damageNo, direction, leaveExisting)
- -- T:go(path, useTorch, torchInterval, leaveExisting)
- local maxLength = 1024
- if length ~= 0 then
- maxLength = length
- end
- if side == 0 then -- left side
- if deletesWater then -- legacy version
- lib.leftSideLegacy(side, length, maxLength, height)
- else -- new version
- lib.side(side, length, maxLength, height)
- end
- else -- right side (1)
- if deletesWater then -- legacy version
- lib.rightSideLegacy(side, length, maxLength, height)
- else -- new version
- lib.side(side, length, maxLength, height)
- end
- end
- return {}
- end
- local function createCorridor(length)
- if length == nil then length = 0 end -- continue until out of blocks
- local currentSteps = 0 -- counter for infinite length. pause every 64 blocks
- local totalSteps = 0 -- counter for all steps so far
- local torchInterval = 0 -- assume no torches
- local torchSpaces = 0 -- if torches present, counter to place every 8 blocks
- if T:getItemSlot("minecraft:torch") > 0 then
- torchInterval = 8
- end
- for steps = 1, length do
- if currentSteps >= 64 and length == 0 then
- -- request permission to continue if infinite
- T:clear()
- print("Completed "..totalSteps..". Ready for 64 more")
- print("Do you want to continue? (y/n)")
- response = read()
- if response:lower() ~= "y" then
- break
- end
- currentSteps = 0
- end
- --go(path, useTorch, torchInterval, leaveExisting)
- T:go("F1x0C2", false, 0, true) -- forward 1; excavate above, cobble below
- currentSteps = currentSteps + 1
- totalSteps = totalSteps + 1
- torchSpaces = torchSpaces + 1
- if torchInterval > 0 and torchSpaces >= 8 then
- if T:getItemSlot("minecraft:torch") > 0 then
- T:turnRight(2)
- T:place("minecraft:torch", -1, "forward")
- T:turnRight(2)
- end
- torchSpaces = 0
- end
- end
- return {}
- end
- local function createEnderTower(stage)
- --[[ lower base = stage 1, upper base = 2, tower = 3 ]]
- local lib = {}
- --[[ go(path, useTorch, torchInterval, leaveExisting, preferredBlock) ]]
- function lib.getEmptySlots()
- local empty = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then
- empty = empty + 1
- end
- end
- return empty
- end
- function lib.getStone(direction, stacks)
- --[[ get block user wants to use ]]
- local suck = turtle.suck
- if direction == "down" then
- suck = turtle.suckDown
- end
- if T:getBlockType(direction) == "minecraft:chest" then
- T:sortInventory()
- local slot = T:getFirstEmptySlot() --find spare slot
- if slot > 0 then --empty slot found
- turtle.select(1)
- if stacks == 0 then
- while suck() do end
- else
- for i = 1, stacks do -- get # stacks of stone from chest
- suck()
- end
- end
- if T:getSlotContains(slot) == "" then
- return T:getMostItem() -- empty chest
- else
- return T:getSlotContains(slot) -- use this as default building block
- end
- else
- return T:getMostItem() -- full inventory
- end
- else
- return T:getMostItem() -- no chest
- end
- end
- function lib.stackBuckets()
- local data = {}
- local bucketSlot = 0
- local emptySlots = 0
- local water = 0
- T:sortInventory()
- for i = 1, 16 do
- -- find first empty bucket
- if turtle.getItemCount(i) > 0 then
- data = turtle.getItemDetail(i)
- if data.name == "minecraft:bucket" then
- if bucketSlot == 0 then
- bucketSlot = i
- else
- turtle.select(i)
- turtle.transferTo(bucketSlot)
- end
- elseif data.name == "minecraft:water_bucket" then
- water = water + 1
- end
- else
- emptySlots = emptySlots + 1
- end
- end
- return emptySlots, water
- end
- function lib.countWaterBuckets()
- local data = {}
- local buckets = 0
- for i = 1, 16 do
- data = turtle.getItemDetail(i)
- if data.name == "minecraft:water_bucket" then
- buckets = buckets + 1
- end
- end
- return buckets
- end
- function lib.baseRun(preferredBlock, count, turn)
- for i = 1, count do
- T:go("C2F1", false, 0, false, preferredBlock)
- end
- T:go("C2"..turn, false, 0, false, preferredBlock)
- end
- function lib.outsideRun(preferredBlock)
- T:place("fence", -1, "down", false)
- T:forward(1)
- T:place(preferredBlock, -1, "down", false)
- T:forward(1)
- T:place(preferredBlock, -1, "down", false)
- T:forward(2)
- T:place(preferredBlock, -1, "down", false)
- end
- function lib.signRun(preferredBlock ,message)
- T:place(preferredBlock, -1, "down", false)
- T:forward(4)
- T:place(preferredBlock, -1, "down", false)
- turtle.back()
- turtle.back()
- T:down(1)
- T:place("sign", -1, "forward", false, message)
- T:go("U1F2")
- end
- function lib.goToWater(height)
- local built = 0 -- measures completed lift height
- while turtle.down() do -- takes turtle to bottom of water source
- height = height + 1
- if turtle.detect() then
- built = built + 1
- end
- end
- T:up(1) -- above watersource assuming it is 1-1.5 blocks deep
- height = height - 1
- -- built = built - 1 not required as next block is water source: not detected
- return built, height
- end
- function lib.fillBuckets(toBuild)
- local emptySlots, water = lib.stackBuckets() -- gets no of empty slots + no of water buckets
- if water < toBuild then -- no of water buckets onboard less than required quantity
- for i = 1, toBuild do -- fill required no of buckets up to max space in inventory
- emptySlots = lib.getEmptySlots()
- if emptySlots == 0 then -- inventory full
- break
- else
- if T:place("minecraft:bucket", -1, "down", false) then
- water = water + 1
- sleep(0.5)
- end
- end
- end
- end
- return water
- end
- function lib.buildLift(preferredBlock)
- local built = 0 -- measures completed lift height
- local height = 0 -- measures total height from starting position
- built, height = lib.goToWater(height) -- returns lift blocks already placed, total height of drop from starting point
- local toBuild = height - built -- no of blocks to increase lift size
- while toBuild > 0 do -- at least 1 block height remaining
- local water = lib.fillBuckets(toBuild) -- no of water buckets onboard (could be more than required)
- if water > toBuild then
- water = toBuild
- end
- while turtle.detect() do -- climb to top of existing lift
- turtle.up()
- height = height - 1
- end
- T:forward(1)
- for i = 1, water do -- build lift by no of water buckets
- if T:place("minecraft:water_bucket", -1, "forward", false) then
- T:up(1)
- height = height - 1
- toBuild = toBuild - 1
- T:place(preferredBlock, -1, "down", false)
- end
- end
- turtle.back()
- -- may still be some height to complete, but needs refill
- if toBuild > 0 then
- lib.goToWater(0) --return to source
- lib.fillBuckets(toBuild)
- end
- end
- if height > 0 then -- if any remaining distance
- T:up(height)
- end
- end
- function lib.buildSection(preferredBlock, solid)
- -- builds a section without any blocks in the centre
- -- second layer of each section end walls have fence posts
- T:go("F1C2 F2C2 F1R1", false, 0, false, preferredBlock) -- first side solid row
- if solid then -- first layer of each section
- T:go("F1C2 F1R1", false, 0, false, preferredBlock) -- top side solid row
- else
- T:go("F1") -- top side solid row
- if not T:place("fence", -1, "down", false) then-- first side
- T:place(preferredBlock, -1, "down", false)
- end
- T:go("F1R1") -- top side solid row
- end
- T:go("F1C2 F2C2 F1R1", false, 0, false, preferredBlock) -- far side solid row
- T:go("F1C2 F1R1U1", false, 0, false, preferredBlock) -- bottom side solid row
- end
- --[[
- clsTurtle methods:
- clsTurtle.place(self, blockType, damageNo, direction, leaveExisting)
- clsTurtle.go(self, path, useTorch, torchInterval, leaveExisting, preferredBlock)
- ]]
- -- remove 1 stack stone from chest
- local preferredBlock = lib.getStone("down", 1) -- use this as default building block
- if stage == 1 then
- -- build base floor
- --T:go("R2F2R1F3R1", false, 0, false, preferredBlock)
- T:go("R2F1C2R1F1C2F1C2F1C2R1", false, 0, false, preferredBlock)
- for i = 1, 2 do
- lib.baseRun(preferredBlock, 8, "R1F1R1")
- lib.baseRun(preferredBlock, 8, "L1F1L1")
- lib.baseRun(preferredBlock, 8, "R1F4R1")
- end
- -- move back to centre, build water source, with soul sand at base of first source
- --T:go("R1F3L1C2F1C2F2D1", false, 0, false, preferredBlock) --just behind chest, 1 below ground level
- T:go("R1F3L1F2C2F1D1", false, 0, false, preferredBlock) --1 block behind chest, 1 below ground level
- T:place("minecraft:soul_sand", -1, "down", false) -- over block 1 of water source
- T:go("F1C2F1C2", false, 0, false, preferredBlock) -- over block 2 of water source
- T:go("F1C2U1C2", false, 0, false, preferredBlock) -- over block 4 of water source
- T:go("F1C2F1C2R2F5R2", false, 0, false, preferredBlock) -- over block 1 of water source
- T:place("minecraft:water_bucket", -1, "down", false)
- T:forward(2) -- over block 3 of water source
- T:place("minecraft:water_bucket", -1, "down", false)
- turtle.back() -- over block 2 of water source
- T:place("minecraft:bucket", -1, "down", false)
- T:go("F2D1R2C2") -- over block 4 of water source
- T:go("U1", false, 0, false, preferredBlock)
- T:place("minecraft:water_bucket", -1, "down", false)
- T:forward(4)
- lib.stackBuckets() -- put all buckets in same slot
- T:dropItem("minecraft:dirt", "up", 0) -- drop dirt up: clsTurtle.dropItem(self, item, direction, keepAmount)
- preferredBlock = lib.getStone("down", 6)
- T:go("R1F2R1U1") -- move to start position
- for i = 1, 2 do
- -- build first level of tower: 2 x outside run, 2 x sign run
- lib.outsideRun(preferredBlock)
- if i == 1 then -- place door
- T:go("L1F1L1F1L1D1")
- T:place("door", -1, "forward", false)
- T:go("U1L1F1R1F1L1")
- end
- T:go("R1F1R1")
- lib.signRun(preferredBlock, "Pint size\nzombies\nProhibited")
- T:go("L1F1L1C2", false, 0, false, preferredBlock)
- T:forward(4) -- miss out centre block
- T:place(preferredBlock, -1, "down", false)
- T:go("R1F1R1")
- lib.signRun(preferredBlock, "Pint size\nzombies\nProhibited")
- T:go("L1F1L1")
- lib.outsideRun(preferredBlock)
- if i == 1 then -- layer 1
- T:go("R1F1R1F1R1D1") -- place door
- T:place("door", -1, "forward", false)
- T:go("U1 R1F1 L1F5 L1U1 F2D1 F2R2 U1") -- go over door
- else -- layer 2
- T:go("L1F5L1F6R2U1") -- over corner of lower platform
- end
- end
- for i = 1, 2 do -- build both sides of platform, leave centre missing
- lib.baseRun(preferredBlock, 8, "R1F1R1")
- lib.baseRun(preferredBlock, 8, "L1F1L1")
- lib.baseRun(preferredBlock, 8, "R1F4R1")
- end
- T:go("R1F3L1C2F1C2F1C2F4C2F1C2F1C2", false, 0, false, preferredBlock) --fill in centre row
- --T:go("R2F6R1F1R1U1") -- go to start of tower base
- T:go("R2F7R2D3") -- go to start on top of chest
- T:sortInventory()
- elseif stage == 2 then
- -- start on top of chest, should have sufficient stone in inventory
- T:go("U3L1F1R1F1U1") -- go to start of tower base
- for i = 1, 7 do -- build 14 block high tower
- lib.buildSection(preferredBlock, false)
- lib.buildSection(preferredBlock, true)
- end
- T:go("R2F4R1F4R1", false, 0, false, preferredBlock) -- build upper platform (154 blocks remaining)
- for i = 1, 2 do -- build both sides of upper platform, leave centre missing
- lib.baseRun(preferredBlock, 12, "R1F1R1")
- lib.baseRun(preferredBlock, 12, "L1F1L1")
- lib.baseRun(preferredBlock, 12, "R1F1R1")
- lib.baseRun(preferredBlock, 12, "L1F1L1")
- lib.baseRun(preferredBlock, 12, "R1F6R1")
- end
- T:go("R1F5 L1C2 F1C2 F1C2 F1C2 F1C2 F4C2 F1C2 F1C2 F1C2 F1C2 ", false, 0, false, preferredBlock) --fill in centre row
- T:go("R2F5") -- return to drop area
- lib.buildLift(preferredBlock) -- build bubble lift
- T:go("F3R1F1R1U1") -- go to start of tower base
- T:go("C2F4 C2R1F1R1", false, 0, false, preferredBlock) -- left side layer 21
- T:go("F2C2 F2C2 L1F1L1", false, 0, false, preferredBlock) -- centre layer 21
- T:go("C2F4 C2R2U1", false, 0, false, preferredBlock) -- right side layer 21
- T:go("C2F4 C2R1F1R1", false, 0, false, preferredBlock) -- right side layer 22
- T:place("fence", -1, "down", false) -- fence centre of bottom side layer 22
- T:go("F2C2 F2L1F1L1", false, 0, false, preferredBlock) -- centre layer 22
- T:go("C2F4 C2R2F2L1F1R2D2", false, 0, false, preferredBlock) --ready to place ladder
- T:place("ladder", -1, "forward", false)
- T:up(1)
- T:place("ladder", -1, "forward", false)
- --T:go("U2R1F4R1F1R1") -- ready to make upper part of tower base
- T:go("U2R1F4R1F1R1") -- ready to make upper part of tower base
- for i = 1, 2 do -- build both sides of platform, leave centre missing
- lib.baseRun(preferredBlock, 8, "R1F1R1")
- lib.baseRun(preferredBlock, 8, "L1F1L1")
- lib.baseRun(preferredBlock, 8, "R1F4R1")
- end
- T:go("R1F3 L1C2 F1C2 F1C2 F1", false, 0, false, preferredBlock) --fill in centre row
- T:place("minecraft:soul_sand", -1, "down", false)
- T:go("F1C2 F2C2 F1C2 F1C2", false, 0, false, preferredBlock)
- T:go("R2F6R1F1R1U1") -- go to start of tower base
- -- build 2 levels, finish signs and ladders
- T:go("C2F2 R1D2 U1", false, 0, false, preferredBlock)
- T:place("ladder", -1, "down", false)
- T:turnRight(1)
- T:place("sign", -1, "forward", false, "UP\n^\n|\n|")
- T:go("U1R2F2C2 R1F2C2 R1", false, 0, false, preferredBlock) --top right corner
- T:go("F4C2B2D1", false, 0, false, preferredBlock)
- T:place("sign", -1, "forward", false, "UP\n^\n|\n|")
- T:go("U1F2R1F1C2F1R1U1", false, 0, false, preferredBlock) --ready for second level
- T:go("C2F2 R2D1", false, 0, false, preferredBlock)
- T:place("sign", -1, "forward", false, "UP\n^\n|\n|")
- T:go("U1R2F2C2R1", false, 0, false, preferredBlock) --top left corner
- T:go("F1R1C2F4C2", false, 0, false, preferredBlock) --mid bottom row
- T:go("L1F1L1C2", false, 0, false, preferredBlock) -- bottom right corner
- T:go("F2R2D1", false, 0, false, preferredBlock)
- T:place("sign", -1, "forward", false, "UP\n^\n|\n|")
- T:go("U1R2F2C2", false, 0, false, preferredBlock) -- top right corner
- -- return to chest
- T:go("L1F1L1 F5D23R2", false, 0, false, preferredBlock) -- return to chest
- T:sortInventory()
- elseif stage == 3 then
- --[[ move to top of structure
- | 4 |
- |3 5|
- | X |
- |2 6|
- | 1 |
- ]]
- local towerHeight = 128 -- even no only suggest 128
- while turtle.detect() do
- turtle.up()
- end
- T:go("F1U1", false, 0, false, preferredBlock) -- return to finish tower
- for i = 1, towerHeight do -- 1
- T:go("C2U1", false, 0, false, preferredBlock)
- end
- T:go("F1L1F1R1D2")
- while turtle.down() do -- 2
- T:fillVoid("up", {preferredBlock})
- end
- T:go("F1R2C1R2F1D1", false, 0, false, preferredBlock)
- for i = 1, towerHeight / 2 do -- 3
- T:go("U2C2", false, 0, false, preferredBlock)
- end
- T:go("U1F1R1F1R1D1", false, 0, false, preferredBlock) -- back of tower facing front
- local deviate = false
- while turtle.down() do -- 4
- T:place("fence", -1, "up", false)
- if turtle.down() then
- T:fillVoid("up", {preferredBlock})
- else
- T:go("F1R2C1R1F1R1D1", false, 0, false, preferredBlock)
- deviate = true
- break
- end
- end
- if not deviate then
- T:go("F1L1F1R1D1", false, 0, false, preferredBlock)
- end
- for i = 1, towerHeight / 2 do -- 5
- T:go("U2C2", false, 0, false, preferredBlock)
- end
- T:go("F2R2", false, 0, false, preferredBlock) -- facing back of tower
- while turtle.down() do -- 6
- T:fillVoid("up", {preferredBlock}) --layer 129
- end
- T:go("F1L2C1U"..towerHeight)
- T:go("F4R1F3R1U1", false, 0, false, preferredBlock)
- -- add small platform at the top
- lib.baseRun(preferredBlock, 8, "R1F1R1")
- lib.baseRun(preferredBlock, 8, "L1F3L1")
- lib.baseRun(preferredBlock, 8, "L1F1L1")
- lib.baseRun(preferredBlock, 8, "R1F1R1")
- T:go("C2 F1C2 F1C2 F4C2 F1C2 F1C2 R2F3", false, 0, false, preferredBlock) --fill in centre row
- lib.buildLift(preferredBlock) -- build bubble lift
- end
- return {}
- end
- local function createFarm(extend)
- -- if extend ~= nil then this has been called from createFarmExtension()
- --
- lib = {}
- function lib.addWaterSource(pattern)
- -- pattern = {"d","c","c","d"} t = place crafting instead of dirt
- -- place(self, blockType, damageNo, direction, leaveExisting, signText)
- T:go("D1x2C2")
- for i = 1, 4 do
- T:dig("forward")
- if pattern[i] == "d" then
- T:place("dirt", -1, "forward", false)
- elseif pattern[i] == "t" then
- if not T:place("minecraft:crafting_table", -1, "forward", false) then
- T:place("dirt", -1, "forward", false) -- dirt if no crafting table
- end
- else
- T:place("stone", -1, "forward", false)
- end
- T:turnRight(1)
- end
- T:up(1)
- T:place("minecraft:water_bucket", -1, "down")
- end
- function lib.placeDirt(count, atCurrent)
- if atCurrent then
- local blockType = T:getBlockType("down")
- if blockType:find("dirt") == nil and blockType:find("grass_block") == nil then
- T:place("dirt", -1, "down", false)
- end
- end
- for i = 1, count do
- T:forward(1)
- T:dig("up")
- local blockType = T:getBlockType("down")
- if blockType:find("dirt") == nil and blockType:find("grass_block") == nil then
- T:place("dirt", -1, "down", false)
- end
- end
- end
- -- extend "", "right" or "forward". only adds a single new farm.
- -- right adds farm and checks for existing front extensions, dealt with separately
- -- clsTurtle.place(blockType, damageNo, direction, leaveExisting)
- if extend == nil then
- extend = ""
- end
- local blockType = ""
- -- extend = "right": placed on cobble corner of existing farm facing right side
- -- extend = "front": placed on cobble corner of existing farm facing front
- -- else placed on ground at corner of potential new farm facing front
- -- step 1 dig ditch round perimeter wall
- if extend == "right" then
- -- move to front corner ground ready for ditch
- T:go("F1L1F12D1R1")
- -- cut ditch round new farm extension
- for i = 1, 12 do
- T:go("x0F1")
- end
- T:go("R1x0")
- for i = 1, 13 do
- T:go("x0F1")
- end
- T:go("R1x0")
- -- now at lower right corner. if extension below, do not cut ditch
- blockType = T:getBlockType("forward")
- if blockType:find("stone") ~= nil then -- already a farm extension on left side
- -- return to start for adding chests and walls
- T:go("U1R1F1L1F12")
- else -- finish ditch
- for i = 1, 12 do
- T:go("x0F1")
- end
- T:go("R1U1F1") -- on corner of new extension
- end
- elseif extend == "forward" then
- T:go("L1F2R1D1")
- -- cut ditch round new farm extension
- for i = 1, 12 do
- T:go("x0F1")
- end
- T:go("R1x0")
- for i = 1, 13 do
- T:go("x0F1")
- end
- T:go("R1x0")
- for i = 1, 11 do
- T:go("x0F1")
- end
- T:go("U1x0F1R1F12R1") -- on corner of new extension
- else -- new farm. cut a groove round the entire farm base
- -- move to left side of intended wall
- T:go("L1F1x0R1")
- for j = 1, 4 do
- for i = 1, 12 do
- T:go("x0F1")
- end
- T:go("R1x0F1")
- end
- T:go("R1F1L1U1")
- end
- -- stage 2 place sapling and double chest
- T:dig("down") --remove cobble if present
- T:place("dirt", -1, "down", false)
- T:go("F1R2")
- T:place("sapling", -1, "forward", false) -- plant sapling
- T:go("L1")
- T:dig("down")
- T:place("minecraft:chest", -1, "down", false)-- place chest below
- T:go("L1F1R1")
- T:dig("down")
- T:place("minecraft:chest", -1, "down", false) -- place chest 2 below
- T:turnLeft(1)
- if extend == "right" then -- cobble wall exists so go forward to its end
- T:forward(9)
- else -- new farm or extend forward
- for i = 1, 9 do -- complete left wall to end of farm
- T:go("F1x0x2C2")
- end
- end
- T:go("R1F1R1x0x2C2F1D1")-- turn round ready for first dirt col
- lib.addWaterSource({"d","c","c","d"}) -- water at top of farm
- lib.placeDirt(9, false) -- place dirt back to start
- lib.addWaterSource({"c","c","t","d"}) -- water source next to chests, includes crafting table
- T:go("U1F1R2")
- if T:getBlockType("down") ~= "minecraft:chest" then
- T:dig("down")
- T:place("minecraft:chest", -1, "down", false)
- end
- T:go("R1F1L1")
- if T:getBlockType("down") ~= "minecraft:chest" then
- T:dig("down")
- T:place("minecraft:chest", -1, "down", false)
- end
- T:go("F1D1")
- lib.placeDirt(9, true)
- local turn = "R"
- for i = 1, 7 do
- T:go("F1U1x0C2"..turn.."1F1"..turn.."1x0x2C2F1D1")
- lib.placeDirt(9, true)
- if turn == "R" then
- turn = "L"
- else
- turn = "R"
- end
- end
- T:go("F1U1x0C2"..turn.."1F1"..turn.."1x0x2C2F1D1")
- lib.addWaterSource({"d","c","c","d"})
- lib.placeDirt(9, false)
- lib.addWaterSource({"c","c","d","d"})
- T:go("F1U1R1C2x0F1x0x2C2R1")
- for i = 1, 11 do
- T:go("F1x0x2C2")
- end
- -- add chest to any existing farm extension to the right
- T:go("L1F1L1")
- if T:getBlockType("down") ~= "minecraft:cobblestone" then -- farm extension already exists to right
- T:place("minecraft:chest", -1, "down", false) --single chest marks this as an extension
- end
- T:go("L1F11")
- return {}
- end
- local function createFarmExtension(size)
- -- assume inventory contains 4 chests, 64 cobble, 128 dirt, 4 water, 1 sapling
- -- check position by rotating to face tree/sapling
- local doContinue = true
- local treePresent = false
- local blockType = T:getBlockType("down")
- local extend = "right" -- default
- if size == 1 then
- extend = "forward"
- end
- if blockType ~= "minecraft:chest" then
- return
- {
- "Chest not present below\n",
- "Unable to calculate position",
- "Move me next to/front of the tree/sapling",
- "lower left corner of the existing farm."
- }
- else
- for i = 1, 4 do
- blockType = T:getBlockType("forward")
- if blockType:find("log") ~= nil or blockType:find("sapling") ~= nil then
- treePresent = true
- break
- end
- T:turnRight()
- end
- if not treePresent then
- return
- {
- "Unable to locate tree or sapling",
- "Plant a sapling on the lower left",
- "corner of the farm, or move me there"
- }
- end
- end
- if doContinue then -- facing tree. check if on front or l side of farm
- if extend == "forward" then
- T:go("R1F11") -- to other side of farm. may be stone or chest below
- blockType = T:getBlockType("down")
- if blockType:find("chest") ~= nil then
- doContinue = false
- end
- else
- T:go("R2F9") -- to right of farm, may be sapling/tree in front
- blockType = T:getBlockType("forward")
- if blockType:find("log") ~= nil or blockType:find("sapling") ~= nil then
- doContinue = false
- end
- end
- if doContinue then -- extend farm.
- createFarm(extend)
- else
- return
- {
- "This farm has already been extended",
- "Move me next to/front of the tree / sapling",
- "of the last extension in this direction."
- }
- end
- end
- return {"Mob Farm Extended"}
- end
- local function createFloorCeiling(width, length, size ) -- size integer 1 to 4
- local useBlock = T:getSlotContains(1)
- print("Using ".. useBlock)
- -- check if block above/below
- local blockBelow = turtle.detectDown()
- local blockAbove = turtle.detectUp()
- local direction = "down"
- if size == 1 then -- Replacing current floor
- -- if no block below, assume is missing and continue
- elseif size == 2 then -- New floor over existing
- -- if no block below, assume in correct position and continue
- -- else move up 1 and continue
- if blockBelow then T:up(1) end
- elseif size == 3 then -- Replacing current ceiling
- -- if no block above, assume is missing and continue
- direction = "up"
- elseif size == 4 then -- New ceiling under existing
- -- if no block above, assume in correct position and continue
- -- else move down 1 and continue
- if blockAbove then T:down(1) end
- direction = "up"
- end
- local evenWidth = false
- local evenHeight = false
- local loopWidth
- -- go(path, useTorch, torchInterval, leaveExisting)
- if width % 2 == 0 then
- evenWidth = true
- loopWidth = width / 2
- else
- loopWidth = math.ceil(width / 2)
- end
- if length % 2 == 0 then
- evenHeight = true
- end
- turtle.select(1)
- -- if width is even no, then complete the up/down run
- -- if width odd no then finish at top of up run and reverse
- for x = 1, loopWidth do
- -- Clear first column (up)
- for y = 1, length do
- T:place(useBlock, -1, direction, false) -- leaveExisting = false
- if y < length then
- T:go("F1", false, 0, false)
- end
- end
- -- clear second column (down)
- if x < loopWidth or (x == loopWidth and evenWidth) then -- go down if on width 2,4,6,8 etc
- T:go("R1F1R1", false,0,false)
- for y = 1, length do
- T:place(useBlock, -1, direction, false) -- leaveExisting = false
- if y < length then
- T:go("F1", false, 0, false)
- end
- end
- if x < loopWidth then
- T:go("L1F1L1", false,0,false)
- else
- T:turnRight(1)
- T:forward(width - 1)
- T:turnRight(1)
- end
- else -- equals width but is 1,3,5,7 etc
- T:turnLeft(2) --turn round 180
- T:forward(length - 1)
- T:turnRight(1)
- T:forward(width - 1)
- T:turnRight(1)
- end
- end
- return {}
- end
- local function createHollow(width, length, height)
- -- this function currently not used
- --should be in bottom left corner at top of structure
- -- dig out blocks in front and place to the left side
- --go(path, useTorch, torchInterval, leaveExisting)
- -- go @# = place any block up/forward/down # = 0/1/2
- for h = 1, height do
- for i = 1, length - 1 do
- T:go("L1@1R1F1", false, 0, true)
- end
- T:go("L1@1R2", false, 0, true, false)
- for i = 1, width - 1 do
- T:go("L1@1R1F1", false, 0, true)
- end
- T:go("L1@1R2", false, 0, true, false)
- for i = 1, length - 1 do
- T:go("L1@1R1F1", false, 0, true)
- end
- T:go("L1@1R2", false, 0, true, false)
- for i = 1, width - 1 do
- T:go("L1@1R1F1", false, 0, true)
- end
- T:go("L1@1R2", false, 0, true, false)
- -- hollowed out, now clear water/ blocks still present
- clearRectangle({width = width, length = length, up = false, down = false})
- --clearRectangle(width, length, false, false)
- if h < height then
- T:down(1)
- end
- end
- return {}
- end
- local function createIceCanal(length)
- local placeIce = true
- local iceOnBoard = true
- local isWater, isSource, isIce = T:isWater("forward")
- if isWater then -- user put turtle inside canal water
- T:up(1)
- end
- -- place ice on alternate blocks until length reached, run out of ice or hit a solid block.
- if length == 0 then length = 1024 end
- for i = 1, length do
- if T:getBlockType("down"):find("ice") == nil then -- no ice below
- if placeIce then
- if not T:place("ice", -1, "down", false) then -- out of ice
- break
- end
- if i == length - 1 then
- break
- end
- else
- T:dig("down") -- remove any other block
- end
- else -- ice already below
- placeIce = true
- end
- if not turtle.forward() then -- movement blocked or out of fuel
- break
- end
- placeIce = not placeIce -- reverse action
- end
- return {}
- end
- local function createIceCanalBorder(side, length)
- --[[ Used to convert water canal to ice with trapdoor / slab margin on one side ]]
- -- position gained from setup left = 0, right = 1
- local lib = {}
- function lib.placeTrapdoor()
- if T:getBlockType("down"):find("trapdoor") == nil then
- T:place("trapdoor", -1, "down", false) -- add trapdoors to canal towpath and activate them
- end
- return false
- end
- function lib.placeSlab()
- if T:getBlockType("down"):find("slab") == nil then
- T:place("slab", -1, "down", false)
- end
- return true
- end
- function lib.placeTorch(torchBlocks, onWater)
- if T:getItemSlot("minecraft:torch", -1) > 0 then
- torchBlocks = 0
- if torchBlocks == 8 and onWater then
- T:fillVoid("down", {}, false)
- T:up(1)
- T:place("minecraft:torch", -1, "down", false)
- T:go("F1D1")
- elseif torchBlocks == 9 and not onWater then
- T:go("R2")
- T:place("minecraft:torch", -1, "forward", false)
- T:go("L2")
- end
- end
- return torchBlocks
- end
- local A = "R"
- local B = "L"
- if side == 1 then
- A = "L"
- B = "R"
- end
- -- check position. Should be facing down canal with wall on same side
- -- so wall will be detected on i = 4 (if present)
- local turns = 0
- --local wallFound = false
- local numBlocks = 0
- if length == 0 then
- length = 2048
- end
- while turtle.down() do end -- move to ground -- canal edge / slab / trapdoor
- local onWater = false
- local torchBlocks = 8 -- force torch placed on first block
- -- check if slab / trapdoor below
- blockType = T:getBlockType("down")
- if blockType:find("slab") ~= nil then
- onWater = true
- elseif blockType:find("trapdoor") ~= nil then
- onWater = false
- torchBlocks = 9
- elseif blockType:find("slab") == nil and blockType:find("trapdoor") == nil then -- not on existing slab / trapdoor
- T:up(1)
- if turtle.detectUp() then -- ceiling present: tunnel
- torchBlocks = 9
- else
- onWater = true
- end
- end
- redstone.setOutput("bottom", true)
- -- add trapdoors to canal towpath and activate them
- for i = 1, length do
- if torchBlocks >= 8 then
- torchBlocks = lib.placeTorch(torchBlocks, onWater)
- end
- --T:go(A.."1x2")
- if turtle.detectUp() then -- ceiling present: inside tunnel
- T:go(A.."1x2")
- onWater = lib.placeTrapdoor()
- T:go(B.."1F1")
- else
- onWater = lib.placeSlab()
- T:forward(1)
- end
- --T:go(B.."1F1")
- numBlocks = numBlocks + 1
- torchBlocks = torchBlocks + 1
- if T:getItemSlot("trapdoor", -1) == 0 or T:getItemSlot("slab", -1) == 0 then
- print("Out of slabs / trapdoors")
- break
- end
- end
- return {numBlocks}
- end
- local function createLadder(destination, level, destLevel)
- -- createLadder("bedrock", 70, -48)
- -- go(path, useTorch, torchInterval, leaveExisting)
- -- place(blockType, damageNo, direction, leaveExisting)
- local retValue = {}
- local function placeLadder(direction, ledge)
- -- 1 check both sides and behind
- local fluid = false
- local block = T:isWaterOrLava("forward", ledge)
- if block:find("water") ~= nil or block:find("lava") ~= nil then
- --[[ surround 2 block shaft with blocks ]]
- T:go("R1C1R1C1R1C1R1F1L1C1R1C1R1C1R1C1F1R2C1x1")
- else
- --[[ no water/lava so prepare ladder site]]
- T:go("F1L1C1R1C1R1C1L1B1", false, 0, true)
- end
- if not T:place("minecraft:ladder", -1, "forward", false) then
- print("Out of ladders")
- turtle.forward()
- error()
- end
- -- 3 check if ledge, torch
- if ledge == 0 then
- T:place("common", -1, direction, false) -- any common block
- elseif ledge == 1 then
- T:place("minecraft:torch", -1, direction, false)
- elseif ledge == 2 then
- ledge = -1
- end
- return ledge
- end
- local ledge = 0
- local height = math.abs(destLevel - level) --height of ladder
- if destination == "surface" then -- create ladder from current level to height specified
- -- check if extending an existing ladder
- for i = 1, height do -- go up, place ladder as you go
- ledge = placeLadder("down", ledge)
- T:up(1)
- ledge = ledge + 1
- end
- else -- ladder towards bedrock
- local success = true
- local numBlocks, errorMsg
- for i = 1, height do -- go down, place ladder as you go
- ledge = placeLadder("up", ledge)
- --success, blocksMoved, errorMsg, blockType = clsTurtle.down(self, steps, getBlockType)
- success, numBlocks, errorMsg, blockType = T:down(1, true)
- ledge = ledge + 1
- -- if looking for stronghold then check for stone_bricks
- if blockType:find("stone_bricks") ~= nil then
- table.insert(retValue, "Stronghold discovered")
- break
- end
- end
- if not success then --success = false when hits bedrock
- -- test to check if on safe level immediately above tallest bedrock
- table.insert(retValue, "Bedrock reached")
- T:findBedrockTop(0)
- -- In shaft, facing start direction, on lowest safe level
- -- create a square space round shaft base, end facing original shaft, 1 space back
- T:go("L1n1R1n3R1n2R1n3R1n1", false, 0, true)
- T:go("U1Q1R1Q3R1Q2R1Q3R1Q1", false, 0, true)
- end
- end
- return retValue
- end
- local function createLadderToWater()
- -- go down to water/lava with alternaate solid/open layers
- -- create a working area at the base
- -- Return to surface facing towards player placing ladders
- local inAir = true
- local numBlocks, errorMsg
- local block, blockType
- local height = 2
- T:go("R2D2", false, 0, true) -- face player, go down 2
- while inAir do --success = false when hits water/lava
- T:go("C1R1C1R2C1R1", false, 0, true)
- T:go("D1C1", false, 0, true)
- height = height + 1
- block, blockType = T:isWaterOrLava("down")
- if string.find(block, "water") ~= nil or string.find(block, "lava") ~= nil then
- inAir = false
- else
- T:down(1)
- height = height + 1
- end
- end
- -- In shaft, facing opposite start direction, on water/lava
- -- create a square space round shaft base, end facing original shaft, 1 space back
- T:go("R2C2F1C2F1C2R1", false, 0, true)
- T:go("F1C2F1C2R1", false, 0, true)
- T:go("F1C2F1C2F1C2F1C2R1", false, 0, true)
- T:go("F1C2F1C2F1C2F1C2R1", false, 0, true)
- T:go("F1C2F1C2F1C2F1C2R1", false, 0, true)
- T:go("F2R1F1", false, 0, true) -- under the upward pillar
- for i = height, 0, -1 do
- T:go("C2e1U1")
- end
- T:down(1)
- return {}
- end
- local function createMine()
- -- go(path, useTorch, torchInterval, leaveExisting, preferredBlock)
- T:clear()
- T:go("m32U1R2M16", true, 8, true) -- mine ground level, go up, reverse and mine ceiling to mid-point
- T:go("U2D2") -- create space for chest
- T:place("minecraft:chest", -1, "up", false)
- T:emptyTrash("up")
- T:go("D1R1m16U1R2M16", true, 8, true) -- mine floor/ceiling of right side branch
- T:emptyTrash("up")
- T:go("D1m16U1R2M16", true, 8, true) -- mine floor/ceiling of left side branch
- T:emptyTrash("up")
- T:go("L1M15F1R1D1", true, 8, true) -- mine ceiling of entry coridoor, turn right
- T:go("F1x0F1x0n14R1n32R1n32R1n32R1n14F1x0F1U1", true, 8, true)-- mine floor of 36 x 36 square coridoor
- T:go("R1F16R2") --return to centre
- T:emptyTrash("up")
- T:go("F16R1") --return to entry shaft
- T:go("F2Q14R1Q32R1Q32R1Q32R1Q14F2R1", true, 8, true) --mine ceiling of 36x36 square coridoor. return to entry shaft + 1
- T:go("F16R2") --return to centre
- T:emptyTrash("up")
- -- get rid of any remaining torches
- while T:getItemSlot("minecraft:torch", -1) > 0 do
- turtle.select(T:getItemSlot("minecraft:torch", -1))
- turtle.dropUp()
- end
- T:go("F16R1F1R1") --return to shaft + 1
- for i = 1, 8 do
- T:go("N32L1F1L1", true, 8, true)
- T:go("N16L1F"..(i * 2).."R2", true, 8, true)
- T:emptyTrash("up")
- if i < 8 then
- T:go("F"..(i * 2).."L1N16R1F1R1", true, 8, true)
- else
- T:go("F"..(i * 2).."L1N16L1", true, 8, true)
- end
- end
- T:go("F17L1") -- close gap in wall, return to ladder + 1
- for i = 1, 8 do
- T:go("N32R1F1R1", true, 8, true)
- T:go("N16R1F"..(i * 2).."R2", true, 8, true)
- T:emptyTrash("up")
- if i < 8 then
- T:go("F"..(i * 2).."R1N16L1F1L1", true, 8, true)
- else
- T:go("F"..(i * 2).."R1N16R1", true, 8, true)
- end
- end
- T:go("F16R1")
- T:clear()
- return{"Mining operation complete"}
- end
- local function createMineBase()
- T:clear()
- -- check ladder:
- T:turnRight(2)
- local blockType, modifier = T:getBlockType("forward")
- while blockType == "" do
- T:forward(1)
- blockType, modifier = T:getBlockType("forward")
- end
- if blockType ~= "minecraft:ladder" then -- in correct position
- -- no ladder, move back 1
- T:back(1)
- end
- -- build pond:
- T:go("R1F1x0L1F1x0F1x0R1") -- at side wall
- T:go("F1n4R2n4U1R2Q4R2Q4R2") -- cut pond 3x1
- T:go("C2F4C2R2F1")
- T:place("minecraft:water_bucket", 0, "down", false)
- T:forward(2)
- T:place("minecraft:water_bucket", 0, "down", false)
- T:go("F2L1F2R1F1L1") -- at start position
- --[[
- T:go("m32U1R2M16D1", true, 8) -- mine ground level, go up, reverse and mine ceiling to mid-point, drop to ground
- T:go("U1R1A15D1R2m15", false, 0) -- Create roof of coridoor, turn and create lower wall + floor
- T:go("U1A15D1R2m15U1x0", false, 0) -- Create roof of coridoor, turn and create lower wall + floor
- T:place("minecraft:chest", -1, "up", false) --place chest in ceiling
- T:emptyTrash("up")
- T:go("L1M15F1R1D1", true, 8) -- mine ceiling of entry coridoor, turn right, drop down
- T:go("F2n14R1n15", true, 8)-- mine floor of first quarter of square
- T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
- T:go("F1x0n14R1n32R1n15", true, 8)
- T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
- T:go("F1x0n14R1n14F2", true, 8)-- mine floor of last quarter of square
- T:go("U1R1F16R2D1") --return to centre
- T:emptyTrash("up")
- T:go("U1F16R1") --return to entry shaft
- T:go("F2Q14R1Q15", true, 8) -- mine ceiling of first quarter
- T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
- T:go("C0F1Q14R1Q32R1Q15", true, 8) --mine ceiling of second half
- T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
- T:go("C0F1Q14R1Q14F2R1", true, 8) -- mine ceiling of last quarter
- T:go("F16D1") --return to centre
- T:emptyTrash("up")
- -- get rid of any remaining torches
- while T:getItemSlot("minecraft:torch", -1) > 0 do
- turtle.select(T:getItemSlot("minecraft:torch", -1))
- turtle.dropUp()
- end
- for i = 1, 8 do
- T:go("N32L1F1L1", true)
- T:go("N16L1F"..(i * 2).."R2", true)
- T:emptyTrash("up")
- T:go("F"..(i * 2).."L1N16R1F1R1", true)
- end
- T:go("L1F17L1") -- close gap in wall, return to ladder + 1
- for i = 1, 8 do
- T:go("N32R1F1R1", true)
- T:go("N16R1F"..(i * 2).."R2", true)
- T:emptyTrash("up")
- T:go("F"..(i * 2).."R1N16L1F1L1", true)
- end
- -- fill water buckets
- -- return to centre
- T:go("R1F16R1")]]
- T:clear()
- return {"Mining operation complete"}
- end
- local function createMineEnhanced()
- T:clear()
- T:go("m32U1R2M16D1x2", true, 8) -- mine ground level, go up, reverse and mine ceiling to mid-point, drop to ground, excavate
- T:emptyTrash("down")
- T:go("U1R1A15D1R2E13m2x2", false, 0) -- Create roof of coridoor, turn and create lower wall + remove floor
- T:emptyTrash("down")
- T:go("U1A15D1R2E13m2x2", false, 0) -- Create roof of coridoor, turn and create lower wall + remove floor
- T:emptyTrash("down")
- T:go("U1L1M15F1R1D1", true, 8) -- mine ceiling of entry coridoor, turn right, drop down
- T:go("F2n14R1n15", true, 8)-- mine floor of first quarter of square
- T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
- T:go("F1x0n14R1n32R1n15", true, 8)
- T:go("L1F1x0C1R1 F1x0L1C1R1 F1x0L1C1R1C1R1 F1x0C1L1") -- make alcove
- T:go("F1x0n14R1n14F2", true, 8)-- mine floor of last quarter of square
- T:go("U1R1F16R2D1") --return to centre
- T:emptyTrash("down")
- T:go("U1F16R1") --return to entry shaft
- T:go("F2Q14R1Q15", true, 8) -- mine ceiling of first quarter
- T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
- T:go("C0F1Q14R1Q32R1Q15", true, 8) --mine ceiling of second half
- T:go("L1F1C1R1 F1L1C1R1 F1L1C1R1C1R1 F1C1L1") -- make alcove
- T:go("C0F1Q14R1Q14F2R1", true, 8) -- mine ceiling of last quarter
- T:go("F16D1") --return to centre
- T:emptyTrash("down")
- -- get rid of any remaining torches
- while T:getItemSlot("minecraft:torch", -1) > 0 do
- turtle.select(T:getItemSlot("minecraft:torch", -1))
- turtle.dropDown()
- end
- --cut access coridoors
- T:go("U1F2R1F1Q14F1 R1F1L1F1R1F2R1F1L1F1R1 F1Q14F2Q14F1 R1F1L1F1R1F2R1F1L1F1R1F1 Q14F1D1") --ceiling
- T:go("F1n14F1 R1F1L1F1R1F2R1F1L1F1R1 F1n14F2n14F1 R1F1L1F1R1F2R1F1L1F1R1F1 n14F1U1") --floor, then up
- T:go("R1F2D1")
- T:go("R1F1C1B1C1L1C1L1F1C1B1C1L1C1L2")
- T:emptyTrash("down")
- T:go("U1F16R1F1R1") --return to entry shaft + 1
- for i = 1, 8 do
- T:go("N32L1F1L1", true)
- if i == 1 then
- T:go("N16L1F2R2", true)
- T:emptyTrash("down")
- T:go("F2L1N16R1F1R1", true)
- elseif i == 8 then
- T:go("L1F1R1N16", true)
- T:emptyTrash("down")
- T:go("N16R1F1R1", true)
- else
- T:go("N16", true)
- T:emptyTrash("down")
- T:go("N16R1F1R1", true)
- end
- end
- T:go("L1F16L1") -- return to shaft + 1
- for i = 1, 8 do
- T:go("N32R1F1R1", true)
- if i == 1 then
- T:go("N16R1F2R2", true)
- T:emptyTrash("down")
- T:go("F2R1N16L1F1L1", true)
- elseif i == 8 then
- T:go("R1F1L1N16", true)
- T:emptyTrash("down")
- T:go("N16R1F1R1", true)
- else
- T:go("N16", true)
- T:emptyTrash("down")
- T:go("N16L1F1L1", true)
- end
- end
- T:go("L1F15R1") -- return
- T:clear()
- return {"Mining operation complete"}
- end
- local function createMobFarmCube(blaze, continue)
- -- Part 1 / 3 Mob Spawner Farm
- -- blaze = true: blaze spawner in nether
- if blaze == nil then blaze = false end
- if continue == nil then continue = false end
- -- continue allows for 2-part operation 1 = main cube, 2 = rails etc
- local lib = {}
- function lib.isSpawner()
- local found = false
- local position = ""
- local blockType = T:getBlockType("down")
- if blockType:find("spawner") ~= nil then
- position = "top"
- found = true
- end
- if position == "" then
- blockType = T:getBlockType("up")
- if blockType:find("spawner") ~= nil then
- position = "bottom"
- found = true
- end
- end
- if position == "" then
- blockType = T:getBlockType("forward")
- if blockType:find("spawner") ~= nil then
- position = "forward"
- found = true
- end
- end
- return found, position
- end
- function lib.searchChests(maxLength)
- local maxLength = maxLength or 1
- blocks = lib.whileInside(maxLength) -- forward to next wall or another chest
- while lib.isChest("forward") do --chest found and emptied
- blocks = lib.whileInside(maxLength) -- forward to next wall
- end
- return blocks
- end
- function lib.enterDungeon(reverse)
- local gotoFloor = false
- local blockType = T:getBlockType("forward")
- if blockType == "" then -- nothing in front so assume already inside/ in wall
- gotoFloor = true
- else -- go forward and check for void
- T:forward(1)
- blockType = T:getBlockType("forward")
- if blockType ~= "" then -- if not void go up and re-check (at bottom of spawner)
- T:up(1)
- blockType = T:getBlockType("forward")
- if blockType ~= "" then -- if not void go down 2 and re-check (at top of spawner)
- T:down(2)
- blockType = T:getBlockType("forward")
- if blockType == "" then -- ready to search
- gotoFloor = true
- end
- else
- gotoFloor = true
- end
- else
- gotoFloor = true
- end
- end
- if gotoFloor then -- go down and look for chests
- -- check if inside wall
- T:turnRight(1)
- local blockTypeR = T:getBlockType("forward")
- T:turnLeft(2)
- local blockTypeL = T:getBlockType("forward")
- T:turnRight(1)
- if blockTypeR ~= "" and blockTypeL ~= "" then -- still inside the wall
- T:forward(1)
- end
- while turtle.down() do end -- go down as spawner on floor 90% prob. May be on a chest
- if lib.isChest("down") then -- on top of a chest, empty and dig
- T:down(1)
- end
- if reverse then --coming from spawner, so find wall then turn round
- lib.searchChests(1)
- T:turnRight(2)
- end
- T:turnLeft(1) -- turn left
- lib.searchChests() -- forward to left wall, check half front wall for chests
- T:turnRight(1) -- turn right
- lib.searchChests() -- checking left wall
- T:turnRight(1) -- turn right
- lib.searchChests() -- checking back wall
- T:turnRight(1) -- turn right
- lib.searchChests() -- checking right wall
- T:turnRight(1) -- turn right
- local blocks = 1
- while turtle.forward() do
- blocks = blocks + 1
- end
- T:go("R2F".. math.floor(blocks / 2))
- -- now at mid-dungeon, next to wall facing right
- -- if chest present, deposit it outside the dungeon
- if T:getItemSlot("chest") > 0 then
- T:go("R1F2x1")
- -- place(self, blockType, damageNo, direction, leaveExisting, signText)
- T:place("chest", -1, "forward", false)
- -- empty out all except stone and slab
- T:emptyInventorySelection("forward", {"cobble", "tuff", "slab", "granite", "andesite", "diorite" }, {0,0,0,0,0,0})
- T:go("L2F2L1")
- end
- T:turnRight(1)
- end
- end
- function lib.isChest(direction)
- direction = direction or "forward"
- local found = false
- local blockType = T:getBlockType(direction)
- if blockType:find("chest") ~= nil then -- chest found. early stages so empty and break it
- found = true
- while T:suck(direction) do end
- T:dig(direction, false) -- false prevents checking for chests
- end
- return found
- end
- function lib.whileInside(blocks)
- blocks = blocks or 1
- local maxLength = blocks
- local toLimit = false
- if maxLength > 1 then
- toLimit = true
- end
- blocks = 1
- while turtle.forward() do
- blocks = blocks + 1
- if toLimit and blocks >= maxLength then
- return blocks
- end
- local cobble = T:getBlockType("down")
- if cobble:find("cobble") == nil then --check for cobble below
- turtle.back()
- turtle.back()
- blocks = blocks - 2
- return blocks
- end
- end
- return blocks
- end
- function lib.searchStrip()
- local blocks = 1
- local found = false
- local position = ""
- lib.whileInside() -- forward to opposite wall / spawner
- while lib.isChest() do --chest found and emptied
- lib.whileInside()
- end
- found, position = lib.isSpawner() -- true/false, top/bottom/nil
- if found then
- return found, position
- end
- return found, position
- end
- function lib.findSpawner(blaze)
- -- assume turtle placed on outside of spawner wall
- -- or as close as possible in Nether
- local found, position = lib.isSpawner() -- true/false, top/bottom/nil
- if not found then
- if not blaze then -- blaze spawner MUST have turtle placed in front or top
- -- assume next to dungeon wall
- local doSearch = false
- local blockType = T:getBlockType("forward")
- if blockType == "" then -- nothing in front so assume already inside/ in wall
- doSearch = true
- else -- go forward and check for void
- T:forward(1)
- blockType = T:getBlockType("forward")
- if blockType ~= "" then -- if not void go up and re-check (at bottom of spawner)
- T:up(1)
- blockType = T:getBlockType("forward")
- if blockType ~= "" then -- if not void go down 2 and re-check (at top of spawner)
- T:down(2)
- blockType = T:getBlockType("forward")
- if blockType == "" then -- ready to search
- doSearch = true
- end
- else
- doSearch = true
- end
- else
- doSearch = true
- end
- end
- if doSearch then -- search started.
- -- check if inside wall
- T:turnRight(1)
- local blockTypeR = T:getBlockType("forward")
- T:turnLeft(2)
- local blockTypeL = T:getBlockType("forward")
- T:turnRight(1)
- if blockTypeR ~= "" and blockTypeL ~= "" then -- still inside the wall
- T:forward(1)
- end
- while turtle.down() do end -- go down first as spawner on floor 90% prob
- T:turnLeft(1) -- turn left, forward to wall, check for chests
- while turtle.forward() do end -- forward to wall or chest
- while lib.isChest() do --chest found and emptied
- while turtle.forward() do end -- forward to wall or another chest
- end
- T:turnRight(2) -- turn right, forward to wall counting
- local blocks = 1
- while turtle.forward() do
- blocks = blocks + 1
- end -- forward to R wall
- T:turnLeft(2) -- turn round
- T:forward(math.floor(blocks / 2))
- T:turnRight(1)
- found, position = lib.searchStrip() -- finds chest, spawner or wall
- if found then
- return found, position
- end
- -- if this line reached, spawner not yet found, blocks = width of dungeon
- T:go("U1R2")
- found, position = lib.searchStrip() -- finds chest, spawner or wall
- return found, position
- end
- end
- end
- return found, position
- end
- function lib.rail(move, isPowered, count)
- if move ~= "" then
- T:go(move)
- end
- for i = 1, count do
- if isPowered then
- if not T:place("minecraft:powered_rail", -1, "down", false) then
- T:place("minecraft:golden_rail", -1, "down", false)
- end
- else
- T:place("minecraft:rail", -1, "down", false)
- end
- if i < count then
- T:forward(1)
- end
- end
- end
- local brick = "minecraft:nether_brick" -- pre 1.16+ name
- if mcMajorVersion < 1.7 and mcMajorVersion >= 1.16 then -- 1.12 to 1.??
- brick = "minecraft:nether_bricks"
- end
- if not continue then -- new mob cube either dungeon or blaze
- -- clsTurtle.go(self, path, useTorch, torchInterval, leaveExisting, preferredBlock)
- -- determine spawner position level 4, move to top of spawner (level 6)
- local found, position = lib.isSpawner() -- already on spawner?
- if not blaze then -- go to bottom of dungeon and empty chests
- if found then -- already on spawner
- if position == "top" then
- T:go("R2F1")
- else
- T:go("R2")
- end
- lib.enterDungeon(true)
- else --outside dungeon
- lib.enterDungeon(false)
- end
- end
- -- is spawner in front / above / below?
- found, position = lib.findSpawner(blaze)
- if found then -- True: move to correct starting position
- if position == "bottom" then
- T:go("B1U2F1")
- elseif position == "forward" then
- T:go("U1F1")
- end
- -- place slab on top T:place(blockType, damageNo, direction, leaveExisting)
- T:up(1)
- T:place("slab", -1, "down", true)
- -- go up 2 blocks, forward 4, right, forward 4, right
- T:go("U2F4R1F4R1")
- -- clear 9x9 and plug ceiling (level 9)
- --"Q": mine block above and/or fill void + mine block below if valuable + left side
- T:go("R2C1R2Q8R1Q8R1Q8R1Q7R1F1", false, 0, false)
- -- 7x7 rectangle filling above
- for i = 1, 3 do
- T:go("M7R1F1R1M7L1F1L1", false, 0, false)
- end
- T:go("M7R2F8R1F7R1", false, 0, false) --back to corner
- -- mine wall: q# mine # blocks forward, check left side and patch
- for i = 1, 2 do
- -- down 1, clear 9x9 border, checking walls (level 8, 7)
- T:go("D1R2C1R2q8R1q8R1q8R1q7R1F1", false, 0, false)
- -- clear remaining 7x7 area
- clearRectangle({width = 7, length = 7, up = false, down = false})
- --clearRectangle(7, 7, false, false)
- T:go("R2F1R1F1R1", false, 0, false) --back to corner
- end
- for i = 1, 2 do
- -- down 1, clear 9x9 border (level 6, 5)
- T:go("D1R2C1R2q8R1q8R1q8R1q7R1", false, 0, false)
- T:go("F7R1F6R1F6R1F5R1", false, 0, false)
- T:go("F5R1F4R1F4R1F6L1F2R2", false, 0, false)
- end
- local count = 3
- if blaze then
- count = 2
- end
- for i = 1, count do
- -- down 1, clear 9x9 border, checking walls (level 4, 3, (2))
- T:go("D1R2C1R2q8R1q8R1q8R1q7R1F1")
- -- clear remaining 7x7 area
- clearRectangle({width = 7, length = 7, up = false, down = false})
- --clearRectangle(7, 7, false, false)
- T:go("R2F1R1F1R1", false, 0, false) --back to corner
- end
- if blaze then
- -- strart in top right corner. border is made of slabs placed up
- T:go("D1R2F1R1F1R1")
- for i = 1, 3 do
- clearRectangle({width = 11, length = 11, up = false, down = false})
- --clearRectangle(11, 11, false, false) --layer 2, 1, 0
- T:down(1)
- end
- T:go("R2F1R1F1R1")
- -- ready to lay floor and border
- -- q# mine # blocks forward, check left side and patch
- T:go("R2C1R2 n12R1 n12R1 n12R1 n11R1F1", false, 0, false)
- -- fill in floor 11x11 rectangle below
- local a, b, numBricks = T:getItemSlot(brick)
- for i = 2, 12 do -- 11 iterations (rows)
- T:go("m10", false, 0, false, brick)
- if i % 2 == 0 then -- 2, 4, 6, 8, 10
- if i < 12 then
- T:go("R1F1R1", false, 0, false, brick)
- end
- else -- 3,5,7,9,11
- T:go("L1F1L1", false, 0, false, brick)
- end
- end
- -- move to starting point in front of spawner,
- -- outside retaining wall' facing in, and ask for supplies
- T:go("L1F5U6R1F2R2")
- continue = true -- script continues below for blaze farm
- else -- not blaze
- -- clear floor and plug holes
- -- n# mine block below and/or fill void + check left side
- T:down(2)
- for j = 1, 2 do
- T:go("R2C1R2n8R1n8R1n8R1n7R1F1", false, 0, true)
- -- 7x7 rectangle filling below
- for i = 1, 4 do
- if i < 4 then
- T:go("m6R1F1R1m6L1F1L1", false, 0, true)
- else
- T:go("m6R1F1R1m6", false, 0, true)
- end
- end
- if j == 1 then
- T:go("U1F1R1F8R1")
- end
- end
- -- return to mid-point front
- T:turnRight(2)
- while turtle.forward() do end
- T:turnRight(1)
- while turtle.forward() do end
- T:go("R2F4R1F2R2") -- exit at bottom of dungeon
- end
- else
- T:clear()
- print("Spawner not found. Place me on top,")
- print("immediately below, or facing it.")
- print("\nEnter to quit")
- read()
- end
- end
- if continue then
- T:sortInventory()
- T:turnRight(2)
- T:emptyTrashItem("forward", "minecraft:netherrack", 0)
- T:emptyTrashItem("forward", brick, 128)
- T:emptyTrashItem("forward", "fence", 0)
- T:turnRight(2)
- --clsTurtle.getItemSlot(self, item, useDamage): return slotData.lastSlot, slotData.leastModifier, total, slotData
- local a, b, numBricks = T:getItemSlot(brick)
- if numBricks < 81 then -- enough for floor
- T:checkInventoryForItem({brick, "stone"}, {81 - numBricks, 81 - numBricks})
- end
- T:checkInventoryForItem({"stone"}, {339})
- T:checkInventoryForItem({"slab"}, {36})
- T:checkInventoryForItem({"minecraft:powered_rail", "minecraft:golden_rail"}, {8, 8})
- T:checkInventoryForItem({"minecraft:rail"}, {64})
- T:checkInventoryForItem({"minecraft:redstone_torch"}, {2})
- T:checkInventoryForItem({"minecraft:hopper_minecart"}, {1})
- T:checkInventoryForItem({"minecraft:stone_button"}, {1})
- print("Stand clear. Starting in 2 secs")
- os.sleep(2) -- pause for 2 secs to allow time to press esc
- -- return to starting point. rail laid first, bricks placed over rails
- T:go("F2L1D5F4R1")
- lib.rail("", true, 2) -- lay 2 plain rail at start
- lib.rail("F1", false, 1) -- lay 1 plain rail
- lib.rail("F1", true, 3) -- lay 3 powered rail
- T:go("L1F1")
- T:place("minecraft:redstone_torch", -1, "down", false) --place redstone torch
- lib.rail("R2F1L1F1", false, 3)
- lib.rail("R1F1R1", false, 8)
- lib.rail("L1F1L1", false, 7)
- lib.rail("R1F1R1", false, 8)
- lib.rail("L1F1L1", false, 9)
- lib.rail("R1F1R1", false, 8)
- lib.rail("L1F1L1", false, 7)
- lib.rail("R1F1R1", false, 8)
- lib.rail("L1F1L1", false, 5) -- final strip
- lib.rail("F1", true, 3)
- T:go("F1C2R1F1R1F1")
- T:place("minecraft:redstone_torch", -1, "down", false)
- T:go("R2F1L1F1L1U1")
- -- lay floor 9 x 9 rectangle filling below
- for i = 2, 10 do -- repeat 9x
- T:go("m8", false, 0, false, brick)
- if i < 10 then
- if i % 2 == 0 then
- T:go("R1F1R1", false, 0, false, brick)
- else
- T:go("L1F1L1", false, 0, false, brick)
- end
- end
- end
- -- replace first rail with cobble and button
- T:go("R1F1R2D2x1C1B1", false, 0, false)
- T:place("minecraft:stone_button", -1, "forward", false)
- T:go("U2F2L1F1x2")
- T:place("minecraft:hopper_minecart", -1, "down", false)
- T:go("L1F1D1R2C1", false, 0, false, brick) -- cover minecart
- T:go("U1R1F2L1C0F1",false, 0, false)
- -- place slabs
- for j = 1, 4 do
- for i = 1, 9 do
- T:place("slab", -1, "up", false)
- T:forward(1)
- end
- if j < 4 then
- T:go("L1C0F1")
- end
- end
- T:go("L1F1L2") -- get in position
- -- build outer edge
- for j = 1, 4 do
- for i = 1, 9 do
- turtle.back()
- T:place("stone", -1, "forward", false)
- end
- if j < 4 then
- T:turnLeft(1)
- turtle.back()
- T:place("stone", -1, "forward", false)
- end
- end
- T:go("L1F1R2C1L1U1")
- for j = 1, 4 do
- for i = 1, 11 do
- T:go("C0x2F1")
- end
- T:go("C0x2R1F1")
- end
- T:go("R2F2R1F1R1")
- T:go("R2C1R2Q14R1Q14R1Q14R1Q13R1D1", false, 0, false)
- T:go("L1F1R1")
- T:go("R2C1R2n14R1n14R1n14R1n13R1", false, 0, false) -- now facing in on top of outer walkway
- T:go("R1 C1U1x0 F1C1U1x0 F1C1U1x0 F1C2 F1C2 F1C2 F1C2 U1L1F1") -- back at original entrance
- end
- return {}
- end
- local function floodMobFarm()
- -- Part 2 / 3 Mob Spawner Farm
- -- turtle on floor, pointing towards water source wall
- -- move forward until hit wall
- while turtle.forward() do end
- -- turn left, move forward until hit wall
- T:turnLeft(1)
- while turtle.forward() do end
- -- back 1, place water
- turtle.back()
- T:place("minecraft:water_bucket", -1, "forward", true)
- -- turn round go forward 7, place water
- T:turnLeft(2)
- while turtle.forward() do end
- -- back 1, place water
- turtle.back()
- T:place("minecraft:water_bucket", -1, "forward", true)
- -- turn round, go forward 3 (centre of wall), turn left, forward 4 (centre of chamber)
- T:go("L2F3L1F4")
- -- go down, left, forward, turn round
- T:go("D1L1F1R2")
- for i = 3, 9, 2 do
- -- check down, dig forward, go forward, check down (i blocks)
- T:go("m"..i-1, false, 0, true)
- if i == 3 or i == 7 then
- -- left, forward, right, forward, turn round
- T:go("L1F1R1F1R2")
- elseif i < 9 then
- T:go("R1F1L1F1R2")
- -- right, forward, left, forward, turn round
- end
- end
- -- right, forward, right, check down / forward 9 x
- T:go("R1F1R1m8R2F4R1") -- now facing bubble lift, next to wall
- -- go down 2, check floor, up 1, place fence
- T:go("D2C2U1", false, 0, true)
- T:place("fence", -1, "down", false)
- T:go("F1D1C2U1", false, 0, true)
- T:place("fence", -1, "down", false)
- T:go("F1U1R2", false, 0, true)
- T:go("F1R1U1")
- T:place("sign", -1, "down", false)
- T:go("U1C0D1")
- T:place("slab", -1, "up", false)
- T:go("R2F1R2")
- T:place("sign", -1, "forward", false)
- T:go("R1F1R2C1R1F1D1L1") --sitting on soul sand/dirt facing spawner
- if not T:place("minecraft:soul_sand", -1, "down", false) then
- T:place("minecraft:dirt", -1, "down", false)
- end
- return {}
- end
- local function createMobBubbleLift(size)
- -- Part 3 / 3 Mob Spawner Farm
- -- size = 0 or 1 (left/right)
- local lib = {}
- function lib.down()
- local moves = 0
- while turtle.down() do
- moves = moves + 1
- end
- return moves
- end
- function lib.up()
- local moves = 0
- while turtle.up() do
- moves = moves + 1
- end
- return moves
- end
- -- check if dirt or soulsand below
- local turn = "R"
- if size == 1 then
- turn = "L"
- end
- local onSand = false
- local blockType = T:getBlockType("down")
- if blockType == "minecraft:soul_sand" then
- onSand = true
- elseif blockType == "minecraft:dirt" then
- T:dig("down")
- if T:place("minecraft:soul_sand", -1, "down", false) then
- onSand = true
- end
- end
- if onSand then
- -- check facing sign, rotate if not
- blockType = T:getBlockType("forward")
- while blockType:find("sign") == nil do
- T:turnRight(1)
- blockType = T:getBlockType("forward")
- end
- for i = 1, 3 do
- -- fill in back and one side, go up
- if turn == "R" then
- T:go("R1C1R1C1R1x1R1U1", false, 0, true)
- else
- T:go("L1C1L1C1L1x1L1U1", false, 0, true)
- end
- end
- for i = 1, 17 do
- -- tunnel up, filling 3 sides
- if turn == "R" then
- T:go("R1C1R1C1R1x1R1C1U1", false, 0, true)
- else
- T:go("L1C1L1C1L1x1L1C1U1", false, 0, true)
- end
- end
- -- move either left/right 8 blocks, repairing ceiling and sides
- if turn == "R" then
- T:go("C0R2C1R1F1C0C1R1C1R2C1L1F1A8", false, 0, true) -- fill top of column
- else
- T:go("C0L2C1L1F1C0C1L1C1L2C1R1F1A8", false, 0, true) -- fill top of column
- end
- -- turn round, go down 1, forward 7 blocks repairing bottom and sides
- T:go("D1C1R2X7", false, 0, true)
- -- turn round, go up, place cobble, forward 4, place cobble
- T:go("R2U1C2F4C2", false, 0, true)
- -- turn round forward 1 place water, forward 2, place water
- T:go("R2F1", false, 0, true)
- T:place("minecraft:water_bucket", -1, "down", false)
- T:forward(2)
- T:place("minecraft:water_bucket", -1, "down", false)
- T:go("R2F1")
- repeat
- -- refill both buckets
- T:place("minecraft:bucket", -1, "down", false)
- sleep(0.5)
- T:place("minecraft:bucket", -1, "down", false)
- -- back 4, down to solid, place water,
- for i = 1, 4 do
- turtle.back()
- end
- local moves = lib.down() -- returns no of blocks descent 0 to 19
- if moves > 0 then
- T:place("minecraft:water_bucket", -1, "forward", false)
- T:go("U1C2")
- if moves > 1 then
- T:place("minecraft:water_bucket", -1, "forward", false)
- T:go("U1C2")
- end
- end
- lib.up() -- 0 - 19
- T:forward(4)
- until moves <= 1
- -- delete water sources and remove cobble
- T:go("R2F3C1R2F1")
- for i = 1, 7 do -- go to end of run placing cobble
- T:go("C2F1")
- end
- T:turnRight(2)
- for i = 1, 7 do -- go to end of run, down 2
- T:go("x2F1x2")
- end
- T:go("R2F7D2")
- for i = 1, 18 do
- -- tunnel down, filling all 4 sides
- T:go("R1C1R1C1R1C1R1C1D1", false, 0, true)
- end
- -- turn round, tunnel forward 6 blocks
- T:go("R2U1F1M5D1R2F1X5")-- end up under drop column
- else
- print("Unable to find or place soulsand.\nEnter to continue")
- read()
- end
- return {}
- end
- local function createMobSpawnerBase(pathLength)
- if pathLength > 0 then
- print("Building path to mob spawner base")
- createPath(pathLength)
- T:back(1)
- end
- T:place("stone", -1, "down", true)
- T:go("R1F1L1", false, 0, true)
- createPath(8)
- T:go("L1F1L1F1", false, 0, true)
- createPath(8)
- T:go("R1F1R1F1", false, 0, true)
- createPath(8)
- T:go("L1F1L1F1", false, 0, true)
- createPath(8)
- T:go("L1F2L1F1", false, 0, true)
- return {}
- end
- local function createMobSpawnerTower(height)
- height = height or 2
- print("Building mob spawner base")
- -- assume placed at sea level on stone block (andesite / granite / diorite)
- --layers 2, 3 (layer 1 done at base construction)
- T:go("U1F7H2L1F1H2R1F2D1R2P1L1F1R1P1R2U1", false, 0, true)
- for i = 1, 8 do
- T:go("C2R1C1L1F1", false, 0, true)
- end
- T:go("L1F1L2C1R1F1R2C1R2", false, 0, true)
- for i = 1, 8 do
- T:go("C2R1C1L1F1", false, 0, true)
- end
- T:go("U1R2F8R1", false, 0, true)
- T:place("minecraft:water_bucket", -1, "down", false)
- T:go("F1R1", false, 0, true)
- T:place("minecraft:water_bucket", -1, "down", false)
- T:forward(16)
- T:go("R1F1D2", false, 0, true)
- for i = 1, 2 do
- sleep(0.5)
- T:place("minecraft:bucket", -1, "down", false)
- end
- T:go("R1F2", false, 0, true)
- for i = 1, 2 do
- T:go("C1R1C1R2C1R1U1")
- end
- -- height of tower
- height = math.ceil(height / 2)
- for i = 1, height do
- T:go("C1U1C1R1C1R1C1R1C1R1U1")
- end
- -- create platform for player
- T:go("R2F1L1C1R1C1R1C1U1C1L1C1L1C1L1F1L1C!R2C1L1U1F1", false, 0, true)
- -- place stone marker
- T:place("stone", -1, "down")
- -- will need to move back before completing
- return {}
- end
- local function createMobSpawnerTank()
- --layer 1 of tower + walkway
- -- move back 1 block before continuing with tower top and walkway
- T:go("R2F1R2")
- T:go("C1U2R1F1L1") -- now dropping cobble from above
- T:go("m10L1F1L1")
- T:go("m9R1F1L1F1C2F1L1F1C2L1F1")
- --layer 2
- T:go("U1F1C2R1F1C2F1L1F1m8L1F3L1m8F2L1F1L1")
- --layer 3
- T:go("U1R1F1C2L1F1C2")
- T:go("F1R1F1L1C2F1C2F1L1F1C2")
- T:go("F1C2F1L1F1C2F1C2F2C2F1")
- T:go("L1F1C2L1F2C2B1")
- --layer 4
- T:go("U1F1L1F1R2")
- for i = 1, 4 do
- T:go("F1C2F1C2F1L1")
- end
- T:go("F1R1F1R2")
- --layer 5
- T:go("U1R2F1m7L1F1L1C2F1C2F7C2F1C2")
- T:go("F1R1F1L1C2F1C2F1L1F1C2F1C2F1")
- T:go("L1F1C2F1C2F2C2L1F1L1F1C2R2F1R2")
- -- layer 6
- T:go("U1R2F9C2L1F1C2F1L1F1C2F1L1F1C2R1F8L1F2R2")
- for i = 1, 4 do
- T:go("F1C2F1C2F1L1")
- end
- T:go("F1L1F1")
- T:place("minecraft:water_bucket", -1, "down")
- T:go("R1F1L1")
- T:place("minecraft:water_bucket", -1, "down")
- T:go("R2F2R1F1R1")
- -- layer 7
- T:go("U1R2F8L1F2C2L1F1L1F1C2R1F7C2L1F2R1C2F1R1")
- for i = 1, 4 do
- T:go("F1C2F1C2F1L1")
- end
- T:go("F1R1F1R2")
- T:go("F2")
- -- place stone inside column, ready for temp water source
- T:place("stone", -1, "down", false)
- -- layer 8
- -- make temp water source in centre. destroy in createMobSpawnerRoof()
- T:go("F1C2R1F1C2R1F1C2F1R1F2U1R2")
- -- spiral construction
- for j = 3, 9, 2 do
- for i = 1, 4 do
- if i < 4 then
- T:go("m"..j.."L1")
- else
- T:go("m"..j.."F1R1F1L2")
- end
- end
- end
- -- fill water source
- T:go("F5L1F5")
- T:place("minecraft:water_bucket", -1, "down", false)
- T:go("F1R1F1R1")
- T:place("minecraft:water_bucket", -1, "down", false)
- T:go("F5m4F2C2F1R1F1C2F1R1F1C2F1R1F1L1C2F1m4")
- T:go("F8F2m3R1F1R1m3")
- T:go("F5L1F5m3R1F1R1m3")
- T:go("F9F2m3R1F1R1m3")
- -- layer 9
- T:up(1)
- for i = 1, 4 do
- T:go("L1F1L1m3R1F1R1m3L1F1L1m3R1F1R1m3F4")
- T:go("L1F1L1m7R1F1R1m7L1F1L1m7R1F1R1m7F1L1F1R1C2F1C2R1F4")
- end
- -- now add water
- T:go("F6")
- for i = 1, 4 do
- T:down(1)
- T:place("minecraft:bucket", -1, "down", false)
- sleep(0.5)
- T:place("minecraft:bucket", -1, "down")
- T:go("U1F8R1")
- T:place("minecraft:water_bucket", -1, "down", false)
- T:go("F1R1")
- T:place("minecraft:water_bucket", -1, "down", false)
- T:go("F8L1")
- end
- for i = 1, 2 do
- T:down(1)
- T:place("minecraft:bucket", -1, "down", false)
- sleep(0.5)
- T:place("minecraft:bucket", -1, "down", false)
- T:go("U1F4L1F4L1")
- T:place("minecraft:water_bucket", -1, "down", false)
- T:go("F9")
- T:place("minecraft:water_bucket", -1, "down", false)
- T:go("L1F5L1F4L2")
- end
- T:go("F9R1F10R1")
- -- layer 10 / 11
- for j = 1, 2 do
- T:go("U1F1m8L1F1C2F1R1F1C2F1R1F1C2F1R1F1R2m8F1R1")
- for i = 1, 3 do
- T:go("F1m17F1R1")
- end
- end
- T:go("F10R1F9D4")
- return {}
- end
- local function createMobSpawnerRoof()
- -- destroy water source first
- T:go("x2C1R1F1x2L1F1x2L1F1x2L1F1x2L2")
- T:go("U5L1F8L1F8L2") -- top left corner facing e
- T:go("m17R1m17R1m17R1m17") -- outer ring. ends facing n
- T:go("R1F2R1F1L1") -- facing e
- for i = 1, 4 do -- outer ring - 1 (with torches) ends facing e
- T:go("m6t1m3t1m5R1F1t1")
- end
- T:go("R1F1L1") -- facing e
- for i = 1, 4 do -- outer ring - 2 ends facing e
- T:go("m13R1m13R1m13R1m13")
- end
- T:go("R1F1L1") -- ends facing e
- T:go("m11R1m11R1m11R1m11") -- ends facing e
- T:go("R1F1R1F1L1F1")
- for i = 1, 4 do
- T:go("m8R1F1t1")
- end
- T:go("R1F1L1")
- T:go("m7R1m7R1m7R1m7")
- T:go("R1F1R1F1L1")
- T:go("m5R1m5R1m5R1m5")
- T:go("R1F1R1F1L1F1")
- for i = 1, 4 do
- T:go("m2R1F1t1")
- end
- T:go("R1F1L1")
- T:go("m1R1m1R1m1R1m1")
- return {}
- end
- local function createPlatform(width, length)
- local forward = true
- for w = 1, width do
- for l = 1, length do
- T:go("x2C2", false, 0, true)
- if l < length then
- T:go("F1", false, 0, true)
- end
- end
- if w < width then
- if forward then
- T:go("R1F1R1", false, 0, true)
- else
- T:go("L1F1L1", false, 0, true)
- end
- end
- forward = not forward
- end
- return {}
- end
- local function createPortal(width, height)
- T:go("D1x1", false, 0, true)
- T:place("stone", -1, "forward", true)
- for i = 1, height - 1 do
- T:go("U1x1", false, 0, true)
- T:place("minecraft:obsidian", 0, "forward", true)
- end
- T:go("U1x1", false, 0, true)
- T:place("stone", -1, "forward", true)
- for i = 1, width - 1 do
- T:go("R1F1L1x1")
- T:place("minecraft:obsidian", 0, "forward", true)
- end
- T:go("R1F1L1x1", false, 0, true)
- T:place("stone", -1, "forward", true)
- for i = 1, height - 1 do
- T:go("D1x1")
- T:place("minecraft:obsidian", 0, "forward", true)
- end
- T:go("D1x1", false, 0, true)
- T:place("stone", -1, "forward", true)
- for i = 1, width - 1 do
- T:go("L1F1R1x1")
- T:place("minecraft:obsidian", 0, "forward", true)
- end
- T:go("U1L1F1R1", false, 0, true)
- return {}
- end
- local function createPortalPlatform()
- --[[ Used in End World to use minecarts to carry player through portal ]]
- local lib ={}
- function lib.findPortal()
- local found = false
- local onSide = false
- for i = 1, 64 do
- if not turtle.up() then -- hit block above
- found = true
- break
- end
- end
- if found then
- -- are we under the centre block, or one of the sides?
- if turtle.detect() then -- under a side
- onSide = true
- else -- nothing in front, probably under centre, or facing wrong direction so check
- for i = 1, 4 do
- turtle.turnRight()
- if turtle.detect() then
- onSide = true
- break
- end
- end
- end
- if onSide then-- move to centre
- T:go("D1F1")
- end
- end
- local height = 3 -- allows for 2 bedrock + starting space
- while turtle.down() do
- height = height + 1
- end
- return found, height
- end
- function lib.addFloor(length)
- for i = 1, length do
- if i < length then
- T:go("C2F1", false, 0, true)
- else
- T:go("C2", false, 0, true)
- end
- end
- end
- function lib.buildLadder(height)
- for i = 1, height do
- T:go("F1C1 R1C1 L2C1 L1F1L2", false, 0, true)
- if i > 3 then
- T:go("C2")
- end
- T:place("minecraft:ladder", 0, "forward", true)
- T:up(1)
- end
- end
- local found, height = lib.findPortal()
- if found then -- position under centre of beacon
- -- build ladder up and create platform
- T:go("L1F1L1F2L2")
- T:checkInventoryForItem({"minecraft:ladder"},{height})
- T:checkInventoryForItem({"stone"},{height * 4 + 40})
- lib.buildLadder(height)
- T:go("F1R1F4R2") -- turn right, forward 4, reverse
- for i = 1, 5 do -- build 7 x 5 platform
- lib.addFloor(7) -- forward place block above to 7 blocks
- if i == 1 or i % 2 == 1 then -- 1,3,5,7
- T:go("L1F1L1")
- else
- T:go("R1F1R1")
- end
- end
- T:go("F3L1F4") -- facing portal entrance, 1 block short
- T:place("minecraft:rail", -1, "forward", false)
- T:go("U1R2")
- T:place("minecraft:rail", -1, "down", false)
- T:forward(1)
- if not T:place("minecraft:powered_rail", -1, "down", false) then
- T:place("minecraft:golden_rail", -1, "down", false)
- end
- T:go("F1C2 U1R2C2 F1")
- T:place("minecraft:minecart", -1, "down", false)
- T:go("F1R2D1")
- T:place("minecraft:stone_button", -1, "forward", false)
- else
- return {"Portal not found. Move me under","the centre if possible.", "wait for purple beacon."}
- end
- return {}
- end
- local function createRailwayDown(drop)
- -- go(path, useTorch, torchInterval, leaveExisting, preferredBlock)
- if drop == 0 then
- local blockTypeD = T:getBlockType("down")
- while blockTypeD == "" do
- T:go("F1D1", false, 0, true)
- blockTypeD = T:getBlockType("down")
- if blockTypeD == "" then
- T:go("C2", false, 0, true)
- end
- end
- else
- for i = 1, drop - 1 do
- T:go("F1D1C2", false, 0, false)
- end
- end
- return {}
- end
- local function createRailwayUp(up)
- for i = 1, up do
- T:go("C1U1F1", false, 0, false)
- end
- return {}
- end
- local function createRetainingWall(length, height)
- local place = false
- if height <= 0 then
- height = 30
- end
- local inWater = false
- for i = 1, 4 do
- if string.find(T:getBlockType("forward"), "water") ~= nil then
- inWater = true
- end
- T:turnRight(1)
- end
- local y = 1
- -- go(path, useTorch, torchInterval, leaveExisting)
- -- start at surface, move back 1 block
- -- each iteration completes 3 columns
- local numBlocks = T:getSolidBlockCount()
- print("Solid blocks in inventory: "..numBlocks)
- if not inWater then
- T:down(1)
- end
- place = clearVegetation("down") -- returns true if air, water or lava below
- if length == 1 then --single column
- local place = clearVegetation("down")
- while place do -- loop will be entered at least once
- T:down(1)
- y = y + 1
- place = clearVegetation("down")
- end
- for i = 1, y - 1 do
- T:go("U1C2", false, 0, true, false)
- end
- elseif length == 2 then--down then up
- T:back(1) -- move 1 block away from wall edge
- local place = clearVegetation("down")
- while place do -- loop will be entered at least once
- T:go("C1D1", false, 0, true, false)
- y = y + 1
- place = clearVegetation("down")
- end
- T:forward(1) -- in case col in front is deeper
- place = clearVegetation("down")
- while place do -- loop will be entered at least once
- T:down(1)
- y = y + 1
- place = clearVegetation("down")
- end
- T:go("B1C1", false, 0, true)
- for i = 1, y - 1 do
- T:go("U1C2", false, 0, true)
- end
- T:go("C1", false, 0, true, false)
- else -- length 3 or more eg 3,22; 11
- local remain = length % 3 -- 0; 1; 2 only possible results
- length = length - remain -- 3-0=3; 4-1=3; 5-2=3; 6-0=6
- for i = 3, length, 3 do -- 3, 6, 9, 12 etc
- numBlocks = T:getSolidBlockCount()
- print("Solid blocks in inventory: "..numBlocks)
- if numBlocks < height * 3 then
- --ask player for more
- T:checkInventoryForItem({"stone"}, {height * 3}, false)
- end
- T:go("B1C1", false, 0, true)
- if i > 3 then -- second iteration
- T:go("B1C1")
- end
- -- place blocks forward while descending
- place = clearVegetation("down")
- while place do -- loop will be entered at least once
- T:go("C1D1", false, 0, true)
- y = y + 1
- place = clearVegetation("down")
- end
- T:forward(1) -- in case col in front is deeper
- place = clearVegetation("down")
- while place do -- loop will be entered at least once
- T:down(1)
- y = y + 1
- place = clearVegetation("down")
- end
- while not turtle.detectUp() do -- go up until column base is met
- T:go("U1C2")
- y = y - 1
- if y < 0 then
- break
- end
- end
- T:go("B1C1B1", false, 0, true)
- -- return to surface, placing forward and below
- for i = 1, y - 1 do
- T:go("C1U1C2", false, 0, true)
- end
- -- put missing block down
- T:go("C1", false, 0, true)
- y = 1 -- reset counter
- end
- if remain == 1 then -- 1 more column
- y = 1
- T:back(1)
- place = clearVegetation("down")
- while place do -- loop will be entered at least once
- T:down(1)
- y = y + 1
- place = clearVegetation("down")
- end
- for i = 1, y - 1 do
- T:go("U1C2", false, 0, true)
- end
- -- put missing block down
- T:go("C1", false, 0, true)
- elseif remain == 2 then -- 2 cols
- y = 1
- T:back(1)
- place = clearVegetation("down")
- while place do -- loop will be entered at least once
- T:go("C1D1", false, 0, true)
- y = y + 1
- place = clearVegetation("down")
- end
- T:forward(1)
- place = clearVegetation("down")
- while place do
- T:down(1)
- y = y + 1
- place = clearVegetation("down")
- end
- T:go("B1C1", false, 0, true)
- for i = 1, y - 1 do
- T:go("U1C2", false, 0, true)
- end
- -- put missing block down
- T:go("C1", false, 0, true)
- end
- end
- return {}
- end
- local function createSafeDrop(height)
- -- dig down height blocks, checking for blocks on all sides
- local drop = 0
- T:down(2)
- drop = 2
- for i = 1, height - 1 do
- for j = 1, 4 do
- -- go(path, useTorch, torchInterval, leaveExisting, preferredBlock)
- T:go("C1R1", false, 0, true)
- end
- if T:down(1) then
- drop = drop + 1
- end
- if T:isWaterOrLava("up") ~= "" then
- T:go("C0x0", false, 0, false) -- delete water/ lava block
- end
- end
- T:go("U1R2x1")
- --place(blockType, damageNo, direction, leaveExisting, signText)
- T:place("minecraft:water_bucket", -1, "down", false)
- T:go("U1x1")
- T:up(drop - 2)
- return {"Safe drop completed "..drop .. " blocks"}
- end
- local function createSandWall(length)
- length = length or 0
- local success = true
- --move above water
- local maxMove = 2
- while turtle.detectDown() and maxMove > 0 do
- T:forward(1)
- maxMove = maxMove - 1
- end
- if length > 0 then
- for i = 1, length - 1 do
- success = dropSand()
- T:forward(1, false)
- end
- success = dropSand()
- else
- while not turtle.detectDown() do -- over water
- while not turtle.detectDown() do -- nested to allow forward movement
- success = dropSand() -- drops sand and checks supplies
- end
- if success then
- T:forward(1, false)
- else -- out of sand
- break
- end
- end
- end
- return {}
- end
- local function createSinkingPlatform(width, length, height)
- local lib = {}
- function lib.stage1a()
- for l = 1, length do
- if l == 1 then
- T:go("L1C1R1C2U1C2D1F1C2", false, 0, true)
- elseif l < length then
- T:go("L1C1R1C2F1C2", false, 0, true)
- else
- T:go("L1C1R1C2C1U1C2D1", false, 0, true)
- end
- end
- end
- function lib.stage1b()
- for l = 1, length do
- if l == 1 then
- T:go("R1C1L1C2U1C2D1F1C2", false, 0, true)
- elseif l < length then
- T:go("R1C1L1C2F1C2", false, 0, true)
- else
- T:go("R1C1L1C2C1U1C2D1", false, 0, true)
- end
- end
- end
- function lib.stage2(forward)
- if forward then
- T:go("C1R1F1L1C1R2", false, 0, true)
- else
- T:go("C1L1F1R1C1L2", false, 0, true)
- end
- end
- local forward = true
- local goingRight = true
- for h = 1, height do
- T:down(1) -- move down into existing platform
- if goingRight then -- first side
- if forward then
- -- complete left side
- T:go("R2C1L2", false, 0, true) -- block 1, 1
- lib.stage1a()
- -- turn ready for next side
- T:go("R1F1L1C1R2C2")
- else
- T:go("L2C1R2", false, 0, true) -- block 1, 1
- lib.stage1b()
- -- turn ready for next side
- T:go("L1F1R1C1L2C2")
- end
- else -- on right side so different approach
- if forward then
- T:go("L2C1R2", false, 0, true) -- block 1, 1
- lib.stage1b()
- -- turn ready for next side
- T:go("C1L1F1R1C1L2C2")
- else
- -- complete left side
- T:go("R2C1L2", false, 0, true) -- block 1, 1
- lib.stage1a()
- -- turn ready for next side
- T:go("C1R1F1L1C1R2C2")
- end
- end
- forward = not forward
- -- continue strips across until at far edge
- for w = 1, width - 2 do
- for l = 1, length do
- if l < length then
- T:go("C2F1", false, 0, true)
- else
- T:go("C2", false, 0, true)
- end
- end
- if goingRight then
- lib.stage2(forward)
- else
- lib.stage2(not forward)
- end
- forward = not forward
- end
- -- far side
- if goingRight then
- if forward then
- lib.stage1b()
- else
- lib.stage1a()
- end
- else
- if forward then
- lib.stage1a()
- else
- lib.stage1b()
- end
- end
- goingRight = not goingRight
- T:turnRight(2)
- forward = not forward
- end
- return {}
- end
- local function createSolid(width, length, height)
- -- this function currently not used
- for i = 1, width do --width could be 1, 2, 3 etc
- createRetainingWall(length, height)
- if i < width then --width = 2 or more
- if i == 1 or i %