【问题标题】:How to generate biomes in spigot plugin如何在 spigot 插件中生成生物群落
【发布时间】:2021-01-29 04:04:56
【问题描述】:

我有一个关于如何在世界上生成随机大小和山丘的随机生物群落的问题。

例如,如果我有生物群系平原,最大噪声高度为 8,而在生物群系山脉中,最大噪声高度为 64,并且这些生物群系之间的过渡会平滑。

我已经有代码,这个代码会生成生物群落方块,并且生物群落之间的过渡不平滑:/

主要:

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;
            }
        }
    }
}

屏幕:

请帮帮我:)

【问题讨论】:

    标签: java minecraft


    【解决方案1】:

    这可能不是您想要的,但this thread 有一些非常巧妙的想法,关于如何使生物群落不仅仅是相互接触的正方形。准备使用大量数学!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-23
      • 2022-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多