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

3x3 Tunnel with Options

Started by thesonofdarwin, 07 January 2013 - 03:36 PM
thesonofdarwin #1
Posted 07 January 2013 - 04:36 PM
Hello all,

I'm just learning lua and this thing went through 5 versions this weekend, slowly adding more features. It works very well for my needs, so I thought I would share. I've tried to break it (mobs, gravel) but I think it's fairly durable. The code will be messy as I don't know the more advanced shortcuts and proper formatting.

What it does:
  • Tunnel Length (Must be an even number)
  • Returns to exact starting location
  • Handles refueling
    • Fuel in Slot 1
    • Smart refueling: You tell it what type of fuel you have (from limited common fuels) and it only refuels as needed.
  • Option to place an inset torch every 4 blocks
    • Will warn you if you don't have enough torches for your tunnel length before beginning.
    • As of right now, there has to be a place for the torch to set. It digs the inset, but no building.
    • Torches in Slot 3
  • Option to toss cobblestone on the floor
    • This checks every 4 steps forward and it requires you to follow the directions by placing 1 cobblestone in Slot 2.
  • Option to pause mid-tunnel to return to chest to drop off items if turtle inventory fills
    • Chest must be immediately behind turtle start position
    • Turtle will drop off items and return to finish the tunnel and then return to starting position
The turtle start position should be as so (see bold X):
XXX
XXX
XXX

Please let me know if you run into any problems aside from the torch issue mentioned above.

v1 http://pastebin.com/e8CkT4vH

