Sponsored By

How Minecraft Generates Massive Virtual Worlds from Scratch

You've probably played in a Minecraft world before, but have you ever wondered how that terrain was generated? In this video I go step by step to show you how chunks and biomes are formed, and modify the source code to show you every part of the process!

Caleb Compton, Blogger

March 1, 2021

11 Min Read


Have you ever wondered how Minecraft worlds were generated? Probably, since you clicked on this video. Well to find out I mined through the Minecraft source code to dig up some answers, and crafted this video to share them with you.

Before we begin, if you haven’t seen my previous terrain generation video, it might be a good idea to watch that one before continuing with this one. In that one I cover a lot the fundamentals of terrain generation by coding a procedurally generated 3D landscape from scratch, and this video will be building on a lot of the foundational concepts introduced in that video. Without further ado, let’s get started.

If you are watching this video you are probably already familiar with Minecraft worlds, but before we get into the details of how they are generated we should first cover some quick background. The first thing to know about Minecraft worlds is that they are huge – each world extends for 30 million blocks in every direction (except for height), and since each block represents one square meter this means that a single Minecraft world has a surface area about 8 times the size of the surface of the Earth. That’s a whole lot of terrain to generate!

That would already be pretty impressive if there was only a single Minecraft world, but there are actually around 2.8 Trillion different possible worlds that can be generated, and each one is unique. This is a mind-boggling amount of content, and what is especially impressive is that it comes in a shockingly small package – while most modern games are tens or even hundreds of Gigabytes, Minecraft fits all of these worlds in only a few hundred Megabytes.

This is only possible because Minecraft doesn’t actually store the worlds themselves – it only stores the instructions to make them. Minecraft terrain, like most 3D terrain in video games, is entirely based on noise. When you begin the game, a random 64 bit number called a Seed is generated (or chosen by the player), and this seed is used to generated the world. Different seeds will produce different worlds, and if you use the same seed you will always get the same result (at least, in the same version of Minecraft, as the details of terrain generation change from version to version).

This seed is used to generate noise functions, which are used to control every aspect of the world. I talked a lot about noise functions in my previous video, but the main idea is that these functions are random in the sense that you can’t predict what you are going to get from them, but they are “smooth” – the value you get depends on the values around it, rather than each one being independent. These functions determine everything from the height of the terrain, to where different biomes are located, to the location of ore clusters and underground strongholds.

Now that we have that background info out of the way, let’s get into the nitty-gritty details. Minecraft terrain generation really happens at two different levels – the individual “chunk”, and the wider world as a whole. It’s kind of like a jigsaw puzzle – the chunks that make up the world are the individual puzzle pieces, and it’s only when they all come together that you begin to see a complete picture. But before we can put the pieces together, we need to look at how each piece is made.

Minecraft worlds don’t generate all at once, but rather one chunk at a time. A Minecraft chunk is a 16 * 16 block area that stretches all the way down to the bedrock, and all the way up to the build limit – making them a total of 256 blocks high. When you first join a Minecraft world it only generates a 16 by 16 chunk area – these are called the “spawn chunks”. Then, as you explore the world new chunks will be generated around you to create the illusion of a massive, seamless world.

When generating a chunk Minecraft goes through several stages. These stages can be roughly divided into height-map generation, ores, adding surface blocks, carving, and adding structures and decorations.

During the height-map stage the world is only made of three types of blocks – stone, water, and air. This stage is just about figuring out the general shape of the terrain, without worrying about what anything should be made of. All land is stone, anything below y = 63 is filled in with water, and the rest is just air.  You can sort of distinguish different biomes by the shape of the terrain, as every biome is generated differently, but at this stage everything looks pretty similar.

After this is what I call the “ore stage”, where the general structure of the world stays the same, but a wider variety of materials can now be found. Instead of everything being made purely of cobblestone, different  types of stone, dirt, and even ores can be found.

The next stage replaces the top layer of blocks and adding a surface to the world. It is at this stage that the different biomes really start to stand apart from one another as, depending on the biome, the surface might be replaced with grass, sand, or other materials.

This is followed by the carving stage. Up until this point each chunk is basically, well, a solid chunk of blocks where the only thing that varies is height and material. In my previous video I talked about the limitations of using heightmaps for terrain generation – you can move things up and down, but you are pretty limited in the kinds of 3D shapes that you can get. The carving stage is where Minecraft handles these limitations by literally carving away parts of the landscape to produce more interesting 3D effects. It is in this stage that you start to get things like caves, ravines, and canyons that could never be produced by a simple heightmap.

