How to generate biomes in spigot plugin

Viewed 653

I have a question about how to generate random biomes in the world with random sizes and hills.

For example, if i have biome plains, and max noise height is 8 and in biome mountains, the max noise height is 64 and the transition between these biomes would smooth.

I already have code and this code generates biome square and transitions between biomes not smooth :/

Main:

public class Generator extends ChunkGenerator {

SimplexOctaveGenerator simplexOctaveGenerator;

public Generator(long seed) {
    simplexOctaveGenerator = new SimplexOctaveGenerator(seed,16);
    simplexOctaveGenerator.setScale((double) 1/100);

}

@Override
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) {


    ChunkData chunk = createChunkData(world);

    int worldX = x * 16;
    int worldZ = z * 16;
    for(int i = worldX; i < worldX + 16; i++) {
        int chunkX = i - worldX;
        for(int j = worldZ; j < worldZ + 16; j++) {
            int chunkZ = j - worldZ;



            double noise = simplexOctaveGenerator.noise(i,j,0.2F,0.2F,true);

            Material toPlace = null;

            SimplexNoiseGenerator temperatureNoise = new SimplexNoiseGenerator(world.getSeed());
            SimplexNoiseGenerator humidityNoise = new SimplexNoiseGenerator(world.getSeed() + 1);
            SimplexNoiseGenerator heightNoise = new SimplexNoiseGenerator(world.getSeed() + 2);

            double temperature = temperatureNoise.noise(i / 100, j / 100);
            double humidity = humidityNoise.noise(i / 100, j / 100);
            double height = heightNoise.noise(i / 80,j / 100);

            for(int k = 0; k < world.getMaxHeight(); k++) {
                biome.setBiome(chunkX, k, chunkZ, BiomeGen.getBiome(temperature, humidity, height));
                Biome biom = biome.getBiome(chunkX, k, chunkZ);
                if(biom == Biome.DESERT) {
                    int y = (int) (noise * 4 + 100);
                    if (k <= 150 && k > y) {
                        toPlace = Material.AIR;
                    } else if (k > y) {
                        toPlace = Material.AIR;
                    } else if (k == y) {
                        toPlace = Material.GRASS_BLOCK;
                    } else if (k < y) {
                        toPlace = Material.STONE;
                    } else {
                        toPlace = Material.AIR;
                    }
                } else {
                    int y = (int) (noise * 16 + 100);
                    if (k <= 150 && k > y) {
                        toPlace = Material.AIR;
                    } else if (k > y) {
                        toPlace = Material.AIR;
                    } else if (k == y) {
                        toPlace = Material.GRASS_BLOCK;
                    } else if (k < y) {
                        toPlace = Material.STONE;
                    } else {
                        toPlace = Material.AIR;

                    }
                }
                chunk.setBlock(chunkX, k, chunkZ, toPlace);
            }
        }

    }

    return chunk;
}
}

BiomeGen:

   public static  Biome getBiome(double temperature, double humidity, double height) {
    if (temperature < -0.5) {
        // Frozen
        if (humidity < 0) {
            // Frozen and dry
            if (height < -0.5) {
                return Biome.FROZEN_OCEAN;
            } else if (height < 0.3) {
                return Biome.SNOWY_TUNDRA;
            } else {
                return Biome.SNOWY_MOUNTAINS;
            }
        } else {
            // Frozen and wet
            if (height < -0.5) {
                return Biome.FROZEN_OCEAN;
            } else if (height < 0.3) {
                return Biome.SNOWY_TAIGA;
            } else {
                return Biome.SNOWY_TAIGA_MOUNTAINS;
            }
        }
    } else if (temperature < 0) {
        // Cold
        if (humidity < 0) {
            // Cold and dry
            if (height < -0.5) {
                return Biome.COLD_OCEAN;
            } else if (height < 0.3) {
                return Biome.MOUNTAIN_EDGE;
            } else {
                return Biome.MOUNTAINS;
            }
        } else {
            // Cold and wet
            if (height < -0.5) {
                return Biome.COLD_OCEAN;
            } else if (height < 0.8) {
                return Biome.TAIGA;
            } else {
                return Biome.TAIGA_MOUNTAINS;
            }
        }
    } else if (temperature < 0.5) {
        // Normal
        if (humidity < 0) {
            // Normal and dry
            if (height < -0.5) {
                return Biome.OCEAN;
            } else if (height < 0.3) {
                return Biome.PLAINS;
            } else {
                return Biome.WOODED_HILLS;
            }
        } else {
            // Normal and wet
            if (height < -0.5) {
                return Biome.OCEAN;
            } else if (height < 0.3) {
                return Biome.BIRCH_FOREST;
            } else {
                return Biome.TALL_BIRCH_HILLS;
            }
        }
    } else {
        // Hot
        if (humidity < 0) {
            // Hot and dry
            if (height < -0.5) {
                return Biome.DESERT_LAKES;
            } else if (height < 0.3) {
                return Biome.DESERT;
            } else {
                return Biome.DESERT_HILLS;
            }
        } else {
            // Hot and wet
            if (height < -0.5) {
                return Biome.OCEAN;
            } else if (height < 0.3) {
                return Biome.JUNGLE;
            } else {
                return Biome.JUNGLE_HILLS;
            }
        }
    }
}

Screen: enter image description here

Please help me :)

1 Answers

This may not be exactly what you are looking for, but this thread has some really neat ideas on how to make the biomes more than just squares touching each other. Prepare to use a lot of math!

Related