Wednesday, January 2, 2013

More turtle fun!

So here's another script for the turtle, this one is made to mine those giant fur trees. You place your turtle facing the tree with a chest at his back. he should be on the left side of two trunk blocks. I took SethBling's original "Fell" script and rewrote it to be a little more fuel efficient as well as add some safety and error checking.

-- Clearing Terminal
term.clear()
term.setCursorPos(1,1)

-- Setting up Variables
local fuel = 1
local gone = 0

turtle.select(fuel)

-- Checking for Fuel before start
if ( not turtle.refuel(1) or turtle.getItemCount(fuel) < 1 ) then
    print("Missing Fuel in Slot 1")
    error()
end

-- Drop Items Function
function dump()
    print("Dumping Goods")
    for i = 2, 16 do
        turtle.select(i)
        turtle.drop()
    end
    turtle.turnLeft()
    turtle.turnLeft()
end

-- Fuel Checking Function
function tFuel(moved,f)
    if turtle.getFuelLevel() < (moved + 10) then
        turtle.select(f)
        if not turtle.refuel(1) then
            print("Need Fuel")
            finished(moved)
        end
    end
end

-- Return Function
function finished(m)
    print("Returning after " .. m + 1 .. " blocks")
    turtle.turnRight()
    turtle.turnRight()
    for i = 0, m do
        turtle.down()
    end
    dump()
    error()
end

print("Felling Tree")

turtle.dig()
turtle.forward

while turtle.digUp() do
    turtle.dig()
    tFuel(gone,fuel)
    turtle.up()
    gone = gone + 1
end

turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()

for i = 0, gone do
    turtle.digDown()
    turtle.down()
    turtle.dig()
end

turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
dump()

No comments:

Post a Comment