feat: worldgen improvements

This commit is contained in:
Ninjdai 2024-10-04 13:15:36 +02:00
parent 12cdc55c75
commit a5cbf6274c
6 changed files with 129 additions and 31 deletions

View File

@ -1,14 +1,14 @@
package dev.ninjdai.werewolf.worldgen; 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.Point;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.coordinate.Vec; import net.minestom.server.coordinate.Vec;
import net.minestom.server.instance.block.Block; import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.generator.GenerationUnit; import net.minestom.server.instance.generator.GenerationUnit;
import net.minestom.server.instance.generator.Generator; import net.minestom.server.instance.generator.Generator;
import net.minestom.server.registry.DynamicRegistry;
import net.minestom.server.world.biome.Biome; 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 org.jetbrains.annotations.NotNull;
import java.util.Random; import java.util.Random;
@ -55,35 +55,91 @@ public class LGGenerator implements Generator {
terrainHeight = Math.max(terrainHeight, y); terrainHeight = Math.max(terrainHeight, y);
} }
} }
decorate(x, terrainHeight, z, unit); DynamicRegistry.Key<Biome> 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) { private void decorate(int x, int y, int z, GenerationUnit unit, DynamicRegistry.Key<Biome> biome) {
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;
double ft = Noises.FEATURES.evaluateNoise(x, z); double ft = Noises.FEATURES.evaluateNoise(x, z);
if (ft > 0.995) { if (biome.equals(Biome.DARK_FOREST)) {
int height = (int) (3 + 3*Noises.FEATURES.evaluateNoise(x, y, z)); 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)); } else if (biome.equals(Biome.DESERT)) {
fork.modifier().fill(new Vec(x, ry, z), new Vec(x+1, ry+height, z+1), Block.OAK_LOG); unit.modifier().setBlock(x, y, z, Block.SAND);
fork.modifier().fill(new Vec(x-2, ry+height, z-2), new Vec(x+3, ry+height+2, z+3), Block.OAK_LEAVES); for (int i = 1; i < 4; i++) {
fork.modifier().fill(new Vec(x-1, ry+height+2, z-1), new Vec(x+2, ry+height+3, z+2), Block.OAK_LEAVES); unit.modifier().setBlock(x, y - i, z, Block.SANDSTONE);
} else if (ft > 0.95) { }
unit.modifier().setBlock(x, ry, z, Block.TALL_GRASS); if (ft > 0.995) {
unit.modifier().setBlock(x, ry+1, z, Block.TALL_GRASS.withProperty("half", "upper")); unit.modifier().setBlock(x, y + 1, z, Block.DEAD_BUSH);
} else if (ft > 0.8) { } else if (ft > 0.99) {
unit.modifier().setBlock(x, ry, z, Block.SHORT_GRASS); unit.modifier().setBlock(x, y + 1, z, Block.SHORT_GRASS);
} else if (ft < -0.99) { } else if (ft < 0.01) {
unit.modifier().setBlock(x, ry, z, Block.POPPY); 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<Biome> 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;
}
};
} }

View File

@ -1,5 +1,8 @@
package dev.ninjdai.werewolf.worldgen; package dev.ninjdai.werewolf.worldgen;
import dev.ninjdai.werewolf.worldgen.noises.InterpolatedNoises;
import dev.ninjdai.werewolf.worldgen.noises.Noises;
public class LGTerrainBuilder extends TerrainBuilder { public class LGTerrainBuilder extends TerrainBuilder {
// 0: no squashing the terrain, 1: basically the surface height // 0: no squashing the terrain, 1: basically the surface height
private final double squashingFactor = 1.5; private final double squashingFactor = 1.5;

View File

@ -8,7 +8,7 @@ public class SplineInterpolatorBuilder {
private DoubleList xList; private DoubleList xList;
private DoubleList yList; private DoubleList yList;
SplineInterpolatorBuilder() { public SplineInterpolatorBuilder() {
this.xList = new DoubleArrayList(); this.xList = new DoubleArrayList();
this.yList = new DoubleArrayList(); this.yList = new DoubleArrayList();
} }

View File

@ -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);
}
}

View File

@ -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.generators.noisegen.opensimplex.FastSimplexNoiseGenerator;
import de.articdive.jnoise.modules.octavation.fractal_functions.FractalFunction; import de.articdive.jnoise.modules.octavation.fractal_functions.FractalFunction;
import de.articdive.jnoise.pipeline.JNoise; import de.articdive.jnoise.pipeline.JNoise;
import dev.ninjdai.werewolf.worldgen.SplineInterpolatorBuilder;
import dev.ninjdai.werewolf.worldgen.utils.AbsClampNoiseModifier; import dev.ninjdai.werewolf.worldgen.utils.AbsClampNoiseModifier;
import net.minestom.vanilla.datapack.worldgen.math.SplineInterpolator; import net.minestom.vanilla.datapack.worldgen.math.SplineInterpolator;

View File

@ -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.opensimplex.FastSimplexNoiseGenerator;
import de.articdive.jnoise.generators.noisegen.perlin.PerlinNoiseGenerator;
import de.articdive.jnoise.generators.noisegen.random.white.WhiteNoiseGenerator; import de.articdive.jnoise.generators.noisegen.random.white.WhiteNoiseGenerator;
import de.articdive.jnoise.modules.octavation.fractal_functions.FractalFunction; import de.articdive.jnoise.modules.octavation.fractal_functions.FractalFunction;
import de.articdive.jnoise.pipeline.JNoise; import de.articdive.jnoise.pipeline.JNoise;
@ -27,6 +28,14 @@ public enum Noises {
FEATURES(JNoise.newBuilder() FEATURES(JNoise.newBuilder()
.white(WhiteNoiseGenerator.newBuilder().setSeed(0).build()) .white(WhiteNoiseGenerator.newBuilder().setSeed(0).build())
.addModifier(new AbsClampNoiseModifier()) .addModifier(new AbsClampNoiseModifier())
.build()),
ROOFED(JNoise.newBuilder()
.perlin(PerlinNoiseGenerator.newBuilder()
.setSeed(0)
.build())
.scale(0.1)
.addModifier(new AbsClampNoiseModifier())
.build()); .build());
final private JNoise noise; final private JNoise noise;