Sandboxels worldgen

This page aims to describe how Sandboxels defines worldgen presets. This system is really complicated.

Terminology

Real number: A number that may have a decimal, such as 0.1 or 36.7.
Integer: A number without a decimal, such as 0 or 12.

baseHeight

baseHeight is a real number that nominally defines the height of the world's bottom relative to the height of the canvas. The default value is 0.5, which is assumed if it is not specified (due to how this is checked, a value of 0 is treated as an unspecified value and 0.5 is used.
Values above or below 0.5 squish the world upwards and stretch it downwards, respectively.

A grass world with its baseHeight set to 0.000001, with only a few pixels of grass.
Grass world with baseHeight 0.000001
A grass world with its baseHeight set to 0.25, with the grass and some of the dirt generated.
Grass world with baseHeight 0.25
A grass world with its baseHeight set to 0.5, showing normal terrain generation.
Grass world with baseHeight 0.5
A grass world with its baseHeight set to 0.75 and a non-zero lowermost bottom, showing generation roughly squished into the second fourth down from the top of the canvas.
Grass world with baseHeight 0.75 and the bottom layer's bottom set to -0.0000001
A grass world with its baseHeight set to 0.75, showing generation roughly squished into the second fourth down from the top of the canvas, and the randomized negative lowermost bottom's added material extending the lowermost layer.
Grass world with baseHeight 0.75 and the bottom layer's bottom left at 0, becoming a negative value and creating extra basalt below the world which is brought into existence by the baseHeight.
A grass world with its baseHeight set to 1, showing the entire terrain squished into a few sparse places in the upper 2 pixels of the screen.
Grass world with baseHeight 1

layers

layers is an array of arrays that describes the worldgen preset's layers and elements. Each array is of the format [real number, string] or [real number, string, real number] (hereafter bottom, element, and chance1).

bottom

