diff --git a/src/main/java/dev/ninjdai/werewolf/worldgen/LGGenerator.java b/src/main/java/dev/ninjdai/werewolf/worldgen/LGGenerator.java index aca8229..d53bc1e 100644 --- a/src/main/java/dev/ninjdai/werewolf/worldgen/LGGenerator.java +++ b/src/main/java/dev/ninjdai/werewolf/worldgen/LGGenerator.java @@ -1,14 +1,14 @@ package dev.ninjdai.werewolf.worldgen; +import dev.ninjdai.werewolf.worldgen.noises.BiomeNoises; +import dev.ninjdai.werewolf.worldgen.noises.Noises; import net.minestom.server.coordinate.Point; -import net.minestom.server.coordinate.Pos; import net.minestom.server.coordinate.Vec; import net.minestom.server.instance.block.Block; import net.minestom.server.instance.generator.GenerationUnit; import net.minestom.server.instance.generator.Generator; +import net.minestom.server.registry.DynamicRegistry; import net.minestom.server.world.biome.Biome; -import net.minestom.vanilla.generation.VanillaWorldGenerationFeature; -import net.minestom.vanilla.tag.Tags; import org.jetbrains.annotations.NotNull; import java.util.Random; @@ -55,35 +55,91 @@ public class LGGenerator implements Generator { terrainHeight = Math.max(terrainHeight, y); } } - decorate(x, terrainHeight, z, unit); + DynamicRegistry.Key biome = getBiome(x, terrainHeight, z); + unit.modifier().setBiome(x, terrainHeight, z, biome); + decorate(x, terrainHeight, z, unit.fork(unit.absoluteStart(), unit.absoluteEnd()), biome); } - private void decorate(int x, int y, int z, GenerationUnit unit) { - unit.modifier().setBlock(x, y + 4, z, Block.GRASS_BLOCK); - for (int i = 0; i < 4; i++) { - Block b = switch ((int) (2*Noises.FEATURES.evaluateNoise(x, y+i, z))) { - case 0 -> Block.COARSE_DIRT; - case 1 -> Block.ROOTED_DIRT; - default -> Block.DIRT; - }; - unit.modifier().setBlock(x, y + i, z, b); - } - int ry = y+5; + private void decorate(int x, int y, int z, GenerationUnit unit, DynamicRegistry.Key biome) { double ft = Noises.FEATURES.evaluateNoise(x, z); - if (ft > 0.995) { - int height = (int) (3 + 3*Noises.FEATURES.evaluateNoise(x, y, z)); + if (biome.equals(Biome.DARK_FOREST)) { + unit.modifier().setBlock(x, y, z, Block.GRASS_BLOCK); + for (int i = 1; i < 4; i++) { + Block b = switch ((int) (3 * Noises.FEATURES.evaluateNoise(x, y - i, z))) { + case 0 -> Block.COARSE_DIRT; + case 1 -> Block.ROOTED_DIRT; + default -> Block.DIRT; + }; + unit.modifier().setBlock(x, y - i, z, b); + } + if (ft > 0.995) { + unit.modifier().fill(new Vec(x, y+1, z), new Vec(x+1, y+7, z+1), Block.DARK_OAK_LOG); + } else if (ft > 0.99) { + unit.modifier().setBlock(x, y + 1, z, Block.TALL_GRASS); + unit.modifier().setBlock(x, y + 2, z, Block.TALL_GRASS.withProperty("half", "upper")); + } else if (ft > 0.8) { + unit.modifier().setBlock(x, y + 1, z, Block.SHORT_GRASS); + } else if (ft < 0.01) { + unit.modifier().setBlock(x, y + 1, z, Block.DANDELION); + } + if (!(Noises.ROOFED.evaluateNoise(x, z) > 0.75)) + unit.modifier().fill(new Vec(x, y+6, z), new Vec(x+1, y+9, z+1), Block.DARK_OAK_LEAVES); - GenerationUnit fork = unit.fork(new Vec(x-2, ry, z-2), new Vec(x+3, ry+height+4, z+3)); - fork.modifier().fill(new Vec(x, ry, z), new Vec(x+1, ry+height, z+1), Block.OAK_LOG); - fork.modifier().fill(new Vec(x-2, ry+height, z-2), new Vec(x+3, ry+height+2, z+3), Block.OAK_LEAVES); - fork.modifier().fill(new Vec(x-1, ry+height+2, z-1), new Vec(x+2, ry+height+3, z+2), Block.OAK_LEAVES); - } else if (ft > 0.95) { - unit.modifier().setBlock(x, ry, z, Block.TALL_GRASS); - unit.modifier().setBlock(x, ry+1, z, Block.TALL_GRASS.withProperty("half", "upper")); - } else if (ft > 0.8) { - unit.modifier().setBlock(x, ry, z, Block.SHORT_GRASS); - } else if (ft < -0.99) { - unit.modifier().setBlock(x, ry, z, Block.POPPY); + } else if (biome.equals(Biome.DESERT)) { + unit.modifier().setBlock(x, y, z, Block.SAND); + for (int i = 1; i < 4; i++) { + unit.modifier().setBlock(x, y - i, z, Block.SANDSTONE); + } + if (ft > 0.995) { + unit.modifier().setBlock(x, y + 1, z, Block.DEAD_BUSH); + } else if (ft > 0.99) { + unit.modifier().setBlock(x, y + 1, z, Block.SHORT_GRASS); + } else if (ft < 0.01) { + int height = (int) (1 + 3 * Noises.FEATURES.evaluateNoise(x, y, z)); + for (int i = 0; i < height; i++) { + unit.modifier().setBlock(x, y + 1 + i, z, Block.CACTUS); + } + } + } else { + unit.modifier().setBlock(x, y, z, Block.GRASS_BLOCK); + for (int i = 1; i < 4; i++) { + Block b = switch ((int) (2 * Noises.FEATURES.evaluateNoise(x, y - i, z))) { + case 0 -> Block.COARSE_DIRT; + case 1 -> Block.ROOTED_DIRT; + default -> Block.DIRT; + }; + unit.modifier().setBlock(x, y - i, z, b); + } + if (ft > 0.995) { + int height = (int) (3 + 3 * Noises.FEATURES.evaluateNoise(x, y, z)); + + GenerationUnit fork = unit.fork(new Vec(x - 2, y, z - 2), new Vec(x + 3, y + height + 4, z + 3)); + fork.modifier().fill(new Vec(x, y, z), new Vec(x + 1, y + height, z + 1), Block.OAK_LOG); + fork.modifier().fill(new Vec(x - 1, y + height, z - 2), new Vec(x + 2, y + height + 2, z + 3), Block.OAK_LEAVES); + fork.modifier().fill(new Vec(x - 2, y + height, z - 1), new Vec(x + 3, y + height + 2, z + 2), Block.OAK_LEAVES); + fork.modifier().fill(new Vec(x - 1, y + height + 2, z - 1), new Vec(x + 2, y + height + 3, z + 2), Block.OAK_LEAVES); + } else if (ft > 0.95) { + unit.modifier().setBlock(x, y + 1, z, Block.TALL_GRASS); + unit.modifier().setBlock(x, y + 2, z, Block.TALL_GRASS.withProperty("half", "upper")); + } else if (ft > 0.8) { + unit.modifier().setBlock(x, y + 1, z, Block.SHORT_GRASS); + } else if (ft < 0.01) { + unit.modifier().setBlock(x, y + 1, z, Block.POPPY); + } } } + + public DynamicRegistry.Key getBiome(int x, int y, int z) { + double m = BiomeNoises.HUMIDITY.evaluateNoise(x, y, z); + if (y < 0) return Biome.OCEAN; + if (y < 10) return Biome.BEACH; + + if (m < 0.16) { + return Biome.DESERT; + } else if (m < 0.5) { + return Biome.PLAINS; + } else { + return Biome.DARK_FOREST; + } + }; } \ No newline at end of file diff --git a/src/main/java/dev/ninjdai/werewolf/worldgen/LGTerrainBuilder.java b/src/main/java/dev/ninjdai/werewolf/worldgen/LGTerrainBuilder.java index 146bdfc..5b9608b 100644 --- a/src/main/java/dev/ninjdai/werewolf/worldgen/LGTerrainBuilder.java +++ b/src/main/java/dev/ninjdai/werewolf/worldgen/LGTerrainBuilder.java @@ -1,5 +1,8 @@ package dev.ninjdai.werewolf.worldgen; +import dev.ninjdai.werewolf.worldgen.noises.InterpolatedNoises; +import dev.ninjdai.werewolf.worldgen.noises.Noises; + public class LGTerrainBuilder extends TerrainBuilder { // 0: no squashing the terrain, 1: basically the surface height private final double squashingFactor = 1.5; diff --git a/src/main/java/dev/ninjdai/werewolf/worldgen/SplineInterpolatorBuilder.java b/src/main/java/dev/ninjdai/werewolf/worldgen/SplineInterpolatorBuilder.java index 06fea90..36dc836 100644 --- a/src/main/java/dev/ninjdai/werewolf/worldgen/SplineInterpolatorBuilder.java +++ b/src/main/java/dev/ninjdai/werewolf/worldgen/SplineInterpolatorBuilder.java @@ -8,7 +8,7 @@ public class SplineInterpolatorBuilder { private DoubleList xList; private DoubleList yList; - SplineInterpolatorBuilder() { + public SplineInterpolatorBuilder() { this.xList = new DoubleArrayList(); this.yList = new DoubleArrayList(); } diff --git a/src/main/java/dev/ninjdai/werewolf/worldgen/noises/BiomeNoises.java b/src/main/java/dev/ninjdai/werewolf/worldgen/noises/BiomeNoises.java new file mode 100644 index 0000000..6a4406f --- /dev/null +++ b/src/main/java/dev/ninjdai/werewolf/worldgen/noises/BiomeNoises.java @@ -0,0 +1,29 @@ +package dev.ninjdai.werewolf.worldgen.noises; + +import de.articdive.jnoise.generators.noisegen.perlin.PerlinNoiseGenerator; +import de.articdive.jnoise.pipeline.JNoise; +import net.minestom.server.registry.DynamicRegistry; +import net.minestom.server.world.biome.Biome; + +public enum BiomeNoises { + HUMIDITY(JNoise.newBuilder() + .perlin(PerlinNoiseGenerator.newBuilder() + .setSeed(0) + .build()) + .scale(0.0015) + .build()); + + final private JNoise noise; + + BiomeNoises(JNoise noise) { + this.noise = noise; + } + + public double evaluateNoise(int x, int z) { + return noise.evaluateNoise(x, z); + } + + public double evaluateNoise(int x, int y, int z) { + return noise.evaluateNoise(x, y, z); + } +} diff --git a/src/main/java/dev/ninjdai/werewolf/worldgen/InterpolatedNoises.java b/src/main/java/dev/ninjdai/werewolf/worldgen/noises/InterpolatedNoises.java similarity index 95% rename from src/main/java/dev/ninjdai/werewolf/worldgen/InterpolatedNoises.java rename to src/main/java/dev/ninjdai/werewolf/worldgen/noises/InterpolatedNoises.java index 6c95226..976833d 100644 --- a/src/main/java/dev/ninjdai/werewolf/worldgen/InterpolatedNoises.java +++ b/src/main/java/dev/ninjdai/werewolf/worldgen/noises/InterpolatedNoises.java @@ -1,8 +1,9 @@ -package dev.ninjdai.werewolf.worldgen; +package dev.ninjdai.werewolf.worldgen.noises; import de.articdive.jnoise.generators.noisegen.opensimplex.FastSimplexNoiseGenerator; import de.articdive.jnoise.modules.octavation.fractal_functions.FractalFunction; import de.articdive.jnoise.pipeline.JNoise; +import dev.ninjdai.werewolf.worldgen.SplineInterpolatorBuilder; import dev.ninjdai.werewolf.worldgen.utils.AbsClampNoiseModifier; import net.minestom.vanilla.datapack.worldgen.math.SplineInterpolator; diff --git a/src/main/java/dev/ninjdai/werewolf/worldgen/Noises.java b/src/main/java/dev/ninjdai/werewolf/worldgen/noises/Noises.java similarity index 80% rename from src/main/java/dev/ninjdai/werewolf/worldgen/Noises.java rename to src/main/java/dev/ninjdai/werewolf/worldgen/noises/Noises.java index 2bf2e96..673d94c 100644 --- a/src/main/java/dev/ninjdai/werewolf/worldgen/Noises.java +++ b/src/main/java/dev/ninjdai/werewolf/worldgen/noises/Noises.java @@ -1,6 +1,7 @@ -package dev.ninjdai.werewolf.worldgen; +package dev.ninjdai.werewolf.worldgen.noises; import de.articdive.jnoise.generators.noisegen.opensimplex.FastSimplexNoiseGenerator; +import de.articdive.jnoise.generators.noisegen.perlin.PerlinNoiseGenerator; import de.articdive.jnoise.generators.noisegen.random.white.WhiteNoiseGenerator; import de.articdive.jnoise.modules.octavation.fractal_functions.FractalFunction; import de.articdive.jnoise.pipeline.JNoise; @@ -27,6 +28,14 @@ public enum Noises { FEATURES(JNoise.newBuilder() .white(WhiteNoiseGenerator.newBuilder().setSeed(0).build()) .addModifier(new AbsClampNoiseModifier()) + .build()), + + ROOFED(JNoise.newBuilder() + .perlin(PerlinNoiseGenerator.newBuilder() + .setSeed(0) + .build()) + .scale(0.1) + .addModifier(new AbsClampNoiseModifier()) .build()); final private JNoise noise;