Showing posts with label cactus. Show all posts
Showing posts with label cactus. Show all posts

Thursday, January 3, 2013

Cactus Builder

So, this script is awesome, but it doesn't work completely. Luckily it works well enough to make it worth sharing. When i wrote it, I totally didn't think about the fact that the turtle has to place a cactus down. I may rewrite this one later if there is a need for it. but it builds the basic structure for you, and all you have to do is add the cactus manually.


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

-- Setting up Variables
local tArgs = { ... }
local fuel = 1
local sand = 2
local block = 3
local cactus = 4
local gone = 0
local slots = {"fuel", "sand", "blocks", "cactus"}

if #tArgs ~= 1 then
    -- Missing Height Argument
    print("Usage: Cactus <layers>")
    print("Slot 1: Fuel")
    print("Slot 2: Sand")
    print("Slot 3: Blocks")
    print("Slot 4: Cactus")
    error()
end

local height = tArgs[1]

--Missing Items Check
if (turtle.getItemCount(fuel) < 1 or turtle.getItemCount(sand) < 1 or turtle.getItemCount(block) < 1 or turtle.getItemCount(cactus) < 1) then
    print("Missing Critical Item")
    error()
end

-- Fuel Checking Function
function tFuel(f)
    if turtle.getFuelLevel() < 60 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

--Place Row
function row(slot)
    for p = 1, 4 do
        turtle.select(slot)
        if turtle.getItemCount(slot) < 3 then
            print("Need more " .. slots[slot])
            while turtle.getItemCount(slot) < 3 do sleep(0.5) end
        end
        turtle.forward()
        turtle.turnLeft()
        turtle.place()
        turtle.turnRight()
        turtle.turnRight()
        turtle.place()
        turtle.turnLeft()
        if slot == cactus then
            turtle.select(block)
            if turtle.getItemCount(block) < 3 then
                print("Need more " .. slots[block])
                while turtle.getItemCount(block) < 3 do sleep(0.5) end
            end
            turtle.placeUp()
        end
        turtle.forward()
        end
end

print("Starting cactus farm of " .. height .. " layers")

for g = 1, height, 2 do
    tFuel(fuel)
    turtle.up()
    row(block)
    turtle.up()
    turtle.turnRight()
    turtle.turnRight()
    row(sand)
    turtle.up()
    turtle.turnRight()
    turtle.turnRight()
    row(cactus)
    turtle.turnRight()
    turtle.turnRight()
    turtle.up()
    turtle.up()
    turtle.up()
    row(block)
    turtle.up()
    turtle.turnRight()
    turtle.turnRight()
    row(sand)
    turtle.up()
    turtle.turnRight()
    turtle.turnRight()
    row(cactus)
    turtle.turnRight()
    turtle.turnRight()
    turtle.up()
    turtle.up()
end