Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tunnelLength = 100
- local cycles = 0
- local ENUM_ORES = {"ore", "uranium","coal", "iron", "copper", "silver", "ruby", "tin", "redstone", "emerald", "diamond", "lapis", "gold", "yellorite", "sapphire", "ruby", "galena"}
- function work()
- while true do
- subIterator = 1
- while subIterator <= tunnelLength do
- if turtle.getFuelLevel() < 150 then
- detail = turtle.getItemDetail(1)
- detail = detail or {}
- if detail.name ~= "minecraft:coal" then
- print("We're out of fuel :(")
- os.sleep(10)
- end
- turtle.select(1)
- turtle.refuel(1)
- end
- if subIterator % 15 == 0 then
- turtle.back()
- turtle.select(2)
- turtle.placeDown()
- for k=2,16 do
- itemDetail = turtle.getItemDetail(k)
- if itemDetail ~= nil then
- if not isAnOre(itemDetail) then
- turtle.select(k)
- turtle.drop()
- elseif itemDetail.name == "minecraft:coal" then
- turtle.select(k)
- turtle.transferTo(1)
- end
- end
- end
- end
- forward(1)
- while followVein() do end
- up(1)
- while followVein() do end
- down(1)
- down(1)
- while followVein() do end
- up(1)
- subIterator = subIterator + 1
- end
- turtle.turnLeft()
- turtle.turnLeft()
- forward(tunnelLength)
- if cycles > 0 then
- turtle.turnLeft()
- forward((cycles * 2)+1)
- turtle.turnRight()
- end
- success,blockData = turtle.inspect()
- if not success then return false end
- --if blockData.name ~= "minecraft:chest" then return false end
- for k=2,16 do
- itemDetail = turtle.getItemDetail(k)
- if itemDetail ~= nil then
- if isAnOre(itemDetail) then
- turtle.select(k)
- turtle.drop()
- elseif itemDetail.name == "minecraft:coal" then
- turtle.select(k)
- turtle.transferTo(1)
- end
- end
- end
- cycles = cycles + 1
- turtle.turnRight()
- for i=0,cycles*2 do
- forward(1)
- digUp(1)
- digDown(1)
- end
- turtle.turnRight()
- end
- end
- instructions = {}
- function followVein()
- instructions = {}
- lastFound = 0
- oresFound = 0
- while true do
- if isBlockAnOre(turtle.inspect()) then
- forward(1)
- insertIntoTable("fwd")
- lastFound = 0
- oresFound = oresFound + 1
- elseif isBlockAnOre(turtle.inspectUp()) then
- up(1)
- insertIntoTable("up")
- lastFound = 0
- oresFound = oresFound + 1
- elseif isBlockAnOre(turtle.inspectDown()) then
- down(1)
- insertIntoTable("down")
- lastFound = 0
- oresFound = oresFound + 1
- else
- lastFound = lastFound + 1
- if lastFound == 1 then
- turtle.turnLeft()
- insertIntoTable("tl")
- elseif lastFound == 2 then
- turtle.turnRight()
- turtle.turnRight()
- insertIntoTable("tr")
- insertIntoTable("tr")
- else
- turtle.turnLeft()
- insertIntoTable("tl")
- break
- end
- end
- end
- for k,v in pairs(instructions) do
- print("Print: ["..k.."] Backtracking: "..v)
- if v == "fwd" then
- turtle.back()
- elseif v == "up" then
- down(1)
- elseif v == "down" then
- up(1)
- elseif v == "tr" then
- turtle.turnLeft()
- elseif v == "tl" then
- turtle.turnRight()
- end
- end
- return oresFound > 0
- end
- function insertIntoTable(dataString)
- if table.getn(instructions) == 0 then
- table.insert(instructions, 1, dataString)
- return
- end
- lastInstruction = instructions[1]
- if lastInstruction ~= nil
- and (lastInstruction == "up" and dataString == "down"
- or lastInstruction == "down"and dataString == "up"
- or lastInstruction == "tl" and dataString == "tr"
- or lastInstruction == "tr" and dataString == "tl") then
- table.remove(instructions, 1)
- else
- table.insert(instructions, 1, dataString)
- end
- end
- function isBlockAnOre(success, data)
- if not success then return false end
- print("Testing"..data.name)
- name = string.lower(data.name)
- for k,v in pairs(ENUM_ORES) do
- if string.find(name, v) then
- return true
- end
- end
- end
- function isAnOre(data)
- name = string.lower(data.name)
- for k,v in pairs(ENUM_ORES) do
- if string.find(name, v) then
- return true
- end
- end
- end
- function down(amount)
- for i=1,amount do
- while not turtle.down() do
- digDown()
- end
- end
- end
- function up(amount)
- for i=1,amount do
- while not turtle.up() do
- digUp()
- end
- end
- end
- function forward(amount)
- for i=1,amount do
- while not turtle.forward() do
- dig()
- end
- end
- end
- function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- os.sleep(0.3)
- end
- end
- function digDown()
- while turtle.detectDown() do
- turtle.digDown()
- os.sleep(0.3)
- end
- end
- function dig()
- while turtle.detect() do
- turtle.dig()
- os.sleep(0.3)
- end
- end
- work()
Advertisement
Add Comment
Please, Sign In to add comment