130 lines
5.2 KiB
Java
Executable file
130 lines
5.2 KiB
Java
Executable file
package game.worldgen;
|
|
|
|
import game.biome.Biome;
|
|
import game.block.Block;
|
|
import game.init.Blocks;
|
|
import game.rng.NoiseGen;
|
|
import game.rng.OctaveGen;
|
|
import game.rng.Random;
|
|
import game.world.State;
|
|
import game.world.WorldServer;
|
|
|
|
public class ReplacerAltBiome implements BlockReplacer
|
|
{
|
|
private final NoiseGen altNoiseGen;
|
|
private final NoiseGen exclNoiseGen;
|
|
|
|
private final State filler;
|
|
private final State liquid;
|
|
private final State alt1;
|
|
private final State alt2;
|
|
private final Block block;
|
|
private final double alt2Noise[] = new double[256];
|
|
private final double alt1Noise[] = new double[256];
|
|
private final double exclNoise[] = new double[256];
|
|
|
|
// public ReplacerAltBiome(Random rand, GeneratorSettings settings)
|
|
// {
|
|
// this(rand, settings.farlands, Blocks.stone.getDefaultState(),
|
|
// settings.useLavaSeas ? Blocks.lava.getDefaultState() : Blocks.water.getDefaultState(),
|
|
// Blocks.sand.getDefaultState(), Blocks.gravel.getDefaultState());
|
|
// }
|
|
|
|
// public ReplacerAltBiome(Dimension dim, Random rand)
|
|
// {
|
|
// this(rand, /* dim.hasFarLands(), */ dim.getFiller(), dim.getLiquid(), dim.getAltFiller2(), dim.getAltFiller1());
|
|
// }
|
|
|
|
public ReplacerAltBiome(Random rand, /* boolean farlands, */ State filler, State liquid, State alt1, State alt2)
|
|
{
|
|
this.altNoiseGen = /* farlands ? new OctaveGenOld(rand, 4) : */ new OctaveGen(rand, 4);
|
|
this.exclNoiseGen = /* farlands ? new OctaveGenOld(rand, 4) : */ new OctaveGen(rand, 4);
|
|
this.filler = filler;
|
|
this.liquid = liquid;
|
|
this.alt1 = alt1;
|
|
this.alt2 = alt2;
|
|
this.block = filler.getBlock();
|
|
}
|
|
|
|
public void replaceBlocks(WorldServer world, int x, int z, ChunkPrimer primer, Random rand, Biome[] biomes)
|
|
{
|
|
int seaLevel = world.getSeaLevel();
|
|
double scale = 0.03125D;
|
|
this.altNoiseGen.generate( this.alt2Noise , x * 16, 0 /*.0D */ , z * 16, 16, 1, 16, scale, 1.0D, scale);
|
|
this.altNoiseGen.generate(this.alt1Noise, z * 16, 109 /*.0134D */, x * 16, 16, 1, 16, scale, 1.0D, scale);
|
|
this.exclNoiseGen.generate( this.exclNoise , x * 16, 0 /*.0D */ , z * 16, 16, 1, 16, scale * 2D, scale * 2D, scale * 2D);
|
|
for(int pz = 0; pz < 16; pz++)
|
|
{
|
|
for(int px = 0; px < 16; px++)
|
|
{
|
|
Biome biome = biomes[pz * 16 + px];
|
|
boolean alt2 = this.alt2Noise[pz + px * 16] + rand.doublev() * 0.20000000000000001D > 0.0D;
|
|
boolean alt1 = this.alt1Noise[px + pz * 16] + rand.doublev() * 0.20000000000000001D > 3D;
|
|
int excl = (int)(this.exclNoise[pz + px * 16] / 3D + 3D + rand.doublev() * 0.25D);
|
|
int rockHeight = -1;
|
|
State topBlock = biome.topBlock;
|
|
State fillerBlock = biome.fillerBlock;
|
|
for(int py = primer.height - 1; py >= 0; py--)
|
|
{
|
|
Block currentBlock = primer.get(px, py, pz).getBlock();
|
|
if(currentBlock == Blocks.air)
|
|
{
|
|
rockHeight = -1;
|
|
continue;
|
|
}
|
|
if(currentBlock != this.block)
|
|
{
|
|
continue;
|
|
}
|
|
if(rockHeight == -1)
|
|
{
|
|
if(excl <= 0)
|
|
{
|
|
topBlock = Blocks.air.getState();
|
|
fillerBlock = this.filler;
|
|
} else
|
|
if(py >= seaLevel - 4 && py <= seaLevel + 1)
|
|
{
|
|
topBlock = biome.topBlock;
|
|
fillerBlock = biome.fillerBlock;
|
|
if(alt1)
|
|
{
|
|
topBlock = Blocks.air.getState();
|
|
}
|
|
if(alt1)
|
|
{
|
|
fillerBlock = this.alt2;
|
|
}
|
|
if(alt2)
|
|
{
|
|
topBlock = this.alt1;
|
|
}
|
|
if(alt2)
|
|
{
|
|
fillerBlock = this.alt1;
|
|
}
|
|
}
|
|
if(py < seaLevel && topBlock.getBlock() == Blocks.air)
|
|
{
|
|
topBlock = this.liquid;
|
|
}
|
|
rockHeight = excl;
|
|
if(py >= seaLevel - 1)
|
|
{
|
|
primer.set(px, py, pz, topBlock);
|
|
} else
|
|
{
|
|
primer.set(px, py, pz, fillerBlock);
|
|
}
|
|
continue;
|
|
}
|
|
if(rockHeight > 0)
|
|
{
|
|
rockHeight--;
|
|
primer.set(px, py, pz, fillerBlock);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|