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

Yet Another Quarry! My 3-layers-per-pass, variable-sized-hole excavator

Started by shiphorns, 01 February 2013 - 05:38 PM
shiphorns #1
Posted 01 February 2013 - 06:38 PM
Firstly, though I'm a career programmer, I'm a Lua noob and have only been using ComputerCraft for a week and a half as part of Feed The Beast. Like many before me, I got introduced to mining turtles by a co-worker who was using the TurtleOS excavate program to mine. I tried it too, and immediately saw the benefit. But what I also saw, is that it didn't do quite what I wanted. So, I decided to take a shot at writing a custom one. I wished to maintain reasonable backwards compatibility with 'excavate' for ease of use by those familiar with that program, so when given just 1 parameter (size) by program does a very similar thing (a square hole to bedrock). But here is what I changed:

What my Quarry 1.0b does differently from excavate:
  • It digs up to 3 layers in each pass, by taking advantage of the turtle's ability to dig forward, below and above itself. It's still fairly slow because it's the same number of dig operations, but it uses only about 1/3 the fuel of 'excavate', and is marginally faster. The fuel use is optimal if your quarry is a multiple of 3 layers deep, and you give the turtle plenty of fuel (see feature 3 below).
  • You can specify one, two or three dimensions for your quarry. If you supply 1 parameter, it digs a square that size to bedrock. if you supply 2 parameters, it digs a rectangle to bedrock with the length and width you supplied. If you supply all 3 parameters, you are specifying length by width by depth.
  • Slot 1 (upper left) is a designated fuel slot. You don't need to pre-fuel the turtle, though this is still an option for long unattended digs. The turtle will refuel from slot 1,1 fuel item at a time, on an as-needed basis, and will not dump from this slot until the end of the run. I personally stack lava cells in there and let 'er rip!
  • My quarry's bottom profile will not be as flat as excavate's because I make no assumption about how many levels bedrock exists on. This is for compatibility with worlds generated by non-Vanilla chunk-generation algorithms (such as MystCraft)
  • I heavily commented my code, so that others can easily understand what I did and make use of it.
Behavior that Quarry 1.0b has in common with excavate:
  • It digs the quarry forward, to the right, and down from where the turtle starts.
  • It expects a chest behind its starting position, to dump its findings and tailings.
  • It detects and attacks mobs using the same boilerplate movement code as excavate, extended to cover forward, up and down digging and attacking
  • It digs away sand and gravel, even if it falls from above after an upward dig.
  • It comes back to a chest behind its starting point to dump when full.
  • It returns to the starting point when it needs fuel (so no running out of fuel while under lava!)
  • It stops when it finds bedrock, can dig out under it, but knows how to back itself out.
What my program does not yet support:
  • Being selective in what it digs. This quarry program digs out every block, unlike AustinKK's. It does this because I don't just want ores, I want tons of netherrack for my magma crucible, and loads of cobble for my automated stronghold stone brick crafting setup. So I filter and sort after digging, using diamond buildcraft pipes.
  • Refueling from a chest. I didn't want to over-complicate things with second chest placement, and you can pre-fuel turtles easily with the built-in refuel program. Also, if you're on a server with IC2, a stack of 64 lava cells in slot 1 is enough to dig a massive hole (about 34 x 34 from y=64 down to bedrock on my 1.4.2. server where 1 lava is 1200 fuel).
  • Placing torches - looking into this.
  • Digging up (sorry, this quarry goes down, like excavate)
  • Surviving chunk unloads or server reboots. I'm looking into this, and checking out how to use 'startup' programs to bootstrap and resume from position-save files. That is a future update.
  • Dig shapes. I know how to dig cylinders and spheres, and I'm working on those programs now, using this simple rectanguloid digger as my code base.
Code is here: http://pastebin.com/PAPDddcb

Download from in the turtle at the prompt like this:
>pastebin get PAPDddcb quarry
unobtanium #2
Posted 01 February 2013 - 08:35 PM
Hello there,
this is very well documented, i have to say that i am impressed.
I really like the parameters the user can give the turtle.
Well done.
ughzug #3
Posted 02 February 2013 - 10:20 AM
very promising program; i look forward to its development~
shiphorns #4
Posted 04 February 2013 - 08:09 AM
Updated to 1.1b this morning, to fix a bug where turtle tried to return home at then end of the run using the wrong function (there was a call to moveTo(0,0,0) that should have been goHome()) This could result in the turtle getting trapped up against a block of bedrock at the end of the run, because it was trying to return home by moving laterally first instead of ascending first.
tssguy123 #5
Posted 05 February 2013 - 02:45 AM
Just curious, how does it know when it's reached bedrock? If dig returns false?

