Search in sources :

Example 1 with InterpolationCell

use of paulevs.edenring.noise.InterpolationCell in project EdenRing by paulevsGitch.

the class CaveGenerator method carve.

public static void carve(ChunkAccess chunkAccess, InterpolationCell cellTerrain) {
    int minX = chunkAccess.getPos().getMinBlockX();
    int minZ = chunkAccess.getPos().getMinBlockZ();
    int minY = chunkAccess.getMinBuildHeight();
    int maxY = chunkAccess.getMaxBuildHeight();
    final float[] buffer9 = new float[9];
    final float[] buffer27 = new float[27];
    Random random = new Random();
    final int maxCell = (maxY - minY) / 8 + 1;
    final BlockPos origin = new BlockPos(minX, minY, minZ);
    TerrainGenerator generator = MultiThreadGenerator.getTerrainGenerator();
    InterpolationCell cellSparse = new InterpolationCell(generator, 4, (maxY - minY) / 16 + 1, 16, 16, new BlockPos(minX - 16, minY, minZ - 16));
    InterpolationCell cellVoronoi = new InterpolationCell(p -> getTunelNoise(p, buffer27, random), 5, (maxY - minY) / 4 + 1, 4, 4, origin);
    InterpolationCell cellBigCave = new InterpolationCell(p -> getBigCaveNoise(cellSparse, p), 3, maxCell, 8, 8, origin);
    InterpolationCell cellPillars = new InterpolationCell(p -> getPillars(p, seed, buffer9, random), 5, (maxY - minY) / 4 + 1, 4, 4, origin);
    MutableBlockPos pos = new MutableBlockPos();
    int maxCheck = maxY - 16;
    for (byte x = 0; x < 16; x++) {
        pos.setX(x);
        for (byte z = 0; z < 16; z++) {
            pos.setZ(z);
            byte index = 0;
            float[] accumulation = new float[8];
            int max = chunkAccess.getHeight(Types.WORLD_SURFACE_WG, x, z) - 10;
            for (short y = (short) max; y > minY; y--) {
                if (y < maxCheck) {
                    float heightNoise = cellTerrain.get(pos.setY(y + 10), true);
                    if (heightNoise <= 0) {
                        continue;
                    }
                    if (y > 8) {
                        heightNoise = cellTerrain.get(pos.setY(y - 8), true);
                        if (heightNoise <= 0) {
                            continue;
                        }
                    }
                }
                pos.setY(y);
                if (chunkAccess.getBlockState(pos).getBlock() == Blocks.STONE) {
                    float noise = cellVoronoi.get(pos, true);
                    accumulation[index++] = noise;
                    if (index >= accumulation.length) {
                        index = 0;
                    }
                    float average = 0;
                    for (byte i = 0; i < accumulation.length; i++) {
                        noise = MHelper.max(noise, accumulation[i]);
                        average += accumulation[i];
                    }
                    noise = (noise + (average / accumulation.length)) * 0.5F - 0.9F;
                    float cellValue = cellTerrain.get(pos, true);
                    noise = -smoothUnion(-noise, cellValue + 0.5F, 1.1F);
                    float bigCave = 0;
                    if (noise < 0.1F) {
                        bigCave = cellBigCave.get(pos, true);
                        noise = -smoothUnion(-noise, -bigCave, 0.1F);
                    }
                    if (noise > -0.1F) {
                        float pillars = cellPillars.get(pos, true);
                        noise = smoothUnion(noise, pillars, 0.1F);
                    }
                    if (noise > 0) {
                        chunkAccess.setBlockState(pos, CAVE_AIR, false);
                        int py = pos.getY();
                        pos.setY(py + 1);
                    }
                }
            }
        }
    }
}
Also used : Random(java.util.Random) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) InterpolationCell(paulevs.edenring.noise.InterpolationCell) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 2 with InterpolationCell

use of paulevs.edenring.noise.InterpolationCell in project EdenRing by paulevsGitch.

the class TerrainFiller method fill.

public static InterpolationCell fill(ChunkAccess chunkAccess) {
    final short minY = (short) chunkAccess.getMinBuildHeight();
    final short maxY = (short) chunkAccess.getMaxBuildHeight();
    ChunkPos chunkPos = chunkAccess.getPos();
    final BlockPos origin = new BlockPos(chunkPos.getMinBlockX(), chunkAccess.getMinBuildHeight(), chunkPos.getMinBlockZ());
    final short maxCell = (short) ((maxY - minY) / 8 + 1);
    TerrainGenerator generator = MultiThreadGenerator.getTerrainGenerator();
    InterpolationCell cellTerrain = new InterpolationCell(generator, 3, maxCell, 8, 8, origin);
    MutableBlockPos pos = new MutableBlockPos();
    for (byte x = 0; x < 16; x++) {
        pos.setX(x);
        for (byte z = 0; z < 16; z++) {
            pos.setZ(z);
            for (short y = minY; y < maxY; y++) {
                pos.setY(y);
                if (cellTerrain.get(pos, true) > 0) {
                    chunkAccess.setBlockState(pos, STONE, false);
                }
            }
        }
    }
    return cellTerrain;
}
Also used : ChunkPos(net.minecraft.world.level.ChunkPos) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) InterpolationCell(paulevs.edenring.noise.InterpolationCell) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 3 with InterpolationCell

use of paulevs.edenring.noise.InterpolationCell in project EdenRing by paulevsGitch.

the class NoiseBasedChunkGeneratorMixin method eden_carveBeforeSurface.

@Inject(method = "buildSurface(Lnet/minecraft/server/level/WorldGenRegion;Lnet/minecraft/world/level/StructureFeatureManager;Lnet/minecraft/world/level/chunk/ChunkAccess;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/core/Holder;value()Ljava/lang/Object;"))
private void eden_carveBeforeSurface(WorldGenRegion worldGenRegion, StructureFeatureManager structureFeatureManager, ChunkAccess chunkAccess, CallbackInfo ci) {
    if (eden_isTarget()) {
        InterpolationCell cellTerrain = TerrainFiller.fill(chunkAccess);
        CaveGenerator.carve(chunkAccess, cellTerrain);
    }
}
Also used : InterpolationCell(paulevs.edenring.noise.InterpolationCell) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

InterpolationCell (paulevs.edenring.noise.InterpolationCell)3 BlockPos (net.minecraft.core.BlockPos)2 MutableBlockPos (net.minecraft.core.BlockPos.MutableBlockPos)2 Random (java.util.Random)1 ChunkPos (net.minecraft.world.level.ChunkPos)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1