Search in sources :

Example 1 with NoisySphereConfig

use of potionstudios.byg.common.world.feature.config.NoisySphereConfig in project BYG by AOCAWOL.

the class NoisyCaveSphere method place.

public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos position, NoisySphereConfig config) {
    setSeed(world.getSeed());
    BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos().set(position.below(2 + random.nextInt(10)));
    BlockPos.MutableBlockPos mutable2 = new BlockPos.MutableBlockPos().set(mutable);
    int stackHeight = config.stackHeight().sample(random);
    NoisySphereConfig.RadiusSettings radiusSettings = config.radiusSettings();
    int xRadius = radiusSettings.xRadius().sample(random) / 2;
    int yRadius = radiusSettings.yRadius().sample(random) / 2;
    int zRadius = radiusSettings.zRadius().sample(random) / 2;
    fastNoise.SetFrequency(config.noiseFrequency());
    double radiusDivisorPerStack = config.radiusDivisorPerStack();
    ArrayList<BlockPos> caveAir = new ArrayList<>();
    for (int stackIDX = 0; stackIDX < stackHeight; stackIDX++) {
        for (int x = -xRadius; x <= xRadius; x++) {
            for (int z = -zRadius; z <= zRadius; z++) {
                for (int y = -yRadius; y <= yRadius; y++) {
                    mutable2.set(mutable).move(x, y, z);
                    // Credits to Hex_26 for this equation!
                    double equationResult = Math.pow(x, 2) / Math.pow(xRadius, 2) + Math.pow(y, 2) / Math.pow(yRadius, 2) + Math.pow(z, 2) / Math.pow(zRadius, 2);
                    double threshold = 1 + 0.7 * fastNoise.GetNoise(mutable2.getX(), mutable2.getY(), mutable2.getZ());
                    if (equationResult >= threshold)
                        continue;
                    if (world.getBlockState(mutable2).canOcclude()) {
                        if (mutable2.getY() <= 30) {
                            placeFluid(world, config.fluidState(), mutable2);
                        } else {
                            BlockState state = config.blockProvider().getState(random, mutable2);
                            if (state.isAir()) {
                                caveAir.add(mutable2.immutable());
                            }
                            world.setBlock(mutable2, state, 2);
                            // Remove non solids
                            for (int i = 0; i < 8; i++) {
                                BlockState blockState = world.getBlockState(mutable2);
                                if ((!blockState.canOcclude() && !blockState.isAir()) || blockState.is(BYGBlocks.CRYPTIC_VENT) || blockState.is(BYGBlocks.TALL_CRYPTIC_VENT) || blockState.is(BYGBlocks.CRYPTIC_FIRE)) {
                                    world.removeBlock(mutable2, false);
                                }
                                mutable2.move(Direction.UP);
                            }
                        }
                    }
                }
                xRadius = (int) (xRadius / radiusDivisorPerStack);
                yRadius = (int) (yRadius / radiusDivisorPerStack);
                zRadius = (int) (zRadius / radiusDivisorPerStack);
            }
        }
        for (BlockPos blockPos : caveAir) {
            for (Holder<PlacedFeature> spawningFeature : config.spawningFeatures()) {
                spawningFeature.value().place(world, chunkGenerator, random, blockPos);
            }
        }
    }
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) NoisySphereConfig(potionstudios.byg.common.world.feature.config.NoisySphereConfig) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.core.BlockPos) PlacedFeature(net.minecraft.world.level.levelgen.placement.PlacedFeature)

Example 2 with NoisySphereConfig

use of potionstudios.byg.common.world.feature.config.NoisySphereConfig in project BYG by AOCAWOL.

the class NoisyCaveSphereWater method place.

