Minecraft的世界生成过程(七)矿物和树

目前的世界是不是还少了点什么——没有树、矿石怎么致富!

本篇应该是最后一篇了,研究下树和矿石之类的点缀的生成

populate函数

上一篇提到的,在provideChunk之后调用

    /**
     * Populates chunk with ores etc etc
     */
    public void populate(IChunkProvider chunkProvider, int chunkX, int chunkZ)
    {
        // 如果生成了可掉落方块则立即掉落
        BlockFalling.fallInstantly = true;
        int minBlockX = chunkX * 16;
        int minBlockZ = chunkZ * 16;
        BlockPos minBlockPos = new BlockPos(minBlockX, 0, minBlockZ);
        // 4个区块中心点生物群系
        BiomeGenBase biome = this.worldObj.getBiomeGenForCoords(minBlockPos.add(16, 0, 16));
        this.rand.setSeed(this.worldObj.getSeed());
        long k = this.rand.nextLong() / 2L * 2L + 1L;
        long l = this.rand.nextLong() / 2L * 2L + 1L;
        this.rand.setSeed((long)chunkX * k + (long)chunkZ * l ^ this.worldObj.getSeed());
        boolean hasVillage = false;
        ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(chunkX, chunkZ);

        net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.terraingen.PopulateChunkEvent.Pre(chunkProvider, worldObj, rand, chunkX, chunkZ, hasVillage));

        // 生成建筑

        if (this.settings.useMineShafts && this.mapFeaturesEnabled)
        {
            this.mineshaftGenerator.generateStructure(this.worldObj, this.rand, chunkcoordintpair);
        }

        if (this.settings.useVillages && this.mapFeaturesEnabled)
        {
            hasVillage = this.villageGenerator.generateStructure(this.worldObj, this.rand, chunkcoordintpair);
        }

        if (this.settings.useStrongholds && this.mapFeaturesEnabled)
        {
            this.strongholdGenerator.generateStructure(this.worldObj, this.rand, chunkcoordintpair);
        }

        if (this.settings.useTemples && this.mapFeaturesEnabled)
        {
            this.scatteredFeatureGenerator.generateStructure(this.worldObj, this.rand, chunkcoordintpair);
        }

        if (this.settings.useMonuments && this.mapFeaturesEnabled)
        {
            this.oceanMonumentGenerator.generateStructure(this.worldObj, this.rand, chunkcoordintpair);
        }

        // 生成湖
        if (   biome != BiomeGenBase.desert
            && biome != BiomeGenBase.desertHills
            && this.settings.useWaterLakes
            && !hasVillage
            && this.rand.nextInt(this.settings.waterLakeChance) == 0
            && net.minecraftforge.event.terraingen.TerrainGen.populate(chunkProvider, worldObj, rand, chunkX, chunkZ, hasVillage, net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType.LAKE))
        {
            int i1 = this.rand.nextInt(16) + 8;
            int j1 = this.rand.nextInt(256);
            int k1 = this.rand.nextInt(16) + 8;
            (new WorldGenLakes(Blocks.water)).generate(this.worldObj, this.rand, minBlockPos.add(i1, j1, k1));
        }

        // 生成岩浆湖
        if (   !hasVillage
            && this.rand.nextInt(this.settings.lavaLakeChance / 10) == 0
            && this.settings.useLavaLakes
            && net.minecraftforge.event.terraingen.TerrainGen.populate(chunkProvider, worldObj, rand, chunkX, chunkZ, hasVillage, net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType.LAVA))
        {
            int i2 = this.rand.nextInt(16) + 8;
            int l2 = this.rand.nextInt(this.rand.nextInt(248) + 8);
            int k3 = this.rand.nextInt(16) + 8;

            if (l2 < this.worldObj.getSeaLevel() || this.rand.nextInt(this.settings.lavaLakeChance / 8) == 0)
            {
                (new WorldGenLakes(Blocks.lava)).generate(this.worldObj, this.rand, minBlockPos.add(i2, l2, k3));
            }
        }

        // 生成地牢(刷怪笼)
        if (this.settings.useDungeons)
        {
            boolean doGen = net.minecraftforge.event.terraingen.TerrainGen.populate(chunkProvider, worldObj, rand, chunkX, chunkZ, hasVillage, net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType.DUNGEON);
            for (int j2 = 0; doGen && j2 < this.settings.dungeonChance; ++j2)
            {
                int i3 = this.rand.nextInt(16) + 8;
                int l3 = this.rand.nextInt(256);
                int l1 = this.rand.nextInt(16) + 8;
                (new WorldGenDungeons()).generate(this.worldObj, this.rand, minBlockPos.add(i3, l3, l1));
            }
        }

        // 生成树和矿石等
        biome.decorate(this.worldObj, this.rand, new BlockPos(minBlockX, 0, minBlockZ));

        // 生成动物
        if (net.minecraftforge.event.terraingen.TerrainGen.populate(chunkProvider, worldObj, rand, chunkX, chunkZ, hasVillage, net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType.ANIMALS))
        {
            SpawnerAnimals.performWorldGenSpawning(this.worldObj, biome, minBlockX + 8, minBlockZ + 8, 16, 16, this.rand);
        }

        minBlockPos = minBlockPos.add(8, 0, 8);

        // 生成冰和雪
        boolean doGen = net.minecraftforge.event.terraingen.TerrainGen.populate(chunkProvider, worldObj, rand, chunkX, chunkZ, hasVillage, net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType.ICE);
        for (int x = 0; doGen && x < 16; ++x)
        {
            for (int z = 0; z < 16; ++z)
            {
                BlockPos topBlock = this.worldObj.getPrecipitationHeight(minBlockPos.add(x, 0, z));
                BlockPos downBlock &
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值