tcr/java/src/game/worldgen/ReplacerAltSurface.java
2025-03-12 18:13:11 +01:00

131 lines
4.9 KiB
Java
Executable file

package game.worldgen;
import game.biome.Biome;
import game.block.Block;
import game.material.Material;
import game.rng.OctaveGen;
import game.rng.Random;
import game.world.State;
import game.world.WorldServer;
public class ReplacerAltSurface implements BlockReplacer
{
private final OctaveGen altNoiseGen;
private final OctaveGen exclNoiseGen;
private final double[] alt2Noise = new double[256];
private final double[] alt1Noise = new double[256];
private final double[] exclNoise = new double[256];
private final State filler;
private final State alt1;
private final State alt2;
private final State liquid;
private final Block fillerBlock;
// public ReplacerAltSurface(Dimension dim, Random rand) {
// this(rand, dim.getFiller(), dim.getAltFiller1(), dim.getAltFiller2(), dim.getLiquid());
// }
public ReplacerAltSurface(Random rand, State filler, State alt1, State alt2, State liquid)
{
this.altNoiseGen = new OctaveGen(rand, 4);
this.exclNoiseGen = new OctaveGen(rand, 4);
this.filler = filler;
this.alt1 = alt1;
this.alt2 = alt2;
this.liquid = liquid;
this.fillerBlock = filler.getBlock();
}
public void replaceBlocks(WorldServer world, int x, int z, ChunkPrimer primer, Random rand, Biome[] biomes)
{
int i = world.getSeaLevel() + 1;
double d0 = 0.03125D;
this.altNoiseGen.generate(this.alt2Noise, x * 16, z * 16, 0, 16, 16, 1, d0, d0, 1.0D);
this.altNoiseGen.generate(this.alt1Noise, x * 16, 109, z * 16, 16, 1, 16, d0, 1.0D, d0);
this.exclNoiseGen.generate(this.exclNoise, x * 16, z * 16, 0, 16, 16, 1, d0 * 2.0D, d0 * 2.0D, d0 * 2.0D);
for (int j = 0; j < 16; ++j)
{
for (int k = 0; k < 16; ++k)
{
boolean flag = this.alt2Noise[j + k * 16] + rand.doublev() * 0.2D > 0.0D;
boolean flag1 = this.alt1Noise[j + k * 16] + rand.doublev() * 0.2D > 0.0D;
int l = (int)(this.exclNoise[j + k * 16] / 3.0D + 3.0D + rand.doublev() * 0.25D);
int i1 = -1;
State iblockstate = this.filler;
State iblockstate1 = this.filler;
for (int j1 = primer.height - 1; j1 >= 0; --j1)
{
// if (j1 < (primer.height - 1) - rand.zrange(5) || this.ceiling == null)
// {
State iblockstate2 = primer.get(k, j1, j);
if (iblockstate2.getBlock() != null && iblockstate2.getBlock().getMaterial() != Material.air)
{
if (iblockstate2.getBlock() == this.fillerBlock)
{
if (i1 == -1)
{
if (l <= 0)
{
iblockstate = null;
iblockstate1 = this.filler;
}
else if (j1 >= i - 4 && j1 <= i + 1)
{
iblockstate = this.filler;
iblockstate1 = this.filler;
if (flag1)
{
iblockstate = this.alt1;
iblockstate1 = this.filler;
}
if (flag)
{
iblockstate = this.alt2;
iblockstate1 = this.alt2;
}
}
if (j1 < i && (iblockstate == null || iblockstate.getBlock().getMaterial() == Material.air))
{
iblockstate = this.liquid;
}
i1 = l;
if (j1 >= i - 1)
{
primer.set(k, j1, j, iblockstate);
}
else
{
primer.set(k, j1, j, iblockstate1);
}
}
else if (i1 > 0)
{
--i1;
primer.set(k, j1, j, iblockstate1);
}
}
}
else
{
i1 = -1;
}
// }
// else
// {
// primer.set(k, j1, j, this.ceiling);
// }
}
}
}
}
}