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

AutoTreeFarm Program V2

Started by Anonomit, 12 August 2012 - 04:24 AM
Anonomit #1
Posted 12 August 2012 - 06:24 AM
EDIT: New, far superior program can be found here: http://bit.ly/Q6zqCt

Credit for original code to BikerEleven

EDIT: BikerEleven has stopped playing minecraft, and has given me permission to take credit for any updates.

Original forum thread can be found here:
http://bit.ly/NYbb3u

This is an update for BikerEleven's [1.3]AutoTreeFarm program

Here are a few of the changes:
Spoiler
  • fixed typo 'startLoging' to 'startLogging'
  • allows for more rednet control by broadcasting messages.
  • turtles now compare instead of detect during harvestTree()
  • turtles will not attempt to plant saplings if they run out
  • turtles are slightly more efficient
  • turtles are smarter
  • turtles now work correctly with spruce and jungle trees
  • turtles will emit redstone from their left side and bottom
  • turtles will now start if a redstone input changes next to them
  • Be careful! if turtles are to the left of each other and emitting redstone, they could trigger each other!

This program will work with Computercraft 1.41 as well as being compatible with Computercraft 1.3 and possibly older versions (not tested)

The original program by BikerEleven had a serious flaw:
the turtle would sometimes get saplings in its inventory in slots other than slot 1. This was because the turtle would dig the leaves at the top of the trees, giving it a sapling 1 in 20 times.

They no longer do that. Instead, they stop digging when there is no more wood to dig. Also, if the turtle runs into any blocks where it didn't expect to, it will drop them.
For instance, if a tree grows with its leaves low to the ground so that the turtle has to dig through, it will notice if it picks up a sapling in a slot other than slot 1 and it will drop the sapling.


You got my attention, so what do I do?
SpoilerA video tutorial FOR THE 1.3 UNUPDATED VERSION can be found here:
http://bit.ly/NWJ84b

Watch this video. The wall of text below will help you understand the program, but the video will be much clearer.
*Still read the text though. There's information about additional programs that make things much easier!

If the program is installed correctly, you should be able to go to any turtle and type 'logger'
Doing so will ask you to choose some settings.

The settings can be changed after they are created by pressing 's'.
To manually start the turtle and all nearby turtles, press 'r'.

If you choose to output redstone, then the turtle will output redstone when it returns from harvesting, and will continue until slots 3-9 are empty.
This allows you to create a pipe system to filter out the wood. I recommend using 'advanced wooden pipes' from the Buildcraft Additional Pipes mod and setting them to exclude saplings and dirt.
The turtle will ask for your desired length and width. 5x5 is a good size. If you make it too big, the turtle won't be able to carry enough saplings to plant them all.
*Make sure there are saplings in the first slot, and dirt in the second!
Birch saplings make the farm as consistent as possible, and work perfectly with BikerEleven's version.
I recommend jungle saplings, as the trees will be taller on average, and the turtle can now tolerate the occasional low-hanging leaves.

If you want dedicated tree farmers, I suggest following the instructions below on how to set up the broadcast console, with two differences:

Instead of shell.run("broadcast") type in:
  • shell.run("logger")
Instead of displaying 'BROADCAST CONSOLE' when you finish the instructions, it should display 'Ready to cycle'

*I recommend using this program with two of my other programs, made specifically to make automatic tree farming simpler :P/>/>
It's worth noting that the equivalent exchange mod, included in Tekkit, puts a value of 32 EMC on each piece of tree wood. Each stack is worth 2048 EMC.
The programs can be found below.

Both programs are for computers, although they would technically work for turtles also.
To make them work, you must set up a computer (preferably high up) with a wireless modem to be the broadcast computer. This computer handles all traffic to and from the turtles.
Note that this computer will become a dedicated computer, and you will not be able to use it for anything else.
Make sure this computer is near the turtles that you want to farm trees. Put it as close as you can, without it being in the way.

In the computer, type:
  • edit startup
A blank screen should open. Now type:
  • shell.run("broadcast")
Now press 'ctrl' to access menu, then press 's' to save.
Now reboot the computer by holding down 'ctrl-r'
It should display 'BROADCAST CONSOLE'

If it does not, then either,
you installed to the wrong directory,
the name is incorrect or has a .txt extension,
or you typed the above command incorrectly.

If it does say 'BROADCAST CONSOLE' then congratulations!