Edit: looked through the code and realized that is how… also, I can definitely tell you're a career programmer by your coding/commenting. Very good work!
theoriginalbit #6
Posted 05 February 2013 - 02:47 AM
Just curious, how does it know when it's reached bedrock? If dig returns false?
By skimming the code it seems its if there is a block there and it returns false 3 times.
shiphorns #7
Posted 06 February 2013 - 07:19 AM
Yes, if the turtle is up against bedrock, turtle.dig() will return false. Bedrock generally isn't going to move, so the retries should be unnecessary in this case; but I retry on a lot of failures to catch the cases where the false return value is either erroneous, due to server hitch or other unexpected situation, or in the case where there is a type of undiggable block I haven't accounted for that might move (or be moved by a player). I know that personal safes are such blocks (undiggable by turtle, moveable by owner) and also that there are permissions and anti-griefing mods that can make blocks undiggable and movable only by the owner.
unobtanium #8
Posted 06 February 2013 - 08:33 AM
What happens if it digs down but at all sides is bedrock? Does it go back up?
shiphorns #9
Posted 06 February 2013 - 06:28 PM
What happens if it digs down but at all sides is bedrock? Does it go back up?

Yes, as soon as the turtle finds itself either facing bedrock, or underneath it, it ends the quarrying and makes its way home. Because the turtle plunges down and digs from underneath, it also has a check for bedrock above itself; if it detects that it's under bedrock, it backs out and returns home.

Basically, the turtle ignores bedrock that's below itself, but as soon as it's in the way or potentially blocking the way home, the quarry run is over. If I were designing this for only a vanilla minecraft overworld, I could make an assumption about how many layers of bedrock there are and try to make the turtle dig down between all the bedrock from the layer just above, but I'm using this quarry program in the Twilight Forest, MystCraft worlds, etc.. and didn't want to make any assumptions about bedrock only being on the bottom 4 layers or anything like that. Worst case, the turtle leaves a some blocks unmined in the layer just above the bedrock. It's not all bad though, because if you're on Tekkit or FTB, you can get those last few diamond with a silk touch pick or rock cutter and macerate them for double the yield–in fact, I've been thinking about trying to make a quarry program that can specifically mine AROUND the good stuff like diamond, iridium and uranium, so that I can hand mine it with the rock cutter.
KitchenSink #10
Posted 09 February 2013 - 02:53 PM
I am VERY new to turtles, so if I'm missing something obvious, please forgive me.

I downloaded this program to the turtle, put a full stack of coal to test and started the program using 'quarry 3'. It goes for a while but when I come back to it, it is stopped, not very far down. Do I need to stay near it? It still has around 55-ish coal left when I get down to check it out…it is not full inventory, and has not ever been back up to the chest I placed on the surface for it.

Things I should check?
bukuskat #11
Posted 10 February 2013 - 02:08 AM
I am VERY new to turtles, so if I'm missing something obvious, please forgive me.

I downloaded this program to the turtle, put a full stack of coal to test and started the program using 'quarry 3'. It goes for a while but when I come back to it, it is stopped, not very far down. Do I need to stay near it? It still has around 55-ish coal left when I get down to check it out…it is not full inventory, and has not ever been back up to the chest I placed on the surface for it.

Things I should check?

If you left the loaded "chunk" it will stop, or log off you client. if you place a "world ancor" (railcraft) or a chunkloader (its in the direwolf mod pack (not sure of the original mod name)) in the area you should be alright untill the turtle digs down enough to leave the loaded area.
le nub #12
Posted 10 February 2013 - 07:39 AM
This looks really neat! Also, this is no biggie, on line 46 there is this line os.pullEvent("char")
this is only going to pull key character events and not "any key" as you described to start the program. Use os.pullEvent("key") to pull any event key press :)/>
shiphorns #13
Posted 16 February 2013 - 10:44 AM
I am VERY new to turtles, so if I'm missing something obvious, please forgive me.

I downloaded this program to the turtle, put a full stack of coal to test and started the program using 'quarry 3'. It goes for a while but when I come back to it, it is stopped, not very far down. Do I need to stay near it? It still has around 55-ish coal left when I get down to check it out…it is not full inventory, and has not ever been back up to the chest I placed on the surface for it.

