Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --recursive digging
- -- usage: recdig <mode> [list]
- local sides = { "top", "front", "bottom", "left", "right", "back" }
- local targs = { ... }
- --local mode = "any" -- dig any block detected
- --local mode = "white" -- takes a whitelist of blocks in form of inventory slots
- --local mode = "black" -- takes a blacklist of blocks in form of inventory slots
- local mode = ""
- local list = {}
- function checkInput()
- local valid = true
- if #targs == 0 then
- valid = false
- end
- if #targs == 1 and targs[1] ~= "any" then
- valid = false
- end
- if #targs > 1 then
- if targs[1] ~= "white" and targs[1] ~= "black" then
- valid = false
- end
- for i = 2,#targs do
- if tonumber(targs[i]) < 1 or tonumber(targs[i]) > 16 then
- valid = false
- end
- end
- end
- if not valid then
- print("usage: recdig <mode> [list]")
- print("modes: any, white, black")
- print("list: list of slots used for black- or white-listing")
- end
- return valid
- end
- function turnAround()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function checkSides()
- sleep(0.25)
- for s = 1,#sides do
- print("checking "..sides[s])
- checkSide(sides[s])
- end
- end
- function wantThis(mode, side) -- returns true or false depending on whether the block we're checking is one we want
- if mode == "any" then
- if side == "up" then
- return turtle.detectUp()
- elseif side == "down" then
- return turtle.detectDown()
- elseif side == "front" then
- return turtle.detect()
- end
- elseif mode == "white" then
- local ret = false
- for l = 1,#list do
- turtle.select(l)
- if side == "up" then
- if turtle.compareUp() then
- ret = true
- end
- elseif side == "down" then
- if turtle.compareDown() then
- ret = true
- end
- elseif side == "front" then
- if turtle.compare() then
- ret = true
- end
- end
- end
- return ret
- elseif mode == "black" then
- local ret = true
- for l = 1,#list do
- turtle.select(l)
- if side == "up" then
- if turtle.compareUp() or not turtle.detectUp() then
- ret = false
- end
- elseif side == "down" then
- if turtle.compareDown() or not turtle.detectDown() then
- ret = false
- end
- elseif side == "front" then
- if turtle.compare() or not turtle.detect() then
- ret = false
- end
- end
- end
- return ret
- end
- end
- function checkSide(side)
- if side == "top" then
- if wantThis(mode, "up") then
- print("block above detected")
- while not turtle.up() do
- if not turtle.digUp() then
- turtle.attackUp()
- end
- end
- checkSides()
- while not turtle.down() do
- turtle.attackDown()
- end
- end
- elseif side == "front" then
- if wantThis(mode, "front") then
- print("blcok in front detected")
- while not turtle.forward() do
- if not turtle.dig() then
- turtle.attack()
- end
- end
- checkSides()
- turnAround()
- while not turtle.forward() do
- turtle.attack()
- end
- turnAround()
- end
- elseif side == "bottom" then
- if wantThis(mode, "down") then
- print("block below detected")
- while not turtle.down() do
- if not turtle.digDown() then
- turtle.attackDown()
- end
- end
- checkSides()
- while not turtle.up() do
- turtle.attackUp()
- end
- end
- elseif side == "left" then
- turtle.turnLeft()
- if wantThis(mode, "front") then
- print("block left detected")
- while not turtle.forward() do
- if not turtle.dig() then
- turtle.attack()
- end
- end
- checkSides()
- turnAround()
- while not turtle.forward() do
- turtle.attack()
- end
- turnAround()
- end
- turtle.turnRight()
- elseif side == "right" then
- turtle.turnRight()
- if wantThis(mode, "front") then
- print("block right detected")
- while not turtle.forward() do
- if not turtle.dig() then
- turtle.attack()
- end
- end
- checkSides()
- turnAround()
- while not turtle.forward() do
- turtle.attack()
- end
- turnAround()
- end
- turtle.turnLeft()
- elseif side == "back" then
- turnAround()
- if wantThis(mode, "front") then
- print("block behind detected")
- while not turtle.forward() do
- if not turtle.dig() then
- turtle.attack()
- end
- end
- checkSides()
- turnAround()
- while not turtle.forward() do
- turtle.attack()
- end
- turnAround()
- end
- turnAround()
- end
- end
- if checkInput() then
- mode = targs[1]
- if #targs > 1 then
- for i = 2,#targs do
- list[i-1] = targs[i]
- end
- end
- if mode == "any" then
- print("Ready to start recursive mining in any-mode. I will mine all blocks I can reach until I run out of blocks or fuel.")
- elseif mode == "black" then
- print("Ready to start recursive mining in "..mode.."-list mode. I will mine all blocks not on the supplied list")
- elseif mode == "white" then
- print("Ready to start recursive mining in "..mode.."-list mode. I will mine all blocks on the supplied list")
- end
- print("ready to start? y/n")
- local yesno = read()
- if yesno ~= "y" then
- exit()
- else
- checkSides()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment