From cd44fbebf83bf42fbbf85f3620a0f4ad7121b456 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Wed, 4 Nov 2020 02:54:34 +0300 Subject: [PATCH] Mountains fixes --- .../features/StructureMountain.java | 2 +- .../features/StructurePaintedMountain.java | 4 +- .../world/structures/piece/MountainPiece.java | 54 ++++++++++--------- .../piece/PaintedMountainPiece.java | 53 +++++++++--------- 4 files changed, 58 insertions(+), 55 deletions(-) diff --git a/src/main/java/ru/betterend/world/structures/features/StructureMountain.java b/src/main/java/ru/betterend/world/structures/features/StructureMountain.java index aa02497f..8de38254 100644 --- a/src/main/java/ru/betterend/world/structures/features/StructureMountain.java +++ b/src/main/java/ru/betterend/world/structures/features/StructureMountain.java @@ -32,7 +32,7 @@ public class StructureMountain extends StructureFeatureBase { if (y > 50) { float radius = MHelper.randRange(50, 100, random); float height = radius * MHelper.randRange(0.8F, 1.2F, random); - MountainPiece piece = new MountainPiece(new BlockPos(x, y, z), radius, height, random.nextInt(), biome); + MountainPiece piece = new MountainPiece(new BlockPos(x, y, z), radius, height, random, biome); this.children.add(piece); } this.setBoundingBoxFromChildren(); diff --git a/src/main/java/ru/betterend/world/structures/features/StructurePaintedMountain.java b/src/main/java/ru/betterend/world/structures/features/StructurePaintedMountain.java index 39f05ba1..0244cfca 100644 --- a/src/main/java/ru/betterend/world/structures/features/StructurePaintedMountain.java +++ b/src/main/java/ru/betterend/world/structures/features/StructurePaintedMountain.java @@ -36,13 +36,13 @@ public class StructurePaintedMountain extends StructureFeatureBase { int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG); if (y > 50) { float radius = MHelper.randRange(50, 100, random); - float height = radius * MHelper.randRange(0.2F, 0.4F, random); + float height = radius * MHelper.randRange(0.4F, 0.6F, random); int count = MHelper.floor(height * MHelper.randRange(0.1F, 0.35F, random) + 1); BlockState[] slises = new BlockState[count]; for (int i = 0; i < count; i++) { slises[i] = VARIANTS[random.nextInt(VARIANTS.length)]; } - this.children.add(new PaintedMountainPiece(new BlockPos(x, y, z), radius, height, random.nextInt(), biome, slises )); + this.children.add(new PaintedMountainPiece(new BlockPos(x, y, z), radius, height, random, biome, slises )); } this.setBoundingBoxFromChildren(); } diff --git a/src/main/java/ru/betterend/world/structures/piece/MountainPiece.java b/src/main/java/ru/betterend/world/structures/piece/MountainPiece.java index 9d427713..27dc22c4 100644 --- a/src/main/java/ru/betterend/world/structures/piece/MountainPiece.java +++ b/src/main/java/ru/betterend/world/structures/piece/MountainPiece.java @@ -27,26 +27,31 @@ import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndStructures; -import ru.betterend.registry.EndTags; import ru.betterend.util.MHelper; public class MountainPiece extends BasePiece { private Map heightmap = Maps.newHashMap(); - private OpenSimplexNoise noise; + private OpenSimplexNoise noise1; + private OpenSimplexNoise noise2; private BlockPos center; private float radius; private float height; private float r2; private Identifier biomeID; private BlockState top; + private int seed1; + private int seed2; - public MountainPiece(BlockPos center, float radius, float height, int id, Biome biome) { - super(EndStructures.MOUNTAIN_PIECE, id); + public MountainPiece(BlockPos center, float radius, float height, Random random, Biome biome) { + super(EndStructures.MOUNTAIN_PIECE, random.nextInt()); this.center = center; this.radius = radius; this.height = height; this.r2 = radius * radius; - this.noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ())); + this.seed1 = random.nextInt(); + this.seed2 = random.nextInt(); + this.noise1 = new OpenSimplexNoise(this.seed1); + this.noise2 = new OpenSimplexNoise(this.seed2); this.biomeID = EndBiomes.getBiomeID(biome); top = biome.getGenerationSettings().getSurfaceConfig().getTopMaterial(); makeBoundingBox(); @@ -63,6 +68,8 @@ public class MountainPiece extends BasePiece { tag.putFloat("radius", radius); tag.putFloat("height", height); tag.putString("biome", biomeID.toString()); + tag.putInt("seed1", seed1); + tag.putInt("seed2", seed2); } @Override @@ -72,7 +79,10 @@ public class MountainPiece extends BasePiece { height = tag.getFloat("height"); biomeID = new Identifier(tag.getString("biome")); r2 = radius * radius; - noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ())); + seed1 = tag.getInt("seed1"); + seed2 = tag.getInt("seed2"); + noise1 = new OpenSimplexNoise(seed1); + noise2 = new OpenSimplexNoise(seed2); top = EndBiomes.getBiome(biomeID).getBiome().getGenerationSettings().getSurfaceConfig().getTopMaterial(); } @@ -100,14 +110,15 @@ public class MountainPiece extends BasePiece { if (minY > 56) { float maxY = dist * height * getHeightClamp(world, 8, px, pz); if (maxY > 0) { - maxY *= (float) noise.eval(px * 0.05, pz * 0.05) * 0.3F + 0.7F; - maxY *= (float) noise.eval(px * 0.1, pz * 0.1) * 0.1F + 0.8F; + maxY *= (float) noise1.eval(px * 0.05, pz * 0.05) * 0.3F + 0.7F; + maxY *= (float) noise1.eval(px * 0.1, pz * 0.1) * 0.1F + 0.8F; maxY += 56; - int cover = (int) (maxY - 1); - boolean needCover = (noise.eval(px * 0.1, pz * 0.1) + MHelper.randRange(-0.4, 0.4, random) - (maxY - 70) * 0.1) > 0; - for (int y = minY - 1; y < maxY; y++) { + int maxYI = (int) (maxY); + int cover = maxYI - 1; + boolean needCover = (noise1.eval(px * 0.1, pz * 0.1) + MHelper.randRange(-0.4, 0.4, random) - (maxY - 70) * 0.1) > 0; + for (int y = minY - 1; y < maxYI; y++) { pos.setY(y); - chunk.setBlockState(pos, needCover && y >= cover ? top : Blocks.END_STONE.getDefaultState(), false); + chunk.setBlockState(pos, needCover && y == cover ? top : Blocks.END_STONE.getDefaultState(), false); } } } @@ -169,18 +180,10 @@ public class MountainPiece extends BasePiece { } h = world.getTopY(Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ()); if (h < 57) { - heightmap.put(p, 0); - return 0; + heightmap.put(p, -4); + return -4; } - - Mutable m = new Mutable(); - m.set(pos.getX(), h - 1, pos.getZ()); - while (h > 56 && world.getBlockState(pos).isIn(EndTags.GEN_TERRAIN)) { - m.setY(m.getY() - 1); - } - h = m.getY(); - - h -= 57; + h = MHelper.floor(noise2.eval(pos.getX() * 0.01, pos.getZ() * 0.01) * noise2.eval(pos.getX() * 0.002, pos.getZ() * 0.002) * 8 + 8); if (h < 0) { heightmap.put(p, 0); @@ -194,7 +197,6 @@ public class MountainPiece extends BasePiece { private float getHeightClamp(StructureWorldAccess world, int radius, int posX, int posZ) { Mutable mut = new Mutable(); - int r2 = radius * radius; float height = 0; float max = 0; for (int x = -radius; x <= radius; x++) { @@ -203,8 +205,8 @@ public class MountainPiece extends BasePiece { for (int z = -radius; z <= radius; z++) { mut.setZ(posZ + z); int z2 = z * z; - if (x2 + z2 < r2) { - float mult = 1 - (float) Math.sqrt(x2 + z2) / radius; + float mult = 1 - (float) Math.sqrt(x2 + z2) / radius; + if (mult > 0) { max += mult; height += getHeight(world, mut) * mult; } diff --git a/src/main/java/ru/betterend/world/structures/piece/PaintedMountainPiece.java b/src/main/java/ru/betterend/world/structures/piece/PaintedMountainPiece.java index 80ea8fc2..1e7a52c4 100644 --- a/src/main/java/ru/betterend/world/structures/piece/PaintedMountainPiece.java +++ b/src/main/java/ru/betterend/world/structures/piece/PaintedMountainPiece.java @@ -26,26 +26,31 @@ import net.minecraft.world.gen.chunk.ChunkGenerator; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndStructures; -import ru.betterend.registry.EndTags; import ru.betterend.util.MHelper; public class PaintedMountainPiece extends BasePiece { private Map heightmap = Maps.newHashMap(); - private OpenSimplexNoise noise; + private OpenSimplexNoise noise1; + private OpenSimplexNoise noise2; private BlockPos center; private float radius; private float height; private float r2; private Identifier biomeID; private BlockState[] slises; + private int seed1; + private int seed2; - public PaintedMountainPiece(BlockPos center, float radius, float height, int id, Biome biome, BlockState[] slises) { - super(EndStructures.PAINTED_MOUNTAIN_PIECE, id); + public PaintedMountainPiece(BlockPos center, float radius, float height, Random random, Biome biome, BlockState[] slises) { + super(EndStructures.PAINTED_MOUNTAIN_PIECE, random.nextInt()); this.center = center; this.radius = radius; this.height = height; this.r2 = radius * radius; - this.noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ())); + this.seed1 = random.nextInt(); + this.seed2 = random.nextInt(); + this.noise1 = new OpenSimplexNoise(this.seed1); + this.noise2 = new OpenSimplexNoise(this.seed2); this.biomeID = EndBiomes.getBiomeID(biome); this.slises = slises; makeBoundingBox(); @@ -62,6 +67,8 @@ public class PaintedMountainPiece extends BasePiece { tag.putFloat("radius", radius); tag.putFloat("height", height); tag.putString("biome", biomeID.toString()); + tag.putInt("seed1", seed1); + tag.putInt("seed2", seed2); ListTag slise = new ListTag(); for (BlockState state: slises) { @@ -77,7 +84,10 @@ public class PaintedMountainPiece extends BasePiece { height = tag.getFloat("height"); biomeID = new Identifier(tag.getString("biome")); r2 = radius * radius; - noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ())); + seed1 = tag.getInt("seed1"); + seed2 = tag.getInt("seed2"); + noise1 = new OpenSimplexNoise(seed1); + noise2 = new OpenSimplexNoise(seed2); ListTag slise = tag.getList("slises", 10); slises = new BlockState[slise.size()]; for (int i = 0; i < slises.length; i++) { @@ -112,12 +122,12 @@ public class PaintedMountainPiece extends BasePiece { pos.setY(minY --); } - float maxY = dist * height * getHeightClamp(world, 4, px, pz); + float maxY = dist * height * getHeightClamp(world, 8, px, pz); if (maxY > 0) { - maxY *= (float) noise.eval(px * 0.05, pz * 0.05) * 0.03F + 0.97F; - maxY *= (float) noise.eval(px * 0.1, pz * 0.1) * 0.01F + 0.99F; + maxY *= (float) noise1.eval(px * 0.05, pz * 0.05) * 0.3F + 0.7F; + maxY *= (float) noise1.eval(px * 0.1, pz * 0.1) * 0.1F + 0.9F; maxY += 56; - float offset = (float) (noise.eval(px * 0.07, pz * 0.07) * 5 + noise.eval(px * 0.2, pz * 0.2) * 2 + 7); + float offset = (float) (noise1.eval(px * 0.07, pz * 0.07) * 5 + noise1.eval(px * 0.2, pz * 0.2) * 2 + 7); for (int y = minY - 1; y < maxY; y++) { pos.setY(y); int index = MHelper.floor((y + offset) * 0.65F) % slises.length; @@ -140,23 +150,15 @@ public class PaintedMountainPiece extends BasePiece { } if (!EndBiomes.getBiomeID(world.getBiome(pos)).equals(biomeID)) { - heightmap.put(p, -6); - return -6; + heightmap.put(p, -4); + return -4; } h = world.getTopY(Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ()); if (h < 57) { - heightmap.put(p, 0); - return 0; + heightmap.put(p, -4); + return -4; } - - Mutable m = new Mutable(); - m.set(pos.getX(), h - 1, pos.getZ()); - while (h > 56 && world.getBlockState(pos).isIn(EndTags.GEN_TERRAIN)) { - m.setY(m.getY() - 1); - } - h = m.getY(); - - h -= 57; + h = MHelper.floor(noise2.eval(pos.getX() * 0.005, pos.getZ() * 0.005) * noise2.eval(pos.getX() * 0.001, pos.getZ() * 0.001) * 8 + 8); if (h < 0) { heightmap.put(p, 0); @@ -170,7 +172,6 @@ public class PaintedMountainPiece extends BasePiece { private float getHeightClamp(StructureWorldAccess world, int radius, int posX, int posZ) { Mutable mut = new Mutable(); - int r2 = radius * radius; float height = 0; float max = 0; for (int x = -radius; x <= radius; x++) { @@ -179,8 +180,8 @@ public class PaintedMountainPiece extends BasePiece { for (int z = -radius; z <= radius; z++) { mut.setZ(posZ + z); int z2 = z * z; - if (x2 + z2 < r2) { - float mult = 1 - (float) Math.sqrt(x2 + z2) / radius; + float mult = 1 - (float) Math.sqrt(x2 + z2) / radius; + if (mult > 0) { max += mult; height += getHeight(world, mut) * mult; }