Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------
- -- A simple miner
- -- Note that it does not use fuel
- -- Copyright 2019 Fatboychummy
- ----------------------------------
- local tArgs = {...}
- --------------------
- --Arguments:
- --1: distance of overall stripmine
- --2: distance between each branch
- --3: how far each branch will dig sideways
- --4: nil
- -------------------
- local ores = {
- basic_block_core = {metas = {[7] = true,[8] = true}},
- resource = {metas = {[1] = true,[2] = true,[3] = true,[4] = true}},
- coal_ore = {metas = {[0] = true}},
- redstone_ore = {metas = {[0] = true}},
- iron_ore = {metas = {[0] = true}},
- gold_ore = {metas = {[0] = true}},
- lapis_ore = {metas = {[0] = true}},
- diamond_ore = {metas = {[0] = true}},
- emerald_ore = {metas = {[0] = true}},
- ore = {metas = {[0] = true, [1] = true, [2] = true, [3] = true, [4] = true, [5] = true}},
- ore_fluid = {metas = {[0] = true}},
- quartz_ore = {metas = {[0] = true}},
- ore_stonequartz = {metas = {[0] = true}},
- blockmetal = {metas = {[0] = true}}
- }
- --[[
- The purpose of the tort functions, is to ensure that the turtle
- go forward/down/up/back, instead of just failing to move.
- ]]
- local tort = {
- forward = function()
- local i = 0
- while not turtle.forward() do
- turtle.attack()
- turtle.dig()
- i = i + 1
- if i > 100 then
- return false
- end
- os.sleep(0.1)
- end
- return true
- end,
- back = function()
- local i = 0
- while not turtle.back() do
- turtle.turnRight()
- turtle.turnRight()
- turtle.attack()
- turtle.dig()
- turtle.turnRight()
- turtle.turnRight()
- i = i + 1
- if i > 100 then
- return false
- end
- os.sleep(0.1)
- end
- return true
- end,
- down = function()
- local i = 0
- while not turtle.down() do
- turtle.attackDown()
- turtle.digDown()
- i = i + 1
- if i > 100 then
- return false
- end
- os.sleep(0.1)
- end
- return true
- end,
- up = function()
- local i = 0
- while not turtle.up() do
- turtle.attackUp()
- turtle.digUp()
- i = i + 1
- if i > 100 then
- return false
- end
- os.sleep(0.1)
- end
- return true
- end
- }
- --Remove extra "minecraft:" from strings
- local function rExtra(str)
- return str:match(":(.+)")
- end
- --Check if a block is an ore.
- local function isOre(block)
- if type(block) ~= "table" then return false end
- local nm = rExtra(block.name) --Remove extra stuff, check if the block is in "ores"
- if ores[nm] then
- if ores[nm]["metas"] then --if it's indexed by metadata (fastest), then go here
- if ores[nm].metas[block.metadata] then --if the metadata is there, then it's an ore.
- return true
- end
- end
- end
- return false
- end
- --Recursively mine out veins of ores
- local function mineStuff(side)
- print(side and "ore " .. tostring(side) or "ore forward")
- --Check if a block should be mined, and if it should, do it.
- local function check(side)
- local fn = turtle.inspect
- if side == "up" then
- fn = turtle.inspectUp
- elseif side == "down" then
- fn = turtle.inspectDown
- end
- --Above:
- --Inspect whichever side is entered.
- if isOre(({fn()})[2]) then
- mineStuff(side)
- end
- --Mine whatever side is detected, if it is an ore.
- end
- local fn = turtle.dig
- local fn2 = tort.forward
- local fn3 = tort.back
- if side == "up" then
- fn = turtle.digUp
- fn2 = tort.up
- fn3 = tort.down
- elseif side == "down" then
- fn = turtle.digDown
- fn2 = tort.down
- fn3 = tort.up
- end
- -- Above: check what side the ore was detected on, and swap which functions to
- --run depending on the situation.
- fn()
- fn2()
- for i = 1,4 do check() turtle.turnRight() end
- check("up")
- check("down")
- fn3()
- --[[Above:
- at it's most basic:
- destroy ore
- move into space ore was at
- search if there's more ore around it
- go back to where we were before.
- ]]
- os.sleep()
- end
- --Dig stripmine
- local function dig(dist)
- assert(type(dist) == "number" and dist >= 1 and dist % 1 == 0,"Expected number, greater than 0, divisible by 1")
- for i = 1,dist do
- local ok,dat = turtle.inspect()
- local ok2,dat2 = turtle.inspectUp()
- local ok3,dat3 = turtle.inspectDown()
- --Detect stuff
- if ok then
- if isOre(dat) then
- mineStuff()
- end
- end
- if ok2 then
- if isOre(dat2) then
- mineStuff("up")
- end
- end
- if ok3 then
- if isOre(dat3) then
- mineStuff("down")
- end
- end
- --Above: if there is ore in front, above, or below, dig it
- turtle.dig()
- turtle.digUp()
- --Dig then dig up so as to make a 2x1 space to walk down
- --[[check2:
- basic:
- look at block to left, if ore, dig
- look at block to right, if ore, dig
- look at blocks above/below, if ore, dig
- go up one space, repeat the above once
- go back down, go forwards.
- ]]
- local function check2()
- turtle.turnLeft()
- if isOre(({turtle.inspect()})[2]) then
- mineStuff()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- if isOre(({turtle.inspect()})[2]) then
- mineStuff()
- end
- turtle.turnLeft()
- if isOre(({turtle.inspectUp()})[2]) then
- mineStuff("up")
- end
- if isOre(({turtle.inspectDown()})[2]) then
- mineStuff("down")
- end
- end
- check2()
- tort.up()
- check2()
- tort.down()
- tort.forward()
- end
- end
- local mxDist = tonumber(tArgs[1])
- local branchDist = tonumber(tArgs[2])
- local branchMxDist = tonumber(tArgs[3])
- local Nil = tArgs[4]
- assert(type(mxDist) == "number","Bad argument #1: Expected number, could not convert.")
- assert(type(branchDist) == "number","Bad argument #2: Expected number, could not convert.")
- assert(type(branchMxDist) == "number","Bad argument #3: Expected number, could not convert.")
- assert(type(Nil) == "nil","Bad argument #4: Expected nil, but got something. Why do you do this to me?")
- local branches = mxDist / branchDist
- dig(mxDist)
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1,branches do
- turtle.turnRight()
- dig(branchMxDist)
- turtle.turnRight()
- turtle.turnRight()
- for o = 1,branchMxDist do
- tort.forward()
- end
- dig(branchMxDist)
- turtle.turnRight()
- turtle.turnRight()
- for o = 1,branchMxDist do
- tort.forward()
- end
- turtle.turnLeft()
- for o = 1,branchDist do
- tort.forward()
- end
- end
Add Comment
Please, Sign In to add comment