1. Source

Terrain generation, Part 1

I’ve been promising to write a technical post on Minecraft for a while, but never really got around to doing so. I’m on a tiny airplane now, though, with nowhere to run, so here we go!

One of the most complex parts of Minecraft is the terrain generation. When I changed the game over from being just single zones of a map to an infinite map, the terrain generation got a whole lot more complicated, as terrain needs to get generated on the fly as the player explores, and it has to be the same no matter what direction the player approaches it from.

1) How infinite is it?

First of all, let me clarify some things about the “infinite” maps: They’re not infinite, but there’s no hard limit either. It’ll just get buggier and buggier the further out you are. Terrain is generated, saved and loaded, and (kind of) rendered in chunks of 16*16*128 blocks. These chunks have an offset value that is a 32 bit integer roughly in the range negative two billion to positive two billion. If you go outside that range (about 25% of the distance from where you are now to the sun), loading and saving chunks will start overwriting old chunks. At a 16/th of that distance, things that use integers for block positions, such as using items and pathfinding, will start overflowing and acting weird.

Those are the two “hard” limits.

Most other things, like the terrain generation seeds and entity locations use 64 bit doubles for locations, and they do much subtler things. For example, at extreme distances, the player may move slower than near the center of the world, due to rounding errors (the position has a huge mantissa, the movement delta has a tiny, so it gets cut off faster). The terrain generator can also start generating weird structures, such as huge blocks of solid material, but I haven’t seen this lately nor examined exactly what behavior causes it to happen. One major problem at long distances is that the physics starts bugging out, so the player can randomly fall into ground blocks or get stuck while walking along a wall.

Many of these problems can be solved by changing the math into a local model centered around the player so the numbers all have vaguely the same magnitude. For rendering, Minecraft already uses local coordinates within the block and offset the block position relative to the player to give the impression of the player moving. This is mostly due to OpengGL using 32 bit floats for positions, but also because the rounding errors are extremely visible when displayed on a screen.

We’re probably not going to fix these bugs until it becomes common for players to experience them while playing legitimately. My gut feeling is that nobody ever has so far, and nobody will. Walking that far will take a very long time. Besides, the bugs add mystery and charisma to the Far Lands.

2) Isn’t that terrain shape pretty awesome?

In the very earliest version of Minecraft, I used a 2D Perlin noise heightmap to set the shape of the world. Or, rather, I used quite a few of them. One for overall elevation, one for terrain roughness, and one for local detail. For each column of blocks, the height was (elevation + (roughness*detail))*64+64. Both elevation and roughness were smooth, large scale noises, and detail was a more intricate one. This method had the great advantage of being very fast as there’s just 16*16*(noiseNum) samples per chunk to generate, but the disadvantage of being rather dull. Specifically, there’s no way for this method to generate any overhangs.

So I switched the system over into a similar system based off 3D Perlin noise. Instead of sampling the “ground height”, I treated the noise value as the “density”, where anything lower than 0 would be air, and anything higher than or equal to 0 would be ground. To make sure the bottom layer is solid and the top isn’t, I just add the height (offset by the water level) to the sampled result.

Unfortunately, I immediately ran into both performance issues and playability issues. Performance issues because of the huge amount of sampling needed to be done, and playability issues because there were no flat areas or smooth hills. The solution to both problems turned out to be just sampling at a lower resolution (scaled 8x along the horizontals, 4x along the vertical) and doing a linear interpolation. Suddenly, the game had flat areas, smooth hills, and also most single floating blocks were gone.

The exact formula I use is a bit involved (and secret!), but it evolved slowly over time as I worked on the game. It still uses the 2D elevation and noisyness maps, though.

STILL TO COME, ON TERRAIN GENERATION:

- Biomes!
- Caves and Large Features
- Trees, Lakes, and Small Features
- The nether!
They’re not infinite, but there’s no hard limit either.
The terrain generator can also start generating weird structures, such as huge blocks of solid material, but I haven’t seen this lately nor examined exactly what behavior causes it to happen.
Dun dun dunnnn. :monocle:
Late x 23 Informative x 6 Artistic x 2 Winner x 1 (list)

2. I challenge someone to get to the point where the savegame starts fucking up.
Agree x 4 (list)

3. Notch said they weren't infinite a long time ago.

Edited:

I challenge someone to get to the point where the savegame starts fucking up.
Old, but same principles.
Informative x 9 Late x 1 Winner x 1 Dumb x 1 (list)

4. I challenge someone to get to the point where the savegame starts fucking up.
Or where they start finding towers or diamond ore.
Agree x 4 (list)

5. As you can see, Notch has implemented floating islands. It's just really big. :buddy:
Winner x 1 (list)

6. Now how do seeds fit into this?

