Skip to content

Commit

Permalink
Fix for caves breaking surface vertically
Browse files Browse the repository at this point in the history
  • Loading branch information
paulevsGitch committed Jun 21, 2021
1 parent 684f307 commit 4dce2d5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn_mappings=6
loader_version=0.11.3

# Mod Properties
mod_version = 0.9.8.2-pre
mod_version = 0.9.8.3-pre
maven_group = ru.betterend
archives_base_name = better-end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import ru.bclib.api.BiomeAPI;
import ru.bclib.api.TagAPI;
import ru.bclib.util.BlocksHelper;
import ru.bclib.world.biomes.BCLBiome;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.EndBiomes;
import ru.betterend.world.biome.cave.EndCaveBiome;
Expand All @@ -43,17 +46,30 @@ private Set<BlockPos> generate(WorldGenLevel world, BlockPos center, Random rand

Set<BlockPos> positions = Sets.newHashSet();
MutableBlockPos pos = new MutableBlockPos();

float a = hasCaves(world, pos.set(x1, 0, z1)) ? 1F : 0F;
float b = hasCaves(world, pos.set(x2, 0, z1)) ? 1F : 0F;
float c = hasCaves(world, pos.set(x1, 0, z2)) ? 1F : 0F;
float d = hasCaves(world, pos.set(x2, 0, z2)) ? 1F : 0F;

for (int x = x1; x < x2; x++) {
pos.setX(x);
float dx = (float) (x - x1) / 16F;
float da = Mth.lerp(dx, a, b);
float db = Mth.lerp(dx, c, d);
for (int z = z1; z < z2; z++) {
pos.setZ(z);
float dz = (float) (z - z1) / 16F;
float density = 1 - Mth.lerp(dz, da, db);
int wheight = world.getHeight(Types.WORLD_SURFACE_WG, x, z);
for (int y = 0; y < y2; y++) {
pos.setY(y);
float gradient = 1 - Mth.clamp((wheight - y) * 0.1F, 0F, 1F);
float val = Mth.abs((float) noiseH.eval(x * 0.02, y * 0.01, z * 0.02));
float vert = Mth.sin((y + (float) noiseV.eval(x * 0.01, z * 0.01) * 20) * 0.1F) * 0.9F;
float dist = (float) noiseD.eval(x * 0.1, y * 0.1, z * 0.1) * 0.12F;
vert *= vert;
if (val + vert + dist < 0.15 && world.getBlockState(pos).is(TagAPI.GEN_TERRAIN) && noWaterNear(world, pos)) {
val = (val + vert * vert + dist) + density + gradient;
if (val < 0.15 && world.getBlockState(pos).is(TagAPI.GEN_TERRAIN) && noWaterNear(world, pos)) {
BlocksHelper.setWithoutUpdate(world, pos, AIR);
positions.add(pos.immutable());
int height = world.getHeight(Types.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
Expand Down Expand Up @@ -192,4 +208,17 @@ protected void placeCeil(WorldGenLevel world, EndCaveBiome biome, Set<BlockPos>
}
});
}

protected boolean hasCaves(WorldGenLevel world, BlockPos pos) {
return hasCavesInBiome(world, pos.offset(-8, 0, -8)) &&
hasCavesInBiome(world, pos.offset(8, 0, -8)) &&
hasCavesInBiome(world, pos.offset(-8, 0, 8)) &&
hasCavesInBiome(world, pos.offset(8, 0, 8));
}

protected boolean hasCavesInBiome(WorldGenLevel world, BlockPos pos) {
Biome biome = world.getBiome(pos);
BCLBiome endBiome = BiomeAPI.getFromBiome(biome);
return endBiome.getCustomData("has_caves", true);
}
}

0 comments on commit 4dce2d5

Please sign in to comment.