hyprunz icon

Digger Tunnel Turtle for Minecraft

hyprunz | PRO | 05/13/15 05:59:55 PM UTC | 0 ⭐ | 344 👁️ | Never ⏰ | []
Lua |

5.36 KB

|

None

|

0 👍

/

0 👎

--Own Tunnel Turtle same size 2X3 but with feature bring items in chest, set torches and refill the border with cobble stone
 
length = 100
torchPl = 5
torchCounter = 0
layerCounter = 0
 
function layerDig()     
    leftLayer()
    refillCopple()
    rightLayer()
    refillCopple()
    checkItemsAndGoEmpty()
        
end
 
function leftLayer()
    Dig()
    ForwardDown()
    checkLeftBorder()
    DigUp()
    MoveUppest()
    checkFrontBorder()
    turn180()
    Dig()
    ForwardUp()
    DigDown()
    MoveLowest()
    Dig()
    ForwardDown()
    checkFrontBorder()
    DigUp()
    MoveUppest()
    checkFrontBorder()
    layerCounter = layerCounter + 1
    placeTorch()
    turtle.turnLeft()
end
 
function rightLayer()
    Dig()
    ForwardUp()
    checkRightBorder()
    DigDown()
    MoveLowest()
    checkFrontBorder()
    turn180()
    Dig()
    ForwardDown()
    DigUp()
    MoveUppest()
    Dig()
    ForwardUp()
    checkFrontBorder()
    placeTorch()
    DigDown()
    MoveLowest()
    checkFrontBorder()
    layerCounter = layerCounter + 1
    turtle.turnRight()
end
 
function Dig()
    while turtle.detect() do
        turtle.dig()
        sleep(0.4)
    end
end
 
function DigUp()
    while turtle.detectUp() do
        turtle.digUp()
        sleep(0.4)
    end 
end
 
function DigDown()
    while turtle.detectDown() do
        turtle.digDown()
        sleep(0.4)
    end
end
 
function BackToChest()
    turn180()
    for i=1, layerCounter, 1 do
        Dig()
        turtle.forward()
    end
    Drop()
    turn180()
end
 
function BackToLayer()
    for i=1, layerCounter, 1 do
        Dig()
        turtle.forward()
    end
end
 
function Drop()
    for i=1, 14, 1 do
        turtle.select(i)
        turtle.drop(64)
    end
end
 
function ForwardDown()
    turtle.forward()
    if(turtle.detectDown() == false) then
        turtle.select(15)
        turtle.placeDown()
    end
end
 
function ForwardUp()
    turtle.forward()
    if(turtle.detectUp() == false) then
        turtle.select(15)
        turtle.placeUp()
    end
end
 
function MoveUppest()
    turtle.up()
    if(turtle.detectUp() == false) then
        turtle.select(15)
        turtle.placeUp()
    end
end
 
function MoveLowest()
    turtle.down()
    if(turtle.detectDown() == false) then
        turtle.select(15)
        turtle.placeDown()
    end
end
 
function turn180()
    turtle.turnLeft()
    turtle.turnLeft()
end
 
function checkLeftBorder()
    turtle.turnLeft()
    checkFrontBorder()
end
 
function checkRightBorder()
    turtle.turnRight()
    checkFrontBorder()
end
 
function checkFrontBorder()
    if(turtle.detect() == false) then
        turtle.select(15)
        turtle.place()
    end
end
 
function placeTorch()
    if(torchCounter == torchPl) then
        turn180()
        turtle.forward()
        turtle.select(16)
        turtle.place()
        torchCounter = 0
        turn180()
        turtle.forward()
    else
        torchCounter = torchCounter + 1
    end
end
 
function checkItemsAndGoEmpty()
    haveToEmpty = 1
    
    for i = 1, 14, 1 do
        if (turtle.getItemCount(i) == 0) then
            haveToEmpty = 0
        end
    end
    
    if (haveToEmpty == 1) then
        BackToChest()
        BackToLayer()
    end
end
 
function refillCopple()
    local cnt = turtle.getItemCount(15)
    if cnt < 8 then
        for i=1, 15, 1 do
            turtle.select(i)
            local comp = turtle.compareTo(16)
            if comp == true then
                turtle.transferTo(16)
            end
        end
    end
end
 
function start()
    local input = 1
    shell.run("clear")
    while input == 1 do
        term.setCursorPos(1,1)
        print("Menu:")
        print("=======================================")
        term.setCursorPos(1,3)
        term.clearLine()
        print("Length of the tunnel: "..length)
        term.clearLine()
        term.setCursorPos(1,5)
        term.clearLine()
        print("Enter [S] for start or [C] for change settings - [Q] quit:")
        term.clearLine()
        
        local inputstring = read()
        
        if inputstring == 'S' or inputstring == 's' then
            if checkStartConditions() == 1 then
                run()
            end
        elseif inputstring == 'C' or inputstring == 'c' then
            setting()
        elseif inputstring == 'Q' or inputstring == 'q' then
            input = 0
            shell.run("clear")
        else
            term.setCursorPos(1,10)
            term.clear()
            print("Invalid Input")
        end
    end
end
 
function checkStartConditions()
    term.setCursorPos(1,10)
    term.clear()
    local retValue = 1
    local torchCount = turtle.getItemCount(16)
    local cobbleCount = turtle.getItemCount(15)
    if torchCount == 0 then
        print("No torches found!")
        retValue = 0
    else
        print("Number of found torches: "..torchCount)
    end
    
    if cobbleCount == 0 then
        print("No cobble stone found!")
        retValue = 0
    else
        print("Number of found cobble stone: "..cobbleCount)
    end
    
    if retValue == 0 then
        print("Start conditions not correct - please fill torches in slot 16 and cobblestone in slot 15")
        return 0
    else
        return 1
    end
end
 
function setting()
    local setting = 1
    local invalidCounter = 0
    shell.run("clear")
    while setting == 1 do
        term.setCursorPos(1,1)
        print("Setting:")
        print("=======================================")
        term.setCursorPos(1,3)
        term.clearLine()
        print("Actual using tunnel length: "..length)
        term.setCursorPos(1,5)
        term.clearLine()
        print("Enter the new length of the tunnel:")
        local inputstring = read()
        
        if(tonumber(inputstring) ~= nil) then
            length = tonumber(inputstring)
            setting = 0
        else
            term.setCursorPos(1,10)
            term.clear()
            print("Invalid Input")
            invalidCounter = invalidCounter + 1
        end
        
        if invalidCounter == 3 then
            setting = 0
        end
    end
    shell.run("clear")
end
 
function run()
    for i=1, length / 2, 1 do
        layerDig()
    end
    
    BackToChest()
end
 
start()

Comments