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

[1.3] AutoTreeFarm program

Started by BikerEleven, 10 March 2012 - 10:25 PM
BikerEleven #1
Posted 10 March 2012 - 11:25 PM
*Having stopped playing minecraft this code is hereby abandoned however other like Anonomit have updated the code you can find the post here http://bit.ly/NhYPsp


This is simply an automatic tree farm designed to maintain a few rows of trees automatic, or semi automatic.

Its main features are:
  • Automatic sapling planting
  • Block placement if unable to plant a sapling
  • Auto harvesting
  • Simple settings menu
  • Feature to output redstone at the end of a harvest for an automatic refill/collector system
To use this system, simply install the file as startup -or another name if its not a dedicated turtle- then when it first runs it will ask if it should output a redstone signal unless its invitory is cleared.
Next it will ask how many rows (columns) should it manage, after that it will ask how many trees per row (column).
Once that is done its ready to get a renet message "startLoging" or hit r on the main screen to start a harvest(cycle).

Saplings go into the first slot (Recomended 50) and dirt gos into the second slot (Recomended 50)

Also on the main screen between cycles you can hit s to bring up the settings menu. Settings are saved between sessions.

Preview video:


[media]http://www.youtube.com/watch?v=l3U2OZb6zwY[/media]


Old download: http://pastebin.com/tByWEdJE
Zer0t3ch #2
Posted 13 March 2012 - 04:45 PM
I like it. Have this installed on my server, and we love it! Thanks! :-)
themandk #3
Posted 23 March 2012 - 12:04 PM
I like it. But what is the name of the pip below the turtle in your redstone setup ??.
I've tried every pip but can not find it.
Thanks.:(/>/>
HTxL #4
Posted 23 March 2012 - 07:24 PM
Very nice
I liked that you used the same technique to check if he puts the right blocks since for some reason when you try to put a block from an empty slot
it moves to a slot with a block and place it….

I really like it thanks for sharing :]
hamish1001 #5
Posted 25 March 2012 - 02:47 AM
awesome, the best thing is that it works thanks :(/>/> :)/>/>
BikerEleven #6
Posted 31 March 2012 - 04:12 PM
I like it. But what is the name of the pip below the turtle in your redstone setup ??.
I've tried every pip but can not find it.
Thanks. :o/>/>

Its a Logistics supplyer pipe, A buildcraft addon by Krapht
MathManiac #7
Posted 18 May 2012 - 03:11 AM
This, my friend, is 97% awesomesauce. The other 3% is epicsauce.
onecaveman #8
Posted 24 June 2012 - 11:57 PM
hi, i have typed in the colde in the turtelos 1.3

but when i run the program i get this error
For input string: "0local"

im new to luna, can you please help me out

im playing on a smp tekkit server..

thank you for your time
kazagistar #9
Posted 25 June 2012 - 12:16 AM
hi, i have typed in the colde in the turtelos 1.3

but when i run the program i get this error
For input string: "0local"

im new to luna, can you please help me out

im playing on a smp tekkit server..

thank you for your time

Did you copy the line numbers? Because that is what it looks like.
onecaveman #10
Posted 25 June 2012 - 01:45 AM
hi, i have typed in the colde in the turtelos 1.3

but when i run the program i get this error
For input string: "0local"

im new to luna, can you please help me out

im playing on a smp tekkit server..

thank you for your time

Did you copy the line numbers? Because that is what it looks like.

no but i copy pasted it from the raw data.
"tap" or what it is called.. is not in the tutelosOS.
i set it up like this in the tutelOS



some of the raw data:


local shouldOutput = false
local width = 0
local length = 0

local function loadSettings()

file = io.open( "settings.txt", "r" )
while true do
line = file:read()
if line == nil then break end

if line == "true" then
shouldOutput = true

the difrent is that the program does not have the "tap" in it. well i can't make it work anyway
Edited on 24 June 2012 - 11:54 PM
KaoS #11
Posted 27 June 2012 - 01:23 PM
I built a different one with buildcraft deployers, the turtle places a sapling, powers the deployer which uses bonemeal to grow the tree, the turtle then mines it out and repeats. it works very fast
Amunak #12
Posted 27 June 2012 - 06:12 PM
First of all I must say that this is awesome. I have a few suggestions for improvements.

- when going over blocks and thinking "this under me is sapling" while going through the cycle, check if the block where the sapling should be really is a sapling - sometimes I run out of saplings and it then plants dirt or wood, so it would be great to have it cycle again and repair those mistakes from previous loops.

- add an option to always recreate the dirt blocks under saplings - when I make an automatic farm, some of the saplings stays on the one dirt block. That's a problem in tekkit where I use it to farm rubber trees. They drop only a few saplings and every waste is a disaster :P/>/>

Continue doing this awesomness, thanks!
TrollZ0R #13
Posted 30 June 2012 - 03:27 PM
Can someone tell me how to connect the Computer with the Turtle?
soloian #14
Posted 20 July 2012 - 06:42 AM
I'm having some problems with this on SMP it doesn't seem to want to break the trunk when it moves up to the side of it nor dose it replace sand with dirt like in the video :S

