Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local blacklist = {"minecraft:air","minecraft:leaves","minecraft:sand","minecraft:diorite","minecraft:andesite","minecraft:granite","minecraft:bedrock","minecraft:flowing_lava","minecraft:flowing_water","minecraft:lava","minecraft:water","minecraft:stone","minecraft:cobblestone","minecraft:dirt","minecraft:gravel","minecraft:clay","minecraft:torch","minecraft:soul_sand","minecraft:netherrack","minecraft:magma","minecraft:fire"}
- local superBlacklist = {"grass","snow","flower","computercraft","marble","limestone","chisel","quark","stone_bricks","plant"}
- local whitelist = {}
- local scanning = false
- local hasChest = (turtle.getItemCount(1) > 0 and turtle.getItemDetail(1).name == "enderstorage:ender_storage")
- turtle.select(hasChest and 2 or 1)
- if #({...}) == 1 and ({...})[1] == "nether" then
- table.insert(superBlacklist,"tconstruct")
- table.insert(superBlacklist,"tinker")
- elseif #({...}) > 0 then
- whitelist = {...}
- if ({...})[1] == "scan" then
- table.remove(whitelist,1)
- scanning = true
- end
- end
- local directions = {["north"]=1,["east"]=2,["south"]=3,["west"]=4}
- local directionStr = {"north","east","south","west"}
- local directionsVector = {{0,0,-1},{1,0,0},{0,0,1},{-1,0,0},{0,1,0},{0,-1,0}}
- local scanner = false
- local maxScan = 0
- term.clear()
- term.setCursorPos(1,1)
- print("Wii Turtle Miner Initialized")
- if peripheral.getType("right") == "plethora:scanner" then
- scanner = peripheral.wrap("right")
- elseif peripheral.getType("left") == "plethora:scanner" then
- scanner = peripheral.wrap("left")
- end
- if scanner then
- for i, v in pairs (scanner.scan()) do
- maxScan = math.max(v.x,maxScan)
- end
- print("Scanner found with radius "..maxScan)
- end
- print("Ender chest " ..(hasChest and "" or " not ").."present.")
- function selfScan(inScan)
- local test = math.floor(#inScan/2)
- if inScan[test].x == 0 and inScan[test].y == 0 and inScan[test].z == 0 then
- return inScan[test]
- else
- test = test + 1
- if inScan[test].x == 0 and inScan[test].y == 0 and inScan[test].z == 0 then
- return inScan[test]
- else
- for i, v in pairs(inScan) do
- if v.x == 0 and v.y == 0 and v.z == 0 then
- return v
- end
- end
- end
- end
- end
- function chestDump()
- if hasChest and turtle.getItemCount(16) > 0 then
- turtle.select(16)
- repeat until not turtle.digUp()
- turtle.select(1)
- turtle.placeUp()
- for i = 2, 16 do
- turtle.select(i)
- turtle.dropUp(64)
- end
- turtle.select(1)
- turtle.digUp()
- end
- end
- function compass(compassScan)
- local self = selfScan((compassScan ~= nil and compassScan or scanner.scan()))
- return self.state.facing
- end
- function setDir(targetDirections)
- local targetDirection = (type(targetDirections) == "string" and targetDirections or directionStr[targetDirections])
- local currentDirection = compass()
- local leftTurns = (directions[currentDirection] - directions[targetDirection]) % 4
- if leftTurns == 1 then
- turtle.turnLeft()
- elseif leftTurns == 2 then
- turtle.turnLeft() turtle.turnLeft()
- elseif leftTurns == 3 then
- turtle.turnRight()
- end
- end
- -- -x = west, x = east
- -- -z = north, z = south
- -- -y = down, y = up
- function getBlock(x,y,z,scanned)
- local width = (maxScan*2)+1
- local scan = scanned[width ^ 2 * (x + maxScan) + width * (y + maxScan) + (z + maxScan) + 1]
- --print(scan.name.." "..scan.x.." "..scan.y.." "..scan.z)
- return scan
- end
- function nav(x,y,z)
- local initialScan = scanner.scan()
- local initialDirection = compass(initialScan)
- local canDoXFirst = true
- local canDoZFirst = true
- for i = 1, math.abs(x) do
- if getBlock((x > 0 and i or -i), 0, 0, initialScan).name == "minecraft:bedrock" then
- canDoXFirst = false
- break
- end
- end
- for i = 1, math.abs(z) do
- if getBlock(x, 0, (z > 0 and i or -i), initialScan).name == "minecraft:bedrock" then
- canDoXFirst = false
- break
- end
- end
- if not canDoXFirst then
- for i = 1, math.abs(z) do
- if getBlock(0, 0, (z > 0 and i or -i), initialScan).name == "minecraft:bedrock" then
- canDoZFirst = false
- break
- end
- end
- for i = 1, math.abs(x) do
- if getBlock((x > 0 and i or -i), 0, z, initialScan).name == "minecraft:bedrock" then
- canDoZFirst = false
- break
- end
- end
- end
- if (not canDoXFirst) and (canDoZFirst) then
- if z < 0 then
- setDir("north")
- elseif z >= 1 then
- setDir("south")
- end
- for i = 1, math.abs(z) do
- rForward()
- mineOre()
- end
- if x < 0 then
- setDir("west")
- elseif x >= 1 then
- setDir("east")
- end
- for i = 1, math.abs(x) do
- rForward()
- mineOre()
- end
- if x < 0 then
- setDir("west")
- elseif x >= 1 then
- setDir("east")
- end
- for i = 1, math.abs(x) do
- rBack()
- end
- if z < 0 then
- setDir("north")
- elseif z >= 1 then
- setDir("south")
- end
- for i = 1, math.abs(z) do
- rBack()
- end
- elseif canDoXFirst then
- if x < 0 then
- setDir("west")
- elseif x >= 1 then
- setDir("east")
- end
- for i = 1, math.abs(x) do
- rForward()
- mineOre()
- end
- if z < 0 then
- setDir("north")
- elseif z >= 1 then
- setDir("south")
- end
- for i = 1, math.abs(z) do
- rForward()
- mineOre()
- end
- if z < 0 then
- setDir("north")
- elseif z >= 1 then
- setDir("south")
- end
- for i = 1, math.abs(z) do
- rBack()
- end
- if x < 0 then
- setDir("west")
- elseif x >= 1 then
- setDir("east")
- end
- for i = 1, math.abs(x) do
- rBack()
- end
- setDir(initialDirection)
- return true
- else
- print("Bedrock blocks "..x.." "..y.." "..z)
- return false
- end
- end
- function rBack()
- if not turtle.back() then
- turtle.turnLeft()
- turtle.turnLeft()
- if ({turtle.inspect()})[2].name == "minecraft:bedrock" then
- return false
- else
- repeat turtle.dig() until turtle.forward()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- return true
- end
- function rUp()
- if not turtle.up() then
- if ({turtle.inspectUp()})[2].name == "minecraft:bedrock" then
- return false
- else
- repeat turtle.digUp() until turtle.up()
- end
- end
- return true
- end
- function rDown()
- if not turtle.down() then
- if ({turtle.inspectDown()})[2].name == "minecraft:bedrock" then
- return false
- else
- repeat turtle.digDown() until turtle.down()
- end
- end
- return true
- end
- function rForward()
- if not turtle.forward() then
- if ({turtle.inspect()})[2].name == "minecraft:bedrock" then
- return false
- else
- repeat turtle.dig() until turtle.forward()
- end
- end
- return true
- end
- function check(things)
- local thing = (type(things) == "string" and {["name"] = things} or things)
- if thing ~= nil then
- if #whitelist > 0 then
- for i, v in pairs(whitelist) do
- if string.match(string.lower(thing.name),v) then
- return true
- end
- end
- else
- for i, v in pairs(blacklist) do
- if thing.name == v then
- return false
- end
- end
- for i, v in pairs(superBlacklist) do
- if string.match(string.lower(thing.name),v) then
- return false
- end
- end
- return true
- end
- end
- return false
- end
- function turtleRefillThing()
- if turtle.getFuelLevel() ~= "unlimited" then
- if turtle.getFuelLevel() < (turtle.getFuelLimit() / 5) then
- local nums = {}
- for p = 1, 16 do
- local o = turtle.getItemDetail(p)
- if o ~= nil then
- if o.name == "minecraft:coal" or o.name == "minecraft:planks" or o.name == "minecraft:fence" then
- table.insert(nums,p)
- end
- end
- end
- for o, p in pairs(nums) do
- turtle.select(p)
- local itemName = (turtle.getItemDetail(p))
- if itemName == nil then
- itemName = {}
- itemName["name"] = "EMPTY"
- end
- if check(itemName) == false then
- turtle.select(p)
- turtle.drop()
- turtle.dropDown()
- turtle.dropUp()
- end
- while turtle.getFuelLevel() < turtle.getFuelLimit() / 5 and turtle.getItemCount(turtle.getSelectedSlot()) > 0 and turtle.getItemDetail(turtle.getSelectedSlot()) ~= nil do
- turtle.refuel()
- end
- if turtle.getFuelLevel() >= turtle.getFuelLimit() / 5 then
- break
- end
- end
- else
- turtle.refuel()
- end
- end
- chestDump()
- turtle.select(hasChest and 2 or 1)
- end
- function clipDir(dir)
- return ((dir - 1) % 4) + 1
- end
- function scanSides(sideScan)
- local currentScan = (sideScan ~= nil and sideScan or scanner.scan())
- local currentDirection = compass(currentScan)
- --local directionsVector = {["north"] = {0,0,-1},["east"] = {1,0,0},["south"] = {0,0,1},["west"] = {-1,0,0},["up"] = {0,1,0},["down"] = {0,-1,0}}
- --local leftTurns = (directions[currentDirection] - directions[targetDirection]) % 4
- local turtleSides = {["left"] = directionsVector[clipDir(directions[currentDirection] - 1)],["front"] = directionsVector[directions[currentDirection]],["right"] = directionsVector[clipDir(directions[currentDirection] + 1)],["back"] = directionsVector[clipDir(directions[currentDirection] - 2)],["up"] = directionsVector[5], ["down"] = directionsVector[6]}
- local blankSides = {}
- for i, v in pairs(turtleSides) do
- local blankSideX, blankSideY, blankSideZ = unpack(v)
- blankSides[i] = getBlock(blankSideX,blankSideY,blankSideZ,currentScan)
- end
- return blankSides
- -- Left = -1, Front = 0, Right = 1, Back = 2
- end
- function turnMine()
- if scanner then
- local initD = compass()
- local sides = scanSides()
- if check(sides["front"]) or check(sides["up"]) or check(sides["down"]) then
- mineOre()
- sides = scanSides()
- end
- if check(sides["right"]) then
- turtle.turnRight()
- mineOre()
- sides = scanSides()
- end
- if check(sides["back"]) then
- setDir(clipDir(directions[initD] + 2))
- mineOre()
- sides = scanSides()
- end
- if check(sides["left"]) then
- setDir(clipDir(directions[initD] + 3))
- mineOre()
- sides = scanSides()
- end
- setDir(initD)
- else
- for i = 1, 4 do
- turtle.turnLeft()
- if i < 4 then
- mineOre()
- end
- end
- end
- end
- function vMult(tab, num)
- local tempTab = {}
- for i = 1, #tab do
- if type(tab[i]) == "number" then
- tempTab[i] = tab[i]*num
- else
- tempTab[i] = tab[i]
- end
- end
- end
- function mineOre()
- turtleRefillThing()
- local startDir = "north"
- local mineScan = {}
- if scanner then
- mineScan = scanner.scan()
- startDir = compass(mineScan)
- sides = scanSides(mineScan)
- if check(sides["front"]) then
- turtle.dig()
- local dX, dY, dZ = unpack(directionsVector[directions[startDir]])
- if check(getBlock(dX,-1,dZ,mineScan)) or check(getBlock(dX,1,dZ,mineScan)) or check(getBlock(dX, dY, dZ, mineScan)) then
- rForward()
- if (check(getBlock(dX,-1,dZ,mineScan))) then
- turtle.digDown()
- if needsSpins2(scanner.scan(),-1) then
- rDown()
- turnMine()
- rUp()
- end
- end
- if (check(getBlock(dX,1,dZ,mineScan))) then
- turtle.digUp()
- if needsSpins2(scanner.scan(),1) then
- rUp()
- turnMine()
- rDown()
- end
- end
- turnMine()
- rBack()
- end
- end
- else
- local work, inspect = turtle.inspect()
- if work then
- if check(inspect) then
- turtle.dig()
- rForward()
- turtle.turnLeft()
- for i = 1, 3 do
- local wo, ex = turtle.inspect()
- if wo and check(ex) and swood then
- mineOre()
- end
- local wo2, ex2 = turtle.inspectDown()
- if wo2 and check(ex2) then
- local meow = turtle.digDown()
- if meow then
- rDown()
- turnMine()
- rUp()
- end
- end
- local wo3, ex3 = turtle.inspectUp()
- if wo3 and check(ex3) then
- local meow = turtle.digUp()
- if meow then
- rUp()
- turnMine()
- rDown()
- end
- end
- if i < 3 then
- turtle.turnRight()
- end
- end
- turtle.turnLeft()
- end
- rBack()
- end
- local worku, inspectu = turtle.inspectUp()
- if worku then
- if check(inspectu) then
- turtle.digUp()
- rUp()
- turnMine()
- rDown()
- end
- end
- local workd, inspectd = turtle.inspectDown()
- if workd then
- if check(inspectd) then
- turtle.digDown()
- rDown()
- turnMine()
- rUp()
- end
- end
- end
- end
- function needsSpins(currentScanz,n,nAtScan)
- return (not scanner) or (scanner and (check(getBlock(1,(nAtScan - n),0,currentScanz)) or check(getBlock(-1,(nAtScan - n),0,currentScanz)) or check(getBlock(0,(nAtScan - n),1,currentScanz)) or check(getBlock(0,(nAtScan - n),-1,currentScanz))))
- end
- function needsSpins2(currentScanz,n)
- return check(getBlock(1,n,0,currentScanz)) or check(getBlock(-1,n,0,currentScanz)) or check(getBlock(0,n,1,currentScanz)) or check(getBlock(0,n,-1,currentScanz))
- end
- function mineLoop()
- turtleRefillThing()
- turtle.select(hasChest and 2 or 1)
- n = 0
- nAtScan = 0
- built = false
- done = false
- local currentScan = {}
- local firstDirection = "north"
- if scanner then
- firstDirection = compass()
- end
- while done == false do
- turtle.digDown()
- if (n == 0) then
- turtleRefillThing()
- rDown()
- n = n + 1
- end
- if scanner then
- local keepScanning = false
- repeat
- local currentScan = scanner.scan()
- nAtScan = n
- print("Scan at level "..n.." found "..(#currentScan).." blocks")
- local keepScanning2 = false
- for i = 1, #currentScan do
- if currentScan[i] and currentScan[i].name ~= nil then
- if currentScan[i].y == 0 and check(currentScan[i]) then
- print("Located "..currentScan[i].name.." at "..currentScan[i].x.." "..currentScan[i].y.." "..currentScan[i].z.." "..n.." "..nAtScan)
- turtleRefillThing()
- keepScanning2 = nav(currentScan[i].x,0,currentScan[i].z)
- break
- end
- end
- end
- if not keepScanning2 then
- keepScanning = true
- end
- until keepScanning
- end
- if needsSpins(currentScan,nAtScan,n) then
- for i = 1,4 do
- mineOre()
- if i < 4 then
- turtle.turnRight()
- end
- end
- end
- local hasBlock, block = turtle.inspectDown()
- if block.name == "minecraft:bedrock" then
- print("Hit bottom, returning.")
- for i = 1,n do
- turtleRefillThing()
- rUp()
- end
- if scanner then
- setDir(firstDirection)
- else
- if n == 1 then
- turtle.turnRight()
- elseif n == 2 then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif n == 3 then
- turtle.turnLeft()
- end
- end
- turtle.select(hasChest and 2 or 1)
- turtle.placeDown()
- done = true
- print("Done.")
- else
- n = n + 1
- turtleRefillThing()
- rDown()
- end
- end
- end
- function scan()
- turtle.select(hasChest and 2 or 1)
- if scanner then
- local items = {}
- local n = 0
- local currentScan = {}
- repeat
- if (n % maxScan) == 0 then
- currentScan = scanner.scan()
- for i = 1, #currentScan do
- if check(currentScan[i]) then
- if items[currentScan[i].name] == nil then
- items[currentScan[i].name] = 1
- else
- items[currentScan[i].name] = items[currentScan[i].name] + 1
- end
- end
- end
- end
- n = n + 1
- until not rDown()
- for i = 1, n - 1 do
- rUp()
- end
- turtle.placeDown()
- for i, v in pairs(items) do
- print("Found "..v.." of "..i)
- os.pullEvent("key")
- end
- else
- print("Scanner not found.")
- end
- end
- if scanning then scan() else mineLoop() end
- chestDump()
Add Comment
Please, Sign In to add comment