add BorderMutator to config

This commit is contained in:
dfsek
2021-01-13 19:02:51 -07:00
parent 18731a5aa0
commit 627f1b75d6
3 changed files with 14 additions and 12 deletions

View File

@@ -4,32 +4,29 @@ 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.Set;
public class BorderMutator implements BiomeMutator {
private final Set<String> borders;
private final String border;
private final NoiseSampler noiseSampler;
private final ProbabilityCollection<TerraBiome> replace;
private final String tag;
private final String replaceTag;
public BorderMutator(Set<String> borders, String tag, NoiseSampler noiseSampler, ProbabilityCollection<TerraBiome> replace) {
this.borders = borders;
public BorderMutator(String border, String replaceTag, NoiseSampler noiseSampler, ProbabilityCollection<TerraBiome> replace) {
this.border = border;
this.noiseSampler = noiseSampler;
this.replace = replace;
this.tag = tag;
this.replaceTag = replaceTag;
}
@Override
public TerraBiome mutate(ViewPoint viewPoint, double x, double z) {
TerraBiome origin = viewPoint.getBiome(0, 0);
if(origin.getTags().contains(tag)) {
if(origin.getTags().contains(replaceTag)) {
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(borders.stream().anyMatch(current.getTags()::contains))
return replace.get(noiseSampler, x, z);
if(current.getTags().contains(border)) return replace.get(noiseSampler, x, z);
}
}
}

View File

@@ -11,6 +11,7 @@ import com.dfsek.terra.biome.BiomeProvider;
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.BorderMutator;
import com.dfsek.terra.biome.pipeline.mutator.ReplaceMutator;
import com.dfsek.terra.biome.pipeline.mutator.SmoothMutator;
import com.dfsek.terra.biome.pipeline.source.RandomSource;
@@ -67,6 +68,11 @@ public class BiomeProviderBuilderLoader implements TypeLoader<BiomeProvider.Biom
String fromTag = mutator.get("from").toString();
ProbabilityCollection<TerraBiome> replaceBiomes = (ProbabilityCollection<TerraBiome>) loader.loadType(Types.TERRA_BIOME_PROBABILITY_COLLECTION_TYPE, mutator.get("to"));
pipelineBuilder.addStage(new MutatorStage(new ReplaceMutator(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"));
pipelineBuilder.addStage(new MutatorStage(new BorderMutator(fromTag, replaceTag, mutatorNoise, replaceBiomes)));
} else throw new LoadException("No such mutator type \"" + mutator.get("type"));
} else throw new LoadException("No such mutator \"" + entry.getKey() + "\"");
}