r/ComputerCraft • • Sep 27 '21

Turtle idea/help needed

Playing minecraft 1.16.5 with ATM6

So I have a base that I am trying to automate with turtles, specifically I wish to automate my rubber production.

The process is as follows: Harvest Acacia tree Place wood in front of fluid extractors, IF a block is not there. Plant acacia sapling. Repeat.

If this possible with LUA coding and turtles? If so can someone help me with the coding?

8 Upvotes

7 comments sorted by

View all comments

2

u/Chaosfox_Firemaker Sep 27 '21

Yep, perfectly doable. Acacia makes it a little bit tricky, but not too bad. I will be talking in pseudo code, rather than lua, but it should still help.

Initial state, acacia sapling in front, space to put the wood bellow.

while the sappling hasnt turned into a log yet

checck if theres a log beloow you, and if there isnt, place one.

dig then, forward

repeat until stop

check the block above you.

if its a log:

dig up

go up

else:

go up

stop

check all four sides:

do the previous repeat if there is a log. until all four sides arent a log

your turtle is now up in the sky and we want to get down. We could gps our way there. Or you could keep track whenever you move the turtle. or you could have everything in functions that undo themselves, just get back to the starting position. then have it place a sapling.

getting the saplings can be a bit harder, a common solution is to have the setup in a water pit that funnels all the dropped saplings in one spot for the turtle to pick up

burn the wood for fuel while your at it

3

u/IKnowATonOfStuffAMA Sep 27 '21 edited Sep 28 '21

A recursive function would be great.

Function acacia()
   Dig up
   Go up
   If acacia log above
      acacia()
   Else
      Check all four sides around turtle, even after finding acacia logs
      If acacia log is found
         dig towards it and move forward
         acacia()
         Move backwards
   go down
End

3

u/[deleted] Sep 28 '21

Recursive functions will eat up memory, a loop iteration will be better or a while conditional. Don't quote me, just bringing knowledge from ANSI C and C++, I know nothing about how lua handles recursion in depth.

2

u/IKnowATonOfStuffAMA Sep 28 '21

Generally, yes. But with turtles, it's usually less than 20-30 recursions and performance is irrelevant next to a turtle's movement speed. But that is a good point, we should be careful not to go too crazy with it.

3

u/[deleted] Sep 28 '21

I'm no pro, but its something to consider if you're machine isn't top of the line. I wouldn't want that many 'executions' running on a fleet of turtles.