The first item in the array is a number, usually between 0 and 1.   bottom defines the bottom start of the layer, or the lowest position (relative to the vertical midpoint of the canvas) above which the layer's element will be placed.   If the bottom value is 0, it will be changed to a random negative number on world generation.
For instance (assuming a baseHeight of 0.5), a bottom value of 0.5 will define a section extending from {1/4 above the bottom of the canvas} to {either the middle height of the canvas, or the bottom value of the next highest (i.e. the previous) layer}; likewise, a bottom value of 1 would indicate a layer that starts and ends at the middle of the canvas (though such a layer wouldn't do anything), and a value of 0 would indicate a layer that starts from the bottom of the canvas (though the value would be changed as described below).
bottom values below 0 will try to generate pixels below the canvas.   Though these pixels do not generate because of the canvas edge, a negative value helps to fill in gaps at the bottom of the world caused by the random height offsets.   The extra material generated below the world will also generate (albeit compressed vertically) if baseHeight is greater than 0.5.
Layers are listed topmost first, with descending bottom values.   Any layers deviating from this order will override the layers after them.
If two layers have the same decimal, the one that is defined first (higher) will apply, but if that layer has a chance value less than 1, its pixels will have a corresponding random chance of being placed over the layer below.

element

The second item is a string.   This value defines the element (such as "dirt" or "iron") that comprises the layer.
element cannot be an array of element names.   Elements that do not exist in the game will be ignored.

chance

The third item is a real number between 0 and 1.   This value defines the probability that a layer's pixels will generate, such as 0 (never), 0.3 (30% of the time) or 1 (always).
The default value is 1.   (The game's code also uses || to check for a nonexistent value, so a value of 0 is ignored and treated as 1.)


The elements "red", "teal", "pink", "lime", and "orange" were modded in specifically for these images.
A world generated with the layers [[0.5, 'lime'], [0, 'teal']], resulting in a world with an upper lime half and a lower teal half.
A world generated with the layers
[
   [0.5, 'lime'],
   [0, 'teal']
]
generating with an upper lime half and a lower teal half.
A world generated with the layers [[0.75, 'lime'], [0.5, 'pink'], [0.25, 'red'], [0, 'teal']], resulting in a world with an upper lime half and a lower teal half.
A world generated with the layers
[
   [0.75, 'lime'],
   [0.5, 'pink'],
   [0.25, 'red'],
   [0, 'teal']
]
generating with (from the top down) lime, pink, red, and teal layers, each 1/4 of the world's thickness.
A world generated with the layers [[0.75, 'lime'], [0, 'pink'], [0.25, 'red'], [0.5, 'teal']], resulting in the pink layer, which is out of descending order, replacing all of the layers after it.
A world generated with the layers
[
   [0.75, 'lime'],
   [0, 'pink'],
   [0.25, 'red'],
   [0.5, 'teal']
]
where the pink layer, which is out of order, replaces all of the layers after it (red and teal).
A world generated with the layers [[0.75, 'lime'], [0.5, 'pink'], [0.25, 'orange', 0.5], [0.25, 'red'], [0, 'teal']], resulting in the orange layer generating over the red layer and replacing 50% of its pixels.
A world generated with the layers
[
   [0.75, 'lime'],
   [0.5, 'pink'],
   [0.25, 'orange', 0.5],
   [0.25, 'red'],
   [0.0, 'teal']
]
where the orange layer, which has the same bottom value as the red layer after it and has a chance value of 0.5. The orange layer randomly replaces half of the pixels from {the red layer below it} with orange pixels.
A world generated with the layers [[0.75, 'lime'], [0.5, 'pink'], [0.25, 'red'], [0.25, 'orange', 0.5], [0, 'teal']], resulting in the orange layer doing nothing because the teal layer it is now over has already ended.
A world generated with the layers
[
   [0.75, 'lime'],
   [0.5, 'pink'],
   [0.25, 'red'],
   [0.25, 'orange', 0.5],
   [0.0, 'teal']
]
where the orange layer with chance 0.5 has the same bottom value as the red layer, but is below it in the array. The orange layer thus applies to the teal layer, but it doesn't do anything because the teal layer already ends at 0.25; the orange layer here has no effect.
A world generated with the layers [[0.75, 'lime'], [0.5, 'pink'], [0.25, 'red'], [0.15, 'orange', 0.5], [0, 'teal']], resulting in the orange layer replacing half of the teal pixels only in the section of teal whose relative height ranges from 0.15 to 0.25.
A world generated with the layers
[
   [0.75, 'lime'],
   [0.5, 'pink'],
   [0.25, 'red'],
   [0.15, 'orange', 0.5],
   [0.0, 'teal']
]
where the orange layer with a chance of 0.5, which is over the teal layer but has a bottom value of 0.15, is only applied to the range of teal from 0.15 up to the start of red at 0.25.
A world generated with the layers [[0.75, 'orange', 0.4], [0.75, 'lime], [0.5, 'orange', 0.2], [0.5, 'pink], [0.25, 'orange', 0.1], [0.25, 'red], [0, 'orange', 0.05], [0, 'teal]], resulting in each layer down having half as may orange pixels as the one above it.
A world generated with the layers
[
   [0.75, 'orange', 0.4],
   [0.75, 'lime'],
   [0.5, 'orange', 0.2],
   [0.5, 'pink'],
   [0.25, 'orange', 0.1],
   [0.25, 'red'],
   [0, 'orange', 0.05],
   [0, 'teal']
]
where each layer has an orange layer above it, each with a different (lower) chance. The concentration of orange pixels decreases with each layer down.

complexity and heightVariance

complexity and heightVariance are values that determine the roughness/unevenness of the world.   complexity is an integer2 with a default value of 20, and heightVariance is a real number with a default value of 0.5.
complexity determines how many times to iterate the random height offsets, and heightVariance determines the size of these offsets.

A world with heightVariance of 10 to the negative 23rd power. It is perfectly flat.
A world with heightVariance 10 to the -23 and complexity 20
A world with heightVariance 0.2 and complexity 10. It is slightly rough.
A world with heightVariance 0.2 and complexity 10
A world with heightVariance 0.2 and complexity 20. It is slightly rough.
A world with heightVariance 0.2 and complexity 20
A world with heightVariance 0.2 and complexity 50. It is slightly rough.
A world with heightVariance 0.2 and complexity 50
A world with heightVariance 0.2 and complexity 100. It is somewhat rough.
A world with heightVariance 0.2 and complexity 100
A world with heightVariance 0.2 and complexity 200. It is rough.
A world with heightVariance 0.2 and complexity 200
A world with heightVariance 0.2 and complexity 500. It is very rough.
A world with heightVariance 0.2 and complexity 500
A world with heightVariance 0.5 and complexity 10. It is somewhat rough.
A world with heightVariance 0.5 and complexity 10
A world with heightVariance 0.5 and complexity 20. It is rough.
A world with heightVariance 0.5 and complexity 20
A world with heightVariance 0.5 and complexity 50. It is very rough.
A world with heightVariance 0.5 and complexity 50
A world with heightVariance 0.5 and complexity 100. It is very rough.
A world with heightVariance 0.5 and complexity 100
A world with heightVariance 0.5 and complexity 200. It is extremely rough.
A world with heightVariance 0.5 and complexity 200
A world with heightVariance 0.5 and complexity 500. It is extremely rough, to the point of being covered erratically in long, thin spikes and holes.
A world with heightVariance 0.5 and complexity 500
A world with heightVariance 0.7 and complexity 10. It is somewhat rough.
A world with heightVariance 0.7 and complexity 10
A world with heightVariance 0.7 and complexity 20. It is between the 0.5/20 world and the 0.5/50 world in terms of roughness.
A world with heightVariance 0.7 and complexity 20
A world with heightVariance 0.7 and complexity 50. It is very rough.
A world with heightVariance 0.7 and complexity 50
A world with heightVariance 0.7 and complexity 100. It is about as rough as the 0.5/200 world.
A world with heightVariance 0.7 and complexity 100
A world with heightVariance 0.7 and complexity 200. It is about as rough as the 0.5/500 world.
A world with heightVariance 0.7 and complexity 200
A world with heightVariance 0.7 and complexity 500. It is extremely rough, even more so than the 0.5/500 world; it is covered in long, thin spikes extending as high as 1/8 of the canvas, and these spikes often surround deep, single-pixel holes.
A world with heightVariance 0.7 and complexity 500
A world with heightVariance 1.0 and complexity 10. It is about as rough as the 0.2/200 world.
A world with heightVariance 1.0 and complexity 10
A world with heightVariance 1.0 and complexity 20. It is very rough.
A world with heightVariance 1.0 and complexity 20
A world with heightVariance 1.0 and complexity 50. It is very rough.
A world with heightVariance 1.0 and complexity 50
A world with heightVariance 1.0 and complexity 100. It is extremely rough.
A world with heightVariance 1.0 and complexity 100
A world with heightVariance 1.0 and complexity 200. It is between the 0.7/200 and 0.7/500 worlds in roughness, with many spikes and even more holes.
A world with heightVariance 1.0 and complexity 200
A world with heightVariance 1.0 and complexity 500. It has huge spikes, one 1/4 of the canvas in height. The ground is almost entirely tall spikes and deep holes, to the point where it is difficult to regard it as ground. Several spikes often appear next to each other and make a bigger spike.
A world with heightVariance 1.0 and complexity 500
A world with heightVariance 1.5 and complexity 10. It is slightly rougher than the 0.5/100 world.
A world with heightVariance 1.5 and complexity 10
A world with heightVariance 1.5 and complexity 20. It is extremely rough.
A world with heightVariance 1.5 and complexity 20
A world with heightVariance 1.5 and complexity 50. It is slightly rougher than the 1.0/100 world.
A world with heightVariance 1.5 and complexity 50
A world with heightVariance 1.5 and complexity 100. It is slightly rougher than the 1.0/200 world.
A world with heightVariance 1.5 and complexity 100
A world with heightVariance 1.5 and complexity 200. It is rougher than the 1.0/500 world, with even more spikes which are often close together and separated by deep holes.
A world with heightVariance 1.5 and complexity 200
A world with heightVariance 1.5 and complexity 500. It is even rougher, with nothing but spikes and holes which sometimes approach the vertical edges of the canvas. Is this even ground anymore?
A world with heightVariance 1.5 and complexity 500

  1. The only layer value that is given any name in the code is the second value (element). The others are only referred to by their indices as layer[0] and layer[2].
  2. complexity is used as the bound in a for loop incremented by 1, so a real complexity would be equivalent to the next highest integer (e.g. 20.1 would be equivalent to 21).

This page previously stated that baseHeight values below 0.5 merely shift the world down. That is incorrect, and they actually stretch it downward.


go to main page