--list of all ores or blocks we want to mine-- local ores = {"minecraft:iron_ore", "minecraft:diamond_ore", "minecraft:coal_ore", "minecraft:gold_ore", "minecraft:emerald_ore", "minecraft:restone_ore"} --stuff to throw away-- local garbage = {"minecraft:dirt", "minecraft:cobblestone", "minecraft:gravel", "minecraft:sand", "minecraft:granite", "minecraft:andesite", "minecraft:diorite"} --if below this number it will use coal to refuel-- local refill = 1000 local tArgs = {...} local tunnelLength = 0 --set tunnels length-- if tonumber(tArgs[1]) > 0 then tunnelLength = tonumber(tArgs[1]) else tunnelLength = 50 end local fuelLevel = turtle.getFuelLevel() local fuelFormula = math.ceil((tunnelLength*4)+(tunnelLength*0.45)+100) --test fuel level. If good ask if ready-- if fuelLevel < fuelFormula then error("[Fuel Required]: " .. fuelFormula - fuelLevel) end --this function checks the block and gives info-- function inspect(side) local worked, data = false, {} if not side then worked, data = turtle.inspect() elseif side == 1 then worked, data = turtle.inspectUp() elseif side == 2 then worked, data = turtle.inspectDown() end if worked then for i=1,#ores do if data.name == ores[i] then return data.name end end return false end end --all movement functions. Makes it look better-- function forward() repeat turtle.dig() until turtle.forward() return true end function back() if not turtle.back() then turtle.turnRight() turtle.turnRight() repeat turtle.dig() until turtle.forward() turtle.turnLeft() turtle.turnLeft() end return true end function up() repeat turtle.digUp() until turtle.up() return true end function down() repeat turtle.digDown() until turtle.down() return true end --this is what does all the looking for ores around the turtle. Recursive function-- function scan( nTry ) if not nTry then nTry = 1 elseif nTry > 180 then return end --check to the right-- turtle.turnRight() if inspect() then forward() scan(nTry+1) back() end turtle.turnLeft() --check to the left-- turtle.turnLeft() if inspect() then forward() scan(nTry+1) back() end turtle.turnRight() --check in front-- if inspect() then forward() scan(nTry+1) back() end --check up-- if inspect(1) then up() scan(nTry+1) down() end --check down-- if inspect(2) then down() scan(nTry+1) up() end end --cleans out and reorganizes the inventory-- function purgeInv() for i=1,16 do if turtle.getItemCount(i) > 0 then local data = turtle.getItemDetail(i) if turtle.getItemCount(i) < 64 then for j=i+1,16 do local d = turtle.getItemDetail(j) if d and d.name == data.name then turtle.select(j) turtle.transferTo(i) end end end for b=1,#garbage do if data.name == garbage[b] then turtle.select(i) turtle.drop() break elseif data.name == "minecraft:coal" then if turtle.getFuelLevel() < refill then turtle.refuel() break end end end end end end --this is the main function where all the other functions are called in order and makes it work-- function main() print("TUNNEL LENGTH: " .. tunnelLength) print("START [Y/N]") while true do local _,c = os.pullEvent("char") if c:lower() == "y" then --start mining-- for t=1,tunnelLength do forward() scan() up() scan() down() purgeInv() end turtle.turnRight() turtle.turnRight() --return trip-- for t=1, tunnelLength do forward() end return else error("You didn't press y") end end end --call the main function to start it all-- main()