mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 00:15:35 +00:00
add BorderMutator
This commit is contained in:
parent
93c33ca455
commit
f28759d07a
@ -8,7 +8,7 @@ import java.util.Set;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ProbabilityCollection<E> {
|
||||
private final Set<Object> cont = new HashSet<>();
|
||||
private final Set<E> cont = new HashSet<>();
|
||||
private Object[] array = new Object[0];
|
||||
private int size;
|
||||
|
||||
@ -45,4 +45,8 @@ public class ProbabilityCollection<E> {
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public Set<E> getContents() {
|
||||
return new HashSet<>(cont);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.dfsek.terra.api.world.biome;
|
||||
|
||||
|
||||
import com.dfsek.terra.api.platform.world.Biome;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by a custom generator's TerraBiome enum.<br>
|
||||
* Represents a custom biome, and contains methods to retrieve information about each type.
|
||||
@ -14,7 +17,7 @@ public interface TerraBiome {
|
||||
*
|
||||
* @return TerraBiome - The Vanilla biome.
|
||||
*/
|
||||
com.dfsek.terra.api.platform.world.Biome getVanillaBiome();
|
||||
Biome getVanillaBiome();
|
||||
|
||||
/**
|
||||
* Gets the BiomeTerrain instance used to generate the biome.
|
||||
@ -24,4 +27,6 @@ public interface TerraBiome {
|
||||
Generator getGenerator(World w);
|
||||
|
||||
int getColor();
|
||||
|
||||
Set<String> getTags();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import parsii.tokenizer.ParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
public class BiomeTemplate extends AbstractableTemplate implements ValidatedConfigTemplate {
|
||||
@ -137,6 +138,15 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
|
||||
@Default
|
||||
private int color = 0;
|
||||
|
||||
@Value("tags")
|
||||
@Default
|
||||
@Abstractable
|
||||
private Set<String> tags;
|
||||
|
||||
public Set<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.biome.pipeline.Position;
|
||||
import com.dfsek.terra.biome.pipeline.TerraBiomeHolder;
|
||||
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.BiomeSource;
|
||||
@ -19,6 +20,9 @@ import org.junit.jupiter.api.Test;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BiomeTest {
|
||||
@Test
|
||||
@ -26,21 +30,28 @@ public class BiomeTest {
|
||||
ProbabilityCollection<TerraBiome> oceanBiomes = new ProbabilityCollection<>();
|
||||
ProbabilityCollection<TerraBiome> landBiomes = new ProbabilityCollection<>();
|
||||
|
||||
TestBiome ocean = new TestBiome(Color.BLUE);
|
||||
TestBiome land = new TestBiome(Color.GREEN);
|
||||
|
||||
ProbabilityCollection<TerraBiome> beachBiomes = new ProbabilityCollection<>();
|
||||
|
||||
TestBiome ocean = new TestBiome(Color.BLUE, "OCEAN_TEMP");
|
||||
TestBiome land = new TestBiome(Color.GREEN, "LAND_TEMP");
|
||||
|
||||
TestBiome beach = new TestBiome(Color.YELLOW, "BEACH");
|
||||
beachBiomes.add(beach, 1);
|
||||
|
||||
|
||||
ProbabilityCollection<TerraBiome> climate = new ProbabilityCollection<>();
|
||||
climate.add(ocean, 1);
|
||||
climate.add(land, 3);
|
||||
|
||||
|
||||
oceanBiomes.add(new TestBiome(Color.BLUE), 10);
|
||||
oceanBiomes.add(new TestBiome(Color.CYAN), 1);
|
||||
oceanBiomes.add(new TestBiome(Color.BLUE, "OCEAN"), 10);
|
||||
oceanBiomes.add(new TestBiome(Color.CYAN, "OCEAN"), 1);
|
||||
|
||||
landBiomes.add(new TestBiome(Color.GREEN), 5);
|
||||
landBiomes.add(new TestBiome(Color.ORANGE), 5);
|
||||
landBiomes.add(new TestBiome(Color.YELLOW), 5);
|
||||
landBiomes.add(new TestBiome(Color.MAGENTA), 1);
|
||||
landBiomes.add(new TestBiome(Color.GREEN, "LAND"), 20);
|
||||
landBiomes.add(new TestBiome(Color.ORANGE, "LAND"), 5);
|
||||
landBiomes.add(new TestBiome(Color.RED, "LAND"), 1);
|
||||
landBiomes.add(new TestBiome(Color.GRAY, "LAND"), 1);
|
||||
|
||||
FastNoiseLite sourceSampler = new FastNoiseLite(123);
|
||||
sourceSampler.setNoiseType(FastNoiseLite.NoiseType.WhiteNoise);
|
||||
@ -56,8 +67,8 @@ public class BiomeTest {
|
||||
holder.fill(source);
|
||||
holder.expand(new FractalExpander(whiteNoise(4)));
|
||||
|
||||
holder.mutate(new ReplaceMutator(Sets.newHashSet(ocean), oceanBiomes, whiteNoise(234)));
|
||||
holder.mutate(new ReplaceMutator(Sets.newHashSet(land), landBiomes, whiteNoise(235)));
|
||||
holder.mutate(new ReplaceMutator("OCEAN_TEMP", oceanBiomes, whiteNoise(234)));
|
||||
holder.mutate(new ReplaceMutator("LAND_TEMP", landBiomes, whiteNoise(235)));
|
||||
|
||||
holder.expand(new FractalExpander(whiteNoise(3)));
|
||||
holder.expand(new FractalExpander(whiteNoise(2)));
|
||||
@ -66,6 +77,9 @@ public class BiomeTest {
|
||||
|
||||
holder.expand(new FractalExpander(whiteNoise(5)));
|
||||
holder.expand(new FractalExpander(whiteNoise(7)));
|
||||
|
||||
holder.mutate(new BorderMutator(Sets.newHashSet("OCEAN"), "LAND", whiteNoise(2356), beachBiomes));
|
||||
|
||||
holder.expand(new FractalExpander(whiteNoise(6)));
|
||||
|
||||
holder.mutate(new SmoothMutator(whiteNoise(35)));
|
||||
@ -114,9 +128,12 @@ public class BiomeTest {
|
||||
|
||||
private final static class TestBiome implements TerraBiome {
|
||||
private final Color color;
|
||||
private final Set<String> tags;
|
||||
|
||||
private TestBiome(Color color) {
|
||||
|
||||
private TestBiome(Color color, String... tags) {
|
||||
this.color = color;
|
||||
this.tags = Arrays.stream(tags).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -133,5 +150,10 @@ public class BiomeTest {
|
||||
public int getColor() {
|
||||
return color.getRGB();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user