diff --git a/src/main/java/ru/betterend/blocks/EndTerrainBlock.java b/src/main/java/ru/betterend/blocks/EndTerrainBlock.java index 2c378e88..ae1840ea 100644 --- a/src/main/java/ru/betterend/blocks/EndTerrainBlock.java +++ b/src/main/java/ru/betterend/blocks/EndTerrainBlock.java @@ -74,13 +74,12 @@ public class EndTerrainBlock extends BlockBase { @Override public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { - if (random.nextInt(16) == 0 && !canSurvive(state, world, pos)) { + if (random.nextInt(16) == 0 && !canStay(state, world, pos)) { world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState()); } } - @Override - public boolean canSurvive(BlockState state, LevelReader worldView, BlockPos pos) { + public boolean canStay(BlockState state, LevelReader worldView, BlockPos pos) { BlockPos blockPos = pos.above(); BlockState blockState = worldView.getBlockState(blockPos); if (blockState.is(Blocks.SNOW) && (Integer) blockState.getValue(SnowLayerBlock.LAYERS) == 1) { diff --git a/src/main/java/ru/betterend/blocks/basis/TripleTerrainBlock.java b/src/main/java/ru/betterend/blocks/basis/TripleTerrainBlock.java index 7e7bdbf1..e9f013d6 100644 --- a/src/main/java/ru/betterend/blocks/basis/TripleTerrainBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/TripleTerrainBlock.java @@ -83,14 +83,14 @@ public class TripleTerrainBlock extends EndTerrainBlock { return; } else if (random.nextInt(16) == 0) { - boolean bottom = canSurviveBottom(world, pos); + boolean bottom = canStayBottom(world, pos); if (shape == TripleShape.TOP) { if (!bottom) { world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState()); } } else { - boolean top = canSurvive(state, world, pos) || isMiddle(world.getBlockState(pos.above())); + boolean top = canStay(state, world, pos) || isMiddle(world.getBlockState(pos.above())); if (!top && !bottom) { world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState()); } @@ -104,7 +104,7 @@ public class TripleTerrainBlock extends EndTerrainBlock { } } - protected boolean canSurviveBottom(LevelReader world, BlockPos pos) { + protected boolean canStayBottom(LevelReader world, BlockPos pos) { BlockPos blockPos = pos.below(); BlockState blockState = world.getBlockState(blockPos); if (isMiddle(blockState)) { diff --git a/src/main/java/ru/betterend/noise/VoronoiNoise.java b/src/main/java/ru/betterend/noise/VoronoiNoise.java index b1a9a619..0106d7de 100644 --- a/src/main/java/ru/betterend/noise/VoronoiNoise.java +++ b/src/main/java/ru/betterend/noise/VoronoiNoise.java @@ -52,6 +52,49 @@ public class VoronoiNoise { return Math.sqrt(d); } + public Random getRandom(double x, double y, double z) { + int ix = MHelper.floor(x); + int iy = MHelper.floor(y); + int iz = MHelper.floor(z); + + float px = (float) (x - ix); + float py = (float) (y - iy); + float pz = (float) (z - iz); + + float d = 10; + + int posX = 0; + int posY = 0; + int posZ = 0; + + for (int pox = -1; pox < 2; pox++) { + for (int poy = -1; poy < 2; poy++) { + for (int poz = -1; poz < 2; poz++) { + RANDOM.setSeed(getSeed(pox + ix, poy + iy, poz + iz)); + float pointX = pox + RANDOM.nextFloat(); + float pointY = poy + RANDOM.nextFloat(); + float pointZ = poz + RANDOM.nextFloat(); + float d2 = MHelper.lengthSqr(pointX - px, pointY - py, pointZ - pz); + if (d2 < d) { + d = d2; + posX = pox; + posY = poy; + posZ = poz; + } + } + } + } + + posX += ix; + posY += iy; + posZ += iz; + + int seed = MHelper.getSeed(posY, posX, posZ); + RANDOM.setSeed(seed); + + return RANDOM; + } + public BlockPos[] getPos(double x, double y, double z, double scale) { int ix = MHelper.floor(x); int iy = MHelper.floor(y); diff --git a/src/main/java/ru/betterend/world/features/terrain/caves/EndCaveFeature.java b/src/main/java/ru/betterend/world/features/terrain/caves/EndCaveFeature.java index 301748c4..9af35a84 100644 --- a/src/main/java/ru/betterend/world/features/terrain/caves/EndCaveFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/caves/EndCaveFeature.java @@ -146,7 +146,7 @@ public abstract class EndCaveFeature extends DefaultFeature { blocks.forEach((pos) -> setBiome(world, pos, biome)); } - private void setBiome(WorldGenLevel world, BlockPos pos, EndCaveBiome biome) { + protected void setBiome(WorldGenLevel world, BlockPos pos, EndCaveBiome biome) { IBiomeArray array = (IBiomeArray) world.getChunk(pos).getBiomes(); if (array != null) { Biome bio = EndBiomes.getActualBiome(biome); @@ -210,7 +210,7 @@ public abstract class EndCaveFeature extends DefaultFeature { end.setZ(bpos.getZ()); } }); - BlocksHelper.fixBlocks(world, start.offset(-5, -5, -5), end.offset(5, 5, 5)); + BlocksHelper.fixBlocks(world, start.offset(-2, -2, -2), end.offset(2, 2, 2)); } protected boolean isWaterNear(WorldGenLevel world, BlockPos pos) { diff --git a/src/main/java/ru/betterend/world/features/terrain/caves/TunelCaveFeature.java b/src/main/java/ru/betterend/world/features/terrain/caves/TunelCaveFeature.java index a95747ae..c414c6a0 100644 --- a/src/main/java/ru/betterend/world/features/terrain/caves/TunelCaveFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/caves/TunelCaveFeature.java @@ -20,36 +20,10 @@ import ru.betterend.util.BlocksHelper; import ru.betterend.world.biome.cave.EndCaveBiome; public class TunelCaveFeature extends EndCaveFeature { + private static final OpenSimplexNoise BIOME_NOISE_X = new OpenSimplexNoise("biome_noise_x".hashCode()); + private static final OpenSimplexNoise BIOME_NOISE_Z = new OpenSimplexNoise("biome_noise_z".hashCode()); + private Set generate(WorldGenLevel world, BlockPos center, Random random) { - /*Random rand = new Random(world.getSeed()); - OpenSimplexNoise noise1 = new OpenSimplexNoise(rand.nextInt()); - OpenSimplexNoise noise2 = new OpenSimplexNoise(rand.nextInt()); - OpenSimplexNoise noise3 = new OpenSimplexNoise(rand.nextInt()); - int x1 = (center.getX() >> 4) << 4; - int z1 = (center.getZ() >> 4) << 4; - int x2 = x1 + 16; - int z2 = z1 + 16; - int y2 = world.getHeight(); - Set positions = Sets.newHashSet(); - MutableBlockPos pos = new MutableBlockPos(); - for (int x = x1; x < x2; x++) { - pos.setX(x); - for (int z = z1; z < z2; z++) { - pos.setZ(z); - for (int y = 0; y < y2; y++) { - pos.setY(y); - float v1 = Mth.abs((float) noise1.eval(x * 0.02, y * 0.02, z * 0.02)); - float v2 = Mth.abs((float) noise2.eval(x * 0.02, y * 0.02, z * 0.02)); - //float v3 = Mth.abs((float) noise3.eval(x * 0.02, y * 0.02, z * 0.02)); - if (MHelper.max(v1, v2) > 0.7 && world.getBlockState(pos).is(EndTags.GEN_TERRAIN)) { - BlocksHelper.setWithoutUpdate(world, pos, AIR); - positions.add(pos.immutable()); - } - } - } - } - return positions;*/ - int x1 = (center.getX() >> 4) << 4; int z1 = (center.getZ() >> 4) << 4; int x2 = x1 + 16; @@ -92,8 +66,9 @@ public class TunelCaveFeature extends EndCaveFeature { return false; } - EndCaveBiome biome = EndBiomes.getCaveBiome(random);//EndBiomes.EMPTY_END_CAVE; - Set caveBlocks = generate(world, pos, random); + EndCaveBiome biome = EndBiomes.getCaveBiome(random); + Set preCaveBlocks = generate(world, pos, random); + Set caveBlocks = mutateBlocks(preCaveBlocks); if (!caveBlocks.isEmpty()) { if (biome != null) { setBiomes(world, biome, caveBlocks); @@ -118,11 +93,23 @@ public class TunelCaveFeature extends EndCaveFeature { placeCeil(world, biome, ceilPositions, random); placeWalls(world, biome, caveBlocks, random); } - fixBlocks(world, caveBlocks); + fixBlocks(world, preCaveBlocks); } return true; } + + private Set mutateBlocks(Set caveBlocks) { + Set result = Sets.newHashSet(); + caveBlocks.forEach(pos -> { + int dx = pos.getX() + (int) (BIOME_NOISE_X.eval(pos.getX() * 0.2, pos.getZ() * 0.2) * 5); + int dz = pos.getZ() + (int) (BIOME_NOISE_Z.eval(pos.getX() * 0.2, pos.getZ() * 0.2) * 5); + if ((dx >> 4) == (pos.getX() >> 4) && (dz >> 4) == (pos.getZ() >> 4)) { + result.add(pos); + } + }); + return result; + } @Override protected Set generate(WorldGenLevel world, BlockPos center, int radius, Random random) {