Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("movement")
- miner = {}
- miner.blacklist = {
- "minecraft:stone",
- "minecraft:dirt",
- "minecraft:diorite",
- "minecraft:andesite",
- "minecraft:granite",
- "minecraft:gravel",
- "minecraft:deepslate"
- }
- miner.logCoords = {}
- miner.logCoords.x = {}
- miner.logCoords.y = {}
- miner.logCoords.z = {}
- miner.logCoords.orient = {}
- miner.parseArgs = function()
- term.clear()
- term.setCursorPos(1, 1)
- print("Welcome to turtle miner, please input Y level of quarry.")
- miner.yLevelArg = read()
- print("Now please input the current Y level of turtle.")
- miner.curYLevelArg = read()
- print("Commencing mining..")
- end
- miner.checkStraight = function()
- local self = false
- for i,v in pairs(miner.blacklist) do
- success, tablee = turtle.inspect()
- if tablee.name == v then
- self = false
- else
- self = true
- end
- end
- return self
- end
- miner.checkUp = function()
- local self = false
- for i,v in pairs(miner.blacklist) do
- success, tablee = turtle.inspectUp()
- if tablee.name == v then
- self = false
- else
- self = true
- end
- end
- return self
- end
- miner.checkDown = function()
- local self = false
- for i,v in pairs(miner.blacklist) do
- success, tablee = turtle.inspectDown()
- if tablee.name == v then
- self = false
- else
- self = true
- end
- end
- return self
- end
- miner.spinCheck = function()
- local self
- for i= 1,4 do
- movement.turnRight()
- if miner.checkStraight() == true then
- self = true
- else
- self = false
- end
- end
- return self
- end
- miner.fullCheck = function()
- local self
- if miner.checkStraight() == false then
- if miner.checkUp() == false then
- if miner.checkDown() == false then
- if miner.spinCheck == false then
- self = false
- else
- self = movement.orientation
- end
- else
- self = "down"
- end
- else
- self = "up"
- end
- else
- self = movement.orientation
- end
- return self
- end
- miner.mineOre = function()
- local mineOre = false
- local allOrient = {
- "north",
- "south",
- "east",
- "west",
- "up",
- "down"}
- for i,v in pairs(allOrient) do
- if v == miner.fullCheck() then
- if v == "up" then
- turtle.digUp()
- movement.up()
- table.insert(miner.logCoords.x, movement.curXPos)
- table.insert(miner.logCoords.y, movement.curYPos)
- table.insert(miner.logCoords.z, movement.curZPos)
- table.insert(miner.logCoords.z, movement.orientation)
- mineOre = true
- elseif v == "down" then
- turtle.digDown()
- movement.down()
- table.insert(miner.logCoords.x, movement.curXPos)
- table.insert(miner.logCoords.y, movement.curYPos)
- table.insert(miner.logCoords.z, movement.curZPos)
- table.insert(miner.logCoords.z, movement.orientation)
- mineOre = true
- else
- turtle.dig()
- movement.forward()
- table.insert(miner.logCoords.x, movement.curXPos)
- table.insert(miner.logCoords.y, movement.curYPos)
- table.insert(miner.logCoords.z, movement.curZPos)
- table.insert(miner.logCoords.z, movement.orientation)
- mineOre = true
- end
- else
- mineOre = false
- end
- end
- return mineOre
- end
- miner.veinMine = function()
- local repeatBoolean = false
- repeat
- if miner.mineOre() == true then
- repeat
- sleep()
- until miner.mineOre() == false
- repeatBoolean = true
- end
- if repeatBoolean == true then
- local tArgs = #miner.logCoords.x
- while repeatBoolean == true do
- movement.goToCoords(miner.logCoords.x[tArgs], miner.logCoords.y[tArgs], miner.logCoords.z[tArgs], miner.logCoords.orient)
- tArgs = tArgs - 1
- if miner.mineOre() == false and tArgs == 1 then
- repeatBoolean = false
- end
- end
- end
- until repeatBoolean == false
- newTArgs = #miner.logCoords.x
- for i= newTArgs, 1, -1 do
- table.remove(miner.logCoords.x, i)
- table.remove(miner.logCoords.y, i)
- table.remove(miner.logCoords.z, i)
- table.remove(miner.logCoords.orient, i)
- end
- end
- miner.goToY = function()
- local changeInY = math.abs(miner.yLevelArg - miner.curYLevelArg)
- for i=1, changeInY do
- turtle.digDown()
- movement.down()
- end
- end
- miner.refuel = function()
- local savedPos = {}
- savedPos.x = movement.curXPos
- savedPos.y = movement.curYPos
- savedPos.z = movement.curZPos
- savedPos.orient = movement.orientation
- local smartFuel = turtle.getFuelLevel()
- local smartFuelMovement = math.abs(movement.curXPos) + math.abs(movement.curYPos) + math.abs(movement.curZPos)
- if smartFuel + 50 < smartFuelMovement then
- if turtle.getItemCount(16) ~= 0 then
- turtle.select(16)
- turtle.refuel()
- turtle.select(1)
- else
- movement.goHome()
- movement.faceDirection("south")
- turtle.up()
- turtle.select(16)
- if turtle.suck(32) == false then
- print("Out of fuel, please add fuel to my 16th slot or the chest.")
- repeat
- sleep(1)
- until turtle.suck(32) and turtle.refuel() == true or turtle.refuel() == true
- end
- turtle.select(1)
- movement.goToCoords(savedPos.x, savedPos.y, savedPos.z, savedPos.orient, "z", "x", "y")
- end
- end
- end
- miner.empty = function()
- local savedPos = {}
- savedPos.x = movement.curXPos
- savedPos.y = movement.curYPos
- savedPos.z = movement.curZPos
- savedPos.orient = movement.orientation
- local garbageAmount = 0
- for i=1,15 do
- garbageAmount = garbageAmount + turtle.getItemCount(i)
- end
- if garbageAmount == 960 then
- movement.goHome()
- movement.faceDirection("south")
- for i=1,15 do
- turtle.select(i)
- if turtle.drop() == false then
- print("Inventory full, please make room.")
- repeat
- sleep(1)
- until turtle.drop() == true
- end
- end
- turtle.select(1)
- movement.goToCoords(savedPos.x, savedPos.y, savedPos.z, savedPos.orient, "z", "x", "y")
- end
- end
- miner.mineForward = function()
- miner.refuel()
- miner.empty()
- print("VeinMine status: "..miner.veinMine())
- turtle.dig()
- self = movement.forward()
- return self
- end
- miner.mine = function()
- local amount = 1
- miner.goToY()
- while true do
- for i=1, amount do
- miner.mineForward()
- end
- movement.turnRight()
- for i=1, amount do
- miner.mineForward()
- end
- amount = amount+1
- movement.turnRight()
- for i=1, amount do
- miner.mineForward()
- end
- movement.turnRight()
- for i=1,amount do
- movement.forward()
- end
- movement.turnRight()
- amount = amount + 1
- end
- end
- miner.startFuel = function()
- if turtle.getFuelLevel() == 0 then
- turtle.select(16)
- if turtle.refuel() == false then
- print("Oops!, You forgot to input fuel into the 16th slot.")
- repeat
- sleep(1)
- until turtle.refuel() == true
- end
- turtle.select(1)
- end
- end
- miner.startFuel()
- miner.parseArgs()
- miner.mine()
Add Comment
Please, Sign In to add comment