This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
OupaOorlog's profile picture

Simple turtle wheat farm

Started by OupaOorlog, 06 October 2012 - 07:40 PM
OupaOorlog #1
Posted 06 October 2012 - 09:40 PM
Simple turtle wheat farm

Things you should know:

1. This farm requires bone meal to run, whether you gather it with IC2, EE, mob farms or manually is up to
you. If out of bone meal the turtle will face the bone meal chest(more on that later) and periodically check
whether new bone meal has been inserted into the chest. If there is it will continue farming otherwise it will
sleep for half a minute and check again.

2. There needs to be sufficient light, at all times, to plant wheat.

3. No fuel required! The turtle does not move(turning does not count) so no fuel is required.

4. No proximity to water is required for the farmland.

5. No state file required.

Required Materials(overview):

1 Dirt Block
1 Farming Turtle
4 Chests for single chests or 7 if you want to use double chests
1 slot of seeds to get the little guy started.(atleast 10 seeds)
X Bone Meal

Setup:

Place the turtle facing an empty block above a dirt block. This will be where you sow, feed and harvest your
wheat. Place three chests(single or double) around the turtle, like so:



Turtle Inventory:

Place a chest, bone meal and seeds in the turtle's inventory as indicated in
the image below. The chest is only there to compare to its environment thus ensuring it is facing the dirt
before starting to farm.



Config:

There are 4 config variables at the top of the code that you can play around with.

1. fullstacks:

true will set the turtle to fill every slot to 64 items before depositing the wheat and additional seeds while
false will use a new slot every time you harvest. I recommend true but false will give you results faster.
Setting it to false will also not replenish seeds automatically as you harvest but will fetch it from the seed chest when out of seeds making it slightly slower over longer periods.

2. bmcDirection: Indicates the direction the bone meal chest is located.

3. scDirection: Indicates the direction the additional seed deposit chest is located.

4. depositDirection: Indicates the direction your wheat will be deposited.

Direction:

Used to tell the turtle which way it is facing and which direction it needs to face for each chest.



Spoiler

local fullstacks = true
local bmcDirection = 4 --bone meal chest direction
local scDirection = 3 -- seed chest direction
local depositDirection = 2 -- output direction

local facing = 1
local chestslot = 14
local seedslot = 15
local bonemealslot = 16

local function TurnRight()
	facing = facing + 1
	if facing > 4 then
		facing = 1
	end
	turtle.turnRight()
end

function FindDirt()
	local facingchest = true
	turtle.select(chestslot)
	facingchest = turtle.compare()
	while facingchest do
		turtle.turnRight()
		turtle.select(chestslot)
		facingchest = turtle.compare()
	end
	facing = 1
end

function SelectEmptySlot()
	for n = 1, 13 do
		if turtle.getItemCount(n) == 0 then
			turtle.select(n)
			break;
		end
	end
end

function SelectSeedSlot()
	turtle.select(seedslot)
end

function CheckEmptySlots()
	local emptySlots = false
	for n = 1, 13 do
		if turtle.getItemCount(n) == 0 then
			emptySlots = true
			break;
		end
	end

	if not emptySlots then
		Deposit()
	end
end

function P(text)
	term.clear()
	term.setCursorPos(1, 1)
	print(text)
end


function GetMoreSeeds()
	P("Stocking seeds")
	while facing ~= scDirection do
		TurnRight()
	end
	turtle.select(seedslot)
	turtle.suck()
end

function GetMoreBM()
	P("Stocking bone meal")
	while facing ~= bmcDirection do
		TurnRight()
	end
	turtle.select(bonemealslot)
	if turtle.suck() then
		return true
	else
		return false
	end
end

function Deposit()
	P("Depositing yield")
	while facing ~= depositDirection do
		TurnRight()
	end

	for n=1,13 do
		turtle.select(seedslot)
		if not turtle.compareTo(n) then
			turtle.select(n)
			turtle.drop()
		end
	end

	while facing ~= scDirection do
		TurnRight()
	end

	for n=1,13 do
		turtle.select(n)
		turtle.drop()
	end
end

function CheckSupplies()
	local supplies = true
	if turtle.getItemCount(seedslot) == 0 then
		GetMoreSeeds()
	end
	if turtle.getItemCount(bonemealslot) == 0 then
		supplies = GetMoreBM()
		if not supplies then
			waitforBM()
		end
	end
end

function waitforBM()
	P("Waiting on more bone meal")
	local continue = true

	while facing ~= bmcDirection do
		TurnRight()
	end

	while continue do
		turtle.select(bonemealslot)
		if turtle.suck() then
			continue = false
		else
			sleep(30)
		end
	end
end


function Farm()
	local continue = true
	while continue do
		FindDirt()
		CheckSupplies()
		P("Starting farm")
		FindDirt()
		CheckEmptySlots()
		FindDirt()
		if fullstacks then
			SelectSeedSlot()
		else
			SelectEmptySlot()
		end
		turtle.dig()
		turtle.dig()
		turtle.select(seedslot)
		turtle.place()
		turtle.select(bonemealslot)
		turtle.place()
	end
end

Farm()


Possibilities:

It would be a relatively simple matter to use the additional seeds and wheat(you will never eat all the bread you will be making)
to craft biofuel from. Run generators with the biofuel and run a mass fab(potentially with scrap) with the generated EU
to make more bone meal. Which makes the system autonomous.

If you already generate enough bone meal, the fuel can go towards running your turtle army or generating EU for other uses.

or this:




Regards,
Oupa Oorlog.
jag #2
Posted 06 October 2012 - 09:44 PM
Looks neat! :D/>/>
Surprisingly large code for the simple functionality, but cool!
Do you got it on pastebin? (easier to download while in-game)
OupaOorlog #3
Posted 06 October 2012 - 10:24 PM
Try http://pastebin.com/mau0Wh39