From 115bb414c0f2f7616d8b1d09aafbb1480324eed7 Mon Sep 17 00:00:00 2001 From: dfsek Date: Thu, 21 Jan 2021 20:29:25 -0700 Subject: [PATCH] configurable blend weight --- .../api/util/mutable/MutableBoolean.java | 20 ++++++++++ .../terra/api/util/mutable/MutableDouble.java | 37 +++++++++++++++++++ .../api/util/mutable/MutableInteger.java | 2 +- .../config/builder/GeneratorBuilder.java | 8 +++- .../terra/config/factories/BiomeFactory.java | 1 + .../terra/config/templates/BiomeTemplate.java | 10 +++++ .../generation/config/WorldGenerator.java | 6 ++- 7 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/api/util/mutable/MutableBoolean.java create mode 100644 common/src/main/java/com/dfsek/terra/api/util/mutable/MutableDouble.java diff --git a/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableBoolean.java b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableBoolean.java new file mode 100644 index 000000000..146bc606a --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableBoolean.java @@ -0,0 +1,20 @@ +package com.dfsek.terra.api.util.mutable; + +public class MutableBoolean implements MutablePrimitive { + private boolean value; + + @Override + public Boolean get() { + return value; + } + + @Override + public void set(Boolean value) { + this.value = value; + } + + public boolean invert() { + value = !value; + return value; + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableDouble.java b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableDouble.java new file mode 100644 index 000000000..fec0a7b48 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableDouble.java @@ -0,0 +1,37 @@ +package com.dfsek.terra.api.util.mutable; + +public class MutableDouble extends MutableNumber { + public MutableDouble(Double value) { + super(value); + } + + @Override + public void increment() { + add(1d); + } + + @Override + public void decrement() { + subtract(1d); + } + + @Override + public void add(Double add) { + value += add; + } + + @Override + public void multiply(Double mul) { + value *= mul; + } + + @Override + public void subtract(Double sub) { + value -= sub; + } + + @Override + public void divide(Double divide) { + value /= divide; + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableInteger.java b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableInteger.java index adbe67404..946cced77 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableInteger.java +++ b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableInteger.java @@ -10,7 +10,7 @@ public class MutableInteger extends MutableNumber { } public void decrement() { - add(-1); + subtract(1); } @Override diff --git a/common/src/main/java/com/dfsek/terra/config/builder/GeneratorBuilder.java b/common/src/main/java/com/dfsek/terra/config/builder/GeneratorBuilder.java index a93eac24b..2cdf1cb64 100644 --- a/common/src/main/java/com/dfsek/terra/config/builder/GeneratorBuilder.java +++ b/common/src/main/java/com/dfsek/terra/config/builder/GeneratorBuilder.java @@ -40,12 +40,18 @@ public class GeneratorBuilder { private int blendStep; + private double blendWeight; + public WorldGenerator build(long seed) { synchronized(gens) { - return gens.computeIfAbsent(seed, k -> new WorldGenerator(seed, noiseEquation, elevationEquation, varScope, noiseBuilderMap, palettes, slantPalettes, noise2d, base, biomeNoise.build((int) seed), elevationWeight, blendDistance, blendStep)); + return gens.computeIfAbsent(seed, k -> new WorldGenerator(seed, noiseEquation, elevationEquation, varScope, noiseBuilderMap, palettes, slantPalettes, noise2d, base, biomeNoise.build((int) seed), elevationWeight, blendDistance, blendStep, blendWeight)); } } + public void setBlendWeight(double blendWeight) { + this.blendWeight = blendWeight; + } + public void setBlendStep(int blendStep) { this.blendStep = blendStep; } diff --git a/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java index bb0212b7a..1fe8aadb0 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java @@ -30,6 +30,7 @@ public class BiomeFactory implements TerraFactory { generatorBuilder.setBiomeNoise(template.getBiomeNoise()); generatorBuilder.setBlendDistance(template.getBlendDistance()); generatorBuilder.setBlendStep(template.getBlendStep()); + generatorBuilder.setBlendWeight(template.getBlendWeight()); return new UserDefinedBiome(template.getVanilla(), generatorBuilder, template); diff --git a/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java index 08d01aa3e..3e175740a 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java @@ -75,7 +75,13 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf @Default private int blendDistance = 3; + @Value("blend.weight") + @Abstractable + @Default + private double blendWeight = 1; + @Value("blend.step") + @Abstractable @Default private int blendStep = 4; @@ -170,6 +176,10 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf return tags; } + public double getBlendWeight() { + return blendWeight; + } + public int getColor() { return color; } diff --git a/common/src/main/java/com/dfsek/terra/generation/config/WorldGenerator.java b/common/src/main/java/com/dfsek/terra/generation/config/WorldGenerator.java index 468391293..2af578a4c 100644 --- a/common/src/main/java/com/dfsek/terra/generation/config/WorldGenerator.java +++ b/common/src/main/java/com/dfsek/terra/generation/config/WorldGenerator.java @@ -35,8 +35,9 @@ public class WorldGenerator implements Generator { private final double elevationWeight; private final int blendDistance; private final int blendStep; + private final double blendWeight; - public WorldGenerator(long seed, String equation, String elevateEquation, Scope vScope, Map noiseBuilders, PaletteHolder palettes, PaletteHolder slantPalettes, boolean noise2d, double base, NoiseSampler biomeNoise, double elevationWeight, int blendDistance, int blendStep) { + public WorldGenerator(long seed, String equation, String elevateEquation, Scope vScope, Map noiseBuilders, PaletteHolder palettes, PaletteHolder slantPalettes, boolean noise2d, double base, NoiseSampler biomeNoise, double elevationWeight, int blendDistance, int blendStep, double blendWeight) { this.palettes = palettes; this.slantPalettes = slantPalettes; @@ -46,6 +47,7 @@ public class WorldGenerator implements Generator { this.elevationWeight = elevationWeight; this.blendDistance = blendDistance; this.blendStep = blendStep; + this.blendWeight = blendWeight; Parser p = new Parser(); p.registerFunction("rand", new RandomFunction()); @@ -104,7 +106,7 @@ public class WorldGenerator implements Generator { @Override public double getWeight() { - return 1; + return blendWeight; } @Override