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

Automatic Sugar Cane Farm

Started by GalaxyMaster, 17 May 2013 - 11:39 AM
GalaxyMaster #1
Posted 17 May 2013 - 01:39 PM
Hi ComputerCrafters,

I just finished a fully automatic melon/pumpkin farm program. This is my second ComputerCraft program and I made it just a day after my first CC program: Automatic Tree Farm. I also made a fully automatic melon/pumpkin farm program today. Link: Automatic Melon/Pumpkin Farm. You need to give it fuel in the first slot. If it runs out of fuel, it will stop. The turtle should go up two blocks and then go past the lanes and if it detects a three tall cane, it will chop down the second and third layer. When it is done with a lane, it should wait one minute.

Note: This program currently only works with 2 lanes of sugar cane. The length of the lanes doesn't matter though.

Note: You need to set up your farm like shown in this picture. The length of the lanes doesn't matter.
Spoiler
Please note that it is very important that the turtle starts in that position. Also, when it asks you for the length when you start it, it means the length of the sugar cane blocks.

How to install:
SpoilerIf you have the http api installed:

Make a mining turtle and enter this:


pastebin get UV0GKKkr programname

You can replace programname with whatever you want the name of the program to be.

If you don't have the http api installed:
Make a mining turtle and make an empty program (name doesn't matter). Then go to your minecraft directory and then to saves, then your world, then computer and then the search the folders there for the program you just made. Open that file in notepad (or textedit for Mac users) and paste the code from here: http://pastebin.com/UV0GKKkr


Version history:
Spoiler1.1 - some minor coding changes thanks to UNOBTANUIM and added a wait of 1 minute after each lane switch.
1.0 - initial release


Screenshots:
Spoiler


Code:
Spoiler


write("Length: ")
length = read()
function moveForward(length)
  for i = 1, length do
	turtle.forward()
  end
end
function switchLanes()
  moveForward(1)
  turtle.turnLeft()
  moveForward(2)
  turtle.turnLeft()
end
function dig()
  turtle.dig()
  moveForward(1)
  turtle.digDown()
end
function roam()
  for i = 1, length do
	while turtle.getFuelLevel() <= 20 do
	  turtle.select(1)
	  turtle.refuel(1)
	end
	if turtle.detect() then
	  dig()
	else
	 moveForward(1)
	end
  end
  switchLanes()
  sleep(60)
end

while turtle.getFuelLevel() <= 20 do
  turtle.select(1)
  turtle.refuel(1)
end
turtle.up()
turtle.up()

while true do
  roam()
end


Be sure to leave feedback and report any bugs you encounter. If you have questions feel free to ask them.
unobtanium #2
Posted 17 May 2013 - 02:08 PM
Once again… its me :P/>

You know that the turtle can dig down as well. You dont have to go down and dig the sugar cane in front every time.
If you are checking if a block is in front, just let the turtle harvest the sugar cane. Then you dont need the "else" because the turtle will go forward in both possible ways. Add forward after the if statement.
This program is going to break if the turtle has to move more then 21 blocks and just has 21 fuel left. Fixing this would be easy by making math: 10+2*length or: 10+4*lengt Nevermind, just saw that you are using the refuel part every time, but you can get rid of it by calculating the movements of the turtle to harvest the suggar cane.
Then you are allways having enough fuel in the turtle even if the farm is 100 blocks long. Its allways better to have more fuel in the turtle then it really needs, because the risk of failing is more less.

What about letting the turtle wait some seconds before going for a harvest trip again? sleep(60) would let the turtle sleep a whole minute.
GalaxyMaster #3
Posted 17 May 2013 - 04:21 PM
UPDATE: 1.1 - some minor coding changes thanks to UNOBTANUIM and added a wait of 1 minute after each lane switch.
SyberSmoke #4
Posted 18 May 2013 - 06:55 PM
Hurm…

1: A little information in the main post about how the program functions would be good. While I like experimenting, I like to also know the base line for what the program should do so if it does something out of the norm I can report it.

2: While a vanilla SC farm would have defined lanes, you may also wish to consider a mode for a Xycraft Xychorium Soil system where the lanes do not need water down the middle.

3: A parameter for not only length of the lain but the number of lanes to tend. a 21 x 21 area can have seven three block wide lanes that the turtle could work.

4: Judging by the image, the turtle does not have a chest to put the goods into or a chest to get fuel from. This would be good for automation as cane could be pulled out of the chest in the case of say a Biofuel factory.

5: Why chop down the entire three tall cane? Why not only lop off the third layer as I believe sugar cane gets a growth bonus to the third layer where as the first is planted and second takes a while to grow compared to the third.
GalaxyMaster #5
Posted 19 May 2013 - 03:51 AM
Hurm…

1: A little information in the main post about how the program functions would be good. While I like experimenting, I like to also know the base line for what the program should do so if it does something out of the norm I can report it.

2: While a vanilla SC farm would have defined lanes, you may also wish to consider a mode for a Xycraft Xychorium Soil system where the lanes do not need water down the middle.

3: A parameter for not only length of the lain but the number of lanes to tend. a 21 x 21 area can have seven three block wide lanes that the turtle could work.

4: Judging by the image, the turtle does not have a chest to put the goods into or a chest to get fuel from. This would be good for automation as cane could be pulled out of the chest in the case of say a Biofuel factory.

5: Why chop down the entire three tall cane? Why not only lop off the third layer as I believe sugar cane gets a growth bonus to the third layer where as the first is planted and second takes a while to grow compared to the third.
1. The turtle should go up two blocks and then go past the lanes and if it detects a three tall cane, it will chop down the second and third layer. When it is done with a lane, it should wait one minute.
2. I only make programs compatible with vanilla items. Because I don't play tekkit, or other big mod-packs, I don't know how these things work and therefore cannot write programs for them.
3. I am working on a system that calculates the movement required to get back to the beginning with more than 2 lanes.
4. I also am working on this. I will make it so when the inventory is almost full, it will go to the sugar cane chest and empty its inventory except for the fuel.
5. It does not chop down the entire three tall cane. It chops down the second and third layer. And the third layer of sugar cane does not grow faster in any way.
SyberSmoke #6
Posted 21 May 2013 - 10:37 PM
2. To help: Xychorium Soil is a block that acts like tilled and hydrated soil. This means the only change in what the turtle would do with this specific mod (Xycraft) would be to have three lanes instead of two lanes with a water lane.
CupricWolf #7
Posted 23 May 2013 - 06:22 PM
2. To help: Xychorium Soil is a block that acts like tilled and hydrated soil. This means the only change in what the turtle would do with this specific mod (Xycraft) would be to have three lanes instead of two lanes with a water lane.
Its still not vanilla. If you want it so bad code it yourself :)/>
LazyNub #8
Posted 31 May 2013 - 09:08 AM
5: Why chop down the entire three tall cane? Why not only lop off the third layer as I believe sugar cane gets a growth bonus to the third layer where as the first is planted and second takes a while to grow compared to the third.