Things I should check?

As noted, turtles stop running if the chunk they are in unloads. If you stay relatively close to the turtle, it will keep going, because logged-in players keep (by default) chunks around them loaded in a radius of something like 10 chunks (so 160m). If you want the turtle to run on SMP when you're not around, you need some kind of chunkloader mod working to keep the area loaded. On our FTBBETAA server, we use the railcraft World Anchors. A world anchor keeps the chunk it's in loaded, as well as the 8 surrounding chunks. So your turtle is safe to move and dig within 16 blocks of the world anchor, no matter where it is in the chunk. Chunks go floor to ceiling, so you don't need to worry about how high or deep the turtle goes.

For large digs, I use the world anchors and sentinels to define rows to chunks to keep loaded.
reenigne #14
Posted 19 February 2013 - 09:39 PM
This is a fantastically useful script! Thank you very much for sharing it! I currently have 4 turtles (1 in each of the cardinal directions) mining 100x100 quarries down to bedrock, the fuel savings over excavate is enormous!

However, as you have established that you are using this for FTB, I would like to suggest one addition that could significantly increase the speed and efficiency of you mine turtles:

Add in a few lines so that the turtle carries around a (properly color-coded) ender-chest, when the turtle gets full, it places the chest next to itself and unloads into the chest, then it mines the chest puts it back into its inventory and continues on its way, you cut out a significant chunk of the time and fuel that would otherwise be used for the turtle to get back to its home chest. I supposed the catch would be to make sure that the turtle does not try and place it into a spot that is filled by, for example, gravel or sand.

This may also assist in allowing you to create more esoteric shapes in the process of mining, as you no longer need a straight path back to the home chest.

Also, just to note, this idea is in no way original to me, there is at least one Direwolf20 episode where he does something similar, but in reverse, pulling building materials out of the chest (just to note it would be possible to refuel in this manner to by pulling fuel out of a automatically stocked ender-chest), instead of putting mined materials in. Likewise I've seen the concept implemented in other modded Minecraft videos too.

Finally: you note that you use world anchors and sentinels, however have you tired this with chunk-loading turtles? I could never get chunk-loading turtles to work with excavate, so I have yet to try it with this script.
shiphorns #15
Posted 20 February 2013 - 11:34 AM
Add in a few lines so that the turtle carries around a (properly color-coded) ender-chest, when the turtle gets full, it places the chest next to itself and unloads into the chest, then it mines the chest puts it back into its inventory and continues on its way, you cut out a significant chunk of the time and fuel that would otherwise be used for the turtle to get back to its home chest

I have experimented with this a bit, and I probably saw the same demo you did :-) The only reason I haven't gone this route so far, is because of how people on my server are using the script. People are mining with anywhere from 4 to 12 turtles going at once, and it works better to have the turtles "home chests" be diamond or gold chests to buffer the flow of goods. If this many turtles each had their own ender chests, and they happened to unload at the same time, it might not be possible for the extraction system back at the base to empty them quickly enough. With everything buffered by regular chests, it's easy to figure the required horsepower, and the whole system is scalable.

I have thought about another idea for minimizing home trips, which would be for the turtles to have a cobblestone reference block, and just dump cobble as they mine. As far as I know, they won't suck it back up like a player would, but I haven't tried this yet. This approach would reduce the amount of engine power required on the receiving end too, since there would be so much less stuff to pump. Many of us are just void-piping the cobble anyways.

What I'm not going to do is selective digging, like austin's script. We find a lot of iridium, diamond and other goodies in the exposed quarry walls, so it's worth it for us to make big empty holes. Especially true since we can manually mine out the iridium and diamonds with a silk touch pick or rock cutter to double the yield.
reenigne #16
Posted 20 February 2013 - 12:50 PM
What I'm not going to do is selective digging, like austin's script. We find a lot of iridium, diamond and other goodies in the exposed quarry walls, so it's worth it for us to make big empty holes. Especially true since we can manually mine out the iridium and diamonds with a silk touch pick or rock cutter to double the yield.

With larger plots open to the sky it's fairly easy to monitor their progress as they go down and swoop in and catch the iridium before they mine it, that's what I do. I'm using the mindcrack pack so it's also worth it to silk touch nikolite as you get half a diamond per industrial ground nikolite ore.

