我有一个关于如何在具有随机大小和山丘的世界中生成随机生物群落的问题。
例如,如果我有平原生物群落,最大噪声高度为 8,而在山地生物群落中,最大噪声高度为 64,并且这些生物群落之间的过渡会平滑。
我已经有了代码,此代码生成生物群系方 block 并且生物群系之间的过渡不平滑:/
主要内容:
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;
}
}
生物基因组:
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;
}
}
}
}
请帮助我:)
最佳答案
这可能不是您要找的,但是this thread关于如何使生物群落不仅仅是相互接触的正方形,有一些非常巧妙的想法。准备使用很多数学!
关于java - 如何在 spigot 插件中生成生物群系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65944246/