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

Wheat Farm

Started by PhilHibbs, 31 January 2013 - 09:36 AM
PhilHibbs #1
Posted 31 January 2013 - 10:36 AM
First I built a wheat farm using deployers and a block breaker. But then I discovered that Deployers don't work with Sulfur Goo, and I had a nice goo farm but no skeleton farm yet.

Turtles, however, have no problem with goo, as any Eastman and Laird fan will know.

I'm sure there's a nice easy auto wheat farm program here somewhere, but here is my version. Solving problems myself is the whole point of ComputerCraft to me anyway.

Set up with Seeds, Bonemeal (or Sulfur Goo), and Wheat in that order, actually I don't think the Wheat is necessary. Bonemeal or Sulfur Goo is fetched from the chest in front of the turtle, and all Wheat and all surplus Seeds greater than 64 are deposited in the chest above.

http://pastebin.com/5kAt175V
pastebin get 5kAt175V farm

Spoiler
-- ****************************************************************************
-- **								FARM									**
-- ****************************************************************************

local n = 0
local refilled = false

-- Fill the specified slot from any later slot that contains the same item, i.e. shuffle everything up to the topmost slots
local function fillSlot(slot)

   local n = 0

   if turtle.getItemSpace(slot) > 0 and turtle.getItemCount(slot) > 0 then
	  for n=16,slot+1,-1 do
		 turtle.select(n)
		 if turtle.compareTo(slot) then
			turtle.transferTo(slot, turtle.getItemSpace(slot))
		 end
	  end
   end
end

local function shuffleLoot()
  
   local n=0
  
   for n=1,15 do
	  fillSlot(n)
   end
end

local function refillUp(slot)
  
   local n=0
  
   if turtle.getItemSpace(slot) > 0 then
	  -- Get more bonemeal or sulfur goo from the chest
	  refilled = false
	  n=slot+1
	  repeat
		 n=n+1
	  until n > 16 or turtle.getItemCount(n) == 0
	  if n <= 16 then
		 turtle.select(n)
		 turtle.suck()
		 -- don't want a full stack, so put some back
		 if turtle.getItemSpace(n) == 0 then
			turtle.drop(turtle.getItemCount(2))
		 end
		 turtle.transferTo(slot, turtle.getItemSpace(2))
	  end
   end
end

shuffleLoot()
refillUp(2)

-- Keep farming while there is still more than 1 fertilizer and free inventory space for at least 1 wheat
while turtle.getItemCount(2) > 1 and turtle.getItemSpace(15) > 0 and turtle.getItemSpace(16) > 0 do

   while turtle.getItemCount(2) > 1 and turtle.getItemSpace(15) > 0 and turtle.getItemSpace(16) > 0 do
	  -- Use all but one of the seeds and bonemeal (or sulfur goo)
	  while turtle.getItemCount(1) > 1 and turtle.getItemCount(2) > 1  do
		 turtle.select(1)
		 turtle.placeDown()
		 sleep(.1)
		 turtle.select(2)
		 turtle.placeDown()
		 sleep(.1)
		 turtle.digDown()
		 turtle.suckDown()
--		 sleep(.1)
--		 turtle.suckDown()
	  end
	  -- Shuffle everything up to the top
	  shuffleLoot()
	  refillUp(2)
   end
   -- Unload into chest above, first all but one wheat in Slot 3
   turtle.select(3)
   turtle.dropUp(turtle.getItemCount(3)-1)
   -- ...then everything else that doesn't match Slot 2 (bonemeal or sulfur goo)
   for n=4,15 do
	  turtle.select(n)
	  if not turtle.compareTo(2) then
		 turtle.dropUp()
	  end
   end
   refillUp(2)
end  

turtle.select(1)
Here's my set up including the Sulfur Goo farm, I need more torches for it.

Spoiler
*Edit* Made the refill more efficient by reversing the slot scan order
Hm, I just let it run to a full inventory for the first time and it seems to quit at that point. Should be fairly simple to fix…
And I'm not entirely happy that I have the same condition on two While loops, I'll see if I can do something about that…
There, that's fixed the loop, it should now run on until the inventory is full of wheat and seeds, and then dump everything into the chest and start over.
It does more sorting than it needs to. Sorting is fairly quick now though.
xInDiGo #2
Posted 01 February 2013 - 06:51 AM
seems interesting! i know in FTB theres a item you can make that will harvest and plant the wheat. if you run pipes from these you can pretty much make it go infinitely. anyways what i did was added a crafting turtle next to the wheat deposit chest and had it craft bread every once in a while.

yours is pretty neat tho, keep up the good work!
PhilHibbs #3
Posted 11 February 2013 - 04:11 AM
seems interesting! i know in FTB theres a item you can make that will harvest and plant the wheat. if you run pipes from these you can pretty much make it go infinitely.
Yes but it doesn't work with Sulfur Goo, but a turtle does.
Quickslash78 #4
Posted 25 February 2013 - 01:44 PM
Is sulphur goo or bonemeal mandatory?
PhilHibbs #5
Posted 02 March 2013 - 02:07 AM
Yes, if you want a farm that works without them then you'll need it to be more than 1 block big or you will be waiting a long time to get even a stack of wheat. This turtle does not move, it just repeatedly farms a single block underneath it with bonemeal or sulfur goo.
Minithra #6
Posted 02 March 2013 - 12:57 PM
Tried this now… and all it does is constantly scan its inventory.
PhilHibbs #7
Posted 04 March 2013 - 08:41 AM
Did you set up the inventory with seeds then bonemeal, and is the dirt underneath it tilled, and is there sufficient light for the seeds to survive being planted?
Minithra #8
Posted 07 March 2013 - 01:50 PM
Did you set up the inventory with seeds then bonemeal, and is the dirt underneath it tilled, and is there sufficient light for the seeds to survive being planted?

I was doing it wrong :D/> Got it working eventually.
huldu #9
Posted 22 March 2013 - 04:19 AM
Is there no way to detect if a crop has grown yet? With 1.5 and the bonemeal changes etc.
PixelToast #10
Posted 22 March 2013 - 04:20 AM
i dont think so :s
you will have to use aperture science turtles or something
theoriginalbit #11
Posted 22 March 2013 - 04:22 AM
Is there no way to detect if a crop has grown yet? With 1.5 and the bonemeal changes etc.
The only way to detect if its fully grown is if you could put the fully grown wheat meta-data item into the turtle and use that to compare, sadly we cannot get that…
From the seed placement and up the meta data changes, the only way to tell if its fully grown is to have an item with the same block id and meta data value.

I think there are some peripherals that add the ability though.
PixelToast #12
Posted 22 March 2013 - 04:47 AM
what mod is the goo from?
PhilHibbs #13
Posted 22 March 2013 - 01:25 PM
Xycraft
oxgon #14
Posted 22 March 2013 - 06:41 PM
Just started using this and its amazingly simple and that's why it's awesome. Great work!