Skip to content

Minecraft Classic map generation algorithm

Alex Mulkerrin edited this page Dec 2, 2015 · 19 revisions

Analysis is based on the decompiled source of the classic c0.30_01c client.

Minecraft Map Generator Summary

Parameters:

  • creator's name
  • level width
  • level depth
  • level height

Returns:

  • Minecraft level object

Terms

Perlin Noise is a noise function where the return value smoothly varies between input values close together https://en.wikipedia.org/wiki/Perlin_noise. It is implemented in a class with a method to create a noise distribution using a given pseudo-random number generator. After being initialised the noise function can be measured with a compute method which takes a 2D coordinate as input and returns a float which varies from -1 to 1 (inclusive?) Input can be a float or integer and the compute method will always return the same value given the same inputs.

Octave Noise is the summation of multiple noise functions where each function has differing frequency and amplitude. When computed it produces a series of results with smoothly varying noise at multiple scales, similar to a fractal or real world terrain height-maps. The implementation in Classic Minecraft is a class which takes as argument to its constructor an integer number of Perlin noise functions to compute and sum together. Each successive noise function/octave has twice the amplitude and half the frequency. This means that an Octave noise function of octave 8 will, when computed for a given 2D position, return a value from -128 to 128.

Combined Noise is used in Classic Minecraft to create a noise function where the rate of change of the returned value can vary over the 2D plane, eg. some valleys will be particularly steep while others have gentle slopes. This is achieved by taking one noise function and using its result to modify the arguments to a second noise function. The class prototype takes two noise functions as arguments, either Perlin or Octave noise functions. its compute method returns:

noise1.compute( x + noise2.compute(x,y), y)

Where x, y are the given 2D coords and noise1, noise2 are the two noise functions.

Analysis

Generation of a Classic Minecraft map, as seen on the sadly defunct browser-embedded version of creative mode that used to be hosted on the main Minecraft site, goes through a sequence of generation steps each time a new map is created:

  • choose map size
  • create height-map, "Raising..."
  • create strata, "Soiling..."
  • carve out caves, "Carving..."
  • create ore veins
  • flood fill-water, "Watering..."
  • flood fill-lava, "Melting..."
  • create surface layers, "Growing..."
  • create plants, "Planting..."

Choose map size

The players is prompted to choose from 3 default sizes; small medium or large. Small is 128 by 128 blocks in x,z coordinates (width and depth), medium is 256 by 256 and large is 512 by 512. All of the options have a height of 64 blocks with a water level at height/2 = 32. The entire map is created at once on generation and the edges of the map are impassible with a bedrock seabed two blocks below the water level.

Create height-map

Using:

  • heightMap, a 2D array of size width X depth
  • noise1, a combined noise function with two octave noise functions (of octave 8) as input.
  • noise2, a combined noise function with two octave noise functions (of octave 8) as input.
  • noise3, an octave noise function (of octave 6)

For each column in the x,z plane assign an elevation value to heightMap computed from:

Let heightLow be noise1.compute( x*1.3, z*1.3) / 6 - 4
Let heightHigh be noise2.compute( x*1.3, z*1.3) / 5 + 6

if noise3.compute(x,z) /8 > 0 {
    set heightResult to heightLow
} else {
    set heightResult to the maximum of heightLow and heightHigh
}

if heightResult < 0 {
    set heightResult to 8/10 its value
}

heightMap(x,z) is then set to the integer component of heightResult.

Create strata

// Todo

Carve out caves

// Todo

Create ore veins

// Todo

Flood-fill water

// Todo

Flood-fill lava

// Todo

Create surface layers

// Todo

Create plants

// Todo

Final adjustments to returned object

// Todo