Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local options = {
- startBlock = "minecraft:spruce_planks",
- wingFreq = 4,
- wingLength = 10,
- wantedOre = {
- "minecraft:coal_ore",
- "minecraft:deepslate_coal_ore",
- "minecraft:iron_ore",
- "minecraft:deepslate_iron_ore",
- "minecraft:copper_ore",
- "minecraft:deepslate_copper_ore",
- "minecraft:gold_ore",
- "minecraft:deepslate_gold_ore",
- "minecraft:redstone_ore",
- "minecraft:deepslate_redstone_ore",
- "minecraft:emeral_ore",
- "minecraft:deepslate_emerald_ore",
- "minecraft:lapis_ore",
- "minecraft:deepslate_lapis_ore",
- "minecraft:diamond_ore",
- "minecraft:deepslate_diamond_ore",
- },
- fuelMin = 100,
- }
- local side
- local current = -1
- local t = turtle
- local function compare(wanted, found)
- for i = 1, #wanted do
- if found == wanted[i] then
- return true
- end
- end
- return false
- end
- local function detect(dir)
- if dir == "forward" then
- return t.detect()
- elseif dir == "down" then
- return t.detectDown()
- elseif dir == "up" then
- return t.detectUp()
- end
- end
- local function inspect(dir)
- local success, data
- if dir == "forward" then
- success, data = t.inspect()
- elseif dir == "down" then
- success, data = t.inspectDown()
- elseif dir == "up" then
- success, data = t.inspectUp()
- end
- return success, data
- end
- local function dig(dir)
- if dir == "forward" then
- t.dig()
- elseif dir == "down" then
- t.digDown()
- elseif dir == "up" then
- t.digUp()
- end
- end
- local function move(dir)
- if dir == "forward" then
- t.forward()
- elseif dir == "down" then
- t.down()
- elseif dir == "up" then
- t.up()
- elseif dir == "back" then
- t.back()
- end
- end
- local function detectTurtle(dir)
- local success, data = inspect(dir)
- if success and data.name == "computercraft:turtle_advanced" then
- return true
- end
- return false
- end
- local function mineMove(dir)
- local dug = false
- while detect(dir) do
- if not detectTurtle(dir) then
- dig(dir)
- dug = true
- else
- sleep(2)
- end
- end
- move(dir)
- return dug
- end
- local function refuel()
- print("refueling...")
- for i=1,16,1 do
- t.select(i)
- t.refuel(t.getItemCount(i))
- end
- t.select(1)
- print("fuel level: "..t.getFuelLevel())
- end
- local function detectOre()
- local opposites = {
- ["forward"] = "back",
- ["back"] = "forward",
- ["up"] = "down",
- ["down"] = "up",
- }
- local function func(dir)
- local success, data = inspect(dir)
- if success and compare(options.wantedOre, data.name) then
- print("found " .. data.name)
- mineMove(dir)
- detectOre()
- mineMove(opposites[dir])
- end
- end
- func("up")
- func("down")
- for _=1,4,1 do
- func("forward")
- t.turnRight()
- end
- end
- local function sideShaft()
- for _=1,options.wingLength,1 do
- mineMove("forward")
- detectOre()
- end
- mineMove("up")
- mineMove("up")
- mineMove("up")
- t.turnLeft()
- t.turnLeft()
- for _=1,options.wingLength,1 do
- detectOre()
- mineMove("forward")
- end
- mineMove("down")
- mineMove("down")
- mineMove("down")
- t.turnLeft()
- t.turnLeft()
- end
- local function mainShaft()
- if t.getFuelLevel() < options.fuelMin then
- refuel()
- end
- while t.detectUp() do
- t.digUp()
- end
- if current == -1 then
- while not t.detect() do
- local success, data = inspect("down")
- if success and data.name == options.startBlock then
- break
- end
- t.forward()
- end
- current = 1
- t.turnLeft()
- t.turnLeft()
- elseif current <= options.wingFreq then
- current = current + 1
- mineMove("forward")
- else
- current = 1
- if side == "left" then t.turnLeft()
- elseif side == "right" then t.turnRight()
- end
- if t.detect() then
- sideShaft()
- end
- if side == "left" then t.turnRight()
- elseif side == "right" then t.turnLeft()
- end
- end
- end
- local function main()
- -- TODO: check fuel levels
- -- TODO: check inventory space
- mainShaft()
- end
- local function init()
- print("BRANCH MINING MK2")
- print("shaft frequency: "..options.wingFreq)
- print("shaft length: "..options.wingLength)
- refuel()
- t.turnLeft()
- if t.detect() then side = "left" end -- TODO: filter out torches and turtles
- t.turnLeft()
- t.turnLeft()
- if t.detect() then side = "right" end
- t.turnRight()
- print("side: "..side)
- if side ~= nil then
- while true do
- main()
- end
- end
- end
- init()
- -- i hate lua
Add Comment
Please, Sign In to add comment