Now you can go to any nearby computer with a wireless modem and type 'log'
Doing so should print the message 'Started Logging'
*Remember that you will need wireless mining turtles to receive the message.
If you type 'log' again, it should say 'Please Wait…' then print out useful information regarding the loggers!
Information includes how many loggers are finished, if any loggers are low on saplings, and if any loggers are out of saplings.

How do I install these programs?
SpoilerFor instructions on installing computercraft programs, see here:
http://bit.ly/OShGWK

To install for tekkit, go to %appdata%.techniclaunchertekkitmodsComputerCraftluaromprograms
Anything placed in this directory will be available to both computers and turtles, IN SINGLEPLAYER.
There is a similar path a server owner must save to if the programs are to work on a server.
You can make programs exclusive to computers or turtles by saving the program to the respective folder.

Where can I get these programs?
SpoilerRight here!
Just paste into a text editor, (like notepad++) and save to the location detailed above.

Make sure to erase the .txt extension at the end of the filename and save as 'All Types', rather than as a 'Normal Text File'.
Otherwise, the program will NOT work!

http://pastebin.com/DXS4N7MM –name this program logger. Save it to the 'turtle' folder.

What about the bonus programs that will make tree farming so much easier? I must have them!
SpoilerCalm down, they're right here:

http://pastebin.com/fe99rTPB –name this program log
http://pastebin.com/54wJt5fV –name this program broadcast

Edit:

–Code Updated!

Spoiler–if you're using tekkit, set up an advanced wooden transport pipe to suck out only the wood.
–if updating, press 's' to recreate settings, otherwise you will get an error.
–turtle now has an option to wait for full saplings between cycles.
–the turtle will output redstone on the bottom, left and right sides.
–make the redstone power a redstone engine, powering a pipe that brings saplings to the turtle.
–depending on how long the pipe is, the turtle will have to throw away a couple saplings if he gets too many.
–use a transposer to automatically pick up any extra saplings.
–turtle will not wait for full saplings unless 'output redstone on cycle' is selected.

–this code is not ideal, but it works if you really want that small amount more automation.
–if not, do not select 'Wait for full saplings'
Bushido #2
Posted 08 September 2012 - 04:02 AM
Can u add when it is full it returns to empty it's inventory and to refill it's saplings some how? other wise it is awesome bro
Anonomit #3
Posted 14 September 2012 - 10:04 PM
if you're using tekkit, set up an advanced wooden transport pipe to suck out only the wood.
make sure the turtle is set to 'output redstone on cycle'. press 's' to recreate settings.
as for refilling saplings, the problem is that if i were to add that in, the turtle would need to be refilled before EVERY trip, manually or with pipes.
maybe i'll release an update that gives an option to refill saplings.
for now though, the saplings will need to be refilled manually, sorry :)/>/>

Edit:
–if updating, press 's' to recreate settings, otherwise you will get an error.
–turtle now has an option to wait for full saplings between cycles.
–the turtle will output redstone on the bottom, left and right sides.
–make the redstone power a redstone engine, powering a pipe that brings saplings to the turtle.
–depending on how long the pipe is, the turtle will have to throw away a couple saplings if he gets too many.
–use a transposer to automatically pick up any extra saplings.
–turtle will not wait for full saplings unless 'output redstone on cycle' is selected.

–this code is not ideal, but it works if you really want that small amount more automation.
–if not, do not select 'Wait for full saplings'
hi_tech_guy_18 #4
Posted 22 September 2012 - 12:25 AM
You need to add a refuel command at the begging so it self refuels pref from the last slot
Bushido #5
Posted 23 September 2012 - 06:27 AM
Computer craft keeps spitting out this http://pastebin.com/RmQSrPG8. The turtle will place saplings and cycle redstone signal and stop when saplings are full but it will stop while trying to harvest the trees.



Edit: Fixed the chat error spam Nocheat doesn't like mining turtles.
Xanafrim #6
Posted 27 September 2012 - 05:42 AM
I JUST started trying out Computer Craft and I found this program. I have installed it and it was working fine but then I fixed the ground a bit where it dropped a level. After I did this I hit "r" and he went on another round. However, ever since then he only takes 2 logs per tree and leaves the rest for me to clean up. I did not alter any of the code so I am no sure what might have happened.

Possibly it is connected to lag as that is an issue for me. I run a single core processor right now, no hyperthreading, 2 GB ram. That's the max this laptop can hold. However, I also am the admin of a paid server that runs tekkit and that is the only place I play. The server does have 1 GB of ram. I am running the current Tekkit pack.

