Possibility to change biome generator

This commit is contained in:
paulevsGitch 2021-12-01 15:43:04 +03:00
parent 72e29223a1
commit 801f9e5a74
7 changed files with 96 additions and 64 deletions

View file

@ -0,0 +1,9 @@
package ru.bclib.interfaces;
import ru.bclib.world.biomes.BCLBiome;
public interface BiomeMap {
void clearCache();
BCLBiome getBiome(double x, double z);
}

View file

@ -18,9 +18,11 @@ import ru.bclib.BCLib;
import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.api.biomes.BiomeAPI;
import ru.bclib.config.ConfigKeeper.StringArrayEntry; import ru.bclib.config.ConfigKeeper.StringArrayEntry;
import ru.bclib.config.Configs; import ru.bclib.config.Configs;
import ru.bclib.interfaces.BiomeMap;
import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.noise.OpenSimplexNoise;
import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.BCLBiome;
import ru.bclib.world.generator.map.hex.HexBiomeMap; import ru.bclib.world.generator.map.hex.HexBiomeMap;
import ru.bclib.world.generator.map.square.SquareBiomeMap;
import java.awt.Point; import java.awt.Point;
import java.util.List; import java.util.List;
@ -40,8 +42,8 @@ public class BCLibEndBiomeSource extends BiomeSource {
private final SimplexNoise noise; private final SimplexNoise noise;
private final Biome centerBiome; private final Biome centerBiome;
private final Biome barrens; private final Biome barrens;
private HexBiomeMap mapLand; private BiomeMap mapLand;
private HexBiomeMap mapVoid; private BiomeMap mapVoid;
private final long seed; private final long seed;
private final Point pos; private final Point pos;
@ -75,8 +77,15 @@ public class BCLibEndBiomeSource extends BiomeSource {
BiomeAPI.END_LAND_BIOME_PICKER.rebuild(); BiomeAPI.END_LAND_BIOME_PICKER.rebuild();
BiomeAPI.END_VOID_BIOME_PICKER.rebuild(); BiomeAPI.END_VOID_BIOME_PICKER.rebuild();
this.mapLand = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndLand(), BiomeAPI.END_LAND_BIOME_PICKER); if (GeneratorOptions.useOldBiomeGenerator()) {
this.mapVoid = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER); this.mapLand = new SquareBiomeMap(seed, GeneratorOptions.getBiomeSizeEndLand(), BiomeAPI.END_LAND_BIOME_PICKER);
this.mapVoid = new SquareBiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER);
}
else {
this.mapLand = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndLand(), BiomeAPI.END_LAND_BIOME_PICKER);
this.mapVoid = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER);
}
this.centerBiome = biomeRegistry.getOrThrow(Biomes.THE_END); this.centerBiome = biomeRegistry.getOrThrow(Biomes.THE_END);
this.barrens = biomeRegistry.getOrThrow(Biomes.END_BARRENS); this.barrens = biomeRegistry.getOrThrow(Biomes.END_BARRENS);
this.biomeRegistry = biomeRegistry; this.biomeRegistry = biomeRegistry;

View file

