<Turtle> (Force) Tree farm *needs testing*

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here
  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

Hoff

Tech Support
Oct 30, 2012
2,901
1,502
218
Alright so I'm working on a (Force) Tree farm script for a turtle. It's still very early in development and as such has only one mode, no interactive options, and you have to build the area yourself :p. As well this program only handles trees that grow in 1x1's(Force trees, birch, apple orchard tree etc).

This program also does not maintain persistence through reboot/crashes/chunk unloading.

Well that's the nitty gritty of it. I'm looking for people to use/test it to find anything it has trouble with, moving to the wrong spots, etc.



Setup
The area looks like this(Minus the 3 random turtles, cobble building, etc):

RdfVNqJ.jpg

19x19 one deep with the corners raised(For placing water and kewl looks :3), and a hole in the center. The dirt blocks are raised to have one space between themselves and the water in a 5x5 pattern with two blocks of air separating each block of dirt.

To fill the water in(You could also use conveyors if you feel fancy) place a 2x2x1 of blocks in each corner then fill in around the edges making it all source blocks. After that break the previously placed blocks and place a bucket in the raised corner.

The turtle station:

nqbfkKp.jpg


8n7pwrU.jpg

This must be large enough to contain the two chests on the right, the ender chest, and the lever. It is placed one farther back than the wall of the capture zone. The ender chest spot is for fuel. The lower diamond chest is saplings and the one above it is bonemeal. Ignore the pipes in the image for now.

The pipes are very simple. One obsidian pipe touching the middle dirt block with golden pipes back to the turtle station.

XEIYthB.png

The pipes under the turtle and chest:

GiHJhw4.png

From left to right. An obsidian pipe two below the turtle(One space of air) so it does not connect to it. Gold piping leading to an iron pipe. This iron pipe is where the turtle drop off and the collection zone meet. You can move this around however you see fit. From there above it is a diamond pipe. The pipe has 3(4) parts to it. The red bit sends the saplings to the left back into the diamond chest and if full into a void pipe(deal with overflow how you wish). The light green goes to two barrels for force logs and nuggets. The void pipe on top is for anything that might get in the mix not sorted(And the other pipe that does into the plain chest is for eggs since a chicken got in :p).

