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.
layers
The first item in the array is a number, usually between 0 and 1.
The second item is a string. This value defines the element (such as
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
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 chance
1).
bottom
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
"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
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.
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.