@ -13,8 +13,10 @@ import ru.bclib.BCLib;
import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.api.biomes.BiomeAPI;
import ru.bclib.config.ConfigKeeper.StringArrayEntry; import ru.bclib.config.ConfigKeeper.StringArrayEntry;
import ru.bclib.config.Configs; import ru.bclib.config.Configs;
import ru.bclib.interfaces.BiomeMap;
import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.BCLBiome;
import ru.bclib.world.generator.map.hex.HexBiomeMap; import ru.bclib.world.generator.map.hex.HexBiomeMap;
import ru.bclib.world.generator.map.square.SquareBiomeMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -29,7 +31,7 @@ public class BCLibNetherBiomeSource extends BiomeSource {
})).apply(instance, instance.stable(BCLibNetherBiomeSource::new)); })).apply(instance, instance.stable(BCLibNetherBiomeSource::new));
}); });
private final Registry<Biome> biomeRegistry; private final Registry<Biome> biomeRegistry;
private HexBiomeMap biomeMap; private BiomeMap biomeMap;
private final long seed; private final long seed;
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
@ -60,7 +62,13 @@ public class BCLibNetherBiomeSource extends BiomeSource {
BiomeAPI.NETHER_BIOME_PICKER.getBiomes().forEach(biome -> biome.updateActualBiomes(biomeRegistry)); BiomeAPI.NETHER_BIOME_PICKER.getBiomes().forEach(biome -> biome.updateActualBiomes(biomeRegistry));
BiomeAPI.NETHER_BIOME_PICKER.rebuild(); BiomeAPI.NETHER_BIOME_PICKER.rebuild();
this.biomeMap = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER); if (GeneratorOptions.useOldBiomeGenerator()) {
this.biomeMap = new SquareBiomeMap(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER);
}
else {
this.biomeMap = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER);
}
this.biomeRegistry = biomeRegistry; this.biomeRegistry = biomeRegistry;
this.seed = seed; this.seed = seed;

View file

