New generator fixes & biome gen
This commit is contained in:
parent
fe414c1003
commit
9a41dc8670
9 changed files with 86 additions and 32 deletions
|
@ -29,7 +29,6 @@ import net.minecraft.world.BlockView;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.WorldView;
|
||||
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.At.Shift;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -17,7 +18,6 @@ import net.minecraft.resource.Resource;
|
|||
import net.minecraft.resource.ResourcePack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.patterns.BlockPatterned;
|
||||
|
||||
|
|
|
@ -28,8 +28,10 @@ public abstract class NoiseChunkGeneratorMixin {
|
|||
@Inject(method = "sampleNoiseColumn([DII)V", at = @At("HEAD"), cancellable = true, allow = 2)
|
||||
private void beSampleNoiseColumn(double[] buffer, int x, int z, CallbackInfo info) {
|
||||
if (settings.get().equals(ChunkGeneratorSettings.END)) {
|
||||
if (TerrainGenerator.canGenerate(x, z)) {
|
||||
TerrainGenerator.fillTerrainDensity(buffer, x, z);
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.google.gson.JsonObject;
|
|||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
|
@ -20,7 +19,6 @@ import net.minecraft.util.Identifier;
|
|||
import net.minecraft.util.JsonHelper;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.recipe.EndRecipeManager;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
|
|
|
@ -20,7 +20,6 @@ import net.minecraft.util.Identifier;
|
|||
import net.minecraft.util.JsonHelper;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.recipe.EndRecipeManager;
|
||||
import ru.betterend.registry.EndTags;
|
||||
|
|
|
@ -15,7 +15,6 @@ import net.minecraft.util.Identifier;
|
|||
import net.minecraft.util.JsonHelper;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.recipe.EndRecipeManager;
|
||||
import ru.betterend.rituals.InfusionRitual;
|
||||
|
|
|
@ -13,14 +13,12 @@ import net.minecraft.world.biome.Biome;
|
|||
import net.minecraft.world.biome.Biome.Category;
|
||||
import net.minecraft.world.biome.BiomeKeys;
|
||||
import net.minecraft.world.biome.source.BiomeSource;
|
||||
import net.minecraft.world.biome.source.TheEndBiomeSource;
|
||||
import net.minecraft.world.gen.ChunkRandom;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.noise.OpenSimplexNoise;
|
||||
import ru.betterend.registry.EndBiomes;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.FeaturesHelper;
|
||||
import ru.betterend.world.biome.EndBiome;
|
||||
|
||||
public class BetterEndBiomeSource extends BiomeSource {
|
||||
public static final Codec<BetterEndBiomeSource> CODEC = RecordCodecBuilder.create((instance) -> {
|
||||
|
@ -38,6 +36,8 @@ public class BetterEndBiomeSource extends BiomeSource {
|
|||
private BiomeMap mapLand;
|
||||
private BiomeMap mapVoid;
|
||||
private final long seed;
|
||||
private int preY = -1;
|
||||
boolean preLand = false;
|
||||
|
||||
public BetterEndBiomeSource(Registry<Biome> biomeRegistry, long seed) {
|
||||
super(getBiomes(biomeRegistry));
|
||||
|
@ -74,6 +74,19 @@ public class BetterEndBiomeSource extends BiomeSource {
|
|||
long j = (long) biomeZ * (long) biomeZ;
|
||||
if (i + j <= 65536L) return this.centerBiome;
|
||||
|
||||
if (biomeX == 0 && biomeZ == 0) {
|
||||
mapLand.clearCache();
|
||||
mapVoid.clearCache();
|
||||
}
|
||||
|
||||
if (TerrainGenerator.isLand(biomeX, biomeZ)) {
|
||||
return mapLand.getBiome(biomeX << 2, biomeZ << 2).getActualBiome();
|
||||
}
|
||||
else {
|
||||
return mapVoid.getBiome(biomeX << 2, biomeZ << 2).getActualBiome();
|
||||
}
|
||||
|
||||
/*
|
||||
float height = TheEndBiomeSource.getNoiseAt(noise, (biomeX >> 1) + 1, (biomeZ >> 1) + 1) + (float) SMALL_NOISE.eval(biomeX, biomeZ) * 5;
|
||||
|
||||
if (height > -20F && height < -5F) {
|
||||
|
@ -85,7 +98,7 @@ public class BetterEndBiomeSource extends BiomeSource {
|
|||
mapLand.clearCache();
|
||||
mapVoid.clearCache();
|
||||
}
|
||||
return endBiome.getActualBiome();
|
||||
return endBiome.getActualBiome();*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,6 +29,7 @@ public class IslandLayer {
|
|||
private final int seed;
|
||||
private final int minY;
|
||||
private final int maxY;
|
||||
private final long center;
|
||||
|
||||
public IslandLayer(int seed, double distance, float scale, int center, int heightVariation) {
|
||||
this.distance = distance;
|
||||
|
@ -37,6 +38,7 @@ public class IslandLayer {
|
|||
this.seed = seed;
|
||||
this.minY = center - heightVariation;
|
||||
this.maxY = center + heightVariation;
|
||||
this.center = MHelper.floor(1000 / distance);
|
||||
}
|
||||
|
||||
private int getSeed(int x, int z) {
|
||||
|
@ -55,13 +57,15 @@ public class IslandLayer {
|
|||
int px = pox + ix;
|
||||
for (int poz = -1; poz < 2; poz++) {
|
||||
int pz = poz + iz;
|
||||
//if (density.eval(px * distance * 0.002, pz * distance * 0.002) > 0) {
|
||||
if ((long) px + (long) pz > center) {
|
||||
RANDOM.setSeed(getSeed(px, pz));
|
||||
double posX = (px + RANDOM.nextFloat()) * distance;
|
||||
double posY = MHelper.randRange(minY, maxY, RANDOM);
|
||||
double posZ = (pz + RANDOM.nextFloat()) * distance;
|
||||
if (density.eval(posX * 0.01, posZ * 0.01) > 0) {
|
||||
positions.add(new BlockPos(posX, posY, posZ));
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
package ru.betterend.world.generator;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import ru.betterend.noise.OpenSimplexNoise;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class TerrainGenerator {
|
||||
private static final ReentrantLock LOCKER = new ReentrantLock();
|
||||
private static final double SCALE_XZ = 8.0;
|
||||
private static final double SCALE_Y = 4.0;
|
||||
private static final int CENTER = MHelper.floor(500 / SCALE_XZ);
|
||||
|
||||
private static IslandLayer largeIslands;
|
||||
private static IslandLayer mediumIslands;
|
||||
|
@ -15,10 +18,6 @@ public class TerrainGenerator {
|
|||
private static OpenSimplexNoise noise1;
|
||||
private static OpenSimplexNoise noise2;
|
||||
|
||||
private static OpenSimplexNoise continentalTop;
|
||||
private static OpenSimplexNoise continentalBottom;
|
||||
private static OpenSimplexNoise continentalSeparator;
|
||||
|
||||
public static void initNoise(long seed) {
|
||||
Random random = new Random(seed);
|
||||
largeIslands = new IslandLayer(random.nextInt(), 300, 200, 63, 0);
|
||||
|
@ -26,23 +25,30 @@ public class TerrainGenerator {
|
|||
smallIslands = new IslandLayer(random.nextInt(), 60, 50, 63, 32);
|
||||
noise1 = new OpenSimplexNoise(random.nextInt());
|
||||
noise2 = new OpenSimplexNoise(random.nextInt());
|
||||
continentalTop = new OpenSimplexNoise(random.nextInt());
|
||||
continentalBottom = new OpenSimplexNoise(random.nextInt());
|
||||
continentalSeparator = new OpenSimplexNoise(random.nextInt());
|
||||
}
|
||||
|
||||
public static boolean canGenerate(int x, int z) {
|
||||
return (long) x + (long) z > CENTER;
|
||||
}
|
||||
|
||||
public static void fillTerrainDensity(double[] buffer, int x, int z) {
|
||||
largeIslands.clearCache();
|
||||
LOCKER.lock();
|
||||
|
||||
double px = (double) x * SCALE_XZ;
|
||||
double pz = (double) z * SCALE_XZ;
|
||||
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);
|
||||
|
||||
for (int y = 0; y < buffer.length; y++) {
|
||||
double py = (double) y * SCALE_Y;
|
||||
//float dist = getContinental(px, py, pz);
|
||||
//dist = dist > 1 ? dist : MHelper.max(dist, largeIslands.getDensity(px, py, pz));
|
||||
float dist = largeIslands.getDensity(px, py, pz);
|
||||
dist = dist > 1 ? dist : MHelper.max(dist, mediumIslands.getDensity(px, py, pz));
|
||||
dist = dist > 1 ? dist : MHelper.max(dist, smallIslands.getDensity(px, py, pz));
|
||||
|
@ -53,13 +59,47 @@ public class TerrainGenerator {
|
|||
}
|
||||
buffer[y] = dist;
|
||||
}
|
||||
|
||||
LOCKER.unlock();
|
||||
}
|
||||
|
||||
private static float getContinental(double px, double py, double pz) {
|
||||
float gradient = ((float) py - 50F) * 0.01F;
|
||||
float top = (float) continentalTop.eval(px * 0.04, py * 0.04, pz * 0.04) * 0.1F - gradient;
|
||||
float bottom = (float) continentalBottom.eval(px * 0.01, py * 0.01, pz * 0.01) * 0.5F + gradient;
|
||||
float separate = (float) Math.abs(continentalSeparator.eval(px * 0.002, py * 0.002, pz * 0.002));
|
||||
return MHelper.min(top, bottom) * (separate * separate) + (float) noise2.eval(px * 0.1, py * 0.1, pz * 0.1) * 0.06F;
|
||||
/**
|
||||
* Check if this is land
|
||||
* @param x - biome pos x
|
||||
* @param z - biome pos z
|
||||
*/
|
||||
public static boolean isLand(int x, int z) {
|
||||
LOCKER.lock();
|
||||
|
||||
x >>= 1;
|
||||
z >>= 1;
|
||||
|
||||
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);
|
||||
|
||||
for (int y = 0; y < 32; y++) {
|
||||
double py = (double) y * SCALE_Y;
|
||||
float dist = largeIslands.getDensity(px, py, pz);
|
||||
dist = dist > 1 ? dist : MHelper.max(dist, mediumIslands.getDensity(px, py, pz));
|
||||
dist = dist > 1 ? dist : MHelper.max(dist, smallIslands.getDensity(px, py, pz));
|
||||
if (dist > -0.5F) {
|
||||
dist += noise1.eval(px * 0.01, py * 0.01, pz * 0.01) * 0.04;
|
||||
dist += noise2.eval(px * 0.05, py * 0.05, pz * 0.05) * 0.02;
|
||||
dist += noise1.eval(px * 0.1, py * 0.1, pz * 0.1) * 0.01;
|
||||
}
|
||||
if (dist > 0) {
|
||||
LOCKER.unlock();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
LOCKER.unlock();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue