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

Treefarm without chunkloaders

Started by henkekalmar, 15 July 2014 - 08:42 PM
henkekalmar #1
Posted 15 July 2014 - 10:42 PM
What I'm trying to make: I'm trying to make a treefarm that doesn't rely on a loaded chunk and will re-boot itself when a player goes back into the area and continues where it left off. Before this project I had only ever done little within lua as in a 10 lines codes. So forgive me but the code is most likely very messy and don't make sense at places. ( for example me doing a os.sleep at weird places. ) - The program is tested with birch wood.

How it's going to do it: at the turtles " start "he would stand ontop of a chest which would become the chest for all the wood. to his left would be the chest for the saplings and in front of him the sapling/tree would be. If he happens to have been unloaded while digging down a tree he will also detect if there's no block under him and make sure the tree is all cleared out and then go down to replant the sapling.

My problem with the program:He just straight up isn't working, he dug down a tree once but he fails to detect when it's grown and he doesn't place items in chests nor does he replant the sapling. I probably made big mistakes in my code as I mentioned I'm very new to this.

http://pastebin.com/aDhGggji
hilburn #2
Posted 16 July 2014 - 12:00 AM
The problem starts with your concept really, if the turtle assumes that it is on top of the chest at the start of the program, when the chunk unloads and reloads it will assume that wherever it is is just above the chest.

I think I have an old rubber farm code which worked in on a server with limited chunkloaders (didn't have one spare for the turtle) which might be adaptable for a full tree farm, but basically to do it without breaking you need to have a) turtle persistence implemented, ie the turtle knows where he is and chooses his actions based on that rather than anything else and saves that location data to survive between restarts. This is quite hard to do well. The alternative is b.) getting it to first return to the chest and then restart the farming cycle, this is less efficient but MUCH easier to do.

If you stick a redstone torch below or next to where the turtle sits next to the chest that is quite an easy confirmation of location, and a start action of Go to ground level (down as far as we can go), go as far west as we can go and then go as far south as we can go is pretty easy to implement by putting a 1 high wall around the farm. If you don't have GPS another solution is go to the ground, go forward until hit wall, check for redstone, while no redstone turn left and go forward until wall. When you are back over the redstone you are then next to the chest and can then restart the actual tree farming code.

Your tree farm code itself.. I'd need a bit longer than I have to spare right now to fully work through it and look at why it's not working, sorry.
Edited on 15 July 2014 - 10:01 PM
Bomb Bloke #3
Posted 16 July 2014 - 03:17 AM
My problem with the program:He just straight up isn't working, he dug down a tree once but he fails to detect when it's grown and he doesn't place items in chests nor does he replant the sapling. I probably made big mistakes in my code as I mentioned I'm very new to this.

What DOES it do? Sit in place, never moving? Throw an error? Spin at random? If it moves for a while then stops, at what point does it stop?

I've a hunch it's out of fuel. Your fueling function is 1) not defined unless the "if" statement on line 54 evaluates as true and 2) never called anyway.

By the way, you could shrink this down a lot with some more loops. Consider what can be done with "while turtle.compare() do", or, for descending, "repeat until not turtle.down()".
henkekalmar #4
Posted 16 July 2014 - 09:35 PM
@Bomb bloke - I fixed the fuelling function once I was ingame, I forgot to update the pastebin. The turtle is running and doesn't stop, it just acts very werid in general - For example if you Place it down and start the program while there is a tree already infront of it it will dig it and then go down but it will not put items in chests. If you Place it down with nothing infront of it it won't do anything atall, same if there is a sapling that later grows into the tree it fails to detect the tree and to cut it down. - So no there are no errors ( and the fuel isn't the issue since I was using a labeled turtle that was already fuled up Before I starte.d )
I know it's possible to shrink down the code alot but as I said I'm very new to this, but thanks alot for mentioning that I will run some tests and try that out in other programs :)/> cheers

