Search in sources :

Example 1 with OpenSimplexNoise

use of ru.bclib.noise.OpenSimplexNoise in project BCLib by paulevsGitch.

the class HexBiomeMap method getNoise.

private double getNoise(double x, double z, byte state) {
    double result = 0;
    for (byte i = 1; i <= noiseIterations; i++) {
        OpenSimplexNoise noise = noises[state];
        state = (byte) ((state + 1) & 1);
        result += noise.eval(x * i, z * i) / i;
    }
    return result;
}
Also used : OpenSimplexNoise(ru.bclib.noise.OpenSimplexNoise)

Example 2 with OpenSimplexNoise

use of ru.bclib.noise.OpenSimplexNoise in project EdenRing by paulevsGitch.

the class IslandTypes method makeSimpleIsland.

private static BiFunction<LayerOptions, Random, SDF> makeSimpleIsland() {
    SDF cone1 = makeCone(0, 0.4F, 0.2F, -0.3F);
    SDF cone2 = makeCone(0.4F, 0.5F, 0.1F, -0.1F);
    SDF cone3 = makeCone(0.5F, 0.45F, 0.03F, 0.0F);
    SDF cone4 = makeCone(0.45F, 0, 0.02F, 0.03F);
    SDF coneBottom = new SDFSmoothUnion().setRadius(0.02F).setSourceA(cone1).setSourceB(cone2);
    SDF coneTop = new SDFSmoothUnion().setRadius(0.02F).setSourceA(cone3).setSourceB(cone4);
    final SDF defaultIsland = new SDFSmoothUnion().setRadius(0.01F).setSourceA(coneTop).setSourceB(coneBottom);
    return (options, random) -> {
        final OpenSimplexNoise noise1 = new OpenSimplexNoise(random.nextInt());
        final OpenSimplexNoise noise2 = new OpenSimplexNoise(random.nextInt());
        final float scale1 = options.scale * 0.0125F;
        final float scale2 = options.scale * 0.025F;
        final float scale3 = options.scale * 0.05F;
        final float scale4 = Mth.clamp((options.scale - 50) / 50F, 0.3F, 1.0F) / options.scale;
        final float islandScale = random.nextFloat() + 0.5F;
        SDF island = new SDFScale().setScale(islandScale).setSource(defaultIsland);
        island = new SDFCoordModify().setFunction(pos -> {
            float x1 = pos.x() * scale1;
            float z1 = pos.z() * scale1;
            float x2 = pos.x() * scale2;
            float z2 = pos.z() * scale2;
            float x3 = pos.x() * scale3;
            float z3 = pos.z() * scale3;
            float dx = (float) noise1.eval(x1, z1) * 20 + (float) noise2.eval(x2, z2) * 10;
            float dy = (float) noise1.eval(x3, z3) * 6 + (float) noise2.eval(x3, z3) * 3;
            float dz = (float) noise2.eval(x1, z1) * 20 + (float) noise1.eval(x2, z2) * 10;
            // float scaleY = 1.0F - MHelper.length(pos.x(), pos.z()) / islandScale;
            pos.set(pos.x() + dx * scale4, pos.y() + dy * scale4, /* * scaleY*/
            pos.z() + dz * scale4);
        }).setSource(island);
        return island;
    };
}
Also used : SDFScale(ru.bclib.sdf.operator.SDFScale) SDFUnion(ru.bclib.sdf.operator.SDFUnion) BiFunction(java.util.function.BiFunction) Random(java.util.Random) SDFCoordModify(ru.bclib.sdf.operator.SDFCoordModify) SDFSphere(ru.bclib.sdf.primitive.SDFSphere) List(java.util.List) SDFSmoothUnion(ru.bclib.sdf.operator.SDFSmoothUnion) SDFCappedCone(ru.bclib.sdf.primitive.SDFCappedCone) SDFDisplacement(ru.bclib.sdf.operator.SDFDisplacement) SDFTranslate(ru.bclib.sdf.operator.SDFTranslate) SDFScale3D(ru.bclib.sdf.operator.SDFScale3D) Builder(com.google.common.collect.ImmutableList.Builder) Mth(net.minecraft.util.Mth) SDF(ru.bclib.sdf.SDF) OpenSimplexNoise(ru.bclib.noise.OpenSimplexNoise) MHelper(ru.bclib.util.MHelper) SDFSmoothUnion(ru.bclib.sdf.operator.SDFSmoothUnion) SDF(ru.bclib.sdf.SDF) SDFCoordModify(ru.bclib.sdf.operator.SDFCoordModify) SDFScale(ru.bclib.sdf.operator.SDFScale) OpenSimplexNoise(ru.bclib.noise.OpenSimplexNoise)