Thanks for any help on this.
Bushido #7
Posted 27 September 2012 - 07:35 AM
At least yours gets some logs all mine does is run into the tree and stop lol.
Anonomit #8
Posted 27 September 2012 - 04:54 PM
I JUST started trying out Computer Craft and I found this program. I have installed it and it was working fine but then I fixed the ground a bit where it dropped a level. After I did this I hit "r" and he went on another round. However, ever since then he only takes 2 logs per tree and leaves the rest for me to clean up. I did not alter any of the code so I am no sure what might have happened.

Possibly it is connected to lag as that is an issue for me. I run a single core processor right now, no hyperthreading, 2 GB ram. That's the max this laptop can hold. However, I also am the admin of a paid server that runs tekkit and that is the only place I play. The server does have 1 GB of ram. I am running the current Tekkit pack.

Thanks for any help on this.

That's strange. Is it possible that you accidentally moved the turtle to a different starting location? The turtle should harvest up a tree until the block above him is not wood. If he stops harvesting early, maybe there is lag, which could be making him check the block too soon. It's a theory. Could you try it out on single player and let me know if there's still a problem?
Anonomit #9
Posted 27 September 2012 - 04:55 PM
At least yours gets some logs all mine does is run into the tree and stop lol.

Hi Bushido, it sounds like your turtle is eaither not a mining turtle or doesn't have permission to break the tree blocks. If this is on a server, check with the server admin to make sure that the area isn't protected from players of minimum rank. perhaps he can OP the fakeplayer [ComputerCraft]?
Bushido #10
Posted 28 September 2012 - 02:39 AM
well im the admin of the server and it is a mining turtle so the only answer left is that the protection zone i have in place is preventing it from mining it thank you i feel stupid that i didn't think of that
Anonomit #11
Posted 28 September 2012 - 03:42 AM
If you're using worldguard, try using the command:
/rg addowner regionname [ComputerCraft]

If that doesn't work, try checking the turtle config file, and make sure the fakeplayer login is enabled. This thread explains why that's important: http://bit.ly/QJqXBF

EDIT: I forgot, it depends what your config setting is for fakeplayer whether you can op all turtles at once or have to allow permissions to each one separately
Cranium #12
Posted 28 September 2012 - 04:08 AM
If using residence, the command would be /res pset plotname [computercraft]turtleid flag true
Lost Ninja #13
Posted 16 October 2012 - 10:14 AM
Is it possible to have this work prior to getting going with wireless systems?

I tried just using the logger program on it's own but it just chops anything placed above it but does nothing else (and no helpful error messages either).

I don't want/need all the other wireless functionality. Just a turtle that farms trees. :/ (No criticism intended.) (And I'm too lazy/thick to write my own.)
slay_mithos #14
Posted 21 October 2012 - 10:02 PM
It is quite a nice script, even without wireless and all, but looking at the code, I found some strange things, like using only 9 slots and wasting 2 units of fuel per tree when cutting.

I wanted to know if you would mind that I change bits to accommodate with my own usage, or if I need to create a blank project for it.

To be honest, I just want a turtle to farm the trees, replant them, and deposit the wood, take some fuel if needed, then wait for 5-10 minutes and go again, with the startup script launching it, and this seems to be working well enough to save me part of the work.

No hard feeling if you decline, or find me rude.
Anonomit #15
Posted 24 October 2012 - 01:02 AM
Is it possible to have this work prior to getting going with wireless systems?

I tried just using the logger program on it's own but it just chops anything placed above it but does nothing else (and no helpful error messages either).

I don't want/need all the other wireless functionality. Just a turtle that farms trees. :/ (No criticism intended.) (And I'm too lazy/thick to write my own.)

This program is not updated for turtles that require fuel, sorry. It's intended of CC 1.3 (for tekkit use). It sound like that may be the problem you're experiencing.

It is quite a nice script, even without wireless and all, but looking at the code, I found some strange things, like using only 9 slots and wasting 2 units of fuel per tree when cutting.

I wanted to know if you would mind that I change bits to accommodate with my own usage, or if I need to create a blank project for it.

To be honest, I just want a turtle to farm the trees, replant them, and deposit the wood, take some fuel if needed, then wait for 5-10 minutes and go again, with the startup script launching it, and this seems to be working well enough to save me part of the work.

No hard feeling if you decline, or find me rude.

