Land generator (WIP)

This commit is contained in:
paulevsGitch 2021-12-16 15:13:25 +03:00
parent 5460ccba2b
commit 934efc9aed
5 changed files with 283 additions and 3 deletions

View file

@ -0,0 +1,67 @@
package ru.betterend.world.generator;
import net.minecraft.util.Mth;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.levelgen.NoiseChunk.NoiseFiller;
public class EndNoiseFiller implements NoiseFiller {
public static final EndNoiseFiller INSTANCE = new EndNoiseFiller();
private double[][][] noiseColumns = new double[3][3][33];
private BiomeSource biomeSource;
private int chunkX;
private int chunkZ;
private EndNoiseFiller() {}
public void setBiomeSource(BiomeSource biomeSource) {
this.biomeSource = biomeSource;
}
@Override
public double calculateNoise(int x, int y, int z) {
if (y < 0 || y > 127) {
return -10;
}
int cx = x >> 4;
int cz = z >> 4;
if (chunkX != cx || chunkZ != cz) {
chunkX = cx;
chunkZ = cz;
int px = cx << 1;
int pz = cz << 1;
for (byte i = 0; i < 3; i++) {
for (byte j = 0; j < 3; j++) {
TerrainGenerator.fillTerrainDensity(noiseColumns[i][j], px + i, pz + j, biomeSource);
}
}
}
byte ix = (byte) ((x & 15) >> 3);
byte iy = (byte) (y >> 2);
byte iz = (byte) ((z & 15) >> 3);
float dx = (x & 7) / 8F;
float dy = (y & 3) / 4F;
float dz = (z & 7) / 8F;
float a = (float) noiseColumns[ix][iz][iy];
float b = (float) noiseColumns[ix + 1][iz][iy];
float c = (float) noiseColumns[ix][iz][iy + 1];
float d = (float) noiseColumns[ix + 1][iz][iy + 1];
float e = (float) noiseColumns[ix][iz + 1][iy];
float f = (float) noiseColumns[ix + 1][iz + 1][iy];
float g = (float) noiseColumns[ix][iz + 1][iy + 1];
float h = (float) noiseColumns[ix + 1][iz + 1][iy + 1];
a = Mth.lerp(dx, a, b);
b = Mth.lerp(dx, c, d);
c = Mth.lerp(dx, e, f);
d = Mth.lerp(dx, g, h);
a = Mth.lerp(dy, a, b);
b = Mth.lerp(dy, c, d);
return Mth.lerp(dz, a, b);
}
}

View file

@ -84,8 +84,49 @@ public class TerrainGenerator {
LOCKER.unlock();
}
public static float getTerrainDensity(int x, int y, int z, BiomeSource biomeSource) {
LOCKER.lock();
largeIslands.clearCache();
mediumIslands.clearCache();
smallIslands.clearCache();
double distortion1 = noise1.eval(x * 0.1, z * 0.1) * 20 + noise2.eval(
x * 0.2,
z * 0.2
) * 10 + noise1.eval(x * 0.4, z * 0.4) * 5;
double distortion2 = noise2.eval(x * 0.1, z * 0.1) * 20 + noise1.eval(
x * 0.2,
z * 0.2
) * 10 + noise2.eval(x * 0.4, z * 0.4) * 5;
double px = (double) x * SCALE_XZ + distortion1;
double pz = (double) z * SCALE_XZ + distortion2;
largeIslands.updatePositions(px, pz);
mediumIslands.updatePositions(px, pz);
smallIslands.updatePositions(px, pz);
float height = getAverageDepth(biomeSource, x << 1, z << 1) * 0.5F;
double py = (double) y * SCALE_Y;
float dist = largeIslands.getDensity(px, py, pz, height);
dist = dist > 1 ? dist : MHelper.max(dist, mediumIslands.getDensity(px, py, pz, height));
dist = dist > 1 ? dist : MHelper.max(dist, smallIslands.getDensity(px, py, pz, height));
if (dist > -0.5F) {
dist += noise1.eval(px * 0.01, py * 0.01, pz * 0.01) * 0.02 + 0.02;
dist += noise2.eval(px * 0.05, py * 0.05, pz * 0.05) * 0.01 + 0.01;
dist += noise1.eval(px * 0.1, py * 0.1, pz * 0.1) * 0.005 + 0.005;
}
if (py > 100) {
dist = (float) Mth.lerp((py - 100) / 27F, dist, -1);
}
LOCKER.unlock();
return dist;
}
private static float getAverageDepth(BiomeSource biomeSource, int x, int z) {
if (getBiome(biomeSource, x, z).getTerrainHeight() < 0.1F) {
/*if (getBiome(biomeSource, x, z).getTerrainHeight() < 0.1F) {
return 0F;
}
float depth = 0F;
@ -94,7 +135,8 @@ public class TerrainGenerator {
int pz = z + OFFS[i].y;
depth += getBiome(biomeSource, px, pz).getTerrainHeight() * COEF[i];
}
return depth;
return depth;*/
return 0F;
}
private static BCLBiome getBiome(BiomeSource biomeSource, int x, int z) {