To minimize the chance of having my mining enderchests fill up all at once I have an array of collecting enderchests with 6 filters/per that filters out the crap stuff into a set of lava relays (RP2 void pipes), the good stuff gets put into a group of (non-lava) relays which connect a single color enderchest that is located in each of my sorting facilities where filters pull out the good stuff by category, minerals, organic, and so on, so all together I have enough filters pulling out of my master enderchest to empty the chest itself in a single tick. I'm switching over to routers though, they seem to be quicker, but cause less lag (although more expensive than filters).

Having the turtles dump useless stuff sounds like it could be a good idea, but how good it would be for performance would depend on how long you have your server set to de-spawn dropped items. too many dropped items that take too long to de-spawn could bring down a server.

I don't think turtles suck up items unless directly interacting with the item (IE: mining the item)

Also: Item Tesseracts, not sure but those may work better than enderchests (If they work with turtles at all). I haven't updated to the latest version of FTB with the latest version of thermal expansion, so I can't check to find out. If it does work though that would be the solution to any chest overloading problem, possibly.
MinecraftFarms12 #17
Posted 23 February 2013 - 09:12 PM
Yo Awesome Quarry I Have 3 Of them Running around my house and they are great execpt for the storage problems they create but who cares :D/> B)/>
ughzug #18
Posted 02 March 2013 - 09:17 AM
turtle gets stuck on return route when bats are in the way.

by in the way i mean bats at rest on the ceiling.
shiphorns #19
Posted 02 March 2013 - 10:49 AM
turtle gets stuck on return route when bats are in the way.

Interesting. I wonder if hanging bats are a special case mob that is detected with turtle.detect(). My goForward() code is pretty much boilerplate and the same as excavate's, which makes me think that hanging bats must return true for detect(), but then can't be removed with turtle.dig(). The only other possibility in terms of code flow is that they can't be killed with turtle.attack(), which seems less likely.

The code assumes that if a block is detected with turtle.detect(), that it can either be dug, or is an unbreakable block (e.g. bedrock). I'm not attempting to attack blocks that are detected, because no other mob is detected with turtle.detect() AFAIK. I could add an attempt to do turtle.attack() within the detect true block and see if that fixes it.
ughzug #20
Posted 02 March 2013 - 11:06 AM
i had left it running overnight, come morning i see the turtle facing a bat hanging upside down. upon moving the bat from the turtles path it resumed its drop off path. if its checking for mobs every movement then the bat must have settled in after the detect during the go forward command?
shiphorns #21
Posted 02 March 2013 - 11:51 AM
if its checking for mobs every movement then the bat must have settled in after the detect during the go forward command?

That's not the issue, because the function repeatedly calls turtle.detect() as long as turtle.forward() is returning false. What's more telling is the fact that the turtle resumed when you removed the bat. This changes the possibilities of what's happening; the bat's not being detected as an undiggable block, because that would cause the program to end. The likeliest scenario is now this:

- The bat is not detected by turtle.detect(), so turtle.attack() is called every iteration, but the bat does not get killed and removed so the turtle ends up stuck in the not turtle.forward() loop. If this is the case, I think it would be considered a CC bug. I'm going to see if I can find some bats and see what the various turtle API functions return when the turtle comes up against them.

EDIT: I can't reproduce it. I set up a turtle at the top of a room, spawn a bunch of bats from eggs, and when a bat hung in front of the turtle, turtle.forward() returns false, turtle.detect() returns false and turtle.attack() causes the bat to take damage and fly away allowing the turtle to move again. I don't see any way for the turtle to get stuck on a bat, at least in the version of the game I'm playing (FTB Beta A with CC 1.46)
ughzug #22
Posted 02 March 2013 - 12:59 PM
hmm its happened 3 times now on the latest dw20 smp map our server is running.

dw20 v5.1
ughzug #23
Posted 02 March 2013 - 10:17 PM
now that bats are no longer spawning i haven't had an issue. it only occurred when it was returning to the chest.
behedwin #24
Posted 16 April 2013 - 11:14 AM
how do i use the debug mode?

without entering a fixed depth?
m2pt5 #25
Posted 17 April 2013 - 08:58 PM
I'm running into a weird problem with this script; when the inventory is full and the turtle tries to go home to unload, I get this error:

"quarry:302: attempt to compare string with number expected, got string"