public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos position, NoisySphereConfig config) {
    setSeed(world.getSeed());
    BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos().set(position);
    BlockPos.MutableBlockPos mutable2 = new BlockPos.MutableBlockPos().set(mutable);
    int stackHeight = config.stackHeight().sample(random);
    NoisySphereConfig.RadiusSettings radiusSettings = config.radiusSettings();
    int xRadius = radiusSettings.xRadius().sample(random);
    int yRadius = radiusSettings.yRadius().sample(random);
    int zRadius = radiusSettings.zRadius().sample(random);
    fastNoise.SetFrequency(config.noiseFrequency());
    double radiusDivisorPerStack = config.radiusDivisorPerStack();
    for (int stackIDX = 0; stackIDX < stackHeight; stackIDX++) {
        for (int x = -xRadius; x <= xRadius; x++) {
            for (int z = -zRadius; z <= zRadius; z++) {
                for (int y = -yRadius; y <= 0; y++) {
                    mutable.setY(world.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, mutable.getX() + x, mutable.getZ() + z));
                    mutable2.set(mutable).move(x, y, z);
                    ChunkAccess chunk = world.getChunk(mutable2);
                    // BitSet airCarvingMask = ((ChunkPrimer) chunk).getOrAddCarvingMask(GenerationStage.Carving.AIR);
                    // Credits to Hex_26 for this equation!
                    double equationResult = Math.pow(x, 2) / Math.pow(xRadius, 2) + Math.pow(y, 2) / Math.pow(yRadius, 2) + Math.pow(z, 2) / Math.pow(zRadius, 2);
                    double threshold = 1 + 0.7 * fastNoise.GetNoise(mutable2.getX(), mutable2.getY(), mutable2.getZ());
                    if (equationResult >= threshold)
                        continue;
                    if (world.getBlockState(mutable2).canOcclude()) {
                        int bitIndex = (mutable2.getX() & 0xF) | ((mutable2.getZ() & 0xF) << 4) | (mutable2.getY() << 8);
                        // airCarvingMask.set(bitIndex);
                        world.setBlock(mutable2, Blocks.WATER.defaultBlockState(), 2);
                        world.scheduleTick(mutable2, Fluids.WATER, 0);
                    }
                }
                xRadius = (int) (xRadius / radiusDivisorPerStack);
                yRadius = (int) (yRadius / radiusDivisorPerStack);
                zRadius = (int) (zRadius / radiusDivisorPerStack);
            }
        }
    }
    return true;
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) NoisySphereConfig(potionstudios.byg.common.world.feature.config.NoisySphereConfig) BlockPos(net.minecraft.core.BlockPos)

Example 3 with NoisySphereConfig

use of potionstudios.byg.common.world.feature.config.NoisySphereConfig in project BYG by AOCAWOL.

the class NoiseSphere method place.

