use of rtg.api.util.DecoUtil in project Realistic-Terrain-Generation by Team-RTG.
the class DecoTree method generate.
@Override
public void generate(IRealisticBiome biome, RTGWorld rtgWorld, Random rand, int worldX, int worldZ, float strength, float river, boolean hasPlacedVillageBlocks) {
if (this.allowed) {
/*
* Determine how many trees we're going to try to generate (loopCount).
* The actual number of trees that end up being generated could be *less* than this value,
* depending on environmental conditions.
*/
float noise = rtgWorld.simplex.noise2(worldX / this.distribution.noiseDivisor, worldZ / this.distribution.noiseDivisor) * this.distribution.noiseFactor + this.distribution.noiseAddend;
int loopCount = this.loops;
loopCount = (this.strengthFactorForLoops > 0f) ? (int) (this.strengthFactorForLoops * strength) : loopCount;
loopCount = (this.strengthNoiseFactorForLoops) ? (int) (noise * strength) : loopCount;
loopCount = (this.strengthNoiseFactorXForLoops) ? (int) (noise * this.strengthFactorForLoops * strength) : loopCount;
if (loopCount < 1) {
return;
}
// Now let's check the configs to see if we should increase/decrease this value.
DecoUtil decoUtil = new DecoUtil(this);
loopCount = decoUtil.calculateLoopCountFromTreeDensity(loopCount, biome);
if (loopCount < 1) {
return;
}
/*
* Since RTG posts a TREE event for each batch of trees it tries to generate (instead of one event per chunk),
* we post this custom event so that we can pass the number of trees RTG expects to generate in each batch.
*
* This provides more contextual information to mods like Recurrent Complex, which can use the info to better
* determine how to handle each batch of trees.
*
* Because the custom event extends DecorateBiomeEvent.Decorate, it still works with mods that don't need
* the additional context.
*/
DecorateBiomeEventRTG.DecorateRTG event = new DecorateBiomeEventRTG.DecorateRTG(rtgWorld.world, rand, new BlockPos(worldX, 0, worldZ), TREE, loopCount);
MinecraftForge.TERRAIN_GEN_BUS.post(event);
if (event.getResult() != Event.Result.DENY) {
loopCount = event.getModifiedAmount();
if (loopCount < 1) {
return;
}
WorldUtil worldUtil = new WorldUtil(rtgWorld.world);
DecoBase.tweakTreeLeaves(this, false, true);
for (int i = 0; i < loopCount; i++) {
// + 8;
int intX = scatter.get(rand, worldX);
// + 8;
int intZ = scatter.get(rand, worldZ);
int intY = rtgWorld.world.getHeight(new BlockPos(intX, 0, intZ)).getY();
if (intY <= this.maxY && intY >= this.minY && isValidTreeCondition(noise, rand, strength)) {
// If we're in a village, check to make sure the tree has extra room to grow to avoid corrupting the village.
if (hasPlacedVillageBlocks) {
if (!worldUtil.isSurroundedByBlock(Blocks.AIR.getDefaultState(), 2, WorldUtil.SurroundCheckType.CARDINAL, rand, intX, intY, intZ)) {
return;
}
}
switch(this.treeType) {
case RTG_TREE:
//this.setLogBlock(strength < 0.2f ? BlockUtil.getStateLog(2) : this.logBlock);
this.tree.setLogBlock(this.logBlock);
this.tree.setLeavesBlock(this.leavesBlock);
this.tree.setTrunkSize(RandomUtil.getRandomInt(rand, this.minTrunkSize, this.maxTrunkSize));
this.tree.setCrownSize(RandomUtil.getRandomInt(rand, this.minCrownSize, this.maxCrownSize));
this.tree.setNoLeaves(this.noLeaves);
this.tree.generate(rtgWorld.world, rand, new BlockPos(intX, intY, intZ));
break;
case WORLDGEN:
WorldGenerator worldgenerator = this.worldGen;
worldgenerator.generate(rtgWorld.world, rand, new BlockPos(intX, intY, intZ));
break;
default:
break;
}
} else {
//Logger.debug("%d/%d/%d - minY = %d; maxY = %d; noise = %f", intX, intY, intZ, minY, maxY, noise);
}
}
} else {
//Logger.debug("Tree generation was cancelled.");
}
}
}
Aggregations