Oh wow, I didn't know this..
Auryn #9
Posted 02 June 2013 - 09:04 PM
Well, not directly connected to your programming, but you can make automations even in vanilla.
Here you have a little example how you can empty the sugar cane and refuel it in vanilla.

When you are returning to the start position, stop the turtle over the left chest and do a "turtle.dropDown()" for all slots with sugarcane.
Then continue to the right chest (probably your start position) and make a "turtle.suckDown()" and refuel.



This is a detail of the refuel station. A storage cart arrive with example coal and drops all the contenent in that chest.
As soon as it's done (the hopper empty) it will send the cart away (example to a mining turtle that fill it with coal again) by powering he single powered track on top of the hopper (the rest of the powered tracks are always on).
A empty storage cart will be sent away straight away.


The sugar cane part works almost exactly the opposite way. Your turtle will drop the canes into the chest and fill up the hopper.
When the storage cart arrives, it will empty the chest and the hopper. As soon as there are less than 24 canes in the hopper, it will send the cart away.
You can change this by changing the distance between comparator and the inverter.
Note that the comparator at the bottom could be a repeater (it doesn't matter) and it send signal to a block with a redstone torch on top that powers the single powered rail just below the hopper. The rest of the powered rails are always on (a redstone torch below one of them).

Naturally you need only one of this stations for a field of sugar canes and not every 2/3 rows.
Edited on 02 June 2013 - 07:07 PM