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

Terraform - change how your biomes look like

Started by Everyone, 15 April 2013 - 11:07 AM
Everyone #1
Posted 15 April 2013 - 01:07 PM
Terraform
turn your deserts into meadows, change dirt beaches to sand beaches, explore caves made of wood!

[media]http://youtu.be/h8jS1eF_als[/media]

What is it?
Terraform is a ComputerCraft Turtle program that digs out blocks and replaces them with the blocks YOU want, keeping the landscape's and caves shape while mining valuable resources at the same time.

Usage and parameters
terra [cycles] [dump] [quick [depth]]
All params are optional. They can be put in any in almost any order; almost, because 'quick' will interpret following it number as the depth to dig.
cycles - number. How many 'steps' infront of the turtle should be terraformed, i.e.: terra 15. If the number of steps is not given, the program will work in supervision mode, requiring conformation for each new cycle.
dump - literal string. Using this param will make the turtle throw up :)/> the inventory content (but not from the config slots) after each cycle.
quick - quick mode, by default it will dig just 5 blocks deep. Useful if you want to quickly replace the top layers and do mining by other means or not at all.
depth - number that comes after 'quick', lets you specify the depth of the quick mode, i.e.: terra 64 quick 3 will go for 64 cycles (or steps) replacing blocks to 3rd layer deep on it's path.

Configuration
Slot 1 - block used for the surface layer
Slot 2 - 'subsurface' block, placed on relative depth from 2 to 4, that's 3 layers.
Slot 3, 4 - 'filler' blocks, those will be used to replace everything else.

Default behavior
• Turtle won't start a terraform cycle unless the fuel level is at least 600. This was made on purpose so that turtle would not run out of fuel in the middle of a cycle deep in a hole (or a lava lake). I took this aproach because coming up with a proper and effective scheme for correct and constant fuel calculations was too mindbending.
• Turtle will try to make the best out of items in it's inventory. If it goes out of a particular block, it will try to restock it out of stuff it dug out.
• The program was written to operate without any supervision as much as possible. The only time the turtle will need your attention is when it goes into pitstop mode. It does that only when:
- fuel level drops below 600 after finishing a cycle
- it runs out of config blocks and cannot restock from internal inventory
- it's inventory is full.
• After a finished cycle the turtle will do one "step" forward, meaning it won't just move straight forward, but will position itself as close to the ground as possible, which means it will climb mountains and go down valleys, removing the need for manual height positioning. Be sure to remove tall grass, flowers, torches, redstones and other types of non-solid blocks, as they are percieved and mapped by the turtle as normal blocks. This can't be dealt with without block id recognition (and we know vanilla CC won't get this feature ever).

Why was it made? A piece of (possibly boring) history.
SpoilerThis program was born out of specific needs that suddenly manifested themselves about the same time. I was in great need of *lots* of cobble, sand, even gravel for a *big* project involving many large scale goals and objectives. I knew I'd need a few quarries for that, however I didn't want grow a wasteland near my living space.

As I was traveling to find a good place for that, I stumbled upon some generator-glitched chunks with a desert and decided that this would be the perfect place. It was, however overun by monsters, including creepers that were blowing up my valueble sand resources and digging them by hand was a real chore. I started to wonder if I could somehow automate the digging process and at the same time strenghten the surface with cobble, so it won't get distroyed as much. That's when the Terraform idea was born and coding started.

V1 was designed to work with many turtles simultaneously thru rednet and remote control. As cool as it may sound, it was very primitive, depended on many external programs, needed lots of supervision, but in the end was doing the job. Later I grew accustomed to this place, which soon became my new home. I couldn't turn it to a wasteland anymore, still I really missed grassy fields… so I rewrote Terraform and introduced layers, also made some attemts to automatize it more so I could just leave it working while doing other tasks. That was V2.

At some point I realized that the whole remote/rednet concept is actually making turtles work slower as each turtle needed to wait for the others to finish it's job. That's when I started working on V3, and God bless it came to that, because as it turned out, V2 had some major bugs. It was only thanks to sheer luck that they somehow never revealed themselves.

V3 was a major rewrite. Previous concept was scrapped completly and the new design revolved around an autonomous turtle, automated as much as possible. All external program dependencies were removed and needed functionality was included in the program to make it standalone. Now whole rows of turtles may work beside each other individually not waiting for each other and not stopping each other. Pitstops don't have to take place on every finished cycle and the overall process is much faster. V3.5 also introduced the quick mode and inventory dump feature.

Future?
SpoilerTerraform has been thoroughly tested. Every found bug has been dealt with. At this time it doesn't contain any major bugs, neither any small ones that I know of.
For my personal needs I find Terraform feature-complete. Of course there are still some potential areas where theoretically the program could be optimized in terms of speed and/or fuel effeciency. I was thinking about a few approaches, but in the end came to conclusion that the complexity of the code needed would require far more time than I can give it. Readability and maintenance would also suffer further as current code is already not-so-clean and a bit hackish in some places. Even tho I tried to stick to good practices, more than often LUA with its kinks is hard (for me) to work with. However some optimization concepts still return to me and crawl on my mind from time to time and I may try to implement them in unforseen future.
Inventory managment itself could also be improved quite a lot if turtles could access information about blocks such as IDs, names, damage values and so on. As we know, that won't happen in vanilla CC and I'm not willing to write special versions of Terraform for differently modded turtles.

Download
MediaFire
Pastebin

Copyright
Do what you want with it, just be sure to give me some credit if you use my code in your project.
superaxander #2
Posted 15 April 2013 - 07:28 PM
This is just…AWESOME!
EDIT:
You might want to use pastebin
pastebin get Ej66aXR7 terra
Andrakon #3
Posted 17 April 2013 - 12:47 AM
Woa totally awesome program! :D/>
I like all the extra history and back story.
It looks like you put a lot of time and effort into it!

Good video too!
Here is the code to embed the video:

[media]http://youtu.be/h8jS1eF_als[/media]
Everyone #4
Posted 19 April 2013 - 09:26 AM
@superaxander: note taken.
@Andrakon: you save the day.

Thanks for the feedback guys, glad you like it. This one got much love as it's in constant use and yeah, the development took a few weeks on-off. I was making my first steps in LUA with this one. Even tho I'm no stranger to programming, LUA does things… in it's own fashion.
Espen #5
Posted 19 April 2013 - 11:09 AM
Nice, that's a useful program.
I haven't actually used it, but I like your structured coding.
Clean, readable and annotated with helpful comments
That alone is worth a [+1] in my opinion.

Kudos, and keep up this good coding hygiene! ^_^/>
TheOddByte #6
Posted 19 April 2013 - 12:49 PM
Haven't quite tested this yet but it seems great and I'll test it tomorrow, But I also think this is worth +1
Keep up the good work! :)/>
HeffeD #7
Posted 08 October 2013 - 06:56 PM
I'm really surprised this great script hasn't received more attention.

I'm currently using it to cover the area around a nether fortress with slabs to ensure that mobs can only spawn in the fortress in an attempt to improve wither skeleton spawn rates.

I tried platforming first, but with the varied terrain, platforms really aren't a great solution. So I thought, I wonder if anyone has created a terrain follower, and sure enough!

So far the script has been absolutely trouble free and the turtles have no problem tackling even the most difficult terrain.

Thanks for sharing this with us! :)/>
apemanzilla #8
Posted 11 October 2013 - 11:11 PM
How… What… Thi… THIS IS AMAZING!
We NEED scripts like these, not just thousands of copied quarry scripts!