From 708ef16a1c516e1f4fd71c0f0c1d763cf2b76e5b Mon Sep 17 00:00:00 2001 From: dfsek Date: Thu, 21 Jan 2021 20:00:51 -0700 Subject: [PATCH] reduce pipeline boilerplate --- .../dfsek/terra/api/math/vector/Vector2.java | 2 +- .../api/util/mutable/MutableInteger.java | 70 ++++++++----------- .../terra/api/util/mutable/MutableNumber.java | 51 ++++++++++++++ .../terra/api/world/biome/Generator.java | 2 + .../terra/biome/StandardBiomeProvider.java | 2 +- .../pipeline/mutator/BorderListMutator.java | 46 ++++++++++++ .../biome/pipeline/mutator/BorderMutator.java | 5 +- .../pipeline/mutator/ReplaceListMutator.java | 35 ++++++++++ .../terra/config/base/ConfigPackTemplate.java | 25 ------- .../config/builder/GeneratorBuilder.java | 7 +- .../terra/config/factories/BiomeFactory.java | 1 + .../com/dfsek/terra/config/loaders/Types.java | 4 ++ .../biome/BiomeProviderBuilderLoader.java | 36 ++++++++-- .../terra/config/templates/BiomeTemplate.java | 8 +++ .../generation/config/WorldGenerator.java | 9 ++- .../math/interpolation/ChunkInterpolator.java | 17 ++--- .../dfsek/terra/registry/TerraRegistry.java | 2 +- .../src/test/java/biome/DistributionTest.java | 2 - 18 files changed, 234 insertions(+), 90 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/api/util/mutable/MutableNumber.java create mode 100644 common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BorderListMutator.java create mode 100644 common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/ReplaceListMutator.java diff --git a/common/src/main/java/com/dfsek/terra/api/math/vector/Vector2.java b/common/src/main/java/com/dfsek/terra/api/math/vector/Vector2.java index aacf31660..3318fc9eb 100644 --- a/common/src/main/java/com/dfsek/terra/api/math/vector/Vector2.java +++ b/common/src/main/java/com/dfsek/terra/api/math/vector/Vector2.java @@ -65,7 +65,7 @@ public class Vector2 implements Cloneable { /** * Add this vector to another. * - * @param other Vector to add + * @param other Vector to increment * @return Mutated vector, for chaining. */ public Vector2 add(Vector2 other) { 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 0bb1c4415..adbe67404 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 @@ -1,51 +1,39 @@ package com.dfsek.terra.api.util.mutable; -public class MutableInteger extends Number implements MutablePrimitive { - private int value; - - public MutableInteger() { - +public class MutableInteger extends MutableNumber { + public MutableInteger(Integer value) { + super(value); } - public MutableInteger(int init) { - this.value = init; - } - - @Override - public int intValue() { - return value; - } - - @Override - public long longValue() { - return value; - } - - @Override - public float floatValue() { - return value; - } - - @Override - public double doubleValue() { - return value; - } - - @Override - public Integer get() { - return value; - } - - @Override - public void set(Integer value) { - this.value = value; - } - - public void add() { + public void increment() { add(1); } + public void decrement() { + add(-1); + } + + @Override + public void add(Integer add) { + value += add; + } + + @Override + public void multiply(Integer mul) { + value *= mul; + } + + @Override + public void subtract(Integer sub) { + value -= sub; + } + + @Override + public void divide(Integer divide) { + value /= divide; + } + public void add(int add) { - this.value += add; + value += add; } } diff --git a/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableNumber.java b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableNumber.java new file mode 100644 index 000000000..7bf03b836 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableNumber.java @@ -0,0 +1,51 @@ +package com.dfsek.terra.api.util.mutable; + +public abstract class MutableNumber extends Number implements MutablePrimitive { + protected T value; + + public MutableNumber(T value) { + this.value = value; + } + + public abstract void increment(); + + public abstract void decrement(); + + public abstract void add(T add); + + public abstract void multiply(T mul); + + public abstract void subtract(T sub); + + public abstract void divide(T divide); + + @Override + public T get() { + return value; + } + + @Override + public void set(T value) { + this.value = value; + } + + @Override + public int intValue() { + return value.intValue(); + } + + @Override + public long longValue() { + return value.longValue(); + } + + @Override + public float floatValue() { + return value.floatValue(); + } + + @Override + public double doubleValue() { + return value.doubleValue(); + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/Generator.java b/common/src/main/java/com/dfsek/terra/api/world/biome/Generator.java index 20c0929bf..db12b70fc 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/Generator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/Generator.java @@ -35,4 +35,6 @@ public interface Generator { NoiseSampler getBiomeNoise(); double getElevationWeight(); + + int getBlendStep(); } diff --git a/common/src/main/java/com/dfsek/terra/biome/StandardBiomeProvider.java b/common/src/main/java/com/dfsek/terra/biome/StandardBiomeProvider.java index ea11efa6e..2952d1640 100644 --- a/common/src/main/java/com/dfsek/terra/biome/StandardBiomeProvider.java +++ b/common/src/main/java/com/dfsek/terra/biome/StandardBiomeProvider.java @@ -76,7 +76,7 @@ public class StandardBiomeProvider implements BiomeProvider { this.resolution = resolution; } - public void setBuilder(NoiseBuilder builder) { + public void setBlender(NoiseBuilder builder) { this.builder = builder; } diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BorderListMutator.java b/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BorderListMutator.java new file mode 100644 index 000000000..0adc7cd78 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BorderListMutator.java @@ -0,0 +1,46 @@ +package com.dfsek.terra.biome.pipeline.mutator; + +import com.dfsek.terra.api.math.ProbabilityCollection; +import com.dfsek.terra.api.math.noise.samplers.NoiseSampler; +import com.dfsek.terra.api.world.biome.TerraBiome; + +import java.util.Map; + +public class BorderListMutator implements BiomeMutator { + private final String border; + private final NoiseSampler noiseSampler; + private final ProbabilityCollection replaceDefault; + private final String defaultReplace; + private final Map> replace; + + public BorderListMutator(Map> replace, String border, String defaultReplace, NoiseSampler noiseSampler, ProbabilityCollection replaceDefault) { + this.border = border; + this.noiseSampler = noiseSampler; + this.replaceDefault = replaceDefault; + this.defaultReplace = defaultReplace; + this.replace = replace; + } + + @Override + public TerraBiome mutate(ViewPoint viewPoint, double x, double z) { + TerraBiome origin = viewPoint.getBiome(0, 0); + if(origin.getTags().contains(defaultReplace)) { + for(int xi = -1; xi <= 1; xi++) { + for(int zi = -1; zi <= 1; zi++) { + if(xi == 0 && zi == 0) continue; + TerraBiome current = viewPoint.getBiome(xi, zi); + if(current == null) continue; + if(current.getTags().contains(border)) { + if(replace.containsKey(origin)) { + TerraBiome biome = replace.get(origin).get(noiseSampler, x, z); + return biome == null ? origin : biome; + } + TerraBiome biome = replaceDefault.get(noiseSampler, x, z); + return biome == null ? origin : biome; + } + } + } + } + return origin; + } +} diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BorderMutator.java b/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BorderMutator.java index 39d825c7c..41c6547dc 100644 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BorderMutator.java +++ b/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BorderMutator.java @@ -26,7 +26,10 @@ public class BorderMutator implements BiomeMutator { if(xi == 0 && zi == 0) continue; TerraBiome current = viewPoint.getBiome(xi, zi); if(current == null) continue; - if(current.getTags().contains(border)) return replace.get(noiseSampler, x, z); + if(current.getTags().contains(border)) { + TerraBiome biome = replace.get(noiseSampler, x, z); + return biome == null ? origin : biome; + } } } } diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/ReplaceListMutator.java b/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/ReplaceListMutator.java new file mode 100644 index 000000000..cfd5e6c31 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/ReplaceListMutator.java @@ -0,0 +1,35 @@ +package com.dfsek.terra.biome.pipeline.mutator; + +import com.dfsek.terra.api.math.ProbabilityCollection; +import com.dfsek.terra.api.math.noise.samplers.NoiseSampler; +import com.dfsek.terra.api.world.biome.TerraBiome; + +import java.util.Map; + +public class ReplaceListMutator implements BiomeMutator { + private final Map> replace; + private final NoiseSampler sampler; + private final ProbabilityCollection replaceDefault; + private final String defaultTag; + + public ReplaceListMutator(Map> replace, String defaultTag, ProbabilityCollection replaceDefault, NoiseSampler sampler) { + this.replace = replace; + this.sampler = sampler; + this.defaultTag = defaultTag; + this.replaceDefault = replaceDefault; + } + + @Override + public TerraBiome mutate(ViewPoint viewPoint, double x, double z) { + TerraBiome center = viewPoint.getBiome(0, 0); + if(replace.containsKey(center)) { + TerraBiome biome = replace.get(center).get(sampler, x, z); + return biome == null ? viewPoint.getBiome(0, 0) : biome; + } + if(viewPoint.getBiome(0, 0).getTags().contains(defaultTag)) { + TerraBiome biome = replaceDefault.get(sampler, x, z); + return biome == null ? viewPoint.getBiome(0, 0) : biome; + } + return center; + } +} diff --git a/common/src/main/java/com/dfsek/terra/config/base/ConfigPackTemplate.java b/common/src/main/java/com/dfsek/terra/config/base/ConfigPackTemplate.java index 207a38b2b..3172bac12 100644 --- a/common/src/main/java/com/dfsek/terra/config/base/ConfigPackTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/base/ConfigPackTemplate.java @@ -21,18 +21,6 @@ public class ConfigPackTemplate implements ConfigTemplate { @Default private Map variables = new HashMap<>(); - @Value("blend.enable") - @Default - private boolean blend = false; - - @Value("blend.frequency") - @Default - private double blendFreq = 0.1; - - @Value("blend.amplitude") - @Default - private double blendAmp = 4.0D; - @Value("structures.locatable") @Default private Map locatable = new HashMap<>(); @@ -132,18 +120,6 @@ public class ConfigPackTemplate implements ConfigTemplate { return variables; } - public boolean isBlend() { - return blend; - } - - public double getBlendFreq() { - return blendFreq; - } - - public double getBlendAmp() { - return blendAmp; - } - public boolean isErode() { return erode; } @@ -160,7 +136,6 @@ public class ConfigPackTemplate implements ConfigTemplate { return erodeOctaves; } - public int getElevationBlend() { return elevationBlend; } 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 f8b7af143..a93eac24b 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 @@ -38,13 +38,18 @@ public class GeneratorBuilder { private int blendDistance; + private int blendStep; 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)); + return gens.computeIfAbsent(seed, k -> new WorldGenerator(seed, noiseEquation, elevationEquation, varScope, noiseBuilderMap, palettes, slantPalettes, noise2d, base, biomeNoise.build((int) seed), elevationWeight, blendDistance, blendStep)); } } + public void setBlendStep(int blendStep) { + this.blendStep = blendStep; + } + public void setBlendDistance(int blendDistance) { this.blendDistance = blendDistance; } 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 e294d44bf..bb0212b7a 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 @@ -29,6 +29,7 @@ public class BiomeFactory implements TerraFactory { generatorBuilder.setElevationWeight(template.getElevationWeight()); generatorBuilder.setBiomeNoise(template.getBiomeNoise()); generatorBuilder.setBlendDistance(template.getBlendDistance()); + generatorBuilder.setBlendStep(template.getBlendStep()); return new UserDefinedBiome(template.getVanilla(), generatorBuilder, template); diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/Types.java b/common/src/main/java/com/dfsek/terra/config/loaders/Types.java index ec20b68c7..206c6226a 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/Types.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/Types.java @@ -9,6 +9,7 @@ import com.dfsek.terra.api.world.palette.Palette; import com.dfsek.terra.api.world.tree.Tree; import java.lang.reflect.Type; +import java.util.Map; import java.util.Set; /** @@ -23,6 +24,7 @@ public final class Types { public static final Type FLORA_PROBABILITY_COLLECTION_TYPE; public static final Type TREE_PROBABILITY_COLLECTION_TYPE; public static final Type TERRA_BIOME_PROBABILITY_COLLECTION_TYPE; + public static final Type TERRA_BIOME_TERRA_BIOME_PROBABILITY_COLLECTION_MAP; static { MATERIAL_SET_TYPE = getType("materialSet"); @@ -32,6 +34,7 @@ public final class Types { FLORA_PROBABILITY_COLLECTION_TYPE = getType("floraProbabilityCollection"); TREE_PROBABILITY_COLLECTION_TYPE = getType("treeProbabilityCollection"); TERRA_BIOME_PROBABILITY_COLLECTION_TYPE = getType("terraBiomeProbabilityCollection"); + TERRA_BIOME_TERRA_BIOME_PROBABILITY_COLLECTION_MAP = getType("terraBiomeProbabilityCollectionMap"); } private Set materialSet; @@ -41,6 +44,7 @@ public final class Types { private ProbabilityCollection floraProbabilityCollection; private ProbabilityCollection treeProbabilityCollection; private ProbabilityCollection terraBiomeProbabilityCollection; + private Map> terraBiomeProbabilityCollectionMap; private static Type getType(String dummyFieldName) { try { diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/BiomeProviderBuilderLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/BiomeProviderBuilderLoader.java index b3308e929..9f2a0d428 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/BiomeProviderBuilderLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/BiomeProviderBuilderLoader.java @@ -12,7 +12,9 @@ import com.dfsek.terra.biome.ImageBiomeProvider; import com.dfsek.terra.biome.StandardBiomeProvider; import com.dfsek.terra.biome.pipeline.BiomePipeline; import com.dfsek.terra.biome.pipeline.expand.FractalExpander; +import com.dfsek.terra.biome.pipeline.mutator.BorderListMutator; import com.dfsek.terra.biome.pipeline.mutator.BorderMutator; +import com.dfsek.terra.biome.pipeline.mutator.ReplaceListMutator; import com.dfsek.terra.biome.pipeline.mutator.ReplaceMutator; import com.dfsek.terra.biome.pipeline.mutator.SmoothMutator; import com.dfsek.terra.biome.pipeline.source.RandomSource; @@ -30,6 +32,7 @@ import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.IOException; import java.lang.reflect.Type; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -46,7 +49,7 @@ public class BiomeProviderBuilderLoader implements TypeLoader map = (Map) c; int resolution = 1; @@ -79,17 +82,40 @@ public class BiomeProviderBuilderLoader implements TypeLoader replaceBiomes = new SelfProbabilityCollectionLoader().load(Types.TERRA_BIOME_PROBABILITY_COLLECTION_TYPE, mutator.get("to"), loader); + pipelineBuilder.addStage(new MutatorStage(new ReplaceMutator(fromTag, replaceBiomes, mutatorNoise))); + } else if(mutator.get("type").equals("REPLACE_LIST")) { + String fromTag = mutator.get("default-from").toString(); + ProbabilityCollection replaceBiomes = new SelfProbabilityCollectionLoader().load(Types.TERRA_BIOME_PROBABILITY_COLLECTION_TYPE, mutator.get("default-to"), loader); + + Map> replace = new HashMap<>(); + for(Map.Entry e : ((Map) mutator.get("to")).entrySet()) { + replace.put((TerraBiome) loader.loadType(TerraBiome.class, e.getKey()), new SelfProbabilityCollectionLoader().load(Types.TERRA_BIOME_PROBABILITY_COLLECTION_TYPE, e.getValue(), loader)); + } + + pipelineBuilder.addStage(new MutatorStage(new ReplaceListMutator(replace, fromTag, replaceBiomes, mutatorNoise))); } else if(mutator.get("type").equals("BORDER")) { String fromTag = mutator.get("from").toString(); String replaceTag = mutator.get("replace").toString(); - ProbabilityCollection replaceBiomes = (ProbabilityCollection) loader.loadType(Types.TERRA_BIOME_PROBABILITY_COLLECTION_TYPE, mutator.get("to")); + ProbabilityCollection replaceBiomes = new SelfProbabilityCollectionLoader().load(Types.TERRA_BIOME_PROBABILITY_COLLECTION_TYPE, mutator.get("to"), loader); + pipelineBuilder.addStage(new MutatorStage(new BorderMutator(fromTag, replaceTag, mutatorNoise, replaceBiomes))); + } else if(mutator.get("type").equals("BORDER_LIST")) { + String fromTag = mutator.get("from").toString(); + String replaceTag = mutator.get("default-replace").toString(); + ProbabilityCollection replaceBiomes = new SelfProbabilityCollectionLoader().load(Types.TERRA_BIOME_PROBABILITY_COLLECTION_TYPE, mutator.get("default-to"), loader); + + Map> replace = new HashMap<>(); + for(Map.Entry e : ((Map) mutator.get("replace")).entrySet()) { + replace.put((TerraBiome) loader.loadType(TerraBiome.class, e.getKey()), new SelfProbabilityCollectionLoader().load(Types.TERRA_BIOME_PROBABILITY_COLLECTION_TYPE, e.getValue(), loader)); + } + + pipelineBuilder.addStage(new MutatorStage(new BorderListMutator(replace, fromTag, replaceTag, mutatorNoise, replaceBiomes))); } else throw new LoadException("No such mutator type \"" + mutator.get("type")); } else throw new LoadException("No such mutator \"" + entry.getKey() + "\""); } @@ -103,7 +129,7 @@ public class BiomeProviderBuilderLoader implements TypeLoader blend = (Map) map.get("blend"); if(blend.containsKey("amplitude")) builder.setNoiseAmp(Integer.parseInt(blend.get("amplitude").toString())); if(blend.containsKey("noise")) - builder.setBuilder(new NoiseBuilderLoader().load(NoiseBuilder.class, blend.get("noise"), loader)); + builder.setBlender(new NoiseBuilderLoader().load(NoiseBuilder.class, blend.get("noise"), loader)); } return builder; } else if(map.get("type").equals("IMAGE")) { 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 731bdf958..08d01aa3e 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,6 +75,10 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf @Default private int blendDistance = 3; + @Value("blend.step") + @Default + private int blendStep = 4; + @Value("erode") @Abstractable @Default @@ -284,6 +288,10 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf return elevationWeight; } + public int getBlendStep() { + return blendStep; + } + @Override public boolean validate() throws ValidationException { color |= 0x1fe00000; // Alpha adjustment 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 13da7a77b..468391293 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 @@ -34,8 +34,9 @@ public class WorldGenerator implements Generator { private final NoiseSampler biomeNoise; private final double elevationWeight; private final int blendDistance; + private final 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) { + 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) { this.palettes = palettes; this.slantPalettes = slantPalettes; @@ -44,6 +45,7 @@ public class WorldGenerator implements Generator { this.biomeNoise = biomeNoise; this.elevationWeight = elevationWeight; this.blendDistance = blendDistance; + this.blendStep = blendStep; Parser p = new Parser(); p.registerFunction("rand", new RandomFunction()); @@ -143,6 +145,11 @@ public class WorldGenerator implements Generator { return elevationWeight; } + @Override + public int getBlendStep() { + return blendStep; + } + public Palette getSlantPalette(int y) { return slantPalettes.getPalette(y); } diff --git a/common/src/main/java/com/dfsek/terra/generation/math/interpolation/ChunkInterpolator.java b/common/src/main/java/com/dfsek/terra/generation/math/interpolation/ChunkInterpolator.java index c788ab873..f4e1572d3 100644 --- a/common/src/main/java/com/dfsek/terra/generation/math/interpolation/ChunkInterpolator.java +++ b/common/src/main/java/com/dfsek/terra/generation/math/interpolation/ChunkInterpolator.java @@ -10,7 +10,7 @@ import java.util.HashMap; import java.util.Map; /** - * Class to abstract away the 16 Interpolators needed to generate a chunk.
+ * Class to abstract away the Interpolators needed to generate a chunk.
* Contains method to get interpolated noise at a coordinate within the chunk. */ public class ChunkInterpolator { @@ -21,30 +21,25 @@ public class ChunkInterpolator { * * @param chunkX X coordinate of the chunk. * @param chunkZ Z coordinate of the chunk. - * @param provider BiomeGrid to use for noise fetching. + * @param provider Biome Provider to use for biome fetching. */ public ChunkInterpolator(World w, int chunkX, int chunkZ, BiomeProvider provider) { - Generator[][] gens = new Generator[5][5]; int xOrigin = chunkX << 4; int zOrigin = chunkZ << 4; - for(int x = 0; x < 5; x++) { - for(int z = 0; z < 5; z++) { - gens[x][z] = provider.getBiome(xOrigin + (x * 4), zOrigin + (z * 4)).getGenerator(w); - } - } - double[][][] noiseStorage = new double[5][5][65]; for(int x = 0; x < 5; x++) { for(int z = 0; z < 5; z++) { - Generator generator = gens[x][z]; + Generator generator = provider.getBiome(xOrigin + (x << 2), zOrigin + (z << 2)).getGenerator(w); Map genMap = new HashMap<>(); + int step = generator.getBlendStep(); int blend = generator.getBlendDistance(); + for(int xi = -blend; xi <= blend; xi++) { for(int zi = -blend; zi <= blend; zi++) { - genMap.computeIfAbsent(provider.getBiome(xOrigin + ((x + xi) << 2), zOrigin + ((z + zi) << 2)).getGenerator(w), g -> new MutableInteger(0)).add(); // Increment by 1 + genMap.computeIfAbsent(provider.getBiome(xOrigin + (x << 2) + (xi * step), zOrigin + (z << 2) + (zi * step)).getGenerator(w), g -> new MutableInteger(0)).increment(); // Increment by 1 } } diff --git a/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java b/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java index 26f955b83..ab045d051 100644 --- a/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java @@ -26,7 +26,7 @@ public abstract class TerraRegistry implements TypeLoader { * Add an object to the registry with a name. * * @param name Name of the tree. - * @param value Object to add + * @param value Object to increment * @return True if tree was overwritten. */ public boolean add(String name, T value) { diff --git a/common/src/test/java/biome/DistributionTest.java b/common/src/test/java/biome/DistributionTest.java index 6dcc6c59c..c0cef141d 100644 --- a/common/src/test/java/biome/DistributionTest.java +++ b/common/src/test/java/biome/DistributionTest.java @@ -22,7 +22,6 @@ import com.dfsek.terra.config.loaders.config.biome.BiomeProviderBuilderLoader; import com.dfsek.terra.config.templates.AbstractableTemplate; import com.dfsek.terra.debug.Debug; import com.dfsek.terra.registry.BiomeRegistry; -import org.junit.jupiter.api.Test; import javax.swing.*; import java.awt.*; @@ -62,7 +61,6 @@ public class DistributionTest { return template.getBiomeProviderBuilder().build(seed); } - @Test public static void main(String... args) throws ConfigException, IOException { Debug.setLogger(Logger.getLogger("Terra")); Debug.setDebug(true);