just how do you generate a world anyway?
That's a good question and there are no doubt many different ways to go about it. The wikipedia page on procedural generation is actually quite a good place to start looking, it gives you the right terminology to google anyway. Supposedly Minecraft now uses a system of fractal generation but originally it used perlin noise functions. Whilst the actual details are a bit thin the idea of using a noise function is enough to get going with.
perlin noise functions
Perlin noise was actually a new concept to me. Fortunately I managed to find an excellent write up It's a really clever trick!
Rather than re-implementing it myself I was able to find a Clojure library that generates 2D noise when supplied with two values between 0 and 1. It also allows you to set the seed which could be useful if I ever need to start dealing with chunking.
So this gives us a smooth graduation of "random" values between 0 and 1 over a 2D axis.
We can take these x and y noise values and multiply them by a height to provide us with a smoothly graduating terrain of hills.
Here's my code with some explanatory comments:
We can then tie this noise grid back into the block generation function:
There isn't too much change here, we just additionally iterate over the y axis within the bounds of the height specified by the noise function.
how does it look?
Pretty cool! That wasn't too hard once I'd had the idea.
what's the git tag?
Clone the repo and run:
git checkout tags/noise-generation
To see the code as it is right now
what's next?
Performing some additional passes over the world, probably with another noise function to generate a surface texture.