mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-14 04:41:13 +00:00
refactor TerraBiome
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.Generator;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.builder.GeneratorBuilder;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
@@ -10,7 +10,7 @@ import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
/**
|
||||
* Class representing a config-defined biome
|
||||
*/
|
||||
public class UserDefinedBiome implements Biome {
|
||||
public class UserDefinedBiome implements TerraBiome {
|
||||
private final GeneratorBuilder gen;
|
||||
private final com.dfsek.terra.api.platform.world.Biome vanilla;
|
||||
private final String id;
|
||||
@@ -32,7 +32,7 @@ public class UserDefinedBiome implements Biome {
|
||||
/**
|
||||
* Gets the Vanilla biome to represent the custom biome.
|
||||
*
|
||||
* @return Biome - The Vanilla biome.
|
||||
* @return TerraBiome - The Vanilla biome.
|
||||
*/
|
||||
@Override
|
||||
public com.dfsek.terra.api.platform.world.Biome getVanillaBiome() {
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
package com.dfsek.terra.biome.grid;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.BiomeGrid;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
||||
|
||||
/**
|
||||
* BiomeGrid implementation that holds a single biome.
|
||||
*/
|
||||
public class SingleBiomeGrid extends BiomeGrid {
|
||||
private final Biome biome;
|
||||
private final TerraBiome biome;
|
||||
|
||||
public SingleBiomeGrid(long seed, Biome biome) {
|
||||
public SingleBiomeGrid(long seed, TerraBiome biome) {
|
||||
super(seed, 0, 0, 1, 1);
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z, GenerationPhase phase) {
|
||||
public TerraBiome getBiome(int x, int z, GenerationPhase phase) {
|
||||
return biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(Location l) {
|
||||
public TerraBiome getBiome(Location l) {
|
||||
return biome;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.dfsek.terra.biome.grid;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.BiomeGrid;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.base.ConfigPackTemplate;
|
||||
@@ -14,7 +14,7 @@ public class UserDefinedGrid extends BiomeGrid {
|
||||
private final ImageLoader.Channel channelX;
|
||||
private final ImageLoader.Channel channelZ;
|
||||
|
||||
public UserDefinedGrid(long seed, double freq1, double freq2, Biome[][] b, ConfigPack c) {
|
||||
public UserDefinedGrid(long seed, double freq1, double freq2, TerraBiome[][] b, ConfigPack c) {
|
||||
super(seed, freq1, freq2, b.length, b[0].length);
|
||||
super.setGrid(b);
|
||||
ConfigPackTemplate t = c.getTemplate();
|
||||
@@ -25,7 +25,7 @@ public class UserDefinedGrid extends BiomeGrid {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z, GenerationPhase phase) {
|
||||
public TerraBiome getBiome(int x, int z, GenerationPhase phase) {
|
||||
if(fromImage) {
|
||||
int xi = imageLoader.getNoiseVal(x, z, getSizeX() - 1, channelX);
|
||||
int zi = imageLoader.getNoiseVal(x, z, getSizeZ() - 1, channelZ);
|
||||
@@ -35,7 +35,7 @@ public class UserDefinedGrid extends BiomeGrid {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(Location l, GenerationPhase phase) {
|
||||
public TerraBiome getBiome(Location l, GenerationPhase phase) {
|
||||
return this.getBiome(l.getBlockX(), l.getBlockZ(), phase);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.dfsek.terra.biome.grid.master;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.math.vector.Vector2;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.BiomeGrid;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
||||
import com.dfsek.terra.biome.BiomeZone;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
@@ -43,7 +43,7 @@ public class TerraRadialBiomeGrid extends TerraBiomeGrid {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z, GenerationPhase phase) {
|
||||
public TerraBiome getBiome(int x, int z, GenerationPhase phase) {
|
||||
int xp = x, zp = z;
|
||||
if(perturb != null && (phase.equals(GenerationPhase.PALETTE_APPLY) || phase.equals(GenerationPhase.POPULATE))) {
|
||||
Vector2 perturbCoords = perturb.getShiftedCoords(x, z);
|
||||
@@ -62,7 +62,7 @@ public class TerraRadialBiomeGrid extends TerraBiomeGrid {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(Location l, GenerationPhase phase) {
|
||||
public TerraBiome getBiome(Location l, GenerationPhase phase) {
|
||||
return getBiome(l.getBlockX(), l.getBlockZ(), phase);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.dfsek.terra.biome.grid.master;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.math.vector.Vector2;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.BiomeGrid;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
||||
import com.dfsek.terra.biome.BiomeZone;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
@@ -38,7 +38,7 @@ public class TerraStandardBiomeGrid extends TerraBiomeGrid {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z, GenerationPhase phase) {
|
||||
public TerraBiome getBiome(int x, int z, GenerationPhase phase) {
|
||||
int xp = x, zp = z;
|
||||
if(perturb != null && (phase.equals(GenerationPhase.PALETTE_APPLY) || phase.equals(GenerationPhase.POPULATE))) {
|
||||
Vector2 perturbCoords = perturb.getShiftedCoords(x, z);
|
||||
@@ -53,7 +53,7 @@ public class TerraStandardBiomeGrid extends TerraBiomeGrid {
|
||||
|
||||
|
||||
@Override
|
||||
public Biome getBiome(Location l, GenerationPhase phase) {
|
||||
public TerraBiome getBiome(Location l, GenerationPhase phase) {
|
||||
return getBiome(l.getBlockX(), l.getBlockZ(), phase);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.biome.pipeline;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.biome.pipeline.expand.BiomeExpander;
|
||||
import com.dfsek.terra.biome.pipeline.mutator.BiomeMutator;
|
||||
import com.dfsek.terra.biome.pipeline.source.BiomeSource;
|
||||
@@ -12,5 +12,5 @@ public interface BiomeHolder {
|
||||
|
||||
void fill(BiomeSource source);
|
||||
|
||||
Biome getBiome(int x, int z);
|
||||
TerraBiome getBiome(int x, int z);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.biome.pipeline;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.biome.pipeline.expand.BiomeExpander;
|
||||
import com.dfsek.terra.biome.pipeline.mutator.BiomeMutator;
|
||||
import com.dfsek.terra.biome.pipeline.source.BiomeSource;
|
||||
@@ -8,22 +8,22 @@ import com.dfsek.terra.biome.pipeline.source.BiomeSource;
|
||||
public class TerraBiomeHolder implements BiomeHolder {
|
||||
private final Position original;
|
||||
private int width;
|
||||
private Biome[][] biomes;
|
||||
private TerraBiome[][] biomes;
|
||||
|
||||
public TerraBiomeHolder(int width, Position original) {
|
||||
this.width = width;
|
||||
biomes = new Biome[width][width];
|
||||
biomes = new TerraBiome[width][width];
|
||||
this.original = original;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void expand(BiomeExpander expander) {
|
||||
Biome[][] old = biomes;
|
||||
TerraBiome[][] old = biomes;
|
||||
int oldWidth = width;
|
||||
|
||||
width = 2 * width - 1;
|
||||
|
||||
biomes = new Biome[width][width];
|
||||
biomes = new TerraBiome[width][width];
|
||||
for(int x = 0; x < oldWidth; x++) {
|
||||
for(int z = 0; z < oldWidth; z++) {
|
||||
biomes[x * 2][z * 2] = old[x][z];
|
||||
@@ -40,7 +40,7 @@ public class TerraBiomeHolder implements BiomeHolder {
|
||||
public void mutate(BiomeMutator mutator) {
|
||||
for(int x = 0; x < width; x++) {
|
||||
for(int z = 0; z < width; z++) {
|
||||
BiomeMutator.ViewPoint viewPoint = new BiomeMutator.ViewPoint(new Biome[][] {
|
||||
BiomeMutator.ViewPoint viewPoint = new BiomeMutator.ViewPoint(new TerraBiome[][] {
|
||||
{getBiome(x - 1, z + 1), getBiome(x, z + 1), getBiome(x + 1, z + 1)},
|
||||
{getBiome(x - 1, z), getBiome(x, z), getBiome(x + 1, z)},
|
||||
{getBiome(x - 1, z - 1), getBiome(x, z - 1), getBiome(x + 1, z - 1)}
|
||||
@@ -60,7 +60,7 @@ public class TerraBiomeHolder implements BiomeHolder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z) {
|
||||
public TerraBiome getBiome(int x, int z) {
|
||||
if(x >= width || z >= width || x < 0 || z < 0) return null;
|
||||
return biomes[x][z];
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.dfsek.terra.biome.pipeline.expand;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.biome.pipeline.Position;
|
||||
|
||||
public interface BiomeExpander {
|
||||
Biome getBetween(Position center, Biome... others);
|
||||
TerraBiome getBetween(Position center, TerraBiome... others);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ 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.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.biome.pipeline.Position;
|
||||
|
||||
public class FractalExpander implements BiomeExpander {
|
||||
@@ -13,7 +13,7 @@ public class FractalExpander implements BiomeExpander {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBetween(Position center, Biome... others) {
|
||||
public TerraBiome getBetween(Position center, TerraBiome... others) {
|
||||
return others[MathUtil.normalizeIndex(sampler.getNoise(center.getAsVector()), others.length)];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package com.dfsek.terra.biome.pipeline.mutator;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.biome.pipeline.Position;
|
||||
|
||||
public interface BiomeMutator {
|
||||
Biome mutate(ViewPoint viewPoint, Position position);
|
||||
TerraBiome mutate(ViewPoint viewPoint, Position position);
|
||||
|
||||
class ViewPoint {
|
||||
private final Biome[][] biomes;
|
||||
private final TerraBiome[][] biomes;
|
||||
|
||||
public ViewPoint(Biome[][] biomes) {
|
||||
public ViewPoint(TerraBiome[][] biomes) {
|
||||
this.biomes = biomes;
|
||||
}
|
||||
|
||||
public Biome getBiome(int x, int z) {
|
||||
public TerraBiome getBiome(int x, int z) {
|
||||
return biomes[x + 1][z + 1];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.dfsek.terra.biome.pipeline.mutator;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.biome.pipeline.Position;
|
||||
|
||||
public class BorderMutator implements BiomeMutator {
|
||||
|
||||
|
||||
@Override
|
||||
public TerraBiome mutate(ViewPoint viewPoint, Position position) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -2,24 +2,24 @@ 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.Biome;
|
||||
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<Biome> replaceable;
|
||||
private final ProbabilityCollection<Biome> replace;
|
||||
private final Set<TerraBiome> replaceable;
|
||||
private final ProbabilityCollection<TerraBiome> replace;
|
||||
private final NoiseSampler sampler;
|
||||
|
||||
public ReplaceMutator(Set<Biome> replaceable, ProbabilityCollection<Biome> replace, NoiseSampler sampler) {
|
||||
public ReplaceMutator(Set<TerraBiome> replaceable, ProbabilityCollection<TerraBiome> replace, NoiseSampler sampler) {
|
||||
this.replaceable = replaceable;
|
||||
this.replace = replace;
|
||||
this.sampler = sampler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome mutate(ViewPoint viewPoint, Position position) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.dfsek.terra.biome.pipeline.mutator;
|
||||
|
||||
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.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.biome.pipeline.Position;
|
||||
|
||||
import java.util.Objects;
|
||||
@@ -16,11 +16,11 @@ public class SmoothMutator implements BiomeMutator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome mutate(ViewPoint viewPoint, Position position) {
|
||||
Biome top = viewPoint.getBiome(1, 0);
|
||||
Biome bottom = viewPoint.getBiome(-1, 0);
|
||||
Biome left = viewPoint.getBiome(0, 1);
|
||||
Biome right = viewPoint.getBiome(0, -1);
|
||||
public TerraBiome mutate(ViewPoint viewPoint, Position position) {
|
||||
TerraBiome top = viewPoint.getBiome(1, 0);
|
||||
TerraBiome bottom = viewPoint.getBiome(-1, 0);
|
||||
TerraBiome left = viewPoint.getBiome(0, 1);
|
||||
TerraBiome right = viewPoint.getBiome(0, -1);
|
||||
|
||||
|
||||
boolean vert = Objects.equals(top, bottom) && top != null;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.biome.pipeline.source;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
public interface BiomeSource {
|
||||
Biome getBiome(int x, int z);
|
||||
TerraBiome getBiome(int x, int z);
|
||||
}
|
||||
|
||||
@@ -2,19 +2,19 @@ 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;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
public class RandomSource implements BiomeSource {
|
||||
private final ProbabilityCollection<Biome> biomes;
|
||||
private final ProbabilityCollection<TerraBiome> biomes;
|
||||
private final NoiseSampler sampler;
|
||||
|
||||
public RandomSource(ProbabilityCollection<Biome> biomes, NoiseSampler sampler) {
|
||||
public RandomSource(ProbabilityCollection<TerraBiome> biomes, NoiseSampler sampler) {
|
||||
this.biomes = biomes;
|
||||
this.sampler = sampler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z) {
|
||||
public TerraBiome getBiome(int x, int z) {
|
||||
return biomes.get(sampler, x, z);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user