At this point the world looks a lot like the Minecraft worlds we know and love, but It still feels…lifeless. The last stage is to add all the finishing touches – plants, animals, trees, and structures. It is in this stage that trees are placed, villages and villagers are spawned, and the world gets filled with flowers, cows, and beehives.

So that is how a single chunk is produced in Minecraft – to go back to our metaphor, we can now produce a single puzzle piece. However, a much like a single puzzle piece can’t give you the full picture, a single chunk doesn’t tell us much about larger structure of the world. How does the game link these chunks together to get a smooth, continuous world? How does the game know whether it should decorate that specific chunk with sand and cactuses and not snow and polar bears? Let’s now take a look at how the overall Minecraft world is put together. Much like chunk generation, the world itself is generated in layers – in fact, there are around 40 different layers that go into producing a Minecraft world. We won’t cover all of them, but we will go through the major stages.

Every Minecraft world starts out entirely as Ocean. Every Biome is numbered in the code, and Ocean happens to be number 0, so in the first layer of world generation it is the only kind of biome that exists. This stage is just about creating the very first layer of noise, on which everything else will be built. This is hard to see with an ocean world, but by messing with the ordering of the different biomes you can change the world so that it is entirely made of any other biome that you want. By changing it to a plains biome, for instance, it becomes much easier to see the underlying noise structure of the world.

The next several stages are all about layering additional levels of noise on top of each other, at different scales. By adding more and more noise layers together the world will become less repetitive, and each new layer also reduces the amount of ocean and adds more land area to the world. By the end of layer 8 the world that used to be almost entirely ocean is now about 50% land, and the terrain is much more complex than it was with the single layer of noise.

The next layer is where we start getting a variety of biomes, as some of the land surface is converted to colder climates. This might be a good time to talk about temperature in Minecraft. Every different biome in Minecraft has a temperature value, and this temperature can also change based on altitude – it gets slightly colder the higher you go. This temperature value affects a number of things. Some things are more obvious, like whether it rains or snows, but others are more subtle, such as the color of water, grass, and leaves, which all change based on the temperature. Note that the temperature depends on the biome – not the other way around – but biomes are generally clustered together with other biomes of similar temperatures. This stage is simply separating areas that will be turned into cold biome clusters, rather than the default “temperate” biomes. It is also important to note that this stage, and the next few after it, are not actually assigning biomes yet – they are only blocking out where different biome clusters should be. The world is still going to be full of oceans and plains until we actually start assigning biomes down the line.

The next several stages are “edge stages”. The idea behind these stages is that it would seem odd to go immediately from a very cold biome to a very warm biome, so if there are biomes with very different temperatures next to eachother they should be separated by something intermediate. These stages add cold clusters between freezing and warm clusters, and lush clusters between warm and cold clusters. This results in smooth transitions between freezing, to cold, to lush or temperate, to hot climates. There is also a stage that adds mushroom islands, which are only found in the oceans and aren’t part of any biome cluster, and another stage that marks certain biomes as “special”. When biomes are finally assigned, those that are marked as special will be unusual variants of the biome, like an eroded badlands instead of standard badlands.

Finally, layer 19 takes these biome clusters and actually assigns specific biomes to them. Each cluster has a group of different biomes to choose from, and each biome in this group has a certain weight assigned to it. For example, a warm biome cluster can turn into either a desert, savanna, or plains biome. Each of these has different odds of forming – deserts are about 50% more likely than savanna, which in turn are twice as likely as plains. Cold, lush and freezing clusters all undergo a similar process. Once these biomes are assigned we will finally have a world with different biomes in it! However, we still have a ways to go before we are finished. One fun thing about this stage is that the biomes are all very tiny and very close together, which makes flying around it very fun for me .

After that we begin adding even more biome variations, such as adding hill and mutated versions of the existing biomes. We also have separate layers for adding special biomes such as sunflower plains and bamboo forests.

We then add a major feature that our world was missing – rivers! Although you can’t really see them at this stage. However, we are now getting pretty close to the end. The next few layers add shorelines between ocean and land biomes, add different types of ocean (such as frozen oceans), and “zooms” into the world to make the biomes larger. After this we are all done, and finally have a completed Minecraft world!

That’s all I have for this week. If you liked this video make sure to leave a like, and subscribe so you don’t miss more videos like this in the future. If you have any questions about this video, or want to suggest topics for future Minecraft or Terrain Generation videos, please leave those in the comments down below. If you liked this video make sure to check out the rest of my channel – I make videos on all sorts of game design and programming topics. And join me next time when I will finally unveil the secrets of the Pokemon multiverse. Until then, thank you so much for watching and I’ll see you all next time.

Read more about:

Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like