Custom Biomegenerator Height

Hi there,

I currently working on a larger project. For this project I need a few country-like islands. I want to link each island to a biome-type -> implemented BiomeGenerator.
So, first I’m creating a heightmap, then setting biomes River, Beach and e.g. Forest to the BiomeGenerator block by block depending on the actual height. But, when the World is created, the heights did not matched.

I want to support the normal generators of Vanilla, Forge, etc. So, I don’t want to implement a complete new WorldGenerator, but set the actual height (of my own heightMap, not of the Vanilla’s heightmap.

Is there any ideas to set a custom height to the existing GeneratorPopulator?

Thanks,
Fabian

Alright, the first thing you should be aware of is that the min/max height specified in the BiomeType are
really misnamed, (they’re named according to those fields in MCP but the mcp field names are incorrect). Its
better to look at the vanilla values for various height sets and think about them more like weights:

height_Default = (0.1F, 0.2F)
height_ShallowWaters = (-0.5F, 0.0F)
height_Oceans = (-1.0F, 0.1F)
height_DeepOceans = (-1.8F, 0.1F)
height_LowPlains = (0.125F, 0.05F)
height_MidPlains = (0.2F, 0.2F)
height_LowHills = (0.45F, 0.3F)
height_HighPlateaus = (1.5F, 0.025F)
height_MidHills = (1.0F, 0.5F)
height_Shores = (0.0F, 0.025F)
height_RockyWaters = (0.1F, 0.8F)
height_LowIslands = (0.2F, 0.3F)
height_PartiallySubmerged = (-0.2F, 0.1F)

(See the related issue here https://github.com/SpongePowered/SpongeCommon/issues/107)

Off the top of my head though the first value is something like a base height weight and the second value is
the variance.

I’m a little unsure though on what you are trying to achieve though, perhaps you can give me a little more information.

If you’re trying to use a heightmap to influence biome placements but still use the vanilla terrain generation
including the generation of the actual end height map then you can do something like this:

public class IslandBiomeGen implements BiomeGenerator {

    private static final double ISLAND_SIZE = 200f;
    private static final double BEACH_RADIUS = ISLAND_SIZE * ISLAND_SIZE;
    private static final double FOREST_SIZE = ISLAND_SIZE - 7;
    private static final double FOREST_RADIUS = FOREST_SIZE * FOREST_SIZE;
    private static final double HILLS_SIZE = FOREST_SIZE - 120;
    private static final double HILLS_RADIUS = HILLS_SIZE * HILLS_SIZE;

    @Override
    public void generateBiomes(MutableBiomeArea buffer) {
        Vector2i min = buffer.getBiomeMin();
        Vector2i max = buffer.getBiomeMax();

        for (int x = min.getX(); x <= max.getX(); x++) {
            for (int y = min.getY(); y <= max.getY(); y++) {
                if (x * x + y * y < HILLS_RADIUS) {
                    buffer.setBiome(x, y, BiomeTypes.EXTREME_HILLS);
                } else if (x * x + y * y < FOREST_RADIUS) {
                    buffer.setBiome(x, y, BiomeTypes.FOREST);
                } else if (x * x + y * y < BEACH_RADIUS) {
                    buffer.setBiome(x, y, BiomeTypes.BEACH);
                } else {
                    buffer.setBiome(x, y, BiomeTypes.OCEAN);
                }
            }
        }
    }
}

This is using a simple series of radii to interpolate a pseudo heightmap of an island centered on (0, 0).
Since I am only specifying the biomes and letting the vanilla heightmap generator do its thing from there
the end result ends up like this:

island

If you wanted more fine grained control over the final heightmap you would implement GenreatorPopulator and set it on the world generator as the BaseGeneratorPopulator.

Okay, maybe “HeightMap” goes in the wrong direction. I generate a height map, because of the different heights of ocean, beach and forest. My code looks very similar to yours, except my heightmap seems a little bit more naturally.

I tested your code, but my generated map not looks the same as yours. What did i do wrong?

My code inserting the biomeGenerator:

    @Listener
    public void onLoadWorld(LoadWorldEvent event) {
        World world = event.getTargetWorld();
        WorldGenerator generator = world.getWorldGenerator();
        generator.setBiomeGenerator(new IslandBiomeGen());
        world.setWorldGenerator(generator);
    }

I used my branch for that example which has a bunch of world generation changes so thats probably the source of the differences. It should be merged into master soon hopefully just working out the final kinks. You can try building the branch yourself and testing it out if you want its feature/populators-phase on all three repositories (SpongeForge/SpongeCommon/SpongeAPI).

1 Like

That must be it. Do you know when approximately the branch is being merged?