This appears to be related to fuel being "unlimited" and trying to compare it to the amount it has calculated to be needed to get home. I found the part where the error was happening and commented it out, then the turtle went home and unloaded, then had another error on line 439 where it tried to calculate fuel to return to its last location. I commented that out too, and now I'm waiting to see if it works.

Edit: Would it be possible to request a version of the script with the fuel slot/checks removed, for those of us who disable fuel requirements?

Edit: Errored again on line 351. Commenting that out too seems to have fixed it, as the turtle returns to the place where it became full and continues its pattern.
dkittrell #26
Posted 19 April 2013 - 09:59 AM
Hey ship, i just wanna make sure, ive used your quarry program for a few days, but ive only done Quarry 20 …. i wanna set a depth so would i do quarry 20 20 15 ? That would be same as quarry 20 but just 15 deep correct or does that mean is goes down to 15? I can easily test when i get home. im just at work and thought about it :)/>
rahk #27
Posted 02 May 2013 - 09:20 AM
I'm running into a weird problem with this script; when the inventory is full and the turtle tries to go home to unload, I get this error:

"quarry:302: attempt to compare string with number expected, got string"

This appears to be related to fuel being "unlimited" and trying to compare it to the amount it has calculated to be needed to get home. I found the part where the error was happening and commented it out, then the turtle went home and unloaded, then had another error on line 439 where it tried to calculate fuel to return to its last location. I commented that out too, and now I'm waiting to see if it works.

Edit: Would it be possible to request a version of the script with the fuel slot/checks removed, for those of us who disable fuel requirements?

Edit: Errored again on line 351. Commenting that out too seems to have fixed it, as the turtle returns to the place where it became full and continues its pattern.

Here is a modified version that fixes those few errors when fuel is set to unlimited. It should still work if you use fuel, although I haven't tested it with fuel.
http://pastebin.com/pnSK4pKt


Also here is one that hasn't been tested yet, but this should remove the prompt about fuel in first slot, and also remove the will not unload the fuel slot if you have fuel set to unlimited. It shouldn't change anything if you use fuel.
http://pastebin.com/G2mzvstM


Hey ship, i just wanna make sure, ive used your quarry program for a few days, but ive only done Quarry 20 …. i wanna set a depth so would i do quarry 20 20 15 ? That would be same as quarry 20 but just 15 deep correct or does that mean is goes down to 15? I can easily test when i get home. im just at work and thought about it :)/>

That means the hole would be 15 deep. Not down to level 15.
Moejo #28
Posted 04 May 2013 - 02:41 PM
Awesome program, pretty efficient on fuel, I use it to hollow out mountains for my base, and mine diamonds down in the deep. Haven't been able to break it yet.
ughzug #29
Posted 07 May 2013 - 10:57 PM
With ftb ultimate 1.01 I haven't had much in the way of issues but my server has been getting restarts lately, and having to run out and reset the mining team gets a bit tedious. Which begs the question, are there any plans to add additional features to this such as persistence and optional ender chest refuel/loot dump?
ratkinsonuk #30
Posted 12 May 2013 - 02:55 PM
I constantly have problems with turtles not returning to home properly, so I have to restart them mining. That means often moving through thousands of empty blocks before they reach the level they were at before they bugged out.

Is there any chance you could add some code that allows us to move the turtle down by n levels before mining, or even move down until you reach solid ground then mine would be more dynamic?

Thanks, Rob.
ratkinsonuk #31
Posted 12 May 2013 - 04:50 PM
I put this quick hack in before the main loop to do the above :-

while not turtle.detectDown() do
goDown(true)
end
djreisch #32
Posted 14 May 2013 - 04:42 PM
So I stick a chest behind it, put coal into it's top left corner of it's inventory and enter in the command "quarry 9 9 5" it asks to hit any button when I put the fuel in but then always gives me this error "quarry:62: attempt to call nil"

What am I doing wrong?
Ira Ludius #33
Posted 10 June 2013 - 02:38 PM
Thanks so much! Works like a charm.
Ira Ludius #34
Posted 10 June 2013 - 02:39 PM
So I stick a chest behind it, put coal into it's top left corner of it's inventory and enter in the command "quarry 9 9 5" it asks to hit any button when I put the fuel in but then always gives me this error "quarry:62: attempt to call nil"

What am I doing wrong?

Line 62 is the turtle.getFuelLevel() function, so make sure you're using the correct version of CC.