I downloaded the file from paste bin so I know im not missing something out of the code can some one help me out thanks


ok i got it working all i needed todo was face the turtle to the south.

but i do have one question how can i make it so on a redstone pulse it starts up? :S so i can make it so its hiden out of the way.
BikerEleven #15
Posted 21 July 2012 - 06:49 AM
- when going over blocks and thinking "this under me is sapling" while going through the cycle, check if the block where the sapling should be really is a sapling - sometimes I run out of saplings and it then plants dirt or wood, so it would be great to have it cycle again and repair those mistakes from previous loops.

I have actualy tryed doing that with the compare function but I ran into consistency errors so I decided to just keep the current system.

- add an option to always recreate the dirt blocks under saplings - when I make an automatic farm, some of the saplings stays on the one dirt block. That's a problem in tekkit where I use it to farm rubber trees. They drop only a few saplings and every waste is a disaster :)/>/>

This could be implimented as an option, i'm working on a few minor changes but at the moment im waiting for the computer craft update before releasing the next upgrade.

I'm having some problems with this on SMP it doesn't seem to want to break the trunk when it moves up to the side of it nor dose it replace sand with dirt like in the video :S

I downloaded the file from paste bin so I know im not missing something out of the code can some one help me out thanks


ok i got it working all i needed todo was face the turtle to the south.

but i do have one question how can i make it so on a redstone pulse it starts up? :S so i can make it so its hiden out of the way.

I have no idea why it would require you to face the south it sounds like a mod glitch, and for the redstone pulse you just need to add this line to the event handler

if event == "redstone" and p1 == "<side of="" redstone="">" then harvest() end
MrRain #16
Posted 26 July 2012 - 05:00 AM
I'm having a problem where the turtle isn't harvesting the tree at all.
stabwoundz #17
Posted 04 August 2012 - 02:01 AM
do i have to copy the program to the turtle before trying to use rednet? i'm fairly new to computercraft so i'm not sure if this is necesary
Anonomit #18
Posted 12 August 2012 - 06:29 AM
I've just posted an update to this program, addressing some of the issues or suggestions left in this topic.

Full credit is, of course, given to BikerEleven for the original code.

The updated version can be found here:
http://bit.ly/NhYPsp

I created a new topic because of all the detail in the post. I linked back to this topic so people can find this version if mine proves to have a bug or inconsistency error.
nicon4454 #19
Posted 29 August 2012 - 10:43 PM
i would also like to know how to connect the turtle to the computer with rednet i have three turtles set up and i would like to be able to make them go from the computer. also can you explain a bit more about the output redstone on cycle. is there a way to get the turtle to unload either let it drop in to the water or drop it in the chest?
Spoiler

i do have to say i really like this mod.
Anonomit #20
Posted 23 September 2012 - 10:55 PM
i would also like to know how to connect the turtle to the computer with rednet i have three turtles set up and i would like to be able to make them go from the computer. also can you explain a bit more about the output redstone on cycle. is there a way to get the turtle to unload either let it drop in to the water or drop it in the chest?
Spoiler

i do have to say i really like this mod.

Hi nicon4454, to make the turtles start by rednet, first find a computer with a modem. Make sure the modem is open. While editting a program, or using the lua prompt, type in:

rednet.open( side )   --ie.   rednet.open( "right" )

Next, to make the turtles start simultaneously, type in:

rednet.broadcast( "startLoging" )

Again, make sure this is inside a program or the lua prompt. As long as your turtles are wireless, and are "ready to cycle", they should begin harvesting.
Pho3niX90 #21
Posted 24 September 2012 - 12:58 PM
I got this script and noticed it was not working for MC 1.3.2 and CC 1.4. SO I modified the code, only difference is that block 16 (Bottom right) needs a fuel item, like for example Coal or Wood, for it to work..


here is the updated code.
Spoiler

local shouldOutput = false
local width = 0
local length = 0

local function loadSettings()

		file = io.open( "settings.txt", "r" )
		while true do
				line = file:read()
				if line == nil then break end
			  
				if line == "true" then
						shouldOutput = true
				else
						shouldOutput = false
				end
			  
				line = file:read()
				if line == nil then break end
			  
				width = tonumber(line)
			  
				line = file:read()
				if line == nil then break end
			  
				length = tonumber(line)
			  
				file:close()
	  
				return true
		end
	  
		file:close()
	  
		return false

end

local function createSettings()

		term.clear()
		term.setCursorPos( 1,1 )
		print( "Set the settings." )

		write( "Output Redstone on cycle: " )
		local str = string.lower( read() )
		if str == "1" or str == "yes" or str == "true" then
				shouldOutput = true
		else
				shouldOutput = false
		end

		write( "Rows: " )
		width = tonumber(read())

		write( "Trees: " )
		length = tonumber(read())
	  
		file = io.open("settings.txt", "w")
		if file == nil then
				--error? could be locked
				return
		end
	  
		if shouldOutput then
				file:write( "true" )
				file:write( "n" )
		else
				file:write( "false" )
				file:write( "n" )
		end
	  
		file:write( width )
		file:write( "n" )
		file:write( length )
		file:write( "n" )
	  
		file:close()
	  
		term.clear()
		term.setCursorPos( 1,1 )
		print( "Ready to cycle" )