public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos position, NoisySphereConfig config) {
    setSeed(world.getSeed(), config.noiseFrequency());
    boolean use2D = random.nextDouble() < config.noise2DChance();
    RadiusMatcher radiusMatcher = config.radiusMatcher();
    BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos().set(position);
    BlockPos.MutableBlockPos mutable2 = new BlockPos.MutableBlockPos().set(mutable);
    NoisySphereConfig.RadiusSettings radiusSettings = config.radiusSettings();
    int xRadius = radiusSettings.xRadius().sample(random) / 2;
    int yRadius = radiusMatcher == RadiusMatcher.ALL ? xRadius : radiusSettings.yRadius().sample(random);
    int zRadius = radiusMatcher == RadiusMatcher.ALL || radiusMatcher == RadiusMatcher.XZ ? xRadius : (radiusSettings.zRadius().sample(random) / 2);
    int lowestX = position.getX();
    int lowestY = position.getY();
    int lowestZ = position.getZ();
    int stackHeight = config.stackHeight().sample(random);
    for (int stackIDX = 0; stackIDX < stackHeight; stackIDX++) {
        for (int x = -xRadius; x <= xRadius; x++) {
            float xFract = x / (float) xRadius;
            for (int z = -zRadius; z <= zRadius; z++) {
                float zFract = z / (float) zRadius;
                for (int y = -yRadius; y <= yRadius + radiusSettings.upperHalfAdditional(); y++) {
                    float yFract = y / (float) yRadius;
                    mutable2.set(mutable).move(x, y, z);
                    // Credits to Hex_26 for this equation!
                    float distanceSquaredFromCenter = xFract * xFract + yFract * yFract + zFract * zFract;
                    float yDistSquared = yFract * yFract;
                    float noise = use2D ? fastNoise.GetNoise(mutable2.getX(), mutable2.getZ()) : fastNoise.GetNoise(mutable2.getX(), mutable2.getY(), mutable2.getZ());
                    float threshold = 1 + 0.7f * noise;
                    // check whether the center of this column at this Y would be empty
                    float factor = yDistSquared / threshold;
                    if (factor >= 1) {
                        // make sure it's not empty
                        distanceSquaredFromCenter /= factor;
                        // add some extra noise back to make it not just a thin one block column
                        // the magnitude of the noise can be configurable
                        // this should probably be using its own noise for best effect
                        distanceSquaredFromCenter -= Math.copySign(noise * 0.2, distanceSquaredFromCenter);
                    }
                    if (distanceSquaredFromCenter >= threshold) {
                        continue;
                    }
                    int squaredDistance = (x * x) + (y * y) + (z * z);
                    if (config.checkSquareDistance() && squaredDistance >= xRadius * zRadius) {
                        continue;
                    }
                    world.setBlock(mutable2, config.topBlockProvider().getState(random, mutable2), 2);
                    world.setBlock(mutable2.move(Direction.DOWN), config.blockProvider().getState(random, mutable2), 2);
                    lowestX = Math.min(lowestX, mutable2.getX());
                    lowestY = Math.min(lowestY, mutable2.getY());
                    lowestZ = Math.min(lowestZ, mutable2.getZ());
                }
            }
        }
        xRadius = (int) (xRadius / config.radiusDivisorPerStack());
        yRadius = (int) (yRadius * 0.1F);
        mutable.setY(mutable.getY() + yRadius);
        zRadius = (int) (zRadius / config.radiusDivisorPerStack());
    }
    for (Holder<PlacedFeature> spawningFeature : config.spawningFeatures()) {
        spawningFeature.value().place(world, chunkGenerator, random, new BlockPos(lowestX, lowestY, lowestZ));
    }
    return true;
}
Also used : RadiusMatcher(potionstudios.byg.common.world.feature.config.RadiusMatcher) NoisySphereConfig(potionstudios.byg.common.world.feature.config.NoisySphereConfig) BlockPos(net.minecraft.core.BlockPos) PlacedFeature(net.minecraft.world.level.levelgen.placement.PlacedFeature)

Example 4 with NoisySphereConfig

use of potionstudios.byg.common.world.feature.config.NoisySphereConfig in project BYG by AOCAWOL.

the class Spike method place.

