local mineVein = require("minevein") local symmetricBranches if arg[1] == nil then symmetricBranches = 20 else symmetricBranches = tonumber(arg[1]) end branchDistance = 2 branchDepth = 16 function keepFueled() if turtle.getFuelLevel() < 200 then for n = 1,16 do turtle.select(n) if turtle.refuel(64) == true then break end end turtle.select(1) end end keepFueled() function blockInfront() local hasBlock, data = turtle.inspect() return hasBlock end function tunnel() print("fuel level: "..tostring(turtle.getFuelLevel())) repeat turtle.dig() until turtle.forward(0) == true turtle.digDown() mineTunnelSidesIfOre() end function turn(direction) if direction == "left" then turtle.turnLeft() elseif direction == "right" then turtle.turnRight() end end function endsWith(string, suffix) return string:sub(-#suffix) == suffix end function isOre(blockData) if blockData ~= nil then print(blockData.name) return endsWith(blockData.name, "ore") else return false end end function mineIfOre(direction) local inspect, dig if direction == "up" then inspect = function() return turtle.inspectUp() end dig = function() return turtle.digUp() end elseif direction == "forward" then inspect = function() return turtle.inspect() end dig = function() return turtle.dig() end elseif direction == "down" then inspect = function() return turtle.inspectDown() end dig = function() return turtle.digDown() end end if inspectPotentialBlockData(inspect, isOre) then --dig() mineVein(isOre) end end function inspectPotentialBlockData(inspect, doSomethingWithBlockData) local hasBlock, data = inspect() if hasBlock then print(data.name) return doSomethingWithBlockData(data) end end function doSomethingOnTunnelSides(doSomethingInDirection) doSomethingInDirection("up") turtle.turnLeft() doSomethingInDirection("forward") turtle.down() doSomethingInDirection("forward") turtle.turnRight() doSomethingInDirection("down") turtle.turnRight() doSomethingInDirection("forward") turtle.up() doSomethingInDirection("forward") turtle.turnLeft() end function mineTunnelSidesIfOre() doSomethingOnTunnelSides(mineIfOre) end function branch(direction) turn(direction) for i = 1,branchDepth do tunnel() end --turtle.dig() turtle.turnLeft() turtle.turnLeft() for i = 1,branchDepth do turtle.forward() end turn(direction) end function symmetricBranchPair() keepFueled() for n = 0,branchDistance do tunnel() end branch("left") branch("right") end -- Go to chest, put mined blocks in one and pick up fuel from the other function exchangeItems() turtle.forward() turtle.down() --chestLeft = peripheral.find("minecraft:chest") turtle.turnLeft() --chestRight = peripheral.find("minecraft:chest") for n = 1,16 do turtle.select(n) slotItem = turtle.getItemDetail(n) if slotItem ~= nil then if endsWith(slotItem.name, "coal") then turtle.turnRight() turtle.turnRight() turtle.drop() turtle.turnLeft() turtle.turnLeft() else turtle.drop() end end end turtle.select(1) turtle.turnRight() turtle.turnRight() turtle.suck() turtle.turnRight() turtle.up() turtle.forward() end function moveAlongBranches(branches) for n = 1,(branches * (branchDistance + 1)) do turtle.forward() end end for n = 1,symmetricBranches do symmetricBranchPair() if turtle.getItemCount(15) ~= 0 then turtle.turnLeft() turtle.turnLeft() moveAlongBranches(n) exchangeItems() moveAlongBranches(n) end end -- return turtle to starting point turtle.turnLeft() turtle.turnLeft() moveAlongBranches(symmetricBranches) print("stripmining operation complete")