[Music] have you ever wondered how many grains of sand are on this planet well a rough estimate is over seven quintillion that's a seven followed by 18 zeros and yet that's not even half the number of the unique words in minecraft so how does minecraft and other games like it build such complex beautifully crafted yet fully procedural wards i'm alan zucconi and in this documentary we'll explore how the game generates its wards from its tallest mountain to its deepest cave welcome to the world generation of minecraft and if by the end of this video you've learned something new about a game you love i hope i'll have earned your subscription [Music] for many of you watching minecraft might be the first and perhaps the only game you've played in which walls are not handcrafted by a level designer but are instead created procedurally and yet the guinness world record for the first game to feature a procedurally generated world gusto elite originally developed for the bbc micro in 1984 the great grandfather of the more recent elite dangerous from 2014 generating new worlds automatically might appeal to some as a lazy way to create endless content for a game but actually it's quite the opposite you need to be such a good programmer and such a good level designer that you can teach a machine what a good level looks like the content must be diverse enough to look novel but not so diverse that it looks typical and it must create walls that are not only interesting to look at but playable in a way that regardless of their actual difficulty feel fair to the player procedural content generation is definitely not for the faint-hearted and no matter how complex your algorithms are they're all powered by one thing only randomness and minecraft is not an exception each world starts from a seed which is basically a number used to initialize the terrain generation and everything it will contain these algorithms might be random but they are also deterministic it means that given the same initial conditions the same seed they'll always produce the same results and these is why each minecraft wood can be recreated just from its seed and since the seeds themselves are stored using 64 bits there are 18. 4 quintillion unique values and unique walls that can be created no man's sky is also using 64-bit seeds which explains why incidentally there are 18. 4 quintillion unique planets in that game too but how can random numbers which is essentially your computer throwing dice create walls well perhaps it's best to start from something slightly smaller than minecraft hello viewer welcome to the dungeons of doom originally released in 1980 rogue is generally credited with being the first graphical adventure game and he served as a major source of inspiration for the thousands of dungeon crawlers which came in the following decades minecraft 2 shares many of the characteristics that made rogue so iconic and generating procedural dungeons for the player to explore is just one of them [Music] so how did rogue create its dungeons of doom back in 1980 talking about typicality have you figured it out yet each level is divided into a 3x3 grid with a random room placed in each cell the algorithm proceeds by selecting a room for the player to spawn in and marks it as reachable it then iterates through all of the other rooms connecting them to a previously reached neighbor if that's possible or skipping to the next one a stair to the next level is then placed in the last room to be connected [Music] rogue can also feature dead ends secret doors and even monster rooms all done in roughly 9000 lines of code over 300 functions 307 to be precise by comparison minecraft 1.
18 counts over 52 000 functions from approximately 4200 files so get your time on armor and your enchanted sword ready because we are about to descend into the treacherous steps of minecraft source code [Music] regardless of its complexity it is undeniable that the universe crafted by mojang is built upon ideas techniques and algorithms that were pioneered by previous games and even movies some of which date from decades ago and so it would really be a disservice to talk about the history of minecraft without mentioning the actual game that inspired it infinite at first glance it looks like a manning game where two teams are competing to collect as much all gold and diamonds as possible but infiniminer was as much about mining as it was about building not just your base but entire stones it's easy to see how this game directly inspired minecraft from the blocks to the pickaxe from the caves to the lava lakes from the gold to the diamonds from the sky to the void even the tnt in a parallel universe this is what minecraft could have been instead and while far from being infinite each infinity minor mark is indeed generated procedurally it all starts with a solid chunk of dirt in which a number of oil veins are painted each one begins at a random position with each iteration moving the vein in a random direction this technique is unsurprisingly known as random walk [Music] mountains and caves are created with the exact same technique the former erected by replacing air with dirt the latter carved by replacing dirt with air diamonds meanwhile are randomly scattered towards the bottom part of the level and while these might sound simple perhaps too simple it was not dissimilar to how minecraft worked for the first nine months of its development in its very first iteration known at the time as cape game each ward was only 256 blocks wide and 64 tall and while infiniminer was never really intended to be well infinite it took indeed 9 months to finally fulfill the dream of a boundless minecraft world and it happens using a very simple trick every time the player goes too far a new chunk of the world is created after that each world would only be bound in size by software limitations on a 32-bit system for example that's roughly up to 4. 3 billion blocks away from the spawn point but wait before you start packing for a journey you can't actually go that far players are restricted to a 60 million by 60 million blocks area which doesn't sound like a lot when compared to infinity but still that's seven times bigger than earth's surface just about half the size of neptune and even so bigger doesn't necessarily mean better no version of minecraft does really offer any new gameplay mechanic at a scale beyond let's say 25 000 blocks while the world look rich and diverse up close a pattern appears the further we zoom out eventually each sufficiently large part of the world will look indistinguishable from any other at that scale minecraft is isotropic pretty much like our universe is expected to be at its largest scale this reveals the true scale at which the game was designed to be played and consequently the scale at which its world generation is truly meant to operate and to be enjoyed [Music] you might have noticed by now how all modern minecraft maps look somewhat patchy this is because each color represents a different bio a region with distinct geographical features such as vegetation animals buildings and climate conditions nine months after the infinite update alpha 1. 2.
0 better known as the halloween update introduced 10 of those biomes and the way in which the game decided which part of the world belonged to which biome was fairly simple and relied on so-called noise maps in a nutshell these are images whose pixels are produced using random numbers based on their initial settings and configuration they can be used to generate a variety of different patterns early versions of minecraft use three of these noise maps one to determine the terrain height and two for the temperature and rainfall and it was the combination of the last two that ultimately determine the biome of a region high temperature and low humidity desert biome low temperature and low humidity tundra biome and so on what worked well is that because the temperature and rainfall maps were fairly smooth so were the transition between biomes meaning that you would have rarely encountered a forest next to let's say a savannah but because the biomes were independent from the terrain you could have them at any height making for some pretty unusual landscape a big overall came with beta 1. 8 the adventure update first it got read of the farlands they marked a sort of point of no return after which the ward generation simply stopped working properly they were found at around 12 million blocks in any direction from the spawn point but getting rid of them was just side effect of a much deeper change the adventure update came with an entirely new terrain generator veteran players might remember that during this era wards had a very distinct vibe they were somewhat continental big islands separated by an even bigger ocean these change completely with minecraft 1. 7.
2 best known as the update that changed the world and indeed it changed it quite a lot starting by massively reducing the size of the oceans and so within the course of three years mojang had significantly changed the way walls generate twice and these had quite a profound impact on all those servers that have been around for a long time such as the infamous 2ptt minecraft's oldest anarchy server vlmc made a very interesting video showing how something as simple as upgrading to a different version permanently scarred the already distressed landscape of to 2b2t now despite some other tweaks in the following updates the wood generator introduced in minecraft 1. 7. 2 has been pretty much in use for almost 10 years and although minecraft 1.
18 somewhat changed that the awards that for years you have explored mined built loved and lost they were all crafted by the same algorithm so i know while you're here you want to know how that actually works so minecraft uses congruential generators to seat pearly noise maps which serve as the octaves for fractal brownian motion noise maps which are then processed in a layer stack of cellular automaton-like operators to determine the biomes which ultimately modulates the amplitude of the fractal density map that controls the terrain height okay perhaps that was not the most effective way to explain how it works so what about if i showed you instead each minecraft world goes through three phases and it all starts with a so-called biomaps which serves as a template to dictate which type of biome goes into each region of the world plains deserts mountains and oceans are all examples of possible biomes and nowadays the overlord alone comes over 60 of them [Music] the second phase of the world generation focuses on the terrain and works in three steps the first one creates a basic outline using the biomap to decide a height each region can have the result is a solid barren landscape entirely made out of stone where every empty block below y equals 62 is turned into water the following step replaces all the surface stone blocks with a type appropriate to their biome grass for planes sun for desert gravel for oceans and so on this is also where the bedrock layer is generated interestingly enough in the java edition its pattern doesn't depend on the word seed and is the same across every minecraft world [Music] in the third step caves and ravines are literally carved out of stone finally the third phase populates the world with the remaining features structures like villagers strongholds and ocean monuments are placed first followed by decorative elements like trees and grass this is also where all veins are added in the world in a process not dissimilar to the ones used by infiniminer generating the biomap is the most critical phase as it serves as the blueprint the rest of the world is built from the map is built using a sequence of fairly simple operations referred to as layers which are stuck on top of each other each layer takes the biomap from the previous one adds some details and passes it on to the next one and minecraft words are crafted using not one but four different stacks the main one is responsible for the land while two smaller ones are used to draw the rivers and to give temperatures to the ocean an additional stock is used to add even more nuances to hills and rivers it all starts with a noise map an image generated randomly which features only two colors representing land and ocean in a 1 to 10 proportion the process is not dissimilar to rolling a d10 for each pixel if you get a 1 it becomes land otherwise it becomes an ocean minecraft obviously doesn't have a d10 at its disposal but it can nonetheless roll random numbers using what is known as a quadratic congruential generator internally the source code calls these the island layer as each individual pixel of this noise map will be the template from which continents will emerge each pixel in fact corresponds to 4096 in-game blocks and the deeper we go in the biome stock the more refined the details are that are this is possible due to a series of scaling layers which increase by a factor of 2 the resolution on which the following layers will operate for example if a pixel from the island layer corresponds to 4096 blocks each pixel added after the zoom will have an in-game size of 2048 blocks minecraft is using the zoom layers for another important task adding variation instead of scaling the maps perfectly they sometimes introduce some small changes they are coded to work more like an old photocopier adding the occasional mistake and smudging the edges of what would otherwise be some perfectly square islands the next layer encountered in the biome stock is designed to expand the existing islands creating a more connected world each piece of land has a chance of expanding into the corners of nearby shallow waters but can also be eroded in the process if we run this layer over and over again we can see that it doesn't always produce the same effect even layers introduce randomness and perhaps a better way to understand how most of them work is to see them as stochastic cell rab automata which is just a fancy way of saying that they're simple rules that change a pixel based on the color of the surrounding one the stochastic part comes into play because some of those rules might be driven by randomness [Music] cellular automata looks deceptively simple but they hide an endless universe of complexity and are one of the most used tools when it comes to procedural content generation in video games and if you want to learn more about them there's an entire documentary on this channel most of the landshape is created by alternating ad island and zoom layers these allow the world to have prominent features at different various resolutions the ocean on the other hand is mostly shaped by these two layers the first one was added in the adventure update to specifically make the world less continental and more connected internally minecraft literally calls it remove too much ocean leaving very little to the imagination all ocean regions surrounded by more ocean have a 50 chance of becoming land these not only creates more fragmented coasts but also brings the amount of land versus ocean from barely 27 to over 50 percent the next layer from the main stack marks all ocean regions which are surrounded by more ocean as deep these will later give rise to shallow and deep ocean biomes up to this point we've only mentioned two things land and ocean as a prelude to biomes a series of climate layers are responsible for determining the temperature of each region either warm temperate cold or frizzy later in the stock this information will determine which biomes these regions can turn into first each piece of land is randomly assigned the temperature warm cold or freezing in a proportion of 4 1 and 1 respectively but with such a random distribution you could very well have a desert next to us with tundra to avoid that the following two layers blend each region's temperature ensuring a smoother transition between them any warm land adjacent to a cool or freezing region will turn into a temperate one instead and any freezing land adjacent to a warm or temperate region will turn cold these temperatures are ultimately the main factor in determining which biome a piece of land will end up being for example warm regions have a 50 chance of turning into a desert 33 into a sabana and the remaining 17 into planes in a similar process temperate cold and freezing regions will have certain probabilities of turning into their respective temperate cold and freezing biomes such as forests tigers and ice plains up to this point the landscape should already look familiar but lacks variation within the individual piles to fix this this layer has a small chance of converting a biome into his hilly variant for example he could turn a desert into a desert hill a forest into a wooded hill or a savanna into a plateau this layer also works on ocean regions and can turn deep oceans into planes or forests this is what disseminates the ocean with a lot of tiny islands the decision on which areas to change comes from an additional noise map which is generated by a separate stack when the color of each pixel is chosen at random and independently from any others like in this case we talk about white noise which is pretty much the same distribution you get when an old tv is now receiving any signal usually every layer operates on the map locally ignoring the big picture and with so many steps it's quite hard to guarantee a harmonious blend between biomes to avoid any problem two more layers are tasked with ensuring a gentle transition between different climates and extreme regions exists at all times the second one in particular sure also adds pictures where light meets shallow oceans rare biomes on the other hand deserve a special mention as their generation works in a slightly different way on top of assigning temperatures the climate layer has a 1 in 13 charts of tag in a region as special and when the time comes to assign biomes based on temperatures special regions get a special treatment [Music] warm temperate and cold climate regions all have their own special biome variants they turn into bedlam plateaus jungles and giant tree tigers a different story takes place for the more niche biomes such as bamboo jungles and sunflower planes as the idea is not to have them on their own but a small patches within much larger regions and so two additional layers are responsible for randomly turning one jungle out of ten into a bamboo jungle and one plane out of 57 into a sunflower plate these somewhat legendary mushroom islands are created in a similar fashion with each ocean block surrounded by water having a 1 in 100 chance of turning into a mushroom field the layer responsible for these is pretty high in the stock which is why mushroom islands tend to be quite large and uniform this is also one of the rarest biomes in minecraft and the only one in which hostile mobs don't naturally spawn the main stark focuses mostly on the land and has nothing to create rivers they are generated in a separate stack which operates on the same noise map used for the hills after being scaled several times the noise map looks quite patchy the river layer works as a kind of edge detection algorithm creating candidate river pads along the seams of those patches they attempt smoother to fix any gaps of rough edges using a low pass filter and finally feed into the main stack through the river mixer layer that simply carves a river into the land with the exception of snowy tundra biomes which gets frozen rivers instead and mushroom fields which apparently have no rivers at all the last bit involved in the biome generation is the ocean temperature stock it adds variety to the ocean which besides being shallow or deep would otherwise have no other distinctive features the stock creates its own temperature map using a technique known as pearling noise that is a very common algorithm for procedural noise maps which was originally developed in 1982 not for a game but for the movie tron if you create a white noise map by rolling a dice for each pixel like the first layer was doing the overall result will look unpleasantly rugged because nearby pixel will likely have very different values early noise instead is known to create very pleasant very smooth images and it does so by generating random values on a grid much larger than the final image we want to render all the points in between and then gently interpolated between those random values resulting in a much smoother finish there is obviously much more to purlin noise than this but this is as far as we will go once ready the map is scaled up to size and merged into the full stack through the ocean mixer layer these finally gives a biome to the ocean regions which can now be warm lukewarm cold or frozen the very final step this time for real is to upscale the map two more times this is not done using the traditional zoom layers that we have seen before but it relies on a different technique which breaks up even more the edges between the different biomes after this we are left with the actual biomap in which each pixel corresponds to an in-game block we are now ready to move to the next stage the second phase of the world generation focuses on the terrain and works in three steps in the third step caves and ravines are literally carved out of stone this is done with a slightly more sophisticated variance of random walk called purlin worms but at its core the idea is the same gently moving a sphere in random directions carving long tunnels along its path out of the three steps the minecraft takes to generate its terrain the first one definitely needs a bit more explanation minecraft builds a complex and interesting terrain through a technique known as fractal brownian motion noise yet another type of noise map fractal noise is constructed by adding together several pearly noise maps sampled at different scales each new one called an octave has doubled the resolution of the previous one but its contribution is also halved fractal noise is famously good at generating plausible looking terrains and it works because it adds different amounts of details at different scales exactly what we can see on a real landscape minecraft could have easily sampled a fractal map at every x-z coordinate to get the respective terrain height like you see here but this is not how the game actually works so how is minecraft getting the terrain height well it starts at the very top of the world at y equal 255 it then keeps moving downwards calculating the fractal noise value at each specific x y and z location along that vertical column the first y coordinate for which the fractal noise is equal to or above zero will become the final height of the terrain and that x and z coordinates an early devlog described the rationale behind this process saying that we should interpret the noise value as the density where anything lower than 0 would be air and anything higher than or equal to zero will be ground that very same post also mentioned how computationally expensive this process is so as a form of optimization this fractal noise map is sampled at a lower resolution with the words split into cells of four by eight by four blocks each to be more precise minecraft isn't used in one single fractal noise map it's using three of them and the reason is simple those noise maps are awesome but they're also fairly uniform by using two initialize with different parameters and blended according to a third noise map minecraft is able to add even more interesting natural looking variation to the terrain but that's still not all in earlier versions of minecraft the biomes and the terrain height map were independent of each other but from beta 1. 8 onwards that is no longer the case the biomap directly affects the terrain generation by modulating how tall each biome can be it does so via two parameters depth and scale those values depend on the type of biome and represent its average height and how much it can vary from that having the biome directly linked to the terrain height ultimately results in a more natural looking landscape preventing bizarre things like a mountain beach for example technically speaking there are at least two more noise maps involved in the terrain generation the depth noise map adds a bit of extra variability to compensate for the fact that the interpolation between cells smooths out the finer details and the surface noise which determines how many blocks of stone need to be replaced with a default block in each biome and there are probably at least 10 more involved in minor details such as the flower distribution but we're not going to go that deep in this video after the biomap and the terrain height we are pretty much left with a finished landscape but devoid of any vegetation animal structure or even all and yet no minecraft world will be truly complete without its dozens of different features grass flowers trees mushrooms mine shafts dungeons ruined portals villages and outposts or veins drip stones and amethyst geoids fossils ocean monuments witch huts jungles and desert temples icebergs igloos shipwrecks ocean ruins and woodland mansions because each one spawns according to its very own rules it would be impossible to cover them all in this video so let's just focus on the only structures that are really necessary to win the game strongholds these underground dungeons serve as the only way to access the end dimension each ward contains only 128 of them which spawn inside eight concentric rings the last of which has a radius between 22 and 24 000 blocks from the origin within each ring the strongholds are generated at roughly equal angles from the center while the actual strongholds are placed along with other structures in the population phase their position is calculated even before the terrain generates unlike all other features strong goals are key to the completion of the game making them a critical step that award generation needs to prioritize over cosmetic decorations or other overly abundant features and that's pretty much it congratulations you are now a procedural generation expert now let's take everything you've learned so far and throw it into the lava with the caves and cliff updates minecraft 1. 18 brings on a completely new terrain generator while before the landscape was only 128 blocks tall now it can stretch up to 320 blocks with so much more vertical space to play with it is not surprising that one of the biggest changes is mountains which are now much taller and proportionate to the rest of the world and to avoid disasters when playing old worlds in minecraft 1.
18 there is some clever blending going on this helps the new chunks to seamlessly integrate with the surrounding landscape and biomes but what really makes the difference is that minecraft 1. 18 uses a completely new algorithm to generate its biomaps and these can be seen quite clearly when we compare them to all the versions built using the layer stack that we've seen before and even more important is the fact that now biomes are to a certain extent 3d these allows underground caves to have their own biomes as the much anticipated lush caves do on top of carving its cave using purlin worms minecraft 1. 18 introduces three new types of caves cheesecakes spaghetti caves and noodle caves yes you heard me right they all generate the same way applying a threshold to a 3d purlin noise map to decide which underground areas are going to be carved out of the solid stone and just by seeding these noise maps with different parameters they can produce large caves long tunnels or a fine network of interconnected passageways cheese spaghetti and noodles and the results are new feature that creates pillars inside caves the update also ties the cave generation with a new ore distribution which is supposed to encourage digging and exploration so i know what you're going to ask how does minecraft 1.
18 actually work well it's complicated and also given how recent it is it might be a bit premature to go into the details of a system that is still subject to fixes and changes but just to quench you first the biome and the rain are now even more linked together if before the landscape was modulated by its biome now they both depend on a 3d climate map each quarter chunk an area of four by four by four blocks gets five climate parameters from a noise map temperature humidity continentalness erosion and weakness beside the first obvious two continentalness controls how far a region is from the coast and erosion dictates how flat or mountainous the terrain should be the last one weirdness determines biome variants each biome is defined by its own ideal temperature humidity continentalness erosion and weirdness with each quarter chunk assigned to the biome the most closely matches those five parameters a standard desert for instance will have high temperature continentalness and erosion while low humidity and weakness all regions matching those parameters will become deserts it is very curious that this new system works in a similar way to alpha 1. 2. 0 but with 5 parameters or 6 if you include the depth instead of just 2.