After setup for the farm currently you must have at least 25 saplings(40 recommended) and bonemeal for as long as you want it to run(I'll add an option not to use it later!). Fuel too of course. The lever can be activated to put the turtle to sleep until activated(10 second sleep time so give him some time to wake up after turning on!).

Anyway...

http://pastebin.com/DL3CAaDL

pastebin get DL3CAaDL ForceFarm


So yea testing and feedback is appreciated.

8/12/13: Release

8/12/13: Updated missing code for last tree of each row
 

Symmetryc

New Member
Jul 29, 2019
317
0
0
I haven't looked through the entire thing, but I'd highly, highly advise you to localize all of your variables. Not only for good practice, but also so that you're variables won't interfere with other programs. Another good practice is to define your functions just like you would any other variables, like this:
Code:
local myFunction = function(thing)
  print(thing)
end
 
  • Like
Reactions: Hoff

Hoff

Tech Support
Oct 30, 2012
2,901
1,502
218
I haven't looked through the entire thing, but I'd highly, highly advise you to localize all of your variables. Not only for good practice, but also so that you're variables won't interfere with other programs. Another good practice is to define your functions just like you would any other variables, like this:
Code:
local myFunction = function(thing)
  print(thing)
end

Yea this is more of a proof of concept. This is a very very basic outline of what I want the program to do. I was going from something I was just toying with on a server to wanting to make it available for anyone.

Also I don't actually know lua and am just going off of stuff I already knew :p
 

casilleroatr

New Member
Jul 29, 2019
1,360
0
0
Nice program, although it might be better to instead of having 1 function for each row, have 2 functions, rowLeft() and rowRight() because 1,3,5 and 2,4 were the same. Also, if you wanted to make this set up expandable in terms of rows then here is an idea.

In the main program bit at the end when you are calling the row functions, you could call them inside a for loop where if the counter equals an even number you use the turn left function and if its an odd number the turn right function. Then it might be easier to increase the size of your farm. If I recall correctly it goes something like this (I'm using the renamed functions that rowLeft() corresponding to secondrow() and fourthrow() and rowRight() for the others).

Code:
for i = 1,5 do
  if (i %2 ~= 0) then
      rowRight()
  else
      rowLeft()
  end
end

I think I got the if the right way round but if it your turtle starts going the wrong way just change the ~= to == and I think that should solve it.[DOUBLEPOST=1376368987][/DOUBLEPOST]Also, I was just looking through your code again. Have you checked the refuel function fully yet. I think that if the turtle does not get any fuel it will crash. Making it sleep before running the loop again would be good. Same with getBonemeal() and getSaplings()
 
  • Like
Reactions: Hoff

Symmetryc

New Member
Jul 29, 2019
317
0
0
I think the 5th row is actually a bit different than the other's, but for the first 4, you can actually compact them down into one function ( that's less lines than the originals, too! )
Code:
local dorow = function(dir)
  for i=1, 4 do
  tree()
  end
  plant()
  bonemeal()
  cut()
  forward()
  turtle[dir]()
  for i=1, 3 do forward() end
  turtle[dir]()
end
 
for i=1, 4 do
  dorow(i%2==1 and "turnRight" or "turnLeft")
end
 
  • Like
Reactions: Hoff

Symmetryc

New Member
Jul 29, 2019
317
0
0
Also, it appears that you can compact down the forwardtest function to this:
Code:
local forwardtest = function()
   forward()
   turtle.back()
end
Incase you're interested, this is how I got to it:
Code:
function forwardtest()
   while true do
      if not forward() then --> forward always returns true, so no need for this if statement
         turtle.back()
         break
      end
   end
end
 
function forwardtest()
   while true do
       forward()
       turtle.back()
       break --> this is always going to break after one run, so no need for this while statement
   end
end
function forwardtest()
     forward()
     turtle.back()
end
 
  • Like
Reactions: Hoff

casilleroatr

New Member
Jul 29, 2019
1,360
0
0
The Code...
I didn't know you could change between turtle.turnRight() and turtle.turnLeft() within the function arguments. Is it that the turtle api (and the others) is stored as a table and the string is the key. I have never thought of it that way. That will help to simplify some of my code further. Thanks! I love computercraft threads.
 

Symmetryc

New Member
Jul 29, 2019
317
0
0
I didn't know you could change between turtle.turnRight() and turtle.turnLeft() within the function arguments. Is it that the turtle api (and the others) is stored as a table and the string is the key. I have never thought of it that way. That will help to simplify some of my code further. Thanks! I love computercraft threads.

It's actually not the function arguments, I'm changing the key of the table. Ex:
Code:
local t = {
  aa = function()
    print("1")
  end;
  ab = function()
    print("2")
  end;
}
local str = "a"
t[str .. "a"]() --> 1
t[str .. "b"]() --> 2
But yeah, all APIs are just tables :p
 

Hoff

Tech Support
Oct 30, 2012
2,901
1,502
218
Also, it appears that you can compact down the forwardtest function to this:

It won't return true if it can't go forward :p

Some of the functions are from toying around with trying to get the turtle to play nice with a golem so they're kinda just fluff atm. Still trying to decide if I want to use them(I was giving the turtle a block behind wherever it needed to plant so that it would always move to that block then back one to plant. The farm was arranged much different than the current :p).

But otherwise thanks a ton guys. Working on actually learning at least something about lua. Tables are completely new to me :3
 

sks0315

New Member
Jul 29, 2019
135
0
0
I can see some improvements to be made, but cool!

Only if MFR can handle force trees(but multifarms can)
 

Symmetryc

New Member
Jul 29, 2019
317
0
0
It won't return true if it can't go forward :p
Uhhh yes it will...[DOUBLEPOST=1376448515][/DOUBLEPOST]
But otherwise thanks a ton guys. Working on actually learning at least something about lua. Tables are completely new to me :3

Hehe if you ever want, I can give you a complete tutorial (on what I know at least) in a PM or something :).
 

Hoff

Tech Support
Oct 30, 2012
2,901
1,502
218
Uhhh yes it will...

OH ROFL. It's not supposed to be forward() it's supposed to be turtle.forward() rofl. I wrote that before actually using it(Or writing the forward() function) so I guess I just forgot the turtle part.

Hehe if you ever want, I can give you a complete tutorial (on what I know at least) in a PM or something :).
If I get lost in the code at some point(I most definitely will at some point) I just might :p
 

Symmetryc

New Member
Jul 29, 2019
317
0
0
OH ROFL. It's not supposed to be forward() it's supposed to be turtle.forward() rofl. I wrote that before actually using it(Or writing the forward() function) so I guess I just forgot the turtle part.

Ah, OK, that makes a lot more sense :p.

If I get lost in the code at some point(I most definitely will at some point) I just might :p
Yeah, feel free, when I was starting out, I looked through the Lua docs and I found somethings that I couldn't really swallow and I needed to talk to someone to explain how somethings worked in simple terms, so I can understand if you're encountering trouble at some point. :)
 
  • Like
Reactions: Hoff