diff --git a/src/main/java/ru/betterend/mixin/common/NoiseBasedChunkGeneratorMixin.java b/src/main/java/ru/betterend/mixin/common/NoiseBasedChunkGeneratorMixin.java deleted file mode 100644 index 392de48e..00000000 --- a/src/main/java/ru/betterend/mixin/common/NoiseBasedChunkGeneratorMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package ru.betterend.mixin.common; - -import net.minecraft.core.Registry; -import net.minecraft.world.level.biome.BiomeSource; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; -import net.minecraft.world.level.levelgen.StructureSettings; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import ru.betterend.world.generator.TerrainGenerator; - -import java.util.function.Supplier; - -@Mixin(NoiseBasedChunkGenerator.class) -public abstract class NoiseBasedChunkGeneratorMixin extends ChunkGenerator { - public NoiseBasedChunkGeneratorMixin(BiomeSource populationSource, BiomeSource biomeSource, StructureSettings structuresConfig, long worldSeed) { - super(populationSource, biomeSource, structuresConfig, worldSeed); - } - - @Inject(method = "(Lnet/minecraft/core/Registry;Lnet/minecraft/world/level/biome/BiomeSource;Lnet/minecraft/world/level/biome/BiomeSource;JLjava/util/function/Supplier;)V", at = @At("TAIL")) - private void be_onInit(Registry registry, BiomeSource biomeSource, BiomeSource biomeSource2, long seed, Supplier supplier, CallbackInfo ci) { - TerrainGenerator.initNoise(seed); - } -} diff --git a/src/main/java/ru/betterend/mixin/common/NoiseChunkMixin.java b/src/main/java/ru/betterend/mixin/common/NoiseChunkMixin.java index f01fcb51..5154eaf1 100644 --- a/src/main/java/ru/betterend/mixin/common/NoiseChunkMixin.java +++ b/src/main/java/ru/betterend/mixin/common/NoiseChunkMixin.java @@ -14,15 +14,15 @@ import ru.betterend.interfaces.TargetChecker; @Mixin(NoiseChunk.class) public class NoiseChunkMixin implements TargetChecker { - private boolean bnv_isNetherGenerator; + private boolean be_isEndGenerator; @Inject(method = "*", at = @At("TAIL")) - private void bnv_onNoiseChunkInit(int i, int j, int k, NoiseSampler noiseSampler, int l, int m, NoiseFiller noiseFiller, NoiseGeneratorSettings noiseGeneratorSettings, Aquifer.FluidPicker fluidPicker, Blender blender, CallbackInfo info) { - bnv_isNetherGenerator = noiseGeneratorSettings.stable(NoiseGeneratorSettings.END); + private void be_onNoiseChunkInit(int i, int j, int k, NoiseSampler noiseSampler, int l, int m, NoiseFiller noiseFiller, NoiseGeneratorSettings noiseGeneratorSettings, Aquifer.FluidPicker fluidPicker, Blender blender, CallbackInfo info) { + be_isEndGenerator = noiseGeneratorSettings.stable(NoiseGeneratorSettings.END); } @Override public boolean isTarget() { - return bnv_isNetherGenerator; + return be_isEndGenerator; } } diff --git a/src/main/java/ru/betterend/mixin/common/NoiseInterpolatorMixin.java b/src/main/java/ru/betterend/mixin/common/NoiseInterpolatorMixin.java index 24d643dc..14dcdfe5 100644 --- a/src/main/java/ru/betterend/mixin/common/NoiseInterpolatorMixin.java +++ b/src/main/java/ru/betterend/mixin/common/NoiseInterpolatorMixin.java @@ -9,6 +9,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import ru.betterend.interfaces.TargetChecker; +import ru.betterend.world.generator.TerrainGenerator; @Mixin(NoiseChunk.NoiseInterpolator.class) public class NoiseInterpolatorMixin { @@ -29,26 +30,16 @@ public class NoiseInterpolatorMixin { final int sizeY = noiseSettings.getCellHeight(); final int sizeXZ = noiseSettings.getCellWidth(); - final int cellsY = accessor.bnv_getCellCountY() + 1; + //final int cellsY = accessor.bnv_getCellCountY() + 1; final int cellsXZ = accessor.bnv_getCellCountXZ() + 1; final int firstCellZ = accessor.bnv_getFirstCellZ(); - final int cellNoiseMinY = accessor.bnv_getCellNoiseMinY(); + //final int cellNoiseMinY = accessor.bnv_getCellNoiseMinY(); x *= sizeXZ; for (int cellXZ = 0; cellXZ < cellsXZ; ++cellXZ) { int z = (firstCellZ + cellXZ) * sizeXZ; - for (int cellY = 0; cellY < cellsY; ++cellY) { - int y = (cellY + cellNoiseMinY) * sizeY; - data[cellXZ][cellY] = be_calculateNoise(x, y, z); - } + TerrainGenerator.fillTerrainDensity(data[cellXZ], x, z, sizeXZ, sizeY); } } - - private float be_calculateNoise(int x, int y, int z) { - float gradient = (64 - y) * 0.1F; - float sinX = (float) Math.sin(x * 0.1); - float sinZ = (float) Math.sin(z * 0.1); - return gradient + sinX + sinZ; - } } diff --git a/src/main/java/ru/betterend/mixin/common/ServerLevelMixin.java b/src/main/java/ru/betterend/mixin/common/ServerLevelMixin.java index 9ad8f7bd..4cb230da 100644 --- a/src/main/java/ru/betterend/mixin/common/ServerLevelMixin.java +++ b/src/main/java/ru/betterend/mixin/common/ServerLevelMixin.java @@ -3,12 +3,18 @@ package ru.betterend.mixin.common; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.progress.ChunkProgressListener; import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.level.CustomSpawner; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.storage.LevelStorageSource.LevelStorageAccess; +import net.minecraft.world.level.storage.ServerLevelData; import net.minecraft.world.level.storage.WritableLevelData; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -20,7 +26,10 @@ import ru.bclib.api.biomes.BiomeAPI; import ru.betterend.BetterEnd; import ru.betterend.registry.EndBlocks; import ru.betterend.world.generator.GeneratorOptions; +import ru.betterend.world.generator.TerrainGenerator; +import java.util.List; +import java.util.concurrent.Executor; import java.util.function.Supplier; @Mixin(ServerLevel.class) @@ -42,6 +51,14 @@ public abstract class ServerLevelMixin extends Level { // //EndBiomes.onWorldLoad(world.getSeed(), world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY)); // } + @Inject(method = "*", at = @At("TAIL")) + private void be_onServerWorldInit(MinecraftServer minecraftServer, Executor executor, LevelStorageAccess levelStorageAccess, ServerLevelData serverLevelData, ResourceKey resourceKey, DimensionType dimensionType, ChunkProgressListener chunkProgressListener, ChunkGenerator chunkGenerator, boolean bl, long seed, List list, boolean bl2, CallbackInfo ci) { + ServerLevel level = ServerLevel.class.cast(this); + if (level.dimension() == Level.END) { + TerrainGenerator.initNoise(seed, chunkGenerator.getBiomeSource(), chunkGenerator.climateSampler()); + } + } + @Inject(method = "getSharedSpawnPos", at = @At("HEAD"), cancellable = true) private void be_getSharedSpawnPos(CallbackInfoReturnable info) { if (GeneratorOptions.changeSpawn()) { diff --git a/src/main/java/ru/betterend/world/generator/EndNoiseFiller.java b/src/main/java/ru/betterend/world/generator/EndNoiseFiller.java deleted file mode 100644 index 97e445c5..00000000 --- a/src/main/java/ru/betterend/world/generator/EndNoiseFiller.java +++ /dev/null @@ -1,67 +0,0 @@ -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); - } -} diff --git a/src/main/java/ru/betterend/world/generator/TerrainGenerator.java b/src/main/java/ru/betterend/world/generator/TerrainGenerator.java index df9f2087..afe82b9c 100644 --- a/src/main/java/ru/betterend/world/generator/TerrainGenerator.java +++ b/src/main/java/ru/betterend/world/generator/TerrainGenerator.java @@ -4,6 +4,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import net.minecraft.util.Mth; import net.minecraft.world.level.biome.BiomeSource; +import net.minecraft.world.level.biome.Climate.Sampler; import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.util.MHelper; import ru.bclib.world.biomes.BCLBiome; @@ -29,8 +30,10 @@ public class TerrainGenerator { private static IslandLayer smallIslands; private static OpenSimplexNoise noise1; private static OpenSimplexNoise noise2; + private static BiomeSource biomeSource; + private static Sampler sampler; - public static void initNoise(long seed) { + public static void initNoise(long seed, BiomeSource biomeSource, Sampler sampler) { Random random = new Random(seed); largeIslands = new IslandLayer(random.nextInt(), GeneratorOptions.bigOptions); mediumIslands = new IslandLayer(random.nextInt(), GeneratorOptions.mediumOptions); @@ -38,15 +41,19 @@ public class TerrainGenerator { noise1 = new OpenSimplexNoise(random.nextInt()); noise2 = new OpenSimplexNoise(random.nextInt()); TERRAIN_BOOL_CACHE_MAP.clear(); + TerrainGenerator.biomeSource = biomeSource; + TerrainGenerator.sampler = sampler; } - public static void fillTerrainDensity(double[] buffer, int x, int z, BiomeSource biomeSource) { + public static void fillTerrainDensity(double[] buffer, int posX, int posZ, int scaleXZ, int scaleY) { LOCKER.lock(); largeIslands.clearCache(); mediumIslands.clearCache(); smallIslands.clearCache(); + int x = Mth.floor(posX / scaleXZ); + int z = Mth.floor(posZ / scaleXZ); double distortion1 = noise1.eval(x * 0.1, z * 0.1) * 20 + noise2.eval( x * 0.2, z * 0.2 @@ -55,17 +62,17 @@ public class TerrainGenerator { 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; + double px = (double) x * scaleXZ + distortion1; + double pz = (double) z * scaleXZ + distortion2; largeIslands.updatePositions(px, pz); mediumIslands.updatePositions(px, pz); smallIslands.updatePositions(px, pz); - float height = getAverageDepth(biomeSource, x << 1, z << 1) * 0.5F; + float height = getAverageDepth(x << 1, z << 1) * 0.5F; for (int y = 0; y < buffer.length; y++) { - double py = (double) y * SCALE_Y; + double py = (double) y * scaleY; 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)); @@ -83,49 +90,11 @@ 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; + private static float getAverageDepth(int x, int z) { + if (biomeSource == null) { + return 0; } - 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; @@ -134,22 +103,35 @@ public class TerrainGenerator { int pz = z + OFFS[i].y; depth += getBiome(biomeSource, px, pz).getTerrainHeight() * COEF[i]; } - return depth;*/ - return 0F; + return depth; } private static BCLBiome getBiome(BiomeSource biomeSource, int x, int z) { - // TODO replace null sampler - return BiomeAPI.getBiome(biomeSource.getNoiseBiome(x, 0, z, null)); + return BiomeAPI.getBiome(biomeSource.getNoiseBiome(x, 0, z, sampler)); } - /** - * Check if this is land - * - * @param x - biome pos x - * @param z - biome pos z - */ - public static boolean isLand(int x, int z) { + static { + float sum = 0; + List coef = Lists.newArrayList(); + List pos = Lists.newArrayList(); + for (int x = -3; x <= 3; x++) { + for (int z = -3; z <= 3; z++) { + float dist = MHelper.length(x, z) / 3F; + if (dist <= 1) { + sum += dist; + coef.add(dist); + pos.add(new Point(x, z)); + } + } + } + OFFS = pos.toArray(new Point[] {}); + COEF = new float[coef.size()]; + for (int i = 0; i < COEF.length; i++) { + COEF[i] = coef.get(i) / sum; + } + } + + public static Boolean isLand(int x, int z) { int sectionX = TerrainBoolCache.scaleCoordinate(x); int sectionZ = TerrainBoolCache.scaleCoordinate(z); @@ -210,83 +192,4 @@ public class TerrainGenerator { return result; } - - /** - * Get something like height - * - * @param x - block pos x - * @param z - block pos z - */ - public static int getHeight(int x, int z, BiomeSource biomeSource) { - int posX = (x >> 3) << 3; - int posZ = (z >> 3) << 3; - float dx = (x - posX) / 8.0F; - float dz = (z - posZ) / 8.0F; - double[][][] buffer = new double[2][2][32]; - - LOCKER.lock(); - for (int i = 0; i < 4; i++) { - int ix = i & 1; - int iz = i >> 1; - int px = ((ix << 3) + posX) >> 3; - int pz = ((iz << 3) + posZ) >> 3; - fillTerrainDensity(buffer[ix][iz], px, pz, biomeSource); - } - LOCKER.unlock(); - - for (int j = 30; j >= 0; j--) { - float a = (float) buffer[0][0][j]; - float b = (float) buffer[1][0][j]; - float c = (float) buffer[0][1][j]; - float d = (float) buffer[1][1][j]; - - float e = (float) buffer[0][0][j + 1]; - float f = (float) buffer[1][0][j + 1]; - float g = (float) buffer[0][1][j + 1]; - float h = (float) buffer[1][1][j + 1]; - - if (a < 0 && b < 0 && c < 0 && d < 0 && e < 0 && f < 0 && g < 0 && h < 0) { - continue; - } - - 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(dz, a, b); - b = Mth.lerp(dz, c, d); - - for (int n = 7; n >= 0; n--) { - float dy = n / 8.0F; - float dens = Mth.lerp(dy, a, b); - if (dens > 0) { - return (j << 3 | n) + 1; - } - } - } - - return -256; - } - - static { - float sum = 0; - List coef = Lists.newArrayList(); - List pos = Lists.newArrayList(); - for (int x = -3; x <= 3; x++) { - for (int z = -3; z <= 3; z++) { - float dist = MHelper.length(x, z) / 3F; - if (dist <= 1) { - sum += dist; - coef.add(dist); - pos.add(new Point(x, z)); - } - } - } - OFFS = pos.toArray(new Point[] {}); - COEF = new float[coef.size()]; - for (int i = 0; i < COEF.length; i++) { - COEF[i] = coef.get(i) / sum; - } - } } diff --git a/src/main/resources/betterend.mixins.common.json b/src/main/resources/betterend.mixins.common.json index d0c31df6..c92e2fc1 100644 --- a/src/main/resources/betterend.mixins.common.json +++ b/src/main/resources/betterend.mixins.common.json @@ -4,7 +4,6 @@ "package": "ru.betterend.mixin.common", "compatibilityLevel": "JAVA_16", "mixins": [ - "NoiseBasedChunkGeneratorMixin", "ChorusPlantFeatureMixin", "PlayerAdvancementsMixin", "ChorusFlowerBlockMixin",