end

term.clear()
term.setCursorPos( 1,1 )
print( "Logger program starting..." )

if fs.exists( "settings.txt" ) then
		if not loadSettings() then
				createSettings()
		end
	  
		term.clear()
		term.setCursorPos( 1,1 )
		print( "Ready to cycle" )

else
		createSettings()
end

rednet.open( "right" )

local function tryMove( direction )

	   turtle.getFuelLevel()
	  
	   if direction == "down" then
				if turtle.detectDown() then
						turtle.digDown()
				end
				while not turtle.down() do
						turtle.digDown()
						sleep(1)
				end
		end
	  
		if direction == "forward" then
				if turtle.detect() then
						turtle.dig()
				end
				while not turtle.forward() do
						turtle.dig()
						sleep(1)
				end
		end
	  
		if direction == "up" then
				if turtle.detectUp() then
						turtle.digUp()
				end
				while not turtle.up() do
						turtle.digUp()
						sleep(1)
				end
		end

end

function CheckFuel()
	   BlocksMil = (width*3) * (length*3)
	   if BlocksMil > turtle.getFuelLevel() then
		turtle.select(16)
turtle.refuel()
	   end
end

local function plantTree()
	  
	   CheckFuel()
		turtle.select(1)
		l = turtle.getItemCount(1)
		turtle.placeDown()
		t = turtle.getItemCount(1)
	  
		if t == l then --must have not been able to place a sapling
				turtle.select(2)
				tryMove("down")
				if turtle.detectDown() then turtle.digDown() end
				turtle.placeDown()
				turtle.select(1)
				tryMove("up")
				turtle.placeDown()
		end

		turtle.select(9)
end

local function harvestTree()
	  
		steps = 1
		tryMove("forward")
	  
		while turtle.detectUp() do
				tryMove( "up" )
				steps = steps + 1
		end
	  
		while steps > 2 do
				tryMove( "down" )
				steps = steps - 1
		end
		plantTree()

end

local function checkTree()

		if turtle.detect() then
				tryMove( "down" )
				harvestTree()
		else
				tryMove( "forward" )
				if not turtle.detectDown() then
						plantTree()
				end
		end

end

local function harvest()

	   CheckFuel()
	   turtle.select(1)
		tryMove( "forward" )
		tryMove( "up" )
		checkTree()
	  
		bump = false
	  
		for w=1, width do
	  
				for l=1, length do
			  
						if l~=length then
								tryMove( "forward" )
								tryMove( "forward" )
								checkTree()
						end
			  
				end
	  
				if w~=width then
						if not bump then
								turtle.turnLeft()
								tryMove( "forward" )
								tryMove( "forward" )
						else
								turtle.turnRight()
								tryMove( "forward" )
								tryMove( "forward" )
						end
						checkTree()
					  
						if bump then
								turtle.turnRight()
						else
								turtle.turnLeft()
						end
					  
						bump = not bump
				end
			  
		end
	  
	  
		--Return
		if not bump then
				turtle.turnLeft()
				tryMove( "forward" )
				turtle.turnLeft()
				for i = 1, length do
						tryMove( "forward" )
						tryMove( "forward" )
						if i~=length then
								tryMove( "forward" )
						end
				end
		else
				tryMove( "forward" )
				tryMove( "forward" )
		end
		turtle.turnLeft()
	  
		if width == 1 then
				tryMove( "forward" )
		else
				for i=1, width - 1 do
						tryMove( "forward" )
						tryMove( "forward" )
						tryMove( "forward" )
				end
				if not bump then
						tryMove( "forward" )
				end
		end
	  
		turtle.turnLeft()
		tryMove( "down" )
		turtle.select(9)
	  
	  
		--Drop off and resupply
		if shouldOutput then
				redstone.setOutput("left", true)
				output = true
			  
				while output do
					  
						for i=3, 9 do
								if turtle.getItemSpace( i ) ~= 64 then
										break
								elseif i==9 and turtle.getItemSpace( 9 ) == 64 then
										output = false
								end
						end
						sleep(0.5)
				end
			  
				redstone.setOutput("left", false)
		end
	  
		print( "Ready to cycle" )
			  
end

while true do
		event, p1, p2 = os.pullEvent()
	  
		if event == "rednet_message" and p2 == "startLoging" then
				harvest()
		end
	  
		if event == "char" and p1 == "s" then
				createSettings()
		end
	  
		if event == "char" and p1 == "r" then
				print("User overide, havest starting.")
				harvest()
		end
end
Anonomit #22
Posted 25 September 2012 - 10:25 PM
Hi Pho3niX90, could you put your code in spoilers? Just use the [*SPOILER] tag, without the *
Thanks!
Pho3niX90 #23
Posted 15 October 2012 - 07:40 PM
Hi Pho3niX90, could you put your code in spoilers? Just use the [*SPOILER] tag, without the *
Thanks!

Done, thanks