Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- https://i.imgur.com/WCia4xK.png (Basic setup)
- -- Auto refules during operations
- -- Auto storage and sorting (ores go in ore container, stones and misc goes in stone container)
- -- Auto "repairs damage done to environment"
- -- If desiered you can add other items to be filtered in the "detectDirt" method, ex included.
- -- Set and forget, easy to use.
- -- to Do: make 2 commands, one for Mining and one for Filling,
- -- Currently executes mining operations. When mining has concluded, it will
- -- restock on fule and comence "repairing damage to the environment" by
- -- refilling the mined area with stone and other materials.
- print("+-------------------------------------+")
- print("| MinerTurtle 1.0, by Jiron |")
- print("+-------------------------------------+")
- print("| Farm set-up: Place down 3 chests |")
- print("| place the mining turtle on the |")
- print("| chest to the left and facing chest. |")
- print("| Put fuel in the right chest. |")
- print("| Overflow chest can be placed unless |")
- print("| you have no needed of it. |")
- print("| Put some fuel in the turtle and |")
- print("| lets define the size of the mine. |")
- print("+-------------------------------------+")
- print("Press enter to continue..")
- getready = io.read()
- print("+-------------------------------------+")
- print("+----------------Setup----------------+")
- print("| O = overflow C = chest T = turtle |")
- print("| ^ Mine Area ^ |")
- print("| O T |")
- print("| C C C |")
- print("| L M R |")
- print("| note: O is placed 1 block above T |")
- print("| Remember: Turtle should be facing |")
- print("| the chest. |")
- print("+-------------------------------------+")
- print("Press enter to continue..")
- print("https://i.imgur.com/WCia4xK.png")
- print("Shows the basic setup")
- print("The mine will be filled after if there")
- print("are materials in middel chest.")
- getsett = io.read()
- print("Width of the mine; in ODD numbers only!")
- re = io.read()
- width = tonumber(re)
- print("Length of mine?")
- rel = io.read()
- print("Start height? check y=Height")
- sh = io.read()
- startHeight = tonumber(sh)
- length = tonumber(rel)
- print("Farm size set to " .. length .. "x" .. width .. "x" .. startHeight)
- --print("Cycle time? in minutes")
- --redir = io.read()
- --Farm
- --waitTime = tonumber(redir * 60)
- tRight = false
- tLeft = true
- start = true
- turtleDepth = 0
- done = false
- flip = false
- gotItem = false
- flipTurtle = false
- banked = false
- function noFaithInUser(number)
- if (number % 2 == 0) then
- print("Error: Width is not odd in size!")
- return true
- end
- start = false
- return flase
- end
- function turnLeft()
- -- print("left")
- block()
- turtle.turnLeft()
- block()
- turtle.forward()
- block()
- turtle.turnLeft()
- tLeft = true
- tRight = false
- block()
- end
- function turnLeftFill()
- -- print("left")
- turtle.place()
- turtle.turnLeft()
- turtle.dig()
- stonePlaceDown()
- turtle.forward()
- turtle.turnLeft()
- turtle.dig()
- tLeft = true
- tRight = false
- stonePlaceDown()
- end
- function turnRight()
- --print("Right")
- block()
- turtle.turnRight()
- block()
- turtle.forward()
- block()
- turtle.turnRight()
- tRight = true
- tLeft = false
- block()
- end
- function turnRightFill()
- --print("Right")
- turtle.place()
- turtle.turnRight()
- turtle.dig()
- stonePlaceDown()
- turtle.forward()
- turtle.turnRight()
- turtle.dig()
- tRight = true
- tLeft = false
- stonePlaceDown()
- end
- function fallingBlock()
- local success, data = turtle.inspect()
- local fBlocks =
- {
- sand = "minecraft:sand",
- gravel = "minecraft:gravel",
- anvil = "minecraft:anvil",
- dragon_egg = "minecraft:dragon_egg"
- }
- if data.name == fBlocks.sand or data.name == fBlocks.gravel or data.name == fBlocks.anvil or data.name == fBlocks.dragon_egg then
- return true
- else
- return false
- end
- end
- function block()
- while fallingBlock() == true do
- turtle.dig()
- sleep(1)
- end
- if turtle.detect() == true then
- turtle.dig()
- turtle.suck()
- turtle.suckDown()
- end
- end
- function detectStone(s)
- local res = detectType(s, "stone")
- local res2 = detectType(s, "red")
- if res == "yes" and res2 == "no" then
- return "yes";
- else
- return "no"
- end
- end
- function detectDirt(s)
- local res = detectType(s, "dirt")
- local res2 = detectType(s, "gravel")
- local res3 = detectType(s, "sand")
- local res4 = detectType(s, "chisel")
- local res5 = detectType(s, "quark")
- --if you want to filter out use the blockname, above items are 'Minecraft:dirt', 'Minecraft:gravel' <- => itemname = gravel
- --local res6 = detectType(s,"itemname")
- if res == "yes" or res2 == "yes" or res3 == "yes" or res4 == "yes" or res5 == "yes" then
- return "yes";
- else
- return "no"
- end
- end
- function detectType(s, type)
- res = string.find(s .. "", type)
- if res ~= nil then
- return "yes";
- else
- return "no"
- end
- end
- function evenOrOdd(number)
- if number % 2 == 0 then
- return true
- else
- return false
- end
- end
- function digForward()
- while fallingBlock() == true do
- turtle.dig()
- sleep(1)
- end
- turtle.dig()
- turtle.suck()
- local t = turtle.forward()
- while t == false do
- turtle.dig()
- turtle.suck()
- t = turtle.forward()
- end
- end
- function digDown()
- turtle.digDown()
- turtle.suckDown()
- turtle.suck()
- turtle.down()
- end
- function goDown(hs)
- if hs > 1 then
- turtle.digDown()
- turtle.suckDown()
- turtle.down()
- hs = hs - 1
- goDown(hs)
- end
- end
- function move(length, first)-- MOVE
- if length >= 0 then
- digForward()
- length = length - 1
- --print("move")
- move(length, false)
- end
- end
- function checkSlotForStone()
- local suc, space = turtle.getItemSpace()
- if suc then
- local data = turtle.getItemDetail()
- if data then
- -- print(data.name)
- local name = data.name
- return detectStone(name)
- end
- else return "no"
- end
- end
- function checkSlotForDirt()
- local suc, space = turtle.getItemSpace()
- if suc then
- local data = turtle.getItemDetail()
- if data then
- -- print(data.name)
- local name = data.name
- return detectDirt(name)
- end
- else return "no"
- end
- end
- function refuel(f)
- for i = f, 16 do -- loop through the slots
- turtle.select(i)-- change to the slot
- if turtle.refuel(0) then -- if it's valid fuel
- turtle.refuel()-- consume half the stack as fuel
- end
- end
- turtle.select(1)
- end
- function refuelTurtle()
- turtle.forward()
- turtle.turnLeft()
- local suc, fuelLevel = turtle.getFuelLevel()
- if turtle.getFuelLevel() ~= "unlimited" then
- for i = 1, 16 do -- loop through the slots
- turtle.select(i)-- change to the slot
- turtle.suck()
- end
- end
- refuel(1)
- storeUnusedFuel(1)
- turtle.turnLeft()
- turtle.forward()
- turtle.forward()
- turtle.turnLeft()
- end
- function storeUnusedFuel(f)
- for i = f, 16 do -- loop through the slots
- turtle.select(i)-- change to the slot
- if turtle.refuel(0) then
- turtle.drop()
- end
- end
- turtle.select(1)
- end
- function storeOre()
- for i = 1, 16 do -- loop through the slots
- turtle.select(i)-- change to the slot
- local validFuelSorce = turtle.refuel(0)
- if checkSlotForStone() == "no" and checkSlotForDirt() == "no" and validFuelSorce == false then
- turtle.drop()
- end
- end
- turtle.select(1)
- end
- function storeCobbel()
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- for i = 1, 16 do -- loop through the slots
- turtle.select(i)-- change to the slot
- local validFuelSorce = turtle.refuel(0)
- local d1, d2 = false
- if checkSlotForStone() ~= "no" and validFuelSorce == false then
- d1 = turtle.drop()
- if d1 ~= true then
- turtle.dropUp()
- end
- end
- if checkSlotForDirt() ~= "no" and validFuelSorce == false then
- d2 = turtle.drop()
- if d2 ~= true then
- turtle.dropUp()
- end
- end
- end
- turtle.select(1)
- turtle.turnRight()
- end
- function fillCobbel()
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- for i = 2, 16 do -- loop through the slots
- turtle.select(i)-- change to the slot
- turtle.suck()
- end
- turtle.select(2)
- x = turtle.getItemCount()
- if x == 0 then
- print("OutOfMaterials")
- turtleDepth = -1
- banked = true
- -- stop it!
- end
- turtle.turnRight()
- gotItem = true
- end
- function stonePlaceDown()
- if gotItem then
- if turtle.getItemCount() > 0 then
- turtle.placeDown()
- else
- for i = 2, 16 do -- loop through the slots
- turtle.select(i)-- change to the slot
- item = turtle.getItemCount()
- if item > 0 then
- gotItem = true
- turtle.transferTo(2)
- turtle.select(2)
- turtle.placeDown()
- break
- end
- if i == 16 then
- gotItem = false
- end
- end
- end
- end
- end
- function moveFill(length)
- if length >= 0 then
- turtle.dig()
- stonePlaceDown()
- local t = turtle.forward()
- while t == false do
- turtle.dig()
- t = turtle.forward()
- end
- length = length - 1
- --print("move")
- moveFill(length)
- end
- end
- function minerStoreAndResupply(newWidth, miner, distance)
- print("Store&Resupply progress..")
- turtle.turnLeft()
- goUp(turtleDepth + 1)
- block()
- move(distance, false)
- turtle.turnLeft()
- block()
- move(length - 1, false)
- if miner == true then
- storeOre()
- storeCobbel()
- else
- fillCobbel()
- end
- refuelTurtle()
- turtle.select(2)
- move(length - 1, false)
- turtle.turnRight()
- move(distance, false)
- turtle.turnLeft()
- goDown(turtleDepth + 1)
- end
- function turtleFill()
- for newWidth = width, 1, -1 do
- if turtleDepth < 0 then
- break
- end
- flip = not flip
- if newWidth == width then
- moveFill(length - 1)
- else if newWidth < width and newWidth > 1 then
- moveFill(length - 1)
- else
- moveFill(length - 1)-- set to -1 for mirror setup
- end
- end
- turtle.select(2)
- --print(flip)
- local countItem = turtle.getItemCount()
- local number = 0
- if evenOrOdd(startHeight) == false then
- number = turtleDepth - 1
- else
- number = turtleDepth
- end
- if countItem < 1 and flip == true and gotItem == false then
- if evenOrOdd(number) == false then
- minerStoreAndResupply(newWidth, false, (width - newWidth) - 1)
- else
- minerStoreAndResupply(newWidth, false, (newWidth - 2))
- end
- end
- if turtle.getFuelLevel() < 6000 and flip == true then
- if evenOrOdd(number) == false then
- minerStoreAndResupply(newWidth, false, (width - newWidth) - 1)
- else
- minerStoreAndResupply(newWidth, false, (newWidth - 2))
- end
- end
- if newWidth > 1 then
- if tRight == false then
- turnRightFill()
- else
- turnLeftFill()
- end
- end
- if newWidth == 1 then
- return newWidth
- end
- end
- end
- function turtleRun()
- for newWidth = width, 1, -1 do
- flipTurtle = not flipTurtle
- -- print("Doin a run")
- if newWidth == width then
- move(length - 1, true)
- else if newWidth < width and newWidth > 1 then
- move(length - 1, false)
- else
- move(length - 1, false)-- set to -1 for mirror setup
- end
- end
- turtle.select(16)
- local countItem = turtle.getItemCount()
- local number = turtleDepth + 1
- if countItem > 0 and flipTurtle == true then
- if evenOrOdd(number) == false then
- minerStoreAndResupply(newWidth, true, (width - newWidth) - 1)
- else
- minerStoreAndResupply(newWidth, true, (newWidth - 2))
- end
- end
- if turtle.getFuelLevel() < 6000 and flipTurtle == true then
- if evenOrOdd(number) == false then
- minerStoreAndResupply(newWidth, true, (width - newWidth) - 1)
- else
- minerStoreAndResupply(newWidth, true, (newWidth - 2))
- end
- end
- turtle.select(1)
- if newWidth > 1 then
- if tRight == false then
- turnRight()
- else
- turnLeft()
- end
- end
- if newWidth == 1 then
- return newWidth
- end
- end
- end
- function moveHome(length)
- if length >= 0 then
- turtle.forward()
- length = length - 1
- moveHome(length)
- end
- end
- function returnToBegining()
- turtle.turnLeft()
- block()
- move(width - 2)
- turtle.turnLeft()
- block()
- move(length - 1)
- end
- function continueMiningOdd(h)
- block()
- moveHome(length - 1)
- turtle.turnRight()
- block()
- moveHome(width - 2)
- turtle.turnRight()
- backToMine(h - 1)
- end
- function continueMiningEven(h)
- backToMine(h - 1)
- end
- function backToMine(h)
- if h > 0 then
- turtle.down()
- h = h - 1
- backToMine(h)
- else
- digDown()
- end
- end
- function toSurface(h)
- if h > 1 then
- turtle.up()
- h = h - 1
- toSurface(h)
- else
- returnToBegining()
- storeOre()
- storeCobbel()
- refuelTurtle()
- if (turtleDepth < startHeight) then
- if evenOrOdd(turtleDepth) then
- continueMiningEven(turtleDepth)
- else
- continueMiningOdd(turtleDepth)
- end
- end
- end
- end
- function goingBank(h)
- if h > 1 then
- turtle.digUp()
- turtle.up()
- h = h - 1
- goingBank(h)
- else
- storeOre()
- storeCobbel()
- refuelTurtle()
- if (turtleDepth < startHeight) then
- if evenOrOdd(turtleDepth) then
- continueMiningEven(turtleDepth)
- else
- continueMiningOdd(turtleDepth)
- end
- end
- end
- end
- function goUp(h)
- if h > 1 then
- turtle.digUp()
- turtle.up()
- h = h - 1
- goUp(h)
- end
- end
- function returnToBase()
- turtle.turnLeft()
- turtle.turnLeft()
- if evenOrOdd(turtleDepth) then
- goingBank(turtleDepth + 1)
- else if evenOrOdd(turtleDepth) == false then
- toSurface(turtleDepth + 1)
- end
- end
- end
- function run()
- local state = turtleRun()
- if state == 1 and turtleDepth ~= (startHeight) then
- digDown()
- turtleDepth = turtleDepth + 1
- print(turtleDepth .. "down" .. startHeight)
- -- flipTurtle = not flipTurtle
- turtle.turnLeft()
- turtle.turnLeft()
- end
- end
- function runFill()
- local state2 = turtleFill()
- turtle.select(2)
- if state2 == 1 then
- turtle.digUp()
- turtle.up()
- turtleDepth = turtleDepth - 1
- print(turtleDepth .. "DF depth")
- turtle.turnLeft()
- turtle.turnLeft()
- end
- end
- function fill()
- turtle.turnLeft()
- turtle.turnLeft()
- fillCobbel()
- refuelTurtle()
- turtle.select(2)
- backToMine(turtleDepth - 2)
- --turtleDepth = turtleDepth - 1
- end
- while true do
- if start == true then
- if noFaithInUser(width) == true then
- break
- end
- startHeight = startHeight - 2
- refuel(1)
- storeCobbel()
- refuelTurtle()
- end
- while turtleDepth <= startHeight do
- if startHeight > turtleDepth then
- run()
- else
- break
- end
- end
- if done == false then
- returnToBase()
- done = true
- end
- done = true
- local fillStart = true
- if fillStart == true then
- fill()
- turtle.select(2)
- fillStart = false
- turtleDepth = turtleDepth - 1
- end
- while turtleDepth >= -1 and done == true do
- if turtleDepth > -1 then
- runFill()
- if (turtleDepth == -1) then
- break
- end
- else
- break
- end
- end
- if banked == false and flip == true then
- turtle.turnRight()
- block()
- move(width - 2)
- turtle.turnLeft()
- block()
- move(length - 1)
- end
- print("Hole dug! Hole frackein done.")
- sleep(10)
- break
- end
Add Comment
Please, Sign In to add comment