use of net.tropicraft.core.common.dimension.noise.NoiseModule in project Tropicraft by Tropicraft.
the class VolcanoGenerator method generate.
public ChunkAccess generate(int chunkX, int chunkZ, ChunkAccess chunk, WorldgenRandom random) {
BlockPos volcanoCoords = VolcanoGenerator.getVolcanoNear(this.biomeSource, this.worldSeed, chunkX, chunkZ, 0);
if (volcanoCoords == null) {
return chunk;
}
int HEIGHT_OFFSET = VolcanoGenerator.getHeightOffsetForBiome(volcanoCoords.getY());
int calderaCutoff = CALDERA_CUTOFF + HEIGHT_OFFSET;
int lavaLevel = LAVA_LEVEL + HEIGHT_OFFSET;
int volcanoTop = VOLCANO_TOP + HEIGHT_OFFSET;
int volcanoCrust = VOLCANO_CRUST + HEIGHT_OFFSET;
chunkX *= CHUNK_SIZE_X;
chunkZ *= CHUNK_SIZE_Z;
int volcCenterX = volcanoCoords.getX();
int volcCenterZ = volcanoCoords.getZ();
long seed = getPositionSeed(volcCenterX, volcCenterZ);
Random rand = new Random(seed);
int radiusX = rand.nextInt(MAX_RADIUS - MIN_RADIUS) + MIN_RADIUS;
int radiusZ = rand.nextInt(MAX_RADIUS - MIN_RADIUS) + MIN_RADIUS;
NoiseModule volcNoise = getNoise(seed);
BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
// if this chunk contains the volcano center
if (volcanoCoords.getX() <= chunkX + 15 && volcanoCoords.getX() >= chunkX && volcanoCoords.getZ() <= chunkZ + 15 && volcanoCoords.getZ() >= chunkZ) {
BlockPos volcanoBlockPos = new BlockPos(volcanoCoords.getX() & 15, 1, volcanoCoords.getZ() & 15);
chunk.setBlockState(volcanoBlockPos, TropicraftBlocks.VOLCANO.get().defaultBlockState(), false);
}
for (int x = 0; x < CHUNK_SIZE_X; x++) {
for (int z = 0; z < CHUNK_SIZE_Z; z++) {
int relativeX = ((x + chunkX) - volcCenterX);
int relativeZ = ((z + chunkZ) - volcCenterZ);
double volcanoHeight = getVolcanoHeight(relativeX, relativeZ, radiusX, radiusZ, volcNoise);
float distanceSquared = getDistanceSq(relativeX, relativeZ, radiusX, radiusZ);
int groundHeight = chunk.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, x, z);
groundHeight = Math.min(groundHeight, lavaLevel - 3);
if (distanceSquared < 1) {
for (int y = CHUNK_SIZE_Y; y > 0; y--) {
pos.set(x, y, z);
if (volcanoHeight + groundHeight < calderaCutoff) {
if (volcanoHeight + groundHeight <= volcanoTop) {
if (y <= volcanoHeight + groundHeight) {
if (y > groundHeight) {
this.placeBlock(pos, VOLCANO_BLOCK, chunk);
} else if (y > groundHeight - 2) {
this.placeBlock(pos, SAND_BLOCK, chunk);
}
}
} else if (y == volcanoCrust - 1) {
if (random.nextInt(3) != 0) {
this.placeBlock(pos, VOLCANO_BLOCK, chunk);
}
} else if (y <= volcanoTop) {
placeBlock(pos, VOLCANO_BLOCK, chunk);
}
} else {
// Flat area on top of the volcano
if (y == volcanoCrust && rand.nextInt(CRUST_HOLE_CHANCE) != 0) {
placeBlock(pos, VOLCANO_BLOCK, chunk);
} else if (y <= lavaLevel) {
placeBlock(pos, LAVA_BLOCK, chunk);
} else {
placeBlock(pos, Blocks.AIR::defaultBlockState, chunk);
}
}
}
}
}
}
return chunk;
}
use of net.tropicraft.core.common.dimension.noise.NoiseModule in project Tropicraft by Tropicraft.
the class VolcanoGenerator method getVolcanoHeight.
/**
* Get the height of volcano generation at the given x/z coordinates, without needing
* to generate any blocks.
*
* @param groundHeight The current known heightmap level at the given coordinates.
* @param x Block x position
* @param z Block z position
* @return The height value of the volcano generating near the given coordinates, at the
* specified x and z. If there is no nearby volcano, returns -1.
* @apiNote This only does a somewhat rough calculation -- it ignores the caldera "edge"
* and treats volcanoes as completely flat at the top (ignoring random holes).
* <p>
* The latter is actually beneficial to the main use, village gen, because otherwise
* village pieces may generate directly on top of a hole (and thus inside the volcano).
* <p>
* It also duplicates a significant amount of logic from {@link #generate(int, int, IChunk, SharedSeedRandom)},
* but I have yet to find a nice way to deduplicate that logic. This whole class could use
* a rewrite at some point with these goals in mind.
* <p>
*/
// TODO Fix the above issues
public int getVolcanoHeight(int groundHeight, int x, int z) {
BlockPos volcanoCoords = getVolcanoNear(this.biomeSource, this.worldSeed, x >> 4, z >> 4, 0);
if (volcanoCoords == null) {
return -1;
}
int volcCenterX = volcanoCoords.getX();
int volcCenterZ = volcanoCoords.getZ();
long seed = getPositionSeed(volcCenterX, volcCenterZ);
Random rand = new Random(seed);
int radiusX = rand.nextInt(MAX_RADIUS - MIN_RADIUS) + MIN_RADIUS;
int radiusZ = rand.nextInt(MAX_RADIUS - MIN_RADIUS) + MIN_RADIUS;
NoiseModule volcNoise = getNoise(seed);
int relativeX = x - volcCenterX;
int relativeZ = z - volcCenterZ;
double ret = getVolcanoHeight(relativeX, relativeZ, radiusX, radiusZ, volcNoise);
int heightOffset = getHeightOffsetForBiome(volcanoCoords.getY());
int lavaLevel = LAVA_LEVEL + heightOffset;
int volcanoCrust = VOLCANO_CRUST + heightOffset;
groundHeight = Math.min(groundHeight, lavaLevel - 3);
return Math.min(volcanoCrust + 1, Mth.ceil(ret + groundHeight));
}
use of net.tropicraft.core.common.dimension.noise.NoiseModule in project Tropicraft by Tropicraft.
the class VolcanoGenerator method getNoise.
private NoiseModule getNoise(long seed) {
NoiseModule volcNoise = new Billowed(seed, 1, 1);
volcNoise.amplitude = 0.45;
return volcNoise;
}
Aggregations