public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos position, NoisySphereConfig config) {
    setSeed(world.getSeed(), config.noiseFrequency());
    boolean use2D = random.nextDouble() < config.noise2DChance();
    RadiusMatcher radiusMatcher = config.radiusMatcher();
    BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos().set(position);
    BlockPos.MutableBlockPos mutable2 = new BlockPos.MutableBlockPos().set(mutable);
    NoisySphereConfig.RadiusSettings radiusSettings = config.radiusSettings();
    int xRadius = (int) ((double) radiusSettings.xRadius().sample(random) / 2);
    int yRadius = radiusMatcher == RadiusMatcher.ALL ? xRadius : (int) (double) (radiusSettings.yRadius().sample(random) / 2);
    int zRadius = radiusMatcher == RadiusMatcher.ALL || radiusMatcher == RadiusMatcher.XZ ? xRadius : (int) (double) (radiusSettings.zRadius().sample(random) / 2);
    int lowestX = position.getX();
    int lowestY = position.getY();
    int lowestZ = position.getZ();
    boolean verifiedHeight = !config.verfiesHeight();
    float perlin = fastNoise.GetPerlin((float) position.getX(), (float) position.getY(), (float) position.getZ());
    double scaledNoise = (perlin) * 8;
    double centerHeight = Mth.lerp(scaledNoise, 2, 7) + 10;
    int stackHeight = config.stackHeight().sample(random);
    int[][] built = new int[xRadius * 2 + 1][zRadius * 2 + 1];
    for (int stackIDX = 0; stackIDX <= stackHeight; ) {
        for (int x = -xRadius; x <= xRadius; x++) {
            mutable2.setX(mutable.getX() + x);
            double xFract = (double) x / xRadius;
            for (int z = -zRadius; z <= zRadius; z++) {
                mutable2.setZ(mutable.getZ() + z);
                double zFract = (double) z / zRadius;
                if (verifiedHeight) {
                    double addedHeight = config.useScaledNoiseHeight() ? getScaledNoiseExtensionHeight(mutable2, centerHeight) : 1;
                    if (addedHeight > built[x + xRadius][z + zRadius]) {
                        for (double y = -yRadius; y <= yRadius; y++) {
                            double yFract = y / yRadius;
                            mutable2.setY((int) (mutable.getY() + y));
                            // Credits to Hex_26 for this equation!
                            double distanceSquaredFromCenter = xFract * xFract + yFract * yFract + zFract * zFract;
                            double yDistSquared = yFract * yFract;
                            float noise = use2D ? fastNoise.GetNoise(mutable2.getX(), mutable2.getZ()) : fastNoise.GetNoise(mutable2.getX(), mutable2.getY(), mutable2.getZ());
                            float threshold = 1 + 0.7f * noise;
                            // check whether the center of this column at this Y would be empty
                            double factor = yDistSquared / threshold;
                            if (factor >= 1) {
                                // make sure it's not empty
                                distanceSquaredFromCenter /= factor;
                                // add some extra noise back to make it not just a thin one block column
                                // the magnitude of the noise can be configurable
                                // this should probably be using its own noise for best effect
                                distanceSquaredFromCenter -= Math.copySign(noise * 0.2, distanceSquaredFromCenter);
                            }
                            // if (distanceSquaredFromCenter >= threshold) {
                            // continue;
                            // }
                            double density = stackIDX == stackHeight && config.pointed() ? (y + yRadius + 1) / ((yRadius * 2) + 1) : 0;
                            double squaredDistance = ((x * x) + (z * z)) / Mth.clampedLerp(0.1, 1, 1 - density);
                            if (config.checkSquareDistance() && squaredDistance >= xRadius * zRadius) {
                                continue;
                            }
                            BlockPos.MutableBlockPos mutable3 = new BlockPos.MutableBlockPos().set(mutable2);
                            for (int noiseExtensionY = 0; noiseExtensionY < addedHeight; noiseExtensionY++) {
                                int minY = Math.min(position.getY(), world.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, mutable3.getX(), mutable3.getZ()));
                                boolean belowSurfaceDepth = minY - mutable3.getY() < config.belowSurfaceDepth().sample(random);
                                // if (!config.verfiesHeight() || belowSurfaceDepth) {
                                world.setBlock(mutable3, config.topBlockProvider().getState(random, mutable3), 2);
                                world.setBlock(mutable3.relative(Direction.DOWN), config.blockProvider().getState(random, mutable3), 2);
                                // }
                                mutable3.move(Direction.UP);
                            }
                            built[x + xRadius][z + zRadius] = Math.max(mutable3.getY(), built[x + xRadius][z + zRadius]);
                            lowestX = Math.min(lowestX, mutable2.getX());
                            lowestY = Math.min(lowestY, mutable2.getY());
                            lowestZ = Math.min(lowestZ, mutable2.getZ());
                        }
                    }
                } else {
                    int oceanFloor = world.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, mutable2.getX(), mutable2.getZ());
                    if (world.isOutsideBuildHeight(oceanFloor - 1) || position.getY() - oceanFloor > 15) {
                        return false;
                    }
                }
            }
        }
        if (verifiedHeight) {
            // xRadius = Math.max(xRadius / config.radiusDivisorPerStack(), 1);
            // yRadius = Math.max(yRadius * 0.1F, 1);
            mutable.setY((int) (mutable.getY() + yRadius));
            // zRadius = Math.max(zRadius / config.radiusDivisorPerStack(), 1);
            stackIDX++;
        }
        verifiedHeight = true;
    }
    for (Holder<PlacedFeature> spawningFeature : config.spawningFeatures()) {
        spawningFeature.value().place(world, chunkGenerator, random, new BlockPos(lowestX, lowestY, lowestZ));
    }
    return true;
}
Also used : RadiusMatcher(potionstudios.byg.common.world.feature.config.RadiusMatcher) NoisySphereConfig(potionstudios.byg.common.world.feature.config.NoisySphereConfig) BlockPos(net.minecraft.core.BlockPos) PlacedFeature(net.minecraft.world.level.levelgen.placement.PlacedFeature)

Example 5 with NoisySphereConfig

use of potionstudios.byg.common.world.feature.config.NoisySphereConfig in project BYG by AOCAWOL.

the class Boulder method place.

public boolean place(Application application, long seed, Random random, BlockPos origin, NoisySphereConfig config) {
    setSeed(seed);
    BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos().set(origin);
    BlockPos.MutableBlockPos mutable2 = new BlockPos.MutableBlockPos().set(mutable);
    int stackHeight = config.stackHeight().sample(random);
    NoisySphereConfig.RadiusSettings radiusSettings = config.radiusSettings();
    int xRadius = radiusSettings.xRadius().sample(random) / 2;
    int yRadius = radiusSettings.yRadius().sample(random) / 2;
    int zRadius = radiusSettings.zRadius().sample(random) / 2;
    fastNoise.SetFrequency(config.noiseFrequency());
    double xRadiusSquared = xRadius * xRadius;
    double yRadiusSquared = yRadius * yRadius;
    double zRadiusSquared = zRadius * zRadius;
    for (int stackIDX = 0; stackIDX < stackHeight; stackIDX++) {
        for (int x = -xRadius; x <= xRadius; x++) {
            for (int z = -zRadius; z <= zRadius; z++) {
                for (int y = yRadius; y >= -yRadius; y--) {
                    mutable2.set(mutable).move(x, y, z);
                    if (application.isOccupied(mutable2)) {
                        continue;
                    }
                    // Credits to Hex_26 for this equation!
                    double equationResult = (x * x) / xRadiusSquared + (y * y) / yRadiusSquared + (z * z) / zRadiusSquared;
                    double threshold = 1 + 0.7 * fastNoise.GetNoise(mutable2.getX(), mutable2.getY(), mutable2.getZ());
                    if (equationResult >= threshold)
                        continue;
                    BlockState state = config.blockProvider().getState(random, mutable2);
                    application.apply(mutable2, state);
                }
            }
        }
    }
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) NoisySphereConfig(potionstudios.byg.common.world.feature.config.NoisySphereConfig) BlockPos(net.minecraft.core.BlockPos)

Aggregations

BlockPos (net.minecraft.core.BlockPos)6 NoisySphereConfig (potionstudios.byg.common.world.feature.config.NoisySphereConfig)6 PlacedFeature (net.minecraft.world.level.levelgen.placement.PlacedFeature)3 BlockState (net.minecraft.world.level.block.state.BlockState)2 RadiusMatcher (potionstudios.byg.common.world.feature.config.RadiusMatcher)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ChunkPos (net.minecraft.world.level.ChunkPos)1 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)1 WeightedStateProvider (net.minecraft.world.level.levelgen.feature.stateproviders.WeightedStateProvider)1