目前的世界是不是还少了点什么——没有树、矿石怎么致富!
本篇应该是最后一篇了,研究下树和矿石之类的点缀的生成
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 &