By all means, edit away! Feel free to post any improvements if you'd like. I may end up making one from scratch eventually to weed out the bugs that have cropped up recently.
slay_mithos #16
Posted 25 October 2012 - 09:36 PM
I made two changes to the program:

The first being I changed the harvestTree a bit to prevent the down() dig() forward() up() that wasted 2 fuel for each tree, replaced by a simple dig() forward() digDown(), and changed step to 3 for the rest to continue working as expected
    local function harvestTree()
		   
		    steps = 3
            turtle.select(3)
            if turtle.detect() then
						    turtle.dig()
				    end
				    while not turtle.forward() do
						    turtle.dig()
				    end
            
            turtle.digDown()
            turtle.select(3)
            tryMove( "up" )
            
		    while turtle.compareUp() do
           		 tryMove( "up" )
				    steps = steps + 1
                    if steps == 20 then
                   		 break
                    end
		    end
		    turtle.select(1)
		    while steps > 2 do
                    turtle.select(1)
				    tryMove( "down" )
                    turtle.select(1)
				    steps = steps - 1
		    end
            if outOfSaplings == 0 then
                    plantTree()
            end
     
    end

For my personnal use, I removed the while true at the end and replaced it with my standard "drop items and refuel" to make it loop every 5 minutes, but that is because of my personnal preferences, so I won't be imposing this on anyone, seing as your program, when used with rednet, is way more robust in its handling.
ChunLing #17
Posted 26 October 2012 - 02:53 AM
How about if the turtle spun around and dug in the various directions to try and catch some saplings (or errant logs from oak trees)?
Anonomit #18
Posted 26 October 2012 - 05:23 PM
I started work on a 1.4.1 version that makes use of the relatively newer APIs. I've previously wanted to keep this program compatible with 1.3, as this is the version Tekkit is running. When I get around to finishing, the turtle will be a lot smarter, and worry about fuel consumption. The 1.4.5 update added the transferTo() function in the turtle API, which will be extremely useful for sucking in saplings and not clogging up item spaces, but I'll see if I can make this work without it first. Maybe I'll have it check the running OS to determine what it can call, but if somebody's using a custom OS I would have to assume it isn't updated any farther than 1.3. Or I could ask the user to input the OS version if it's a custom one. I'll see how it turns out.
Taiine #19
Posted 27 October 2012 - 09:36 PM
Hello! I've been using this and am enjoying it very much and plan to include it in my soon to be tekkit playthough. However I ran into an issue.

The turtles are supose to stop sending out a redstone signal when all but the first two invatory slots are empty. However mine continue to send out a signal even when I remove everything from them.

I'm using redstone engines with advanced wooden pips to pull the items out, it works great as as soon and the turtle lands it powers the engines however it doesn't stop… leading to a few exploshions Is this a bug, or something I am doing wrong?
Anonomit #20
Posted 29 October 2012 - 02:19 AM
If I recall, the version right now (I guess I should start numbering them) has a couple options that may be the problem. Try pressing the 's' key to recreate the settings. If you have 'wait for full saplings' turned on, the turtle will continue outputting redstone until slot 1 is full of saplings. I personally don't recommend this option, but it does allow a degree more automation in cunjunction with buildcraft. Unless you're pumping saplings into the turtle, or plan to manually refill him every cycle, I suggest you leave that particular option turned off. The 'output redstone on cycle' option however, should, of course, remain turned on. Btw, what exploded? Anyway, let me know if this was the problem, and if it wasn't, re-post with your CC version and as much information on how to reproduce this and I'll see if I can figure out what's up.
Taiine #21
Posted 29 October 2012 - 08:12 PM
output redstone on cycle true
wait for full saplings false
and 5x5.
and use your logger programs to start them up from with in my base.

As for what went boom, it's one of my redstone engines. I heard the boom and thought one of my other machines had blown but they were all fine. After checking everything I went to the top of my cave where my farms located to find one of my four redstone engines had blown, with two others flickering from orange to red and the other red and about to blow as well. All due to the turtles not stopping their redstone signal when the turtles are empty and thus over working my engines.

if I tell it not to send out a redstone signel, then it never does when it stopsd and will sit there full of logs and not trigger the engines.

Heres a test set up I put together to try and sort out the issue. This is how it ius in my world, just minus the more proper spacing, sapling collection and pips going to my main storage.

http://i.imgur.com/7GN8M.png

and a close up.
http://i.imgur.com/qJN0S.png