@hillburn I'm not really trying to have it detect it's location rather I'm having it reset to it's starting location if it has stopped in the middle of digging down a tree
Let me explain the general idea of the program in more detail and how I want the turtle to think:
By having it firstly see if there's a log ifront of it, if it isn't it will dig up and go up and see there. Again if there's no log there that means the turtle couldn't have left a tree unharvested. so if they all end up negative it will go straight down to the bottom since the turtle only moves in the Y axes. Once down to the buttom it will spin around until it detects a chest ( since there should be a chest to the turtle's left side ) and once it has it will check if it has any saplings in it's inventory and if not it will take some from that chest and turn to the right where it then should be pointing the dirt block, it will place the sapling down and wait for it to grow.
so if I have a code like this I can't think of any point where it wouldn't be able to reset itself, if I would load the chunks when it's waiting for the tree to grow it won't detect the " unfinished " tree since there would be a sapling infront of it not a log, it will attempt to go up and check there but will end up negative. It will go all the way down which it can't do because there's a chest under it preventing it to.
GPS is a valid and maybe easier but I just decided not to go with that when I started this :P/> - Making a key block is a great idea but I don't think it will be needed here since if it detects a chest below it there is only one possible location where it could be, same if it was infront of it.
- Not heard about that rubber tree farm you're talking about.
hilburn #5
Posted 16 July 2014 - 10:20 PM
Ahhhhh ok I gotcha, I was unclear as to the design of your farm, mine was a big 10x10 tree monstrosity (do NOT ask why I needed so much rubber) with 4 spaces between each tree which is why I needed to find the base station, and there's a very good reason you won't have heard about that particular code, I wrote it :)/>/> But yeah, if you are just going up/down to a single spot then yeah you don't need that.

btw a possible issue, I am not sure but I think a turtle's presence in a block adjacent to the sapling might prevent it growing, I'm not sure though.,

If I understand your code you want to do something like this (please forgive my terrible pseudocode)


function checkup()
  if check forward == wood then dig forward end
  dig up
  go up
  check forward
  if wood then
	checkup()
  else
	godownall()
  end
end
function godownall()
  while true do go down end
  plantsapling()
end
function plantsapling()
  if nosaplings then
	 pick up sapling from chest
  end
  plant()
end
function plant()
  turn to dirt
  place sapling
end
while true do
  checkup()
sleep(20)
end
Edited on 17 July 2014 - 08:52 AM
Bomb Bloke #6
Posted 17 July 2014 - 03:16 AM
if you Place it down and start the program while there is a tree already infront of it it will dig it and then go down but it will not put items in chests.

Your "reset" sequence does involve cutting down a tree, but does not involve dumping items into your chest. Really I recommend taking out the tree-chopping code from that part of the script and concentrating on getting the turtle to ground level ASAP. If you're planting regular saplings, they should be able to grow over any existing foliage that's left over anyways.

If you Place it down with nothing infront of it it won't do anything atall, same if there is a sapling that later grows into the tree it fails to detect the tree and to cut it down.

Your "reset" sequence also involves going downwards ten times (line 45). If this isn't possible (eg because the turtle is already at ground level), the turtle will keep trying forever (line 19) and never move on with the rest of the script.

Try replacing 45 with "repeat until not turtle.down()".

(do NOT ask why I needed so much rubber)

A chunk-sized farm really does produce insane amounts of the stuff. I like to use it with an Igneous Extruder to make stone torches. I wonder if it's possible to make actual blocks out of it yet… I'd build rubber jumping castles…

btw a possible issue, I am not sure but I think a turtle's presence in a block adjacent to the sapling might prevent it growing, I'm not sure though.

Nah, that's not an issue.
hilburn #7
Posted 17 July 2014 - 09:20 AM
I wonder if it's possible to make actual blocks out of it yet… I'd build rubber jumping castles…

Unfortunately not, slimy trees however… :)/>