use of rtg.api.util.WorldUtil in project Realistic-Terrain-Generation by Team-RTG.
the class DecoCrop 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) {
WorldUtil worldUtil = new WorldUtil(rtgWorld.world);
WorldGenerator worldGenerator = new WorldGenCrops(type, size, density, height, water);
if (this.chance < 1) {
return;
}
for (int l1 = 0; l1 < this.strengthFactor * strength; ++l1) {
// + 8;
int i1 = worldX + rand.nextInt(16);
// + 8;
int j1 = worldZ + rand.nextInt(16);
int k1 = rtgWorld.world.getHeight(new BlockPos(i1, 0, j1)).getY();
if (k1 >= this.minY && k1 <= this.maxY && rand.nextInt(this.chance) == 0) {
// If we're in a village, check to make sure the boulder has extra room to grow to avoid corrupting the village.
if (hasPlacedVillageBlocks) {
if (!worldUtil.isSurroundedByBlock(Blocks.AIR.getDefaultState(), 2, WorldUtil.SurroundCheckType.CARDINAL, rand, i1, k1, j1)) {
return;
}
}
worldGenerator.generate(rtgWorld.world, rand, new BlockPos(i1, k1, j1));
}
}
}
}
use of rtg.api.util.WorldUtil in project Realistic-Terrain-Generation by Team-RTG.
the class DecoShrub 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) {
DecoBase.tweakShrubLeaves(this, false, true);
// Shrub size.
this.size = (this.size == -1) ? rand.nextInt(4) + 1 : this.size;
if (this.minSize > 0 && this.maxSize > 0 && this.maxSize >= this.minSize) {
this.size = this.minSize + rand.nextInt(this.maxSize - this.minSize + 1);
}
// Do we want random shrubs?
if (this.useDefaultRandom && this.randomLogBlocks.length > 0 && this.randomLogBlocks.length == this.randomLeavesBlocks.length) {
int rnd = rand.nextInt(this.randomLogBlocks.length);
this.setLogBlock(this.randomLogBlocks[rnd]);
this.setLeavesBlock(this.randomLeavesBlocks[rnd]);
}
WorldUtil worldUtil = new WorldUtil(rtgWorld.world);
WorldGenerator worldGenerator = new WorldGenShrubRTG(this.size, this.logBlock, this.leavesBlock, this.sand);
int loopCount = this.loops;
loopCount = (this.strengthFactor > 0f) ? (int) (this.strengthFactor * strength) : loopCount;
for (int i = 0; i < loopCount; i++) {
// + 8;
int intX = worldX + rand.nextInt(16);
// + 8;
int intZ = worldZ + rand.nextInt(16);
int intY = rtgWorld.world.getHeight(new BlockPos(intX, 0, intZ)).getY();
if (this.notEqualsZeroChance > 1) {
if (intY >= this.minY && intY <= this.maxY && rand.nextInt(this.notEqualsZeroChance) != 0) {
generateWorldGenerator(worldGenerator, worldUtil, rtgWorld.world, rand, intX, intY, intZ, hasPlacedVillageBlocks);
}
} else {
if (intY >= this.minY && intY <= this.maxY && rand.nextInt(this.chance) == 0) {
generateWorldGenerator(worldGenerator, worldUtil, rtgWorld.world, rand, intX, intY, intZ, hasPlacedVillageBlocks);
}
}
}
}
}
use of rtg.api.util.WorldUtil in project Realistic-Terrain-Generation by Team-RTG.
the class DecoSponge 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) {
WorldUtil worldUtil = new WorldUtil(rtgWorld.world);
WorldGenerator worldGenerator = new WorldGenSponge(spongeBlock, 0, rand, validGroundBlocks);
for (int l1 = 0; l1 < this.strengthFactor * strength; ++l1) {
// + 8;
int i1 = worldX + rand.nextInt(16);
// + 8;
int j1 = worldZ + rand.nextInt(16);
int k1;
switch(this.heightType) {
case NEXT_INT:
k1 = RandomUtil.getRandomInt(rand, this.minY, this.maxY);
break;
case GET_HEIGHT_VALUE:
k1 = rtgWorld.world.getHeight(new BlockPos(i1, 0, j1)).getY();
break;
default:
k1 = rtgWorld.world.getHeight(new BlockPos(i1, 0, j1)).getY();
break;
}
if (k1 >= this.minY && k1 <= this.maxY && rand.nextInt(this.chance) == 0) {
worldGenerator.generate(rtgWorld.world, rand, new BlockPos(i1, k1, j1));
}
}
}
}
use of rtg.api.util.WorldUtil in project Realistic-Terrain-Generation by Team-RTG.
the class DecoFallenTree 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) {
float noise = rtgWorld.simplex.noise2(worldX / this.distribution.noiseDivisor, worldZ / this.distribution.noiseDivisor) * this.distribution.noiseFactor + this.distribution.noiseAddend;
WorldUtil worldUtil = new WorldUtil(rtgWorld.world);
//Do we want to choose a random log?
if (this.randomLogBlocks.length > 0) {
this.setLogBlock(this.randomLogBlocks[rand.nextInt(this.randomLogBlocks.length)]);
}
WorldGenerator worldGenerator = null;
int finalSize = 4;
// Adjust the chance according to biome config.
this.setLogConditionChance(decoUtil.adjustChanceFromMultiplier(this.getLogConditionChance(), biome.getConfig().FALLEN_LOG_DENSITY_MULTIPLIER.get()));
if (this.maxSize > this.minSize) {
finalSize = this.minSize + rand.nextInt(this.maxSize - this.minSize);
worldGenerator = new WorldGenLog(this.logBlock, this.leavesBlock, finalSize);
} else if (this.maxSize == this.minSize) {
finalSize = this.minSize;
worldGenerator = new WorldGenLog(this.logBlock, this.leavesBlock, finalSize);
} else {
worldGenerator = new WorldGenLog(this.logBlock, this.leavesBlock, finalSize);
}
for (int i = 0; i < this.loops; i++) {
if (isValidLogCondition(noise, strength, rand)) {
// + 8;
int x22 = worldX + rand.nextInt(16);
// + 8;
int z22 = worldZ + rand.nextInt(16);
int y22 = rtgWorld.world.getHeight(new BlockPos(x22, 0, z22)).getY();
if (y22 <= this.maxY) {
// If we're in a village, check to make sure the log has extra room to grow to avoid corrupting the village.
if (hasPlacedVillageBlocks) {
if (!worldUtil.isSurroundedByBlock(Blocks.AIR.getDefaultState(), finalSize, WorldUtil.SurroundCheckType.CARDINAL, rand, x22, y22, z22)) {
return;
}
}
worldGenerator.generate(rtgWorld.world, rand, new BlockPos(x22, y22, z22));
}
}
}
}
}
use of rtg.api.util.WorldUtil in project Realistic-Terrain-Generation by Team-RTG.
the class WorldGenLog method generate.
public boolean generate(World world, Random rand, int x, int y, int z) {
IBlockState g = world.getBlockState(new BlockPos(x, y - 1, z));
if (g.getMaterial() != Material.GROUND && g.getMaterial() != Material.GRASS && g.getMaterial() != Material.SAND && g.getMaterial() != Material.ROCK) {
return false;
}
WorldUtil worldUtil = new WorldUtil(world);
// The direction of the log (0 = X; 1 = Z)
int dir = rand.nextInt(2);
int i;
IBlockState b;
int air = 0;
ArrayList<Integer> aX = new ArrayList<Integer>();
ArrayList<Integer> aY = new ArrayList<Integer>();
ArrayList<Integer> aZ = new ArrayList<Integer>();
ArrayList<IBlockState> aBlock = new ArrayList<IBlockState>();
for (i = 0; i < logLength; i++) {
b = world.getBlockState(new BlockPos(x - (dir == 0 ? 1 : 0), y, z - (dir == 1 ? 1 : 0)));
if (b.getMaterial() != Material.AIR && b.getMaterial() != Material.VINE && b.getMaterial() != Material.PLANTS) {
break;
}
x -= dir == 0 ? 1 : 0;
z -= dir == 1 ? 1 : 0;
if (airCheck(world, rand, x, y, z) > 0) {
return false;
}
}
for (i = 0; i < logLength * 2; i++) {
b = world.getBlockState(new BlockPos(x + (dir == 0 ? 1 : 0), y, z + (dir == 1 ? 1 : 0)));
if (b.getMaterial() != Material.AIR && b.getMaterial() != Material.VINE && b.getMaterial() != Material.PLANTS) {
break;
}
air += airCheck(world, rand, x, y, z);
if (air > 2) {
return false;
}
/**
* Before we place the log block, let's make sure that there's an air block immediately above it.
* This is to ensure that the log doesn't override, for example, a 2-block tall plant,
* which some mods (like WAILA) have trouble handling.
*
* Also, to ensure that we don't have 'broken' logs, if one log block fails the check,
* then no logs actually get placed.
*/
if (!worldUtil.isBlockAbove(Blocks.AIR.getDefaultState(), 1, world, x, y, z, true)) {
//Logger.debug("Found non-air block above log at %d %d %d", x, y, z);
return false;
}
// Store the log information instead of placing it straight away.
aX.add(x);
aY.add(y);
aZ.add(z);
// If we can't rotate the log block for whatever reason, then just place it as it is.
try {
aBlock.add(logBlock.withProperty(BlockLog.LOG_AXIS, (dir == 0 ? BlockLog.EnumAxis.X : BlockLog.EnumAxis.Z)));
} catch (Exception e) {
aBlock.add(logBlock);
}
if (this.generateLeaves) {
addLeaves(world, rand, dir, x, y, z);
}
x += dir == 0 ? 1 : 0;
z += dir == 1 ? 1 : 0;
}
for (int i1 = 0; i1 < aBlock.size(); i1++) {
world.setBlockState(new BlockPos(aX.get(i1).intValue(), aY.get(i1).intValue(), aZ.get(i1).intValue()), aBlock.get(i1), 2);
}
return true;
}
Aggregations