Once the turtles have finished gathering wood and return, they land and with output redstone on cycle on, they will trigger the engines that thus pull out just the logs. But the output redstone does not stop once empty. If I have output set to no, then it sits there and does nothging.

So wasn't the output to stop when everything but the first two slots were full?

http://i.imgur.com/gwcLi.png
waiting a while.. bottomleft is set to not output redstone.. it returned and did nothinbg, still full of logs. the rest are now empty of logs but the output is still going.

http://i.imgur.com/h3EtH.png
and we are in the red!

Sat around for a while longer and..
http://i.imgur.com/LHYqq.png
Boom.
slay_mithos #22
Posted 29 October 2012 - 11:08 PM
Strange, a redstone engine is supposed to never blow up as long as it is attached to a wooden pipe…
I have some that suck on empty chests all day, and never exploded.
There might be something it didn't like with your pipes, but that sound more like a bug of BC than a turtle problem to me.
Taiine #23
Posted 30 October 2012 - 03:18 AM
Still.. the turtle is to stop outputting redstone once all but the first two are empty.. but it clearly is not.
slay_mithos #24
Posted 30 October 2012 - 12:12 PM
Well, in your case, maybe, but some might want to use that redstone for other purposes too (reloading, running an other computer, lighting a lamp, anything goes).
Taiine #25
Posted 30 October 2012 - 12:41 PM
So you're saying you changed it from the orignal code to not turn it off when empty?
Can't you add that back in as an option?
I did have mine in my base aqttached to lamps that would power on to tell me when each turtle was 'unloading'. but that of corse also wont turn off.

Bah trying to semi automate this with out the need of waiting for saplings just became harder >.<
slay_mithos #26
Posted 30 October 2012 - 02:37 PM
Err, I didn't change any of the original code apart from the cutting mechanism,and it's not in the pastebin.

What I am saying is that there are other ways than that to unload the turtle that are closer from what you need.

One example would be to disable the redstone signal and use buildcraft redstone gates or even autarchic ones to empty your turtles.

That said, I personaly prefer not to let the program run by itself, and I automated it an other way that keeps the first 3 slots (sapplings, dirt and wood), as well as the 16th that I use for fuel.

you could also try out the mod that adds a way to recharge the fuel level via IC2 energy, as the have to wait a long time anyway.

Ok, now I will try this out with fir wood, might be fun^^
RayceFarelle #27
Posted 12 November 2012 - 07:49 PM
I JUST started trying out Computer Craft and I found this program. I have installed it and it was working fine but then I fixed the ground a bit where it dropped a level. After I did this I hit "r" and he went on another round. However, ever since then he only takes 2 logs per tree and leaves the rest for me to clean up. I did not alter any of the code so I am no sure what might have happened.

Possibly it is connected to lag as that is an issue for me. I run a single core processor right now, no hyperthreading, 2 GB ram. That's the max this laptop can hold. However, I also am the admin of a paid server that runs tekkit and that is the only place I play. The server does have 1 GB of ram. I am running the current Tekkit pack.

Thanks for any help on this.

That's strange. Is it possible that you accidentally moved the turtle to a different starting location? The turtle should harvest up a tree until the block above him is not wood. If he stops harvesting early, maybe there is lag, which could be making him check the block too soon. It's a theory. Could you try it out on single player and let me know if there's still a problem?

Hi there,

I also face a similar problem. Before I install any programs on a server, I always run a preliminary testing on singleplayer, personal server and then post it up the public server. However, during the singleplayer testing, I encountered the same problem. Essentially, the wireless mining turtle would only collect 2 logs, 1 in its flight path and the other being the roots where the sapling is located. It will then plant a sapling where the root of the tree used to be and then continue down its flight path, ignoring the rest of the tree above it. No codes has been changed and all instructions on installing it has been followed to the word. Also, the turtle is initially placed on a wide flat land and was not moved from its initial starting point. Any help on this matter will be greatly appreciated as we look forward to have this program on the public server.

Best regards.
Anonomit #28
Posted 18 November 2012 - 11:54 AM
Hmmm, this must have to do with the turtle using the compare() function to tell if it has reached the top of a tree.Check if any items have made their way into slot 3. I think it uses that one to compare. I'm almost finished from-scratch, clean and updated one that should be a lot less error-prone. Remember to check back soon, I'll post it once I'm done the settings.
Anonomit #29
Posted 20 November 2012 - 04:25 PM
I finished the new program! Hopefully this one will turn out far less messy and error-prone.
Here it is: http://bit.ly/Q6zqCt