mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-16 22:01:07 +00:00
reduce pipeline boilerplate
This commit is contained in:
@@ -21,18 +21,6 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
@Default
|
||||
private Map<String, Double> 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<String, String> 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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ public class BiomeFactory implements TerraFactory<BiomeTemplate, TerraBiome> {
|
||||
generatorBuilder.setElevationWeight(template.getElevationWeight());
|
||||
generatorBuilder.setBiomeNoise(template.getBiomeNoise());
|
||||
generatorBuilder.setBlendDistance(template.getBlendDistance());
|
||||
generatorBuilder.setBlendStep(template.getBlendStep());
|
||||
|
||||
|
||||
return new UserDefinedBiome(template.getVanilla(), generatorBuilder, template);
|
||||
|
||||
@@ -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<MaterialData> materialSet;
|
||||
@@ -41,6 +44,7 @@ public final class Types {
|
||||
private ProbabilityCollection<Flora> floraProbabilityCollection;
|
||||
private ProbabilityCollection<Tree> treeProbabilityCollection;
|
||||
private ProbabilityCollection<TerraBiome> terraBiomeProbabilityCollection;
|
||||
private Map<TerraBiome, ProbabilityCollection<TerraBiome>> terraBiomeProbabilityCollectionMap;
|
||||
|
||||
private static Type getType(String dummyFieldName) {
|
||||
try {
|
||||
|
||||
+31
-5
@@ -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<BiomeProvider.Biom
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeProvider.BiomeProviderBuilder load(Type t, Object c, ConfigLoader loader) throws LoadException {
|
||||
public BiomeProvider.BiomeProviderBuilder load(Type t, Object c, ConfigLoader loader) throws LoadException { // TODO: clean this up
|
||||
Map<String, Object> map = (Map<String, Object>) c;
|
||||
|
||||
int resolution = 1;
|
||||
@@ -79,17 +82,40 @@ public class BiomeProviderBuilderLoader implements TypeLoader<BiomeProvider.Biom
|
||||
pipelineBuilder.addStage(new ExpanderStage(new FractalExpander(mutatorNoise)));
|
||||
else throw new LoadException("No such expander \"" + mutator.get("type"));
|
||||
} else if(entry.getKey().equals("mutate")) {
|
||||
if(mutator.get("type").equals("SMOOTH"))
|
||||
if(mutator.get("type").equals("SMOOTH")) {
|
||||
pipelineBuilder.addStage(new MutatorStage(new SmoothMutator(mutatorNoise)));
|
||||
else if(mutator.get("type").equals("REPLACE")) {
|
||||
} else if(mutator.get("type").equals("REPLACE")) {
|
||||
String fromTag = mutator.get("from").toString();
|
||||
ProbabilityCollection<TerraBiome> replaceBiomes = new SelfProbabilityCollectionLoader<TerraBiome>().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<TerraBiome> replaceBiomes = new SelfProbabilityCollectionLoader<TerraBiome>().load(Types.TERRA_BIOME_PROBABILITY_COLLECTION_TYPE, mutator.get("default-to"), loader);
|
||||
|
||||
Map<TerraBiome, ProbabilityCollection<TerraBiome>> replace = new HashMap<>();
|
||||
for(Map.Entry<String, Object> e : ((Map<String, Object>) mutator.get("to")).entrySet()) {
|
||||
replace.put((TerraBiome) loader.loadType(TerraBiome.class, e.getKey()), new SelfProbabilityCollectionLoader<TerraBiome>().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<TerraBiome> replaceBiomes = (ProbabilityCollection<TerraBiome>) loader.loadType(Types.TERRA_BIOME_PROBABILITY_COLLECTION_TYPE, mutator.get("to"));
|
||||
ProbabilityCollection<TerraBiome> replaceBiomes = new SelfProbabilityCollectionLoader<TerraBiome>().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<TerraBiome> replaceBiomes = new SelfProbabilityCollectionLoader<TerraBiome>().load(Types.TERRA_BIOME_PROBABILITY_COLLECTION_TYPE, mutator.get("default-to"), loader);
|
||||
|
||||
Map<TerraBiome, ProbabilityCollection<TerraBiome>> replace = new HashMap<>();
|
||||
for(Map.Entry<String, Object> e : ((Map<String, Object>) mutator.get("replace")).entrySet()) {
|
||||
replace.put((TerraBiome) loader.loadType(TerraBiome.class, e.getKey()), new SelfProbabilityCollectionLoader<TerraBiome>().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<BiomeProvider.Biom
|
||||
Map<String, Object> blend = (Map<String, Object>) 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")) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user