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

Shaft miner v1.71 is out! Now with more code and less bugs!

Started by PROdotes, 04 September 2012 - 05:51 PM
PROdotes #1
Posted 04 September 2012 - 07:51 PM
So, after 3 or 4 days now, here's what the little guy can do.

shaft init
this mines a 2x3x2 hole and waits for you to place down a chest to prepare the area for mining.

shaft help
displays a ton of help info

shaft left
digs 5x3x2 blocks to the left, telling you if you forgot to remove the chest (or if there's a block where a chest should be) and then positions itself 4 blocks left from the position it was so you can start a new shaft

shaft right
same thing just without the chest and to the right

shaft length height blocks
this is the main part of the program.
length is the (duh) length of the shaft you want, it goes from 1 to whatever
height is the height of the shaft, by default it's 2 if you just type in the length and it goes up to 60
blocks is the number of blocks in the inventory that will serve as "don't mine this". it goes from 0 to 10 (but 0 might make the turtle go crazy) and is 3 by default, if you don't type in 3 numbers.


the turtle also places down torches every 8 blocks and unless someone jumps infront of him while he's in the process of mining, he should always get back since it he can't move it goes into sleep mode until he can.
it's now also smart enough to ignore bedrock if it finds any but if it's in his main shaft he will go crazy. so ALWAYS start mining at 5+ height to avoid bedrock in a straight path.

and that's about it.
if you have any ideas on how to add onto this, feel free to comment since i'll soon be running out of ideas :D/>/>

edit: changes in 1.7
1. refuel command is now a lot smarter… just trust me on that one :P/>/>
2. made it smarter in collision detection, only way to break it now is to jump on top of it while it's mining a shaft or if it hits bedrock in the main shaft.
3. added option to find it's way back home in case of chunk unloading.
for this to work, you'll also need the startup script
http://pastebin.com/A5X6DuZS
or just "pastebin get A5X6DuZS startup"
4. this is now 95% foolproof i hope :)/>/>
5. unless people really want something specific or someone reports a bug, I think this will be the last update. Only option I might consider adding in 1.8 is auto-branch mining… but having an input look like "shaft 50 4 20 2" is already kinda complicated to use ;)/>/>
edit: changes in 1.71
fixed 2 bugs that caused the turtle to nor properly backtrack. sorry about the derp :)/>/>
also, if you're using 2+ turtles at the same time, the unloading portion of the code will not work since I made them write to the same file. fixable but not critical :)/>/>


pastebin link:
http://pastebin.com/QwkJfVad version 1.71

http://pastebin.com/3EPSHvn2 version 1.7

http://pastebin.com/CTGHjq4Z version 1.5


or you can use "pastebin get QwkJfVad shaft"

big thanks to RandomHavoc for the bedrock suggestion :)/>/>





things to consider adding:
building access to a mining shaft with ladders (straight down 1x2)
building access to a mining shaft with stairs (down diagonal with 3 headspace and stairs)
option to go send it dig X deep
option to dig a quarry X,Y,Z in size
option to dig a quarry underground, starting N deep, X,Y,Z in size
smarter refuel (in case someone tells it to mine a desert) done!
smarter pathfinding (in case someone tells it to go mine a quarry or shaft starting from lvl 5 or lower)
cave exploration mode (if it hits a cave currently it just ignores it cause of pathfinding and refueling issues)
PROdotes #2
Posted 06 September 2012 - 05:21 PM
edit: this is the old 1.1 version

There we go, updated the text and added the new version… you can check it out at http://pastebin.com/qJEwQBMb
It's almost 400 lines of code, almost 9000 characters… and almost 2 days of work… (well… 2 days with a job and RL hehe)
edit: new link, it's not over 500 lines of code, over 11k characters and still 2 days of work :D/>/>
PROdotes #3
Posted 08 September 2012 - 04:37 PM
40 hits on pastebin i see…
so if anyone is actually using this, question…
should I add an option or maybe change the code so the turtle does this…
input would be current level of the turtle, level to mine at and how high to mine…
so, example… "shaft 65 12 2" would tell the turtle: ok, you're now at height 65… dig down to level 2 and then start mining a shaft 2 high… it could be an optional thing… like "shaft down 65 12 2" executes it… and just "shaft 50" mines a 50 long shaft… or you have to say "shaft normal 50" for the normal version… that would also mean that the first argument would always be a word…

I'm just contemplating what I usually do when i mine and try to make the turtle do my job… but different people have different needs…
maybe you can even do "shaft ladder 65 12 2" and it would make a 1x2 hole while going down and put down ladders for you to use…
or maybe "shaft stairs 65 12 2" and it will go diagonally and make a staircase to level 12 and then start mining a shaft…

