←  Turtle Programs

ComputerCraft | Programmable Computers for Minecraft

»

My first big program - Branch Mining (safely)

Justinjah91's Photo Justinjah91 02 Oct 2018

EDIT: Updated 12/11/2019 - Turtles just started misplacing torches on themselves instead of the floor. Added a small fix to the code.

Hey everybody,

I'd like to share my first somewhat ambitious mining program with you all! I initially started with a program that would mine out a 3x3 tunnel for minecarts, but I've adapted it into a 3x3 branch miner. I don't particularly care for tiny cramped branch mines as they make me feel claustrophobic, so this is my approach. I know it isn't the most efficient way to mine, but I like it.

What this program does:
  • Runs a branch mine with multiple turtles running in tandem, with each turtle excavating either a "branch" or the "trunk" of the mine. It is set up to handle all the weirdness of gravel, sand, water, lava, mobs, caverns, etc with one exception: Creepers. I don't have any idea how to prevent a creeper from exploding when hit by a turtle, so if you have some insight there I would greatly appreciate it!
  • Each turtle will mine out a 3x3 area. As it does so, it will compare the blocks in the walls with whatever is placed in its first inventory slot. If that block does not match slot 1, it will be replaced with whatever is in slot 2. For example, I use this with stone in slot 1 and cobblestone in slot 2. This means that anything in the walls that ISN'T stone will be replaced with cobblestone. If you were to place cobblestone in slots 1 and 2, the walls would end up being solid cobblestone. As it mines out each slice of a tunnel, the turtle will place torches so that the tunnel remains safe from mob spawns. For optimum torch utilization, users are recommended to make the length of their tunnels a multiple of 10.
  • Before beginning each 3x3 slice of a tunnel, the turtle will check to make sure it has enough materials to adequately complete that slice. If it does not, it will return to the beginning of the branch mine to resupply. If the turtle's inventory gets full, it will also return to this position to unload.
  • As the main trunk is mined out, the turtle assigned to this task will leave redstone torches behind in addition to normal torches. These function as markers to let the turtles know which way to go to get to the drop-off chest.
  • When the turtles are finished with mining out the branches, they will return to the main trunk and position themselves for the next branch. The user will need to specify the direction that the turtle will need to go (either right or left) to reach the next tunnel position.
  • Lastly, more than 1 turtle can be assigned to work on each side of the main trunk (each working on their own tunnels). The number of turtles needs to be specified by the user. I myself am partial to having one turtle on the trunk, and two on either side of the trunk working on branches (for a total of 5 turtles)
  • Word of warning: Don't get in the way of the turtles! They are set up to deal with mobs (like slimes) that get in their way. They will attack you!
Here's the setup: https://imgur.com/a/p9jCJT1
Here's the code: https://pastebin.com/XYMvEYDB

Usage: safebranch <type> <length> <direction> <#turtles>
  • <type>: valid inputs are "side" or "main" (side is a branch tunnel, main is the trunk)
  • <length>: length of tunnel. For optimum torch utilization, I recommend using a multiple of 10 here. When doing the main tunnel, you should choose a length greater than or equal to 5 times the number of turtles on each side of the trunk. You also want to set this up so that the main trunk gets finished before the branches to avoid... awkwardness.
  • <direction>: valid inputs are "R" or "L". This determines the direction that the turtle will need to go to reach the next tunnel once it has finished this one. This argument is only valid for side(branch) tunnels. Omit it for the main tunnel.
  • <#turtles>: The number of turtles simultaneously mining on this side of the main tunnel. This argument is only valid for side(branch) tunnels. Omit it for the main tunnel.
  • Additional notes: Omitting ALL of the arguments will provide a text prompt to the user to walk them through the setup. Calling "safebranch help" will display a brief help text.
I am completely self taught in programming, so I may have picked up some bad habits. Let me know if you find any problems and I'll do my best to fix them! You can find me on reddit!
Edited by Justinjah91, 10 March 2020 - 12:26 AM.
Quote

BrunoZockt's Photo BrunoZockt 02 Apr 2019

View PostJustinjah91, on 02 October 2018 - 07:00 AM, said:

I don't have any idea how to prevent a creeper from exploding when hit by a turtle, so if you have some insight there I would greatly appreciate it!

I'm like 90% sure that turtles survive explosions. However I don't know of a way to prevent the explosion itself other than not hitting the creeper. Maybe you could have a bucket of water in the turtles inventory and let it place it before hitting a mob and picking it back up after so that the explosion doesn't destroy anything. I haven't tested this and it seems a little overkill for this very rare occurance but might be a possibility.
Quote

Justinjah91's Photo Justinjah91 14 Dec 2019

View PostBrunoZockt, on 02 April 2019 - 10:07 PM, said:

View PostJustinjah91, on 02 October 2018 - 07:00 AM, said:

I don't have any idea how to prevent a creeper from exploding when hit by a turtle, so if you have some insight there I would greatly appreciate it!

I'm like 90% sure that turtles survive explosions. However I don't know of a way to prevent the explosion itself other than not hitting the creeper. Maybe you could have a bucket of water in the turtles inventory and let it place it before hitting a mob and picking it back up after so that the explosion doesn't destroy anything. I haven't tested this and it seems a little overkill for this very rare occurance but might be a possibility.

It's less about the survival of the turtle and more about the creepers compromising the integrity of the tunnel walls, thus leading to a breach through which mobs can enter the otherwise safe mine. I think I'm going to pass on the bucket idea, but thanks for the suggestion!
Quote

FearlessPigeon's Photo FearlessPigeon 20 Feb 2020

Hey, i'm a bit late on this post but i wanted to try out your code, i'm pretty new with computer craft. How would I put your code into my turtle? copying the whole thing doesn't work and i would rather not go through and copy each and every line.
Thanks
Quote

Lyqyd's Photo Lyqyd 28 Mar 2020

You'd typically use the pastebin command:

pastebin get XYMvEYDB safebranch
Quote