Example 3 with OpenSimplexNoise

use of ru.bclib.noise.OpenSimplexNoise in project EdenRing by paulevsGitch.

the class IslandTypes method makeTallSphereIsland.

private static BiFunction<LayerOptions, Random, SDF> makeTallSphereIsland() {
    SDF sphere = new SDFSphere().setRadius(1.0F);
    sphere = new SDFScale3D().setScale(0.25F, 1.0F, 0.25F).setSource(sphere);
    final SDF defaultIsland = sphere;
    return (options, random) -> {
        float scale = random.nextFloat() + 0.5F;
        if (options.scale > 60) {
            scale = 60 * scale / options.scale;
        } else if (options.scale < 30) {
            scale = 30 * scale / options.scale;
        }
        SDF island = new SDFScale().setScale(scale).setSource(defaultIsland);
        if (options.scale > 35) {
            float distance = scale * 0.6F;
            float offset = random.nextFloat() * MHelper.PI2;
            byte count = (byte) MHelper.randRange(3, 5, random);
            for (byte i = 0; i < count; i++) {
                float angle = (float) i / count * MHelper.PI2 + offset;
                float px = (float) Math.sin(angle) * distance;
                float pz = (float) Math.cos(angle) * distance;
                SDF part = new SDFScale().setScale(scale * MHelper.randRange(0.3F, 0.6F, random)).setSource(defaultIsland);
                part = new SDFTranslate().setTranslate(px, MHelper.randRange(-0.25F, 0.25F, random) * distance, pz).setSource(part);
                island = new SDFUnion().setSourceA(island).setSourceB(part);
            }
        }
        final OpenSimplexNoise noise1 = new OpenSimplexNoise(random.nextInt());
        final float scale1 = 0.5F * options.scale;
        final float noiseScale = Mth.clamp((options.scale - 30) / 30F, 0.1F, 1.0F);
        final float scale2 = 20F / options.scale * noiseScale;
        island = new SDFDisplacement().setFunction(pos -> (float) noise1.eval(pos.x() * scale1, pos.y() * scale1, pos.z() * scale1) * scale2).setSource(island);
        return island;
    };
}
Also used : SDFScale(ru.bclib.sdf.operator.SDFScale) SDFUnion(ru.bclib.sdf.operator.SDFUnion) BiFunction(java.util.function.BiFunction) Random(java.util.Random) SDFCoordModify(ru.bclib.sdf.operator.SDFCoordModify) SDFSphere(ru.bclib.sdf.primitive.SDFSphere) List(java.util.List) SDFSmoothUnion(ru.bclib.sdf.operator.SDFSmoothUnion) SDFCappedCone(ru.bclib.sdf.primitive.SDFCappedCone) SDFDisplacement(ru.bclib.sdf.operator.SDFDisplacement) SDFTranslate(ru.bclib.sdf.operator.SDFTranslate) SDFScale3D(ru.bclib.sdf.operator.SDFScale3D) Builder(com.google.common.collect.ImmutableList.Builder) Mth(net.minecraft.util.Mth) SDF(ru.bclib.sdf.SDF) OpenSimplexNoise(ru.bclib.noise.OpenSimplexNoise) MHelper(ru.bclib.util.MHelper) SDFSphere(ru.bclib.sdf.primitive.SDFSphere) SDF(ru.bclib.sdf.SDF) SDFDisplacement(ru.bclib.sdf.operator.SDFDisplacement) SDFUnion(ru.bclib.sdf.operator.SDFUnion) SDFScale(ru.bclib.sdf.operator.SDFScale) SDFTranslate(ru.bclib.sdf.operator.SDFTranslate) OpenSimplexNoise(ru.bclib.noise.OpenSimplexNoise) SDFScale3D(ru.bclib.sdf.operator.SDFScale3D)

Example 4 with OpenSimplexNoise

