mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-14 04:41:13 +00:00
basic framework
This commit is contained in:
@@ -17,6 +17,7 @@ public class UserDefinedBiome implements Biome {
|
||||
private final BiomeTemplate config;
|
||||
private final ConfigPack pack;
|
||||
private UserDefinedBiome erode;
|
||||
private int color;
|
||||
|
||||
|
||||
public UserDefinedBiome(com.dfsek.terra.api.platform.world.Biome vanilla, GeneratorBuilder gen, BiomeTemplate config, ConfigPack pack) {
|
||||
@@ -25,6 +26,7 @@ public class UserDefinedBiome implements Biome {
|
||||
this.id = config.getID();
|
||||
this.config = config;
|
||||
this.pack = pack;
|
||||
this.color = config.getColor();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,4 +60,9 @@ public class UserDefinedBiome implements Biome {
|
||||
public Generator getGenerator(World w) {
|
||||
return gen.build(w.getSeed());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.dfsek.terra.biome.pipeline;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.biome.pipeline.expand.BiomeExpander;
|
||||
import com.dfsek.terra.biome.pipeline.mutator.BiomeMutator;
|
||||
import com.dfsek.terra.biome.pipeline.source.BiomeSource;
|
||||
|
||||
public interface BiomeHolder {
|
||||
void expand(BiomeExpander expander);
|
||||
|
||||
void mutate(BiomeMutator mutator);
|
||||
|
||||
void fill(BiomeSource source);
|
||||
|
||||
Biome getBiome(int x, int z);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.biome.pipeline;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Vector2;
|
||||
|
||||
public class Position {
|
||||
private final int x;
|
||||
private final int y;
|
||||
|
||||
public Position(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public Vector2 getAsVector() {
|
||||
return new Vector2(x, y);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.dfsek.terra.biome.pipeline;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.biome.pipeline.expand.BiomeExpander;
|
||||
import com.dfsek.terra.biome.pipeline.mutator.BiomeMutator;
|
||||
import com.dfsek.terra.biome.pipeline.source.BiomeSource;
|
||||
|
||||
public class TerraBiomeHolder implements BiomeHolder {
|
||||
private final Position original;
|
||||
private int width;
|
||||
private Biome[][] biomes;
|
||||
|
||||
public TerraBiomeHolder(int width, Position original) {
|
||||
this.width = width;
|
||||
biomes = new Biome[width][width];
|
||||
this.original = original;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void expand(BiomeExpander expander) {
|
||||
Biome[][] old = biomes;
|
||||
int oldWidth = width;
|
||||
|
||||
width = 2 * width - 1;
|
||||
|
||||
biomes = new Biome[width][width];
|
||||
for(int x = 0; x < oldWidth; x++) {
|
||||
for(int z = 0; z < oldWidth; z++) {
|
||||
biomes[x * 2][z * 2] = old[x][z];
|
||||
if(z != oldWidth - 1) biomes[x * 2][z * 2 + 1] = expander.getBetween(new Position(x, z + 1), old[x][z], old[x][z + 1]);
|
||||
if(x != oldWidth - 1) biomes[x * 2 + 1][z * 2] = expander.getBetween(new Position(x + 1, z), old[x][z], old[x + 1][z]);
|
||||
if(x != oldWidth - 1 && z != oldWidth - 1)
|
||||
biomes[x * 2 + 1][z * 2 + 1] = expander.getBetween(new Position(x + 1, z + 1), old[x][z], old[x + 1][z + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mutate(BiomeMutator mutator) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fill(BiomeSource source) {
|
||||
for(int x = 0; x < width; x++) {
|
||||
for(int z = 0; z < width; z++) {
|
||||
biomes[x][z] = source.getBiome(original.getX() + x, original.getY() + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z) {
|
||||
return biomes[x][z];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.dfsek.terra.biome.pipeline.expand;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.biome.pipeline.Position;
|
||||
|
||||
public interface BiomeExpander {
|
||||
Biome getBetween(Position center, Biome... others);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.dfsek.terra.biome.pipeline.expand;
|
||||
|
||||
import com.dfsek.terra.api.math.MathUtil;
|
||||
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.biome.pipeline.Position;
|
||||
|
||||
public class FractalExpander implements BiomeExpander {
|
||||
private final NoiseSampler sampler;
|
||||
|
||||
public FractalExpander(NoiseSampler sampler) {
|
||||
this.sampler = sampler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBetween(Position center, Biome... others) {
|
||||
return others[MathUtil.normalizeIndex(sampler.getNoise(center.getAsVector()), others.length)];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.dfsek.terra.biome.pipeline.mutator;
|
||||
|
||||
public interface BiomeMutator {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.dfsek.terra.biome.pipeline.source;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
|
||||
public interface BiomeSource {
|
||||
Biome getBiome(int x, int z);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.dfsek.terra.biome.pipeline.source;
|
||||
|
||||
import com.dfsek.terra.api.math.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
|
||||
public class RandomSource implements BiomeSource {
|
||||
private final ProbabilityCollection<Biome> biomes;
|
||||
private final NoiseSampler sampler;
|
||||
|
||||
public RandomSource(ProbabilityCollection<Biome> biomes, NoiseSampler sampler) {
|
||||
this.biomes = biomes;
|
||||
this.sampler = sampler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z) {
|
||||
return biomes.get(sampler, x, z);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user