I pretty much want this little guy to be my 1 and only turtle for mining… that means, eventually he'll also be able to make a quarry… but I want to start with the easy stuff and make functions as I go…
For later on, when i start learning rednet, the plan is to make a sorting/retrieval system. 1 input and 1 output chest and the option to tell the turtle "sort" and it empties the input chest and puts the items it doesn't know into the output chest when it's done. option "add [item name]" where it will check if that item name already exists in the system, if not, it will ask you tu put at least 1 item into the inventory and then allocate a new place for that item in the sorting room. And option "retrive # [item]" where it will retrive a certain number of that item from the system, and tell you if you're out.

Maybe even "check [item]" for it to go and check how much of the item yuo have left and give you a simple "you have x [item] left"…

yea… i'm bored… can't play gw2 all the time when i'm not working ^^

also, PS… i have to rewrite the mining code soon… stupid recursions…
RandomHavoc #4
Posted 08 September 2012 - 06:33 PM
I've been playing with it a bit, but there was no check for bedrock in the version I tried so when the turtle followed an ore vein down to bedrock it got stuck repeatedly trying to mine a bedrock block. That sort of makes it useless for my style of mining, as I frequently run into bedrock while searching for diamonds. I could rewrite it to check, but at that point I'd be better off just writing my own mining code from scratch. Overall a good program, and does a good job at what it does do.
PROdotes #5
Posted 08 September 2012 - 06:51 PM
hm… yea… i never mine at bedrock spawn height, always above… fix is pretty easy but it deppends how deep you mine… i guess i could add a few lines into the digAndMove() and maybe the mineUp() function… but how deep do you actually mine? :D/>/> since bedrock spawn at headheight 6.6… so 4 and below…
RandomHavoc #6
Posted 08 September 2012 - 06:55 PM
hm… yea… i never mine at bedrock spawn height, always above… fix is pretty easy but it deppends how deep you mine… i guess i could add a few lines into the digAndMove() and maybe the mineUp() function… but how deep do you actually mine? :D/>/> since bedrock spawn at headheight 6.6… so 4 and below…

Generally when I mine I start my first branches at lvl 8, and then every 3 blocks above that. That makes the floor block lvl 7 so following ore even 2-3 block deep can lead you to bedrock. It's just my preference, but I actually prefer running into lava lakes as I use obsidian as a building material, and lava as a lightsource in my construction.

Also worth noting, at y:10 and below in my experience ores can daisy chain together quite a bit, so following a coal vein can lead to a gold vein, can lead to a redstone vein, can lead to an iron vein, etc, which can also take you fairly deep compared to where you started.
PROdotes #7
Posted 08 September 2012 - 07:07 PM
yea… the current code has a problem… then it runs into a huge ore vein it's constantly calling itself until java crashes…
but i see where the problem is… it doesn't know how to handle bedrock… it ignores slots 16-x and bedrock is not in them so it tries to mine it, thinking it's something precious…
should not take more then 30 minutes to fix since i know the code… but I'll start to rewrite some of it once i'm done eating to not crash on large veins, and then implement bedrock handing…
I'll also add an option to customize the shaft height so people can put it to level 5 and tell it to go 10 high… that way it should get all diamonds in a row…

and then i'll release version 1.5 i guess :D/>/>

ty for the input ^^
RandomHavoc #8
Posted 08 September 2012 - 07:09 PM
Thank you for the program, I know it takes a lot of time to code these types of things, which is why I went trolling the forums for a good one before trying to code my own.. :D/>/>
PROdotes #9
Posted 08 September 2012 - 07:20 PM
yea… it really deppends on what you want from the code… and how "safe" you want the code to be… if I was writing this for myself only, there would be a LOT less error handing and info in the code… and I can't think of all the things that could happen to the little guy so feedback helps… and different people have different styles of mining… I usualy just dig to 12 and start to mine once i have a stack of wood, a few sappling and 2-3 seeds on me :D/>/>
RandomHavoc #10
Posted 08 September 2012 - 07:37 PM
Yeah, I definitely understand that one.. lol I wrote a small program to build a 13x13 room addition for my house as I always seem to be adding those things on, but the code is a mess, and highly specialized. There's next to no error handling at all, so if it encounters something unexpected it just breaks.. heh.. But for my purposes it does the job, just not suitable for release..
PROdotes #11
Posted 09 September 2012 - 01:57 PM
there… I think that's mostly if for this script… yell if you find bugs or have something you REALLY want me to add… but i think i'm done playing with my shaft :D/>/>
notyepenyar #12
Posted 16 December 2012 - 02:44 PM
Whenever I start the program, the turtle just goes straight down