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

[1.4] The lazy man's way to clear a chunk

Started by Pooslice, 20 October 2012 - 07:14 PM
Pooslice #1
Posted 20 October 2012 - 09:14 PM
Development on this program has been suspended. If anyone wants to continue this project feel free to copy the code and make a new thread.



Too lazy to mine yourself? Want to see others doing all the work? You have no problems with letting innocent baby turtles work in the mines day and night? Then this is for you!

http://pastebin.com/pdMZ17KV

What does it do?
  • Clears a whole chunk (16x16 blocks) down to bedrock.
Features:
  • Automatically refuels from drone inventory or refuel station.
  • Usually clears a chunk in less than 20 minutes using a total of 17 wireless mining turtles.
  • User interaction is required only at setup.
  • Immune against lava, water, mobs and any combination of those.
  • All collected blocks are placed in chests at the top.
  • Has some cleverness to save on fuel.
Restrictions:
  • Uses commands added in 1.4. Will not run on earlier CC versions.
  • Will leave out blocks that are located in a vertical gap between bedrock blocks.
  • Will leave some cobblestone blocks if lava and water merge after a drone has already passed by.
  • Needs a clear starting area of 16x16x1 blocks.
  • Will only work with iron chests or any other inventory that can be placed next to each other in a direct horizontal line.
  • Does not check for full chests on drop.
  • Not logoff- and server-shutdown-proof
  • My first real lua project. So the coding style is kind of sloppy and there are redundancies. Feel free to refactor and edit.
Usage:
  • Place a wireless mining turtle somewhere. The area that will be digged out will be 15 blocks forward and to the right of this turtle. There should be no blocks on the turtle's level (y coordinate) in this area.
  • Start the program with 'drone setup'
  • Follow the instructions. You will need 16 wireless mining turtles, 16 iron (or better) chests, one disk drive, one floppy disk and some fuel. I recommend at least three stacks of coal for one chunk.
  • Grab a coffee and watch the magic.
The code is published with no rights reserved. If and how you make use of it is your own decision and I will not be held responsible. Also note that I do not have the time to make a lot of updates or regularly check the forums for comments. It was a fun little project to get used to some lua and I am releasing this to the community with the hope that it might be of use to someone.

Changelog:
Spoilerv4.1
  • Fixed a wrong loop-condition that prevented initial startup before anyone noticed *cough*
v4
  • Fixed a bug where drones could get confused if two controller turtles were used directly next to each other.
  • Finished turtles now get picked up by the main turtle at the end and are placed in their respective chest.
  • Introduced the 'force' parameter to start immediately without further user interaction.
  • Improved some of the pathfinding for handling unexpected blocks in the turtle's way during maintenance.
  • Improved fuel management during vertical digging (after hitting bedrock).
  • Reduced some waiting times.
v3
  • Changed the moving algorithm as suggested by ChunLing. Should be a bit faster now and not slowed down by water or lava.
  • Downloading and saving the program under a different name than "drone" should now work.
  • The disk drive is now placed within the 16x16 area. It will be removed by the last turtle.
  • Improved the fuel management.
v2
  • Will now also work in fuelless mode.
  • Drones boot automatically and do not need to be right-clicked.
v1
dustpuppy #2
Posted 20 October 2012 - 09:23 PM
You don't need user to right click every turtle.

turtle = peripheral.wrap("bottom")
turtle.turnOn()
jag #3
Posted 20 October 2012 - 10:04 PM
You don't need user to right click every turtle.

turtle = peripheral.wrap("bottom")
turtle.turnOn()
It's not a good idea to name the new peripheral to turtle!
If you do this you wont after be able to use for example turtle.turnLeft().
Pooslice #4
Posted 20 October 2012 - 10:10 PM
You don't need user to right click every turtle.

turtle = peripheral.wrap("bottom")
turtle.turnOn()
It's not a good idea to name the new peripheral to turtle!
If you do this you wont after be able to use for example turtle.turnLeft().

Thanks for the suggestions. I totally forgot about the peripheral API. New version here. I will change the link as soon as a test run is through.

New Code:

print("Placing drone " .. i + 1 .. " of 16.")
  print()
  -- place the drone
  turtle.select(1)
  while turtle.detectDown() do sleep(1) end
  turtle.placeDown()
  -- boot the drone, thanks to dustpuppy for reminding me about the peripheral API
  peripheral.call("bottom", "turnOn")
ChunLing #5
Posted 20 October 2012 - 10:16 PM
World destruction using baby turtle soldiers. You monster, you.

Looks adorable. Why does water slow down the mining…oh, I see, it's because you detect before trying to move. For a project like this, it's actually a pretty good idea to put source water on top, so that it fills the hole (preventing horrible accidents and hostile mob spawning) and turns any lava you uncover into obsidian. If you have the turtles move before detecting, this doesn't slow them down. It I ever get around to writing a specialized excavation program, it will definitely include watering the hole.
Pooslice #6
Posted 20 October 2012 - 10:27 PM
World destruction using baby turtle soldiers. You monster, you.

Next goal: Self-replicating turtles :)/>/>

