add BorderMutator

This commit is contained in:
dfsek
2021-01-12 19:25:01 -07:00
parent 93c33ca455
commit f28759d07a
7 changed files with 97 additions and 22 deletions
@@ -7,6 +7,8 @@ import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.builder.GeneratorBuilder;
import com.dfsek.terra.config.templates.BiomeTemplate;
import java.util.Set;
/**
* Class representing a config-defined biome
*/
@@ -17,7 +19,8 @@ public class UserDefinedBiome implements TerraBiome {
private final BiomeTemplate config;
private final ConfigPack pack;
private UserDefinedBiome erode;
private int color;
private final int color;
private final Set<String> tags;
public UserDefinedBiome(com.dfsek.terra.api.platform.world.Biome vanilla, GeneratorBuilder gen, BiomeTemplate config, ConfigPack pack) {
@@ -27,6 +30,8 @@ public class UserDefinedBiome implements TerraBiome {
this.config = config;
this.pack = pack;
this.color = config.getColor();
this.tags = config.getTags();
tags.add("BIOME:" + id);
}
/**
@@ -65,4 +70,9 @@ public class UserDefinedBiome implements TerraBiome {
public int getColor() {
return color;
}
@Override
public Set<String> getTags() {
return tags;
}
}
@@ -1,13 +1,39 @@
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 com.dfsek.terra.biome.pipeline.Position;
public class BorderMutator implements BiomeMutator {
import java.util.Set;
public class BorderMutator implements BiomeMutator {
private final Set<String> borders;
private final NoiseSampler noiseSampler;
private final ProbabilityCollection<TerraBiome> replace;
private final String tag;
public BorderMutator(Set<String> borders, String tag, NoiseSampler noiseSampler, ProbabilityCollection<TerraBiome> replace) {
this.borders = borders;
this.noiseSampler = noiseSampler;
this.replace = replace;
this.tag = tag;
}
@Override
public TerraBiome mutate(ViewPoint viewPoint, Position position) {
return null;
TerraBiome origin = viewPoint.getBiome(0, 0);
if(origin.getTags().contains(tag)) {
for(int x = -1; x <= 1; x++) {
for(int z = -1; z <= 1; z++) {
if(x == 0 && z == 0) continue;
TerraBiome current = viewPoint.getBiome(x, z);
if(current == null) continue;
if(borders.stream().anyMatch(current.getTags()::contains))
return replace.get(noiseSampler, position.getX(), position.getY());
}
}
}
return origin;
}
}
@@ -5,21 +5,19 @@ import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.biome.pipeline.Position;
import java.util.Set;
public class ReplaceMutator implements BiomeMutator {
private final Set<TerraBiome> replaceable;
private final String replaceableTag;
private final ProbabilityCollection<TerraBiome> replace;
private final NoiseSampler sampler;
public ReplaceMutator(Set<TerraBiome> replaceable, ProbabilityCollection<TerraBiome> replace, NoiseSampler sampler) {
this.replaceable = replaceable;
public ReplaceMutator(String replaceable, ProbabilityCollection<TerraBiome> replace, NoiseSampler sampler) {
this.replaceableTag = replaceable;
this.replace = replace;
this.sampler = sampler;
}
@Override
public TerraBiome mutate(ViewPoint viewPoint, Position position) {
return replaceable.contains(viewPoint.getBiome(0, 0)) ? replace.get(sampler, position.getX(), position.getY()) : viewPoint.getBiome(0, 0);
return viewPoint.getBiome(0, 0).getTags().contains(replaceableTag) ? replace.get(sampler, position.getX(), position.getY()) : viewPoint.getBiome(0, 0);
}
}