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

Simple quarry/treecut programs with enderchest

Started by Zaflis, 18 January 2014 - 09:20 AM
Zaflis #1
Posted 18 January 2014 - 10:20 AM
I am new to computercraft and LUA, but not new to programming. I totally refused to even try other programs cause i like to experiment with these things :P/> It's like a game on its own. Anyway, i have gotten 3 turtle programs to so stable state that i can show them to you. They all use similar code with minor differences.

Turtle inventory slot 15 is for charcoal enderchest. It assumes you have other same color coded enderchest somewhere to keep the chest always full.

Inventory slot 16 is for another enderchest, used to dump all loot away to your sorting system. Resume should work on Quarry and Orequarry now. Use startup program to automate it, or manually type without parameters "quarry" or "orequarry" to resume them, whichever program was running.

1. Quarry
http://pastebin.com/aDaDM2Kr

#####
#####
#####
####^
Place turtle in bottom right corner of quarry you want, and it will head forward from there. If started with command "quarry 20 40", it will dig width 20 and depth 40 size quarry all the way down to bedrock. Will dig everything in its path and attempt to also suck in dungeon chests, because i noticed that dig() will not break full chests. Turtle will be moving in "S"-pattern and digging blocks front, up and down, then moving 3 rows down and so on.

You can use more specific commands like "quarry 2 3 100" would dig 2 wide, 3 high and 100 blocks deep tunnel.

Turtle will continue until the quarry is entirely digged, and then come back to where it started. It will occasionally place enderchest on top of itself to empty inventory, dig it back and carry on. Same for fuel.

2. Orequarry
http://pastebin.com/JaJQcv4q

Inventory slot 1 is used for 1 stone block (cobblestone won't do) so it knows to not dig them if possible.
Works similar to 1.Quarry program, but will not dig stone from up or down. This turtle will come back directly, most likely digging some things left blocking the way.

3. Treecut
http://pastebin.com/LVYDbAzc

This one is simple to use; place in front of a tree and tell it "cut"… and it will cut the entire tree down :lol:/> It starts by measuring depth of the tree by digging hole through it. At this point it knows min and max Z, so now it comes back half way and digs right. Assuming that tree width and depth are same, once it detects empty block, it has determined min and max X aswell. (NOTE: grass or dirt blocks may confuse it, thinking they are part of tree too, so have the ground around tree levelled). Now it goes back to middle and cuts to treetop, goes minX, minZ and starts script similar to 1. Quarry.

This will cut any size of trees, 1x1, 2x2 or even giant 13x13 redwood trees (i know it works cause my turtles have cut over 7 of them so far). It will leave branches there though…

Extra note on treecut program; the script ends by moving itself to where it started from. But the way i did it is using a bit more sophisticated function, it could in the future be used in all movements of these programs. You can tell the function to move to any coordinate (relative to where it started from), and it will automatically turn and move in efficient way.

4. Startup
http://pastebin.com/fLpm3c9g

Startup program will take care of resuming work on chunkloading or server restart. Potentially supports all 3 above programs, but at the time of writing this, only 1. quarry program supports resume, and is still being tested for bugs.

Finally

And don't forget to put up a chunkloader to cover the entire work areas. Turtles are very lightweight for performance, when compared to buildcraft quarrys, but if you put 4 turtles each dig 32x32 areas, that's 64x64 quarry overall and very cheap to make. This is what i get with such:
[attachment=1446:ores.jpg]
There are 4 thermal centrifuges with 3x overclocks processing that chest… they can't keep up in the turtles pace!
Edited on 21 January 2014 - 05:41 AM
Bentenmaru #2
Posted 18 January 2014 - 12:20 PM
Should really try and learn programming with LUA, but are a total noob when it comes to LUA and programming, thankfully i have you on the server to do the coding and trying :D/>
Zaflis #3
Posted 20 January 2014 - 06:18 AM
Quarry and Orequarry should now resume their work automatically. This requires the 4th program to be named as "startup" in the turtle's folder. If you have another startup program, all you need to do is call "quarry" or "orequarry" without parameters if files "_status" and "_area" exists.

I did many tests with chunkloading, and i can still find it misalign itself sometimes. But it remembers its variables well, and should come back to surface, even if it's not exactly spot it started from. I am writing the status file exactly after turtle.forward() command and changing position variable, so i don't even know what to do to improve it, other than some gps system. But the way i setup quarries might be travelling thousands of blocks away from base and then setting it teleport waypoint there… No gps signals carry the whole world, so that "fix" would fail in theory already.

But the resume, even if it works in only 95% of times, is still good to have there for those unexpected server restarts. I expect there to be chunkloader anyway, or i won't be getting any ore back while playing.
Zaflis #4
Posted 03 February 2014 - 10:05 AM
I guess a screenshot of the turtles in action helps giving some idea on what this program does. This is the basic "quarry" program in action with 4 mining turtles, each digging a 32x32 area. By this screen you may imagine what "orequarry" looks like, basically digs only 1/3rd of what this does, focusing on just ore and what it needs in order to move forward.

surferpup #5
Posted 03 February 2014 - 10:48 AM
Nice work. I agree with you – it is a blast to create your own programs, and it looks like you are off to a fantastic start.