Yes, covering with water works. However, there will be some cobble blocks left occassionally. Most of the time that's because of lava flowing in from the outside after a turtle has already passed the spot.
ChunLing #7
Posted 20 October 2012 - 10:46 PM
Replicators…that can't possibly go wrong.
jag #8
Posted 20 October 2012 - 11:08 PM
I guess it pretty simple to just make the main control turtle pick up the disk drive and the turtle minions when they'r done
lewanator1 #9
Posted 21 October 2012 - 12:47 PM
when i type drone setup i get "no such program" although i copyed and pasted into my turtle file and called it mine did i do somthing wrong?
Pooslice #10
Posted 21 October 2012 - 01:47 PM
I guess it pretty simple to just make the main control turtle pick up the disk drive and the turtle minions when they'r done

Hm, I don't think that they will stack in the inventory anymore. Will have to test it, though. The program is altering files on the turtles' storage for logging (if enabled).

when i type drone setup i get "no such program" although i copyed and pasted into my turtle file and called it mine did i do somthing wrong?

Sorry, you cannot simply rename it. The script uses some commands like shell.run("drone", …) to call itself. I originally wrote this as separate programs and joined them together later on.
lewanator1 #11
Posted 21 October 2012 - 01:49 PM
how would i fix it and how do i use it sorry im a noob
Apothecarian #12
Posted 21 October 2012 - 03:20 PM
This is AWESOME! Thank you for sharing!
Pooslice #13
Posted 21 October 2012 - 10:59 PM
how would i fix it and how do i use it sorry im a noob

I just posted a new version. This should solve your problem. I did not have time to test everything thoroughly. Let me know if there are any problems.

I guess it pretty simple to just make the main control turtle pick up the disk drive and the turtle minions when they'r done

Did quick short test. They do not stack in the inventory. But the disk drive is now removed after all turtles have been launched.

Something else. Has anyone a better solution for getting the current script name? This is what I came up with on the fly:

SCRIPTPATH = shell.getRunningProgram()
if string.find(SCRIPTPATH, "/") then
SCRIPTNAME = string.reverse(SCRIPTPATH)
SCRIPTNAME = string.reverse(string.sub(SCRIPTNAME, 0, string.find(SCRIPTNAME, "/")-1))
else
SCRIPTNAME = SCRIPTPATH
end
I also tried

tArgs = { ... }
SCRIPTNAME = tArgs[0]
but that does not seem to work.
jag #14
Posted 21 October 2012 - 11:38 PM
I guess it pretty simple to just make the main control turtle pick up the disk drive and the turtle minions when they'r done

Did quick short test. They do not stack in the inventory. But the disk drive is now removed after all turtles have been launched.
You could let the main turtle pick up the "minions" and place them in their chests.
Silent #15
Posted 22 October 2012 - 10:27 AM
The whole thing fails because I have fuel disabled haha, it deploys the first turtle then it just sits there dropping slot 5 all day XD
Pooslice #16
Posted 22 October 2012 - 12:13 PM
The whole thing fails because I have fuel disabled haha, it deploys the first turtle then it just sits there dropping slot 5 all day XD

That issue has been fixed since v2 and I've tested it many times. You shouldn't have that problem after updating.
Silent #17
Posted 24 October 2012 - 06:28 AM
Ok it works now duno what I did before ^_^/>/>
oryor #18
Posted 24 October 2012 - 08:29 PM
will this program work on 1.3?
ChunLing #19
Posted 25 October 2012 - 12:26 AM
Nope, it uses commands added since then.
oryor #20
Posted 25 October 2012 - 12:29 AM
ah thats why i was having issues thanks
ChunLing #21
Posted 25 October 2012 - 12:45 AM
You can go through and try to remove the new commands, like turtle.attack[Up/Down]. Most of them aren't essential to the logic of the program, they just help make it more robust (and use fuel).
Pooslice #22
Posted 25 October 2012 - 08:30 AM
You'd also have to change the chest setup. Commands like turtle.dropUp() do not place the dropped items in the chests in 1.3. So you'd have to use something else to collect the items. Transposers from RedPower2 or obsidian pipes from BuildCraft come to mind. The added effort to collect the items was the reason why I abandoned the idea for the project in 1.3.

Also: turtle.attack() does not use any fuel. I also thought, that any attempt to move (e.g. with turtle.forward() when a block was in front) would use fuel, but that is also not the case.
ChunLing #23
Posted 25 October 2012 - 09:44 AM
No, I just meant that your program has code to deal with fuel, so a version without the fuel commands wouldn't work. And, as you say, there are other options for collecting excess resources, which should be available to a tekkit user, but they are…more fiddly.
Pooslice #24
Posted 25 October 2012 - 07:26 PM
Oh, then I misunderstood that comment. Sorry :P/>/>

Just finished another version and will upload after testing. Changelog v4:
Spoiler
  • Fixed a bug where drones could get confused if two controller turtles were used directly next to each other.
  • Finished turtles now get picked up by the main turtle at the end and are placed in their respective chest.
  • Introduced the 'force' parameter to start immediately without further user interaction.
  • Improved some of the pathfinding for handling unexpected blocks in the turtle's way during maintenance.
  • Improved fuel management during vertical digging (after hitting bedrock).
  • Reduced some waiting times.

