Wednesday, January 9, 2013

Flooring

Don't you just hate having to fill in floors one block at a time? Well I have the solution for you! Get a turtle to do that for you. Just give him fuel and blocks and set him free! Here you go:


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

-- Setting up Variables
local tArgs = { ... }
local fuel = 1

if #tArgs ~= 1 then
    -- Missing Height Argument
    print("Usage: Floor <area>")
    print("Slot 1: Fuel")
    print("Slot 2-16: Blocks")
    error()
end

local area = tArgs[1]

-- Fuel Checking Function
function tFuel(f)
    if turtle.getFuelLevel() < 10 then
        turtle.select(f)
        if not turtle.refuel(1) then
            print("Need Fuel")
            while turtle.getItemCount(f) < 2 do sleep(0.5) end
        end
    end
end

function place()
    if not turtle.detectDown() then
        for s = 2, 16 do
            if turtle.getItemCount(s) ~= 0 then
                turtle.select(s)
                break
            end
        end
        turtle.placeDown()
    end
end

print("Starting floor of " .. area .. " square blocks")

for gone = 1, area do
    for gtwo = 1, area do
        tFuel(fuel)
        turtle.forward()
        place()
    end
    turtle.forward()
    if( gone % 2) == 0 then
        turtle.turnRight()
        turtle.forward()
        turtle.turnRight()
    else
        turtle.turnLeft()
        turtle.forward()
        turtle.turnLeft()
    end
end

No comments:

Post a Comment