v2 http://pastebin.com/ng9fxwEM Apologies, overwrote this version.
  • Fixed turtles running out of fuel while returning home from long distances (added a check)
  • Fixed the turtle return path becoming obstructed if something fell as the result of player action (now checks and removes blocks)
  • Added a progress meter (Progress: Current of Total
v3 http://pastebin.com/ng9fxwEM
  • Error produced on servers where fuel isn't required. I fixed this by adding an option for unlimited fuel.
  • Turtle getting lost if the player blocks its path during the full inventory chest drop-off trip has been corrected.
v4 http://pastebin.com/7WkihA5U
  • It seems that cans/cells/capsules are not working correctly anymore as a fuel source. I added a note to be sure they work in your version before selecting them as a fuel. I will remove this if I find that they're never going to be a fuel option again.
  • Added an option to drop off ALL items into a chest upon completion. This works in addition to mid-cycle drops.
  • Added an option to terminate program at the end of the tunnel once complete (dropping down to bottom left corner) enabling you to continue tunneling in the same direction without having to move the turtle. Note, however, that while this still enables mid-cycle chest depositing to work, it will negate end-of-cycle chest depositing.
  • In the works: Custom tunnel dimensions. I've the width worked out, but I'm not ready to implement until I get it all working as I like.
FC360 #2
Posted 27 January 2013 - 03:02 AM
Awesome program however how come it only accepts even numbers for length?
Dweller_Benthos #3
Posted 27 January 2013 - 03:44 AM
Very interesting. I've just started trying out computer craft stuff and this looks like it might do what I want, with a few tweaks. I may try this later today, but in the meantime, a few Q's:

I'd rather have a 1x3 tunnel, so I can then walk down it and find the exposed ores myself, since that's one of the most fun things I find in Minecraft. Looks like removing the two minewall left-right functions will do that? A cool feature would be a user selectable tunnel size.

I use sulfur torches because I have tons of sulfur left over from processing other stuff, and coal has too many other uses, I take it as long as it's a torch like device, it will recognize it, and use it properly? Also, every 4 seems pretty close for torches, it seems easy enough to change that to 7 or 8, whichever is the safe distance to keep mobs from spawning. Again, user selectable = cool feature, lol.

Also, option for lava as fuel? Seems that's the most powerful one, and coal has other more important uses.
thatirishguy #4
Posted 27 January 2013 - 06:15 PM
you could add say, get more torched from another chest, you have a possible 5 to choose from, so everything could be refillable. also i belive whatever you give it as fuel, like charcoal is great/renewable. lava would be hard to automate, as the turtle could not grab or place into a chest specific slot.
thesonofdarwin #5
Posted 28 January 2013 - 09:31 AM
Awesome program however how come it only accepts even numbers for length?

As I originally wrote this for personal use, it was infinitely easier to write under the assumption everything would always be even and just fill in or clear out an extra 3x3x1 area if I wanted odd. If I allowed the turtle to accept odd numbers, it would mess up other things without a rewrite. Now that I know a little more about lua, I'll look into going back and removing the even distance limitation.


I'd rather have a 1x3 tunnel, so I can then walk down it and find the exposed ores myself, since that's one of the most fun things I find in Minecraft. Looks like removing the two minewall left-right functions will do that? A cool feature would be a user selectable tunnel size.

I use sulfur torches because I have tons of sulfur left over from processing other stuff, and coal has too many other uses, I take it as long as it's a torch like device, it will recognize it, and use it properly? Also, every 4 seems pretty close for torches, it seems easy enough to change that to 7 or 8, whichever is the safe distance to keep mobs from spawning. Again, user selectable = cool feature, lol.

Also, option for lava as fuel? Seems that's the most powerful one, and coal has other more important uses.

More customizable options for tunnel size will eventually be coming. I'd taken a bit of a break from Minecraft, but will be returning and start working on more things in the near future.

If you remove mineleft and mineright, you'll minimally lose the ability to place torches and drop cobblestone. Instead, what you should do, is edit the function minecycle(). Without being at the computer, it'd be something like this:

function minecycle()
for z = 1, tunnellength/2 do
fuelcheck()
digUp()
digDown()
moveforward()
torchpos = torchpos + 1
placetorch()
progress()
end
end
I think that would work and still retain the rest of the functionality.

Sulfur torches should still work. The code only looks at the position, not the item. So if you placed stone there it would place stone instead of torches. As long as sulfur torches have the same placement functionality as normal torches, it would be fine. As far as placement, I was having problems with enemies spawning at every 6. Easily made customizable in the future.

Lava will definitely be added in the form of stackable cans/capsules. That was just an oversight on my part.


you could add say, get more torched from another chest, you have a possible 5 to choose from, so everything could be refillable. also i belive whatever you give it as fuel, like charcoal is great/renewable. lava would be hard to automate, as the turtle could not grab or place into a chest specific slot.

I could add the ability to refill torches (or fuel, for that matter), but they'd have to be the same torch type it started out with. But the turtle can mine 256 length before running out if filled up. I've not let mine ever go that far - will the turtle even return if you try to tackle such distances? I had imagined that chunk loading issues would have prevented that. I guess you could run a chunk loading turtle/cart alongside it.
shiphorns #6
Posted 30 January 2013 - 07:43 PM
The torches are a nice touch!
Dweller_Benthos #7
Posted 01 February 2013 - 05:37 PM
Yes, I looked into the code and with my limited understanding, think I figured out how to make it do what I want. Sulfur torches work fine, tested that with the regular program. The only thing I'd like it to do if creating a 1x3 tunnel would be to place the torch on the wall instead of an alcove like it does now. Couldn't the turtle.placeUp() command be used instead of the current dig an alcove, place torch routine? I haven't had time to test it yet. Nice program though, once I get a chance, I'm sure I can get it to work the way I want, and a 1x3 tunnel should be a pretty quick dig for it.

Oh yeah, what's it do if it hits a cave? Stop? Move forward until it finds something to dig? It would be nice to add a function that if there is air below it to place cobblestone there to make a bridge across open spaces like caves and ravines. More things to look into.

What about the off chance it hits a monster spawner? LOL, the more I think on it, the more questions I get.
sjkeegs #8
Posted 02 February 2013 - 05:24 AM
The only thing I'd like it to do if creating a 1x3 tunnel would be to place the torch on the wall instead of an alcove like it does now. Couldn't the turtle.placeUp() command be used instead of the current dig an alcove, place torch routine?

It would be nice to add a function that if there is air below it to place cobblestone there to make a bridge across open spaces like caves and ravines.

What about the off chance it hits a monster spawner? LOL, the more I think on it, the more questions I get.
Yes, placeUp() will place a torch on the wall in a 1 wide tunnel, and placeDown() can build a bridge.

Monster Spawners… I want to avoid digging out monster spawners, but the only thing I can come up with to avoid digging them is to use mossy cobble as a warning block and if it's detected, then halt the digging process.
Dweller_Benthos #9
Posted 03 February 2013 - 04:08 AM
Thanks, I still need to fiddle with it, haven't had the time lately.
KiwiKlutz #10
Posted 03 February 2013 - 03:24 PM
Hey, sorry for asking here but when I finish a tunnel, than I went to move the turtle to another location. how I save the script, and when it finishes he came back to the start place when I want to continue from where it stop? Thank you very much. (:
Bob3104558 #11
Posted 03 February 2013 - 05:48 PM
I love this program!! If i might make a couple subjection: Option for tunnel size 1x2 2x2, also have it so when the turtle finishes its mining it will store contents, not just store them when full, maybe place blocks on the walls and floor if their not already there.

For anyone who wants to use his program to make a 1x2 tunnel i modified it, also it can still place the torch like usual. Also i added a simple drop function to drop everything in the chest when its done except slot 1-3, its really late here i cant think of the for loop i could use so i just did it the long way. Hope you dont care that im pasting a copy of your script modified, if so i will remove it. Thanks

http://pastebin.com/EpPxVaUh
Dweller_Benthos #12
Posted 04 February 2013 - 06:17 AM
OK, I think I have it working like I want, and figured out how to tell it to move so it doesn't lose it's programming, but what's the trick to using coal fuel cells? Whenever I put one in the fuel slot, it just says out of fuel, and the refuel command just reports fuel = 0. There is only one type of coal fuel cell that I can see, the computer craft wiki calls it a coalfuel can, but I don't see one listed in the NEI list, only the coalfuel cell. I'd really like to use these, as they are the most powerful and much more efficient than coal itself, and my previous idea of lava doesn't allow refueling due to not being able to stack them.

Is Gregtech messing things up again?

TL:DR - how do you use coal fuel cells?
Bob3104558 #13
Posted 04 February 2013 - 06:32 AM
OK, I think I have it working like I want, and figured out how to tell it to move so it doesn't lose it's programming, but what's the trick to using coal fuel cells? Whenever I put one in the fuel slot, it just says out of fuel, and the refuel command just reports fuel = 0. There is only one type of coal fuel cell that I can see, the computer craft wiki calls it a coalfuel can, but I don't see one listed in the NEI list, only the coalfuel cell. I'd really like to use these, as they are the most powerful and much more efficient than coal itself, and my previous idea of lava doesn't allow refueling due to not being able to stack them.

Is Gregtech messing things up again?

TL:DR - how do you use coal fuel cells?

According to the computercraft wiki turtles cannot use coalfuel cells

http://computercraft.info/wiki/Turtle.refuel
Dweller_Benthos #14
Posted 04 February 2013 - 09:12 AM
OK, I think I have it working like I want, and figured out how to tell it to move so it doesn't lose it's programming, but what's the trick to using coal fuel cells? Whenever I put one in the fuel slot, it just says out of fuel, and the refuel command just reports fuel = 0. There is only one type of coal fuel cell that I can see, the computer craft wiki calls it a coalfuel can, but I don't see one listed in the NEI list, only the coalfuel cell. I'd really like to use these, as they are the most powerful and much more efficient than coal itself, and my previous idea of lava doesn't allow refueling due to not being able to stack them.

Is Gregtech messing things up again?

TL:DR - how do you use coal fuel cells?

According to the computercraft wiki turtles cannot use coalfuel cells

http://computercraft...i/Turtle.refuel

Yes, I noticed the wiki says coalfuel cans, but as far as I can tell, they do not exist. Coalfuel cells, though, do exist. So, what can they actually use? If you put 6 coalfuel cells in a canning machine, you get a fuel can, is that what can run the turtle? Seems a bit confusing.

Is there an error in the mod where it's expecting a can that does not exist, where it should be called cell?

Some quick testing in creative shows it can't use biofuel of any kind, can, capsule, or cell. It can't use coalfuel cells, as I can't find any coalfuel cans. It can use lava cells, though, which are stackable, and cheap, you just lose the tin from the cell as it's consumed. I think it should be easy enough for me to add the lava fuel option.

Fuel cans don't work either, so either the wiki is wrong or the mod has a bug. Guess I'll further my inquiries in another more appropriate forum.
thesonofdarwin #15
Posted 04 February 2013 - 09:41 AM
I updated the program adding a few new options. Terminating prior to returning home at end of cycle, as well as depositing entire inventory into chest upon returning home after completion.

It seems that cans/capsules/cells are no longer working as a fuel source (at least not in my version, I tried every possibility). I added a comment to the fuel select screen to ensure it's working before using that option. A simple turtle.refuel() in lua or refuel all not in lua will tell you. If anyone has information on what happened to them and if they'll be returning, let me know.

I will be adding tunnel dimension options in the future after I work out a few things. Torch placement settings will also be coming, but since I'll have to modify this to accomplish the tunnel dimension, I figured I'd just hold off for now.

I don't know that I'll be adding anything to complete walls/floors if you run into a cave, or dungeon detection. At some point the turtle isn't going to have any inventory left to mine after keeping stacks of building materials and reference blocks, so if you want to go ahead and modify it on your own to accomplish those tasks, you're welcome to. I can offer my beginner guidance on how I'd tackle such a thing.
Dweller_Benthos #16
Posted 04 February 2013 - 05:03 PM
Very cool. I've been beating my head against a wall with video card issues or I would have done more with this. Only thing that could be added to the fuels are lava cells which do work, and are probably what I'll be using. I would think adding this


print("Coalfuel Can = 4 **")
print("** Ensure these work in your version")
print("Lava Cell = 5")
fueltype = read()

function fueltypeset()
if fueltype == "1" then
fueltype = 80
elseif fueltype == "2" then
fueltype = 160
elseif fueltype == "3" then
fueltype = 520
elseif fueltype == "4" then
fueltype = 1520
elseif fueltype == "5" then
fueltype = 1000

Should make it work with lava cells.


Fuel cans work, you just have to make them in a canning machine and you can't cheat them in with NEI. See here: http://www.computerc...es-not-working/


Much later….

Finished my 1x3 version, here's the code http://pastebin.com/j77RzEbt if that's OK. If not, let me know and I'll take it back down. Basically it makes a 1x3 (1 wide, 3 high) tunnel, places torches every 8 blocks, can use lava cells for fuel, and will fill any empty spaces in the tunnel floor on it's way back. Put cobble or whatever material you want for floor fill in slot 16 (last one, lower right). I also added a bit more delay in the move forward function too allow a little more time for gravel to fall, it seemed sometimes it was (still does sometimes) letting gravel fall on top of the turtle, then when it moves on, the gravel will block the tunnel. Not a big deal, but there. Didn't want to delay it too much more, a fast tunnel was the goal.
Mav #17
Posted 12 February 2013 - 12:28 AM
As someone else said i think, It would be good if the torches were 8 apart which would still give enough light and only use half as much.

PS Excellent program, thanks.
Dweller_Benthos #18
Posted 12 February 2013 - 03:11 AM
As someone else said i think, It would be good if the torches were 8 apart which would still give enough light and only use half as much.

PS Excellent program, thanks.

My version posted above your post has the torches 8 apart. The reason the original one has them 4 apart is that those are placed in an alcove dug out of the side of the tunnel. A cool effect, but for a utilitarian mining tunnel like I need, I changed it to be more useful and resource friendly.
thesonofdarwin #19
Posted 12 February 2013 - 04:00 AM
You would have to remove recessing as Benthos mentioned, otherwise you'll get spawn at 8. The reasoning for the alcove torches is not just aesthetic, however. It allows the turtle to place torches under water and the water will not destroy the torch.
ayit #20
Posted 01 March 2013 - 03:50 AM
Ive been using this program for a while now and ive noticed that the turtles will randomly not pick up items and just drop them. On large tunnels this can be extremely annoying seeing llots of ores and cobblestone just wasted if you dont go and collect it from time to time.
Habibi #21
Posted 06 March 2013 - 09:07 AM
Can you possibly add that it picks up lava as a fuel? :)/>
thesonofdarwin #22
Posted 11 March 2013 - 05:00 AM
Ive been using this program for a while now and ive noticed that the turtles will randomly not pick up items and just drop them. On large tunnels this can be extremely annoying seeing llots of ores and cobblestone just wasted if you dont go and collect it from time to time.

I use this program everyday going hundreds of blocks and have never seen this. The only reasons items would get dropped is if it wasn't set up correctly before being sent on its way:

1. If you have drop cobblestone turned on but didn't put cobblestone in the correct slot.
2. You made your tunnel length too long without factoring in inventory management. If you don't drop cobble (correctly) your inventory will be full almost instantly. Note: Full inventory equals one item in every slot. There are more unique blocks in minecraft than the turtle has slots for.

One thing that might, very occasionally, cause items to not be picked up is the following:
Your inventory is "full" and the turtle runs into unique blocks between the full inventory checks (occurs every 4 blocks forward). The likelihood of that happening is so very small if you have the turtle set to return and deposit in a chest.
thesonofdarwin #23
Posted 11 March 2013 - 05:06 AM
Can you possibly add that it picks up lava as a fuel? :)/>/>

That the turtle would have a readily available source of lava is a very unique situation. I won't be adding it to the mod, but if you send me a PM with the type of situation you would use this in I can probably direct you to the edits you would need to make.

I apologize I've not updated this code at all recently. I've had to spend a lot of time doing VBA coding for work so I've not had tons of free time lately to delve back into lua. I've not abandoned the project, it's just on temporary hold.
airtonix #24
Posted 28 March 2013 - 09:19 PM
@thesonofdarwin, so where is the link to version 5?

Also use github imo.

Also Visual Basic? wut? seriously? I feel your pain, since I would only touch that under threat of firing squad.

Much prefer QT4 and PySide instead.
grampaexpozure #25
Posted 14 June 2013 - 08:41 PM
this is a very helpful and user friendly program. much appreciated sir gg.