icdb icon

[ComputerCraft] stripmine

icdb | PRO | 09/21/14 01:22:13 PM UTC | 0 ⭐ | 687 👁️ | Never ⏰ | []
Lua |

1.94 KB

|

None

|

0 👍

/

0 👎

local tArgs = { ... }
if #tArgs == 1 then
    length = tArgs[1]
    deep = 5
elseif #tArgs == 2 then
    length = tArgs[1]
    deep = tArgs[2]
    if length < "1" and deep < "0" then
        print("length > 0")
        print("deep >= 0")
        return
    end
else
    print("Usage:")
    print("stripmine <length> <deep>")
    print("length > 0")
    print("deep > -1")
    print("if deep is empty: deep = 5")
    return
end
 
function forward(a)
    for i=1,a do
        while turtle.forward() == false do
            turtle.attack()
            turtle.dig()
        end
    end 
end
 
function right(a)
    for i=1,a do
        turtle.turnRight()
    end
end
 
function left(a)
    for i=1,a do
        turtle.turnLeft()
    end
end
 
function dig(a)
    for i=1,a do
        lava()
        while turtle.detect()==true or turtle.forward() == false do 
            turtle.dig() 
            turtle.attack()
            sleep(0.3)
        end
 
        while turtle.detectUp()==true do 
            turtle.attackUp()
            turtle.digUp() 
            sleep(0.4)
        end
    end
end
 
function drop()
    for i=1,14 do
        turtle.select(i)
        turtle.drop()
    end
    turtle.select(1)
end
 
function lava()
    if turtle.getItemCount(15)>0 then
    turtle.select(15)
    turtle.place()
    if turtle.refuel() == false then
        --Whatever we picked up is invalid for fuel, put it back down
        turtle.place()
    end
    turtle.placeDown()
    if turtle.refuel() == false then
        --Whatever we picked up is invalid for fuel, put it back down
        turtle.placeDown()
    end
    turtle.placeUp()
    if turtle.refuel() == false then
        --Whatever we picked up is invalid for fuel, put it back down
        turtle.placeUp()
    end
    turtle.select(1)
    end
end
 
for j=1,length do
    print(j," of ", length)
    dig(3)
    turtle.back()
    turtle.select(16)
    turtle.placeUp()
    turtle.forward()
    right(1)
    dig(deep)
    left(2)
    forward(deep)
    dig(deep)
    right(2)
    forward(deep)
    left(1)
    if (j % 10) == 0 then
        right(2)
        forward(j*3)
        left(1)
        drop()
        left(1)
        forward(j*3)
    end
end
right(2)
forward(length*3)
left(1)
drop()
left(1)

Comments