Generation
Basics
Each Instance
has an optional Generator
that is responsible for generating areas of various sizes.
The area size is abstracted as a GenerationUnit
representing an aggregate of sections, the generator then has the ability to place blocks (and biomes) using relative and absolute coordinates. The dynamically sized area allows the API to be more flexible, and allows the instance to choose whether to generate full chunks at once or section by section without changing the generator.
Generation tasks are currently forwarded to the common JDK pool. Virtual threads will be used once Project Loom is integrated into the mainline.
Your first flat world
Here is the naive way of generating a flat world from y=0 to y=40
GenerationUnit#absoluteStart
returns the lowest coordinate of the unit which is useful for absolute placements. Now, we can heavily simplify the code by using one of our hand-optimized methods:
Modifying over unit borders
Modification over the border of a GenerationUnit
cannot be done without extra steps. GenerationUnit
s cannot be resized during generation, instead we need to create a new GenerationUnit
that encloses the area around our target blocks. We can do this through the GenerationUnit#fork
methods.
Forked units are designed to be placed into the instance whenever it is possible to do so. This eliminates any section bordering issues that may arise.
There are two fork methods, both useful in their own ways. Here is a simple example of adding a structure (snowman):\
Adding structures using forks is trivial.
However, for this GenerationUnit#fork
method, you must know how large these structures are beforehand. To alleviate this condition, there is an alternative GenerationUnit#fork
method that gives access to a direct Block.Setter
. This Block.Setter
automatically adjusts the fork's size depending on the blocks you set using it.
Here is the same example written with the Block.Setter
utility:
These examples will generate a flat snow world with chunky snowmen scattered throughout, cleanly applying the snowmen whenever it is possible to do so.
Example with missing terrain for clarity:
Heightmaps with JNoise
This example shows a simply approach to building heightmaps using JNoise, this can be expanded to other noise implementations as well.
Here's and example of what that looks like:
Last updated