7. Since we're on the topic of glitchy worlds has anyone ever found natural cobblestone on a newly generated map?
Agree x 14 Disagree x 1 Late x 1 (list)

8. Since we're on the topic of glitchy worlds has anyone ever found natural cobblestone on a newly generated map?
1 block in the sky.
I thought it was odd because i don't see how cobblestone would even be on a list of blocks to be generated.

9. Dungeons have normal cobble don't they?
Agree x 27 (list)

10. This happened to me after converting.
Winner x 61 Disagree x 5 Funny x 2 Informative x 1 (list)

11. Since we're on the topic of glitchy worlds has anyone ever found natural cobblestone on a newly generated map?
I've found natural dirt on a newly generated map.

I haven't seen a single space in the bedrock in a long time, has anyone seen a split in the bedrock?
Agree x 4 (list)

12. Funny, I had chunk glitches yesterday, I think it was due to walking a few miles from the original spawn location, when I quit and came back I had lost all my items and a huge random chunk of hill was in the spot my road was at.

13. I've found natural dirt on a newly generated map.

I haven't seen a single space in the bedrock in a long time, has anyone seen a split in the bedrock?
Yes i've seen lots.
Agree x 2 (list)

14. I've found natural dirt on a newly generated map.

I haven't seen a single space in the bedrock in a long time, has anyone seen a split in the bedrock?
Nearly everytime I reach bedrock.

15. I've found natural dirt on a newly generated map.

Um, there is natural dirt everywhere, it's prolly the 2nd most used block in generating worlds.
Disagree x 2 (list)

16. Um, there is natural dirt everywhere, it's prolly the 2nd most used block in generating worlds.
lol wow
Dumb x 1 (list)

17. lol wow
wat
Agree x 2 (list)

18. wat
you missed the joke entirely
Funny x 4 (list)

19. you missed the joke entirely
Oh
Funny x 25 Friendly x 3 Winner x 2 Dumb x 1 (list)

20. I've found natural dirt on a newly generated map.

I haven't seen a single space in the bedrock in a long time, has anyone seen a split in the bedrock?
I once found a lake in the bedrock on my server, but that is about it. The sad part is that that map was soo screwed up I had to delete it.

21. you missed the joke entirely
It wasn't a very good one to be honest.
Agree x 28 Friendly x 1 (list)

22. This happened to me after converting.
All that happened to my converted map was a bunch of areas where my guy would randomly become stuck in place.
Agree x 1 (list)

23. It wasn't a very good one to be honest.
Friendly x 13 Funny x 2 Dumb x 1 (list)

24. oh no im sad now
Did it hurt your self Esteam? :downsrim:
Funny x 52 Winner x 5 Agree x 1 Zing x 1 (list)

25. This happened to me after converting.
Holy shit.

26. Did it hurt your self Esteam? :downsrim:
thats not even how you spell e oh

ha i get it !!!
Funny x 20 Winner x 2 Zing x 1 (list)

27. This happened to me after converting.
Agree x 1 (list)

28. I've found natural dirt on a newly generated map.

I haven't seen a single space in the bedrock in a long time, has anyone seen a split in the bedrock?
I've had a lake/line of water which started from the surface then went all the way down to bedrock then past it.
I'm guessing a set of chunks all got corrupted in that world.

29. Do the shit in those videos do the same thing in SMP maps?

That'd be sweet.

30. This happened to me after converting.
Whats with the hacked in tools. I'm not saying you hacked in all those ores or anything, but why did you have to hack in diamond tools when you have all that ore. And why didn you hide it when the video started? And why did you hack in 64 stacks of tools?

31. Now how do seeds fit into this?
It's a seed for a random number generator which his perlin noise algorithms use.

32. Whats with the hacked in tools. I'm not saying you hacked in all those ores or anything, but why did you have to hack in diamond tools when you have all that ore. And why didn you hide it when the video started? And why did you hack in 64 stacks of tools?
He used InvEdit to give himself 64 of every tool I guess, so he doesn't need to ever get a new pick for example.

33. Going to the limits and posting the results

Edited:

a weird grassless mountain

Edited:

really cool landscape

34. Going to the limits and posting the results

Edited:

a weird grassless mountain
That stuff happens more often than you would think.
Agree x 5 Disagree x 2 (list)

35. Cobble can be generated naturally where water meets lava.

36. But in the air?

37. im at 35000,1000 but theres still nothing interesting

38. I challenge someone to get to the point where the savegame starts fucking up.
It was done a long time ago, at the start of Infdev in fact.

Edited:

Notch said they weren't infinite a long time ago.

Edited:

Old, but same principles.
This is basically what still happens today.

39. He used InvEdit to give himself 64 of every tool I guess, so he doesn't need to ever get a new pick for example.
Yes I was making some large buildings underground in that world so I hacked my tools.

40. But in the air?
Oh, no. That's definitely an anomaly.