The next version will contain more changes. I want to clear even the blocks between bedrock and include a system to light everything up and prevent mobspawning (mobfarm, anyone?). But it will take time and I have some other projects queued up. ^_^/>/>
EntombedJester #25
Posted 16 November 2012 - 02:21 PM
I used this program and it works beautifully they only thing I'm not to sure about is that I can't use the same floppy during a drone setup because i get an error drones:690: file exists.

the other thing that is stopping me from using this outside a creative test is that after the use the turtles no longer stack which makes me worry about how I am going to reuse them in order to start another dig site. Thats 48 diamonds that are useless unless they stack again
Pooslice #26
Posted 17 November 2012 - 04:58 AM
I used this program and it works beautifully they only thing I'm not to sure about is that I can't use the same floppy during a drone setup because i get an error drones:690: file exists.

the other thing that is stopping me from using this outside a creative test is that after the use the turtles no longer stack which makes me worry about how I am going to reuse them in order to start another dig site. Thats 48 diamonds that are useless unless they stack again

You are right on both topics. Does the program cancel after the "File exists"-error? If not, it should not be a problem. This should also be easy to fix by inserting a fs.delete-call before the copy. The result would be like:

-- write startup file to floppy
  if fs.exists("disk/" .. SCRIPTNAME) then
    fs.delete("disk/" .. SCRIPTNAME)
  end
  fs.copy(SCRIPTPATH, "disk/" .. SCRIPTNAME)

I have also thought of the second problem, but I have yet to come up with a solution. I haven't played around or tested in which cases turtles stack again and in which they don't. As always (RL)-time-management is also an issue. It seems, I will not be able to work on this for some time :)/>/>
EntombedJester #27
Posted 17 November 2012 - 08:45 AM
After talking with some people over in Ask a Pro and doing some personal bug testing it seems that the turtles having separate individual fuel levels is the issue. i ran them through the program then just manually moved and broke them until they were out of fuel then they stacked right back up. However i thought turtles were not supposed to keep fuel when broken unless labeled but when labeled don't stack with other turtles. Are you at any point programming the turtles so that they would keep their fuel (labeling maybe?) but problem mostly solved.
Pooslice #28
Posted 18 November 2012 - 04:10 AM
After talking with some people over in Ask a Pro and doing some personal bug testing it seems that the turtles having separate individual fuel levels is the issue. i ran them through the program then just manually moved and broke them until they were out of fuel then they stacked right back up. However i thought turtles were not supposed to keep fuel when broken unless labeled but when labeled don't stack with other turtles. Are you at any point programming the turtles so that they would keep their fuel (labeling maybe?) but problem mostly solved.

No, I do not label the turtles nor do I use any files or permanent storage (except for logging, but that is disabled by default). I am also wondering why they keep their fuel level.

I took an hour and wrote another version of the script in which the turtles move up and down until their fuel level is at 0 and then get picked up. In most cases everything went smoothly during the tests and the turtles stacked after getting collected by the controller turtle. But I still had cases in which they divided up into two stacks or more. I have no clue where this behavior is coming from. Perhaps I am overlooking something, but at the moment this seems random.

If you want to have a look at the new script, you can do so here: http://pastebin.com/5vCWyFdX
EntombedJester #29
Posted 18 November 2012 - 07:00 AM
So after more testing the program ran into error :768: no peripheral attached http://i.imgur.com/6QLiC.png. It had only placed 7 drones it didn't place they 8th. This was on the second run of the same set of drones, disk, drive, and master turtle. About getting two stacks that happened to me every time so far found out if you just put them all down and break them it fixes it and they stack right up for another run. The only thing I think is not good is that every time the turtles are replaced in the world they create another folder in the Computer section of world saves, on a server this could end up adding a lot of extra files. I know you can't do anything about this just pointing it out, I'm going over to suggest a way to make labeled stack-able turtles so that that doesn't happen, which in turn would solve that fuel issue so that you wouldn't have to use up all their fuel. Other than that its working great.

EDIT: Went to suggest feature it was already being discussed…http://www.computercraft.info/forums2/index.php?/topic/6023-computer-id/
Quickslash78 #30
Posted 25 March 2013 - 03:31 PM
Numerous problems in FTB Ultimate version (didn't bother to see which version it was) And the refueling station does not work properly, as well as opening rednet on all sides causes issues, namely the quarry won't start, because it checks for a modem on all sides.
SuicidalSTDz #31
Posted 25 March 2013 - 03:42 PM
Numerous problems in FTB Ultimate version (didn't bother to see which version it was) And the refueling station does not work properly, as well as opening rednet on all sides causes issues, namely the quarry won't start, because it checks for a modem on all sides.
You are aware this thread is from last year, right?

Started by Pooslice, Oct 20 2012 03:14 AM
Cranium #32
Posted 25 March 2013 - 04:27 PM
Don't reply to necro. Report it.