Search in sources :

Example 1 with WorldgenRandom

use of net.minecraft.world.level.levelgen.WorldgenRandom 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;
}
Also used : NoiseModule(net.tropicraft.core.common.dimension.noise.NoiseModule) Blocks(net.minecraft.world.level.block.Blocks) TropicraftBlocks(net.tropicraft.core.common.block.TropicraftBlocks) Random(java.util.Random) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom) BlockPos(net.minecraft.core.BlockPos)

Example 2 with WorldgenRandom

use of net.minecraft.world.level.levelgen.WorldgenRandom in project Tropicraft by Tropicraft.

the class MangroveSurfaceBuilder method initNoise.

@Override
public void initNoise(long seed) {
    if (this.seed != seed || this.mudNoise == null) {
        WorldgenRandom random = new WorldgenRandom(seed);
        this.mudNoise = new PerlinSimplexNoise(random, IntStream.rangeClosed(0, 2));
        this.streamNoise = new PerlinSimplexNoise(random, IntStream.rangeClosed(0, 2));
    }
    this.seed = seed;
}
Also used : PerlinSimplexNoise(net.minecraft.world.level.levelgen.synth.PerlinSimplexNoise) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom)

Example 3 with WorldgenRandom

use of net.minecraft.world.level.levelgen.WorldgenRandom in project Tropicraft by Tropicraft.

the class TropicraftChunkGenerator method fillFromNoise.

@Override
public CompletableFuture<ChunkAccess> fillFromNoise(Executor executor, StructureFeatureManager structures, ChunkAccess chunk) {
    CompletableFuture<ChunkAccess> future = super.fillFromNoise(executor, structures, chunk);
    return future.thenApply(chunkAccess -> {
        ChunkPos chunkPos = chunk.getPos();
        WorldgenRandom random = new WorldgenRandom(this.seed);
        volcano.generate(chunkPos.x, chunkPos.z, chunk, random);
        return chunkAccess;
    });
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) ChunkPos(net.minecraft.world.level.ChunkPos) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom)

Example 4 with WorldgenRandom

use of net.minecraft.world.level.levelgen.WorldgenRandom in project Tropicraft by Tropicraft.

the class HomeTreeBranchPiece method place.

@Override
public boolean place(StructureManager templates, WorldGenLevel world, StructureFeatureManager structures, ChunkGenerator generator, BlockPos origin, BlockPos p_230378_6_, Rotation rotation, BoundingBox chunkBounds, Random random, boolean p_230378_10_) {
    WorldgenRandom rand = new WorldgenRandom();
    rand.setDecorationSeed(world.getSeed(), origin.getX(), origin.getZ());
    final int branchLength = rand.nextInt(10) + 15;
    // TODO make configurable
    int branchX1 = origin.getX();
    int branchZ1 = origin.getZ();
    final double minAngle = Math.toRadians(this.minAngle);
    final double maxAngle = Math.toRadians(this.maxAngle);
    final double angle = minAngle + rand.nextFloat() * (maxAngle - minAngle);
    int branchX2 = (int) ((branchLength * Math.sin(angle)) + branchX1);
    int branchZ2 = (int) ((branchLength * Math.cos(angle)) + branchZ1);
    int branchY2 = rand.nextInt(4) + 4;
    BlockState wood = TropicraftBlocks.MAHOGANY_LOG.get().defaultBlockState();
    final BlockState leaf = TropicraftBlocks.MAHOGANY_LEAVES.get().defaultBlockState();
    final int leafCircleSizeConstant = 3;
    final int y2 = origin.getY() + branchY2;
    placeBlockLine(world, new BlockPos(branchX1, origin.getY(), branchZ1), new BlockPos(branchX2, y2, branchZ2), wood, chunkBounds);
    placeBlockLine(world, new BlockPos(branchX1 + 1, origin.getY(), branchZ1), new BlockPos(branchX2 + 1, y2, branchZ2), wood, chunkBounds);
    placeBlockLine(world, new BlockPos(branchX1 - 1, origin.getY(), branchZ1), new BlockPos(branchX2 - 1, y2, branchZ2), wood, chunkBounds);
    placeBlockLine(world, new BlockPos(branchX1, origin.getY(), branchZ1 + 1), new BlockPos(branchX2, y2, branchZ2 + 1), wood, chunkBounds);
    placeBlockLine(world, new BlockPos(branchX1, origin.getY(), branchZ1 - 1), new BlockPos(branchX2, y2, branchZ2 - 1), wood, chunkBounds);
    placeBlockLine(world, new BlockPos(branchX1, origin.getY() - 1, branchZ1), new BlockPos(branchX2, y2 - 1, branchZ2), wood, chunkBounds);
    placeBlockLine(world, new BlockPos(branchX1, origin.getY() + 1, branchZ1), new BlockPos(branchX2, y2 + 1, branchZ2), wood, chunkBounds);
    genLeafCircle(world, branchX2, y2 - 1, branchZ2, leafCircleSizeConstant + 5, leafCircleSizeConstant + 3, leaf, chunkBounds);
    genLeafCircle(world, branchX2, y2, branchZ2, leafCircleSizeConstant + 6, 0, leaf, chunkBounds);
    genLeafCircle(world, branchX2, y2 + 1, branchZ2, leafCircleSizeConstant + 10, 0, leaf, chunkBounds);
    genLeafCircle(world, branchX2, y2 + 2, branchZ2, leafCircleSizeConstant + 9, 0, leaf, chunkBounds);
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom) BlockPos(net.minecraft.core.BlockPos)

Aggregations

WorldgenRandom (net.minecraft.world.level.levelgen.WorldgenRandom)4 BlockPos (net.minecraft.core.BlockPos)2 Random (java.util.Random)1 ChunkPos (net.minecraft.world.level.ChunkPos)1 Blocks (net.minecraft.world.level.block.Blocks)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)1 PerlinSimplexNoise (net.minecraft.world.level.levelgen.synth.PerlinSimplexNoise)1 TropicraftBlocks (net.tropicraft.core.common.block.TropicraftBlocks)1 NoiseModule (net.tropicraft.core.common.dimension.noise.NoiseModule)1