use of ru.bclib.noise.OpenSimplexNoise in project EdenRing by paulevsGitch.

the class StonePillar method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
    WorldGenLevel level = featurePlaceContext.level();
    BlockPos center = featurePlaceContext.origin();
    Random random = featurePlaceContext.random();
    center = getPosOnSurface(level, center);
    if (center.getY() < 5) {
        return false;
    }
    float height = MHelper.randRange(1.5F, 3.5F, random);
    center = center.above(Mth.floor(height));
    float r1 = MHelper.randRange(2.5F, 3.5F, random);
    float r2 = MHelper.randRange(1.5F, 2.5F, random);
    SDF sdf = new SDFCappedCone().setHeight(height * 2).setRadius1(r1).setRadius2(r2).setBlock(Blocks.STONE);
    int count = random.nextInt(3);
    float radius = r2 * MHelper.randRange(1.5F, 2F, random);
    for (int i = 0; i < count; i++) {
        height += radius * 0.7F;
        SDF sphere = new SDFSphere().setRadius(MHelper.randRange(2F, 4F, random)).setBlock(Blocks.STONE);
        sphere = new SDFScale3D().setScale(MHelper.randRange(2F, 3F, random), 1, MHelper.randRange(2F, 3F, random)).setSource(sphere);
        sphere = new SDFTranslate().setTranslate(0, height, 0).setSource(sphere);
        sdf = new SDFSmoothUnion().setRadius(4f).setSourceA(sdf).setSourceB(sphere);
        height += radius;
        radius += MHelper.randRange(0.75F, 1.5F, random);
    }
    OpenSimplexNoise noise = new OpenSimplexNoise(random.nextInt());
    sdf = new SDFDisplacement().setFunction(pos -> {
        float disp = (float) noise.eval(pos.x() * 0.06F, pos.y() * 0.06F, pos.z() * 0.06F) * 2.0F;
        disp += (float) noise.eval(pos.x() * 0.1F, pos.y() * 0.1F, pos.z() * 0.1F) * 0.35F;
        return disp;
    }).setSource(sdf);
    BlockState bottom = EdenBlocks.EDEN_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM);
    BlockState middle = EdenBlocks.EDEN_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE);
    BlockState top = EdenBlocks.EDEN_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP);
    BlockState roots = Blocks.HANGING_ROOTS.defaultBlockState();
    sdf.addPostProcess(info -> {
        if (info.getState().is(EdenBlocks.EDEN_VINE) || info.getState().is(Blocks.HANGING_ROOTS)) {
            return info.getState();
        }
        if (info.getPos().getY() > 3 && info.getStateDown().isAir() && random.nextInt(8) == 0) {
            if (random.nextBoolean()) {
                info.setBlockPos(info.getPos().below(), roots);
            } else {
                int h = MHelper.randRange(1, 3, random);
                for (int i = 0; i < h; i++) {
                    int p = i + 1;
                    info.setBlockPos(info.getPos().below(p), i == 0 ? top : i == p ? bottom : middle);
                }
            }
        }
        if (info.getStateUp().isAir() && noise.eval(info.getPos().getX() * 0.4F, info.getPos().getY() * 0.4F, info.getPos().getZ() * 0.4F) > 0.1) {
            if (random.nextInt(5) == 0) {
                info.setBlockPos(info.getPos().above(), Blocks.GRASS.defaultBlockState());
            }
            return EdenBlocks.MOSSY_STONE.defaultBlockState();
        } else if (noise.eval(info.getPos().getX() * 0.4F, info.getPos().getY() * 0.4F + 50, info.getPos().getZ() * 0.4F) > 0.3) {
            return Blocks.MOSSY_COBBLESTONE.defaultBlockState();
        } else if (noise.eval(info.getPos().getX() * 0.4F, info.getPos().getY() * 0.4F + 100, info.getPos().getZ() * 0.4F) > 0.3) {
            return Blocks.COBBLESTONE.defaultBlockState();
        } else if (noise.eval(info.getPos().getX() * 0.4F, info.getPos().getY() * 0.4F + 150, info.getPos().getZ() * 0.4F) > 0.3) {
            if (info.getStateUp().isAir() && random.nextInt(5) == 0) {
                info.setBlockPos(info.getPos().above(), Blocks.GRASS.defaultBlockState());
            }
            return Blocks.MOSS_BLOCK.defaultBlockState();
        }
        return info.getState();
    });
    sdf.setReplaceFunction(state -> {
        return state.isAir() || state.getBlock() instanceof EdenGrassBlock || state.is(Blocks.DIRT);
    }).fillRecursive(level, center);
    return true;
}
Also used : FeaturePlaceContext(net.minecraft.world.level.levelgen.feature.FeaturePlaceContext) NoneFeatureConfiguration(net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) DefaultFeature(ru.bclib.world.features.DefaultFeature) Blocks(net.minecraft.world.level.block.Blocks) TripleShape(ru.bclib.blocks.BlockProperties.TripleShape) SDFSphere(ru.bclib.sdf.primitive.SDFSphere) EdenGrassBlock(paulevs.edenring.blocks.EdenGrassBlock) SDFSmoothUnion(ru.bclib.sdf.operator.SDFSmoothUnion) SDFCappedCone(ru.bclib.sdf.primitive.SDFCappedCone) WorldGenLevel(net.minecraft.world.level.WorldGenLevel) BlockPos(net.minecraft.core.BlockPos) SDFDisplacement(ru.bclib.sdf.operator.SDFDisplacement) SDFTranslate(ru.bclib.sdf.operator.SDFTranslate) SDFScale3D(ru.bclib.sdf.operator.SDFScale3D) Mth(net.minecraft.util.Mth) BlockProperties(ru.bclib.blocks.BlockProperties) SDF(ru.bclib.sdf.SDF) EdenBlocks(paulevs.edenring.registries.EdenBlocks) OpenSimplexNoise(ru.bclib.noise.OpenSimplexNoise) MHelper(ru.bclib.util.MHelper) SDFSmoothUnion(ru.bclib.sdf.operator.SDFSmoothUnion) EdenGrassBlock(paulevs.edenring.blocks.EdenGrassBlock) SDFCappedCone(ru.bclib.sdf.primitive.SDFCappedCone) SDFScale3D(ru.bclib.sdf.operator.SDFScale3D) SDFSphere(ru.bclib.sdf.primitive.SDFSphere) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) SDF(ru.bclib.sdf.SDF) SDFDisplacement(ru.bclib.sdf.operator.SDFDisplacement) SDFTranslate(ru.bclib.sdf.operator.SDFTranslate) BlockPos(net.minecraft.core.BlockPos) OpenSimplexNoise(ru.bclib.noise.OpenSimplexNoise) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 5 with OpenSimplexNoise

use of ru.bclib.noise.OpenSimplexNoise in project EdenRing by paulevsGitch.

the class CaveGenerator method init.

public static void init(long seed) {
    Random random = new Random(seed);
    simplexNoise = new OpenSimplexNoise(random.nextInt());
    CaveGenerator.seed = random.nextInt();
}
Also used : Random(java.util.Random) OpenSimplexNoise(ru.bclib.noise.OpenSimplexNoise)

Aggregations

OpenSimplexNoise (ru.bclib.noise.OpenSimplexNoise)6 Random (java.util.Random)5 Mth (net.minecraft.util.Mth)4 SDF (ru.bclib.sdf.SDF)4 SDFDisplacement (ru.bclib.sdf.operator.SDFDisplacement)4 SDFScale3D (ru.bclib.sdf.operator.SDFScale3D)4 SDFSmoothUnion (ru.bclib.sdf.operator.SDFSmoothUnion)4 SDFTranslate (ru.bclib.sdf.operator.SDFTranslate)4 SDFCappedCone (ru.bclib.sdf.primitive.SDFCappedCone)4 SDFSphere (ru.bclib.sdf.primitive.SDFSphere)4 MHelper (ru.bclib.util.MHelper)4 Builder (com.google.common.collect.ImmutableList.Builder)3 List (java.util.List)3 BiFunction (java.util.function.BiFunction)3 SDFCoordModify (ru.bclib.sdf.operator.SDFCoordModify)3 SDFScale (ru.bclib.sdf.operator.SDFScale)3 SDFUnion (ru.bclib.sdf.operator.SDFUnion)3 BlockPos (net.minecraft.core.BlockPos)1 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)1 Blocks (net.minecraft.world.level.block.Blocks)1