@ -16,6 +16,7 @@ public class GeneratorOptions {
private static boolean customEndBiomeSource = true; private static boolean customEndBiomeSource = true;
private static boolean addNetherBiomesByCategory = false; private static boolean addNetherBiomesByCategory = false;
private static boolean addEndBiomesByCategory = false; private static boolean addEndBiomesByCategory = false;
private static boolean useOldBiomeGenerator = false;
public static void init() { public static void init() {
biomeSizeNether = Configs.GENERATOR_CONFIG.getInt("nether.biomeMap", "biomeSize", 256); biomeSizeNether = Configs.GENERATOR_CONFIG.getInt("nether.biomeMap", "biomeSize", 256);
@ -25,6 +26,7 @@ public class GeneratorOptions {
customEndBiomeSource = Configs.GENERATOR_CONFIG.getBoolean("options", "customEndBiomeSource", true); customEndBiomeSource = Configs.GENERATOR_CONFIG.getBoolean("options", "customEndBiomeSource", true);
addNetherBiomesByCategory = Configs.GENERATOR_CONFIG.getBoolean("options", "addNetherBiomesByCategory", false); addNetherBiomesByCategory = Configs.GENERATOR_CONFIG.getBoolean("options", "addNetherBiomesByCategory", false);
addEndBiomesByCategory = Configs.GENERATOR_CONFIG.getBoolean("options", "addEndBiomesByCategory", false); addEndBiomesByCategory = Configs.GENERATOR_CONFIG.getBoolean("options", "addEndBiomesByCategory", false);
useOldBiomeGenerator = Configs.GENERATOR_CONFIG.getBoolean("options", "useOldBiomeGenerator", false);
} }
public static int getBiomeSizeNether() { public static int getBiomeSizeNether() {
@ -70,4 +72,8 @@ public class GeneratorOptions {
public static boolean addEndBiomesByCategory() { public static boolean addEndBiomesByCategory() {
return addEndBiomesByCategory; return addEndBiomesByCategory;
} }
public static boolean useOldBiomeGenerator() {
return useOldBiomeGenerator;
}
} }

View file

@ -1,5 +1,6 @@
package ru.bclib.world.generator.map.hex; package ru.bclib.world.generator.map.hex;
import ru.bclib.interfaces.BiomeMap;
import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.noise.OpenSimplexNoise;
import ru.bclib.util.MHelper; import ru.bclib.util.MHelper;
import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.BCLBiome;
@ -9,7 +10,7 @@ import java.awt.Point;
import java.util.HashMap; import java.util.HashMap;
import java.util.Random; import java.util.Random;
public class HexBiomeMap { public class HexBiomeMap implements BiomeMap {
private static final float RAD_INNER = (float) Math.sqrt(3.0) * 0.5F; private static final float RAD_INNER = (float) Math.sqrt(3.0) * 0.5F;
private static final float COEF = 0.25F * (float) Math.sqrt(3.0); private static final float COEF = 0.25F * (float) Math.sqrt(3.0);
private static final float COEF_HALF = COEF * 0.5F; private static final float COEF_HALF = COEF * 0.5F;
@ -38,12 +39,14 @@ public class HexBiomeMap {
this.seed = (int) (seed & 0xFFFFFFFF); this.seed = (int) (seed & 0xFFFFFFFF);
} }
@Override
public void clearCache() { public void clearCache() {
if (chunks.size() > 127) { if (chunks.size() > 127) {
chunks.clear(); chunks.clear();
} }
} }
@Override
public BCLBiome getBiome(double x, double z) { public BCLBiome getBiome(double x, double z) {
BCLBiome BCLBiome = getRawBiome(x, z); BCLBiome BCLBiome = getRawBiome(x, z);
if (BCLBiome.getEdge() != null) { if (BCLBiome.getEdge() != null) {

View file

@ -5,7 +5,6 @@ import ru.bclib.world.generator.BiomePicker;
import java.util.Random; import java.util.Random;
@Deprecated
public class SquareBiomeChunk { public class SquareBiomeChunk {
private static final int BIT_OFFSET = 4; private static final int BIT_OFFSET = 4;
protected static final int WIDTH = 1 << BIT_OFFSET; protected static final int WIDTH = 1 << BIT_OFFSET;
@ -19,7 +18,7 @@ public class SquareBiomeChunk {
private final BCLBiome[] biomes; private final BCLBiome[] biomes;
public SquareBiomeChunk(SquareBiomeMap map, Random random, BiomePicker picker) { public SquareBiomeChunk(Random random, BiomePicker picker) {
BCLBiome[] PreBio = new BCLBiome[SM_CAPACITY]; BCLBiome[] PreBio = new BCLBiome[SM_CAPACITY];
biomes = new BCLBiome[CAPACITY]; biomes = new BCLBiome[CAPACITY];

View file

@ -4,6 +4,7 @@ import com.google.common.collect.Maps;
import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.levelgen.LegacyRandomSource; import net.minecraft.world.level.levelgen.LegacyRandomSource;
import net.minecraft.world.level.levelgen.WorldgenRandom; import net.minecraft.world.level.levelgen.WorldgenRandom;
import ru.bclib.interfaces.BiomeMap;
import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.noise.OpenSimplexNoise;
import ru.bclib.util.MHelper; import ru.bclib.util.MHelper;
import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.BCLBiome;
@ -11,24 +12,23 @@ import ru.bclib.world.generator.BiomePicker;
import java.util.Map; import java.util.Map;
@Deprecated public class SquareBiomeMap implements BiomeMap {
public class SquareBiomeMap {
private final WorldgenRandom RANDOM;
private final Map<ChunkPos, SquareBiomeChunk> maps = Maps.newHashMap(); private final Map<ChunkPos, SquareBiomeChunk> maps = Maps.newHashMap();
private final int size;
private final int sizeXZ;
private final int depth;
private final OpenSimplexNoise noiseX; private final OpenSimplexNoise noiseX;
private final OpenSimplexNoise noiseZ; private final OpenSimplexNoise noiseZ;
private final WorldgenRandom random;
private final BiomePicker picker; private final BiomePicker picker;
private final long seed; private final long seed;
private final int sizeXZ;
private final int depth;
private final int size;
public SquareBiomeMap(long seed, int size, BiomePicker picker) { public SquareBiomeMap(long seed, int size, BiomePicker picker) {
maps.clear(); maps.clear();
RANDOM = new WorldgenRandom(new LegacyRandomSource(seed)); random = new WorldgenRandom(new LegacyRandomSource(seed));
noiseX = new OpenSimplexNoise(RANDOM.nextLong()); noiseX = new OpenSimplexNoise(random.nextLong());
noiseZ = new OpenSimplexNoise(RANDOM.nextLong()); noiseZ = new OpenSimplexNoise(random.nextLong());
this.sizeXZ = size; this.sizeXZ = size;
depth = (int) Math.ceil(Math.log(size) / Math.log(2)) - 2; depth = (int) Math.ceil(Math.log(size) / Math.log(2)) - 2;
this.size = 1 << depth; this.size = 1 << depth;
@ -36,57 +36,15 @@ public class SquareBiomeMap {
this.seed = seed; this.seed = seed;
} }
public long getSeed() { @Override
return seed;
}
public void clearCache() { public void clearCache() {
if (maps.size() > 32) { if (maps.size() > 32) {
maps.clear(); maps.clear();
} }
} }
private BCLBiome getRawBiome(int bx, int bz) { @Override
double x = (double) bx * size / sizeXZ; public BCLBiome getBiome(double x, double z) {
double z = (double) bz * size / sizeXZ;
double nx = x;
double nz = z;
double px = bx * 0.2;
double pz = bz * 0.2;
for (int i = 0; i < depth; i++) {
nx = (x + noiseX.eval(px, pz)) / 2F;
nz = (z + noiseZ.eval(px, pz)) / 2F;
x = nx;
z = nz;
px = px / 2 + i;
pz = pz / 2 + i;
}
bx = MHelper.floor(x);
bz = MHelper.floor(z);
if ((bx & SquareBiomeChunk.MASK_WIDTH) == SquareBiomeChunk.MASK_WIDTH) {
x += (bz / 2) & 1;
}
if ((bz & SquareBiomeChunk.MASK_WIDTH) == SquareBiomeChunk.MASK_WIDTH) {
z += (bx / 2) & 1;
}
ChunkPos cpos = new ChunkPos(MHelper.floor(x / SquareBiomeChunk.WIDTH), MHelper.floor(z / SquareBiomeChunk.WIDTH));
SquareBiomeChunk chunk = maps.get(cpos);
if (chunk == null) {
RANDOM.setLargeFeatureWithSalt(0, cpos.x, cpos.z, 0);
chunk = new SquareBiomeChunk(this, RANDOM, picker);
maps.put(cpos, chunk);
}
return chunk.getBiome(MHelper.floor(x), MHelper.floor(z));
}
public BCLBiome getBiome(int x, int z) {
BCLBiome biome = getRawBiome(x, z); BCLBiome biome = getRawBiome(x, z);
if (biome.getEdge() != null || (biome.getParentBiome() != null && biome.getParentBiome().getEdge() != null)) { if (biome.getEdge() != null || (biome.getParentBiome() != null && biome.getParentBiome().getEdge() != null)) {
@ -112,4 +70,44 @@ public class SquareBiomeMap {
return biome; return biome;
} }
private BCLBiome getRawBiome(double bx, double bz) {
double x = bx * size / sizeXZ;
double z = bz * size / sizeXZ;
double nx = x;
double nz = z;
double px = bx * 0.2;
double pz = bz * 0.2;
for (int i = 0; i < depth; i++) {
nx = (x + noiseX.eval(px, pz)) / 2F;
nz = (z + noiseZ.eval(px, pz)) / 2F;
x = nx;
z = nz;
px = px / 2 + i;
pz = pz / 2 + i;
}
int ix = MHelper.floor(x);
int iz = MHelper.floor(z);
if ((ix & SquareBiomeChunk.MASK_WIDTH) == SquareBiomeChunk.MASK_WIDTH) {
x += (iz / 2) & 1;
}
if ((iz & SquareBiomeChunk.MASK_WIDTH) == SquareBiomeChunk.MASK_WIDTH) {
z += (ix / 2) & 1;
}
ChunkPos cpos = new ChunkPos(MHelper.floor(x / SquareBiomeChunk.WIDTH), MHelper.floor(z / SquareBiomeChunk.WIDTH));
SquareBiomeChunk chunk = maps.get(cpos);
if (chunk == null) {
random.setLargeFeatureWithSalt(0, cpos.x, cpos.z, 0);
chunk = new SquareBiomeChunk(random, picker);
maps.put(cpos, chunk);
}
return chunk.getBiome(MHelper.floor(x), MHelper.floor(z));
}
} }