Map stack

This commit is contained in:
paulevsGitch 2021-12-09 11:37:05 +03:00
parent 9bde4c11b9
commit 60ee68d8d1
7 changed files with 91 additions and 21 deletions

View file

@ -5,5 +5,5 @@ import ru.bclib.world.biomes.BCLBiome;
public interface BiomeMap { public interface BiomeMap {
void clearCache(); void clearCache();
BCLBiome getBiome(double x, double z); BCLBiome getBiome(double x, double y, double z);
} }

View file

@ -144,7 +144,7 @@ public class BCLibEndBiomeSource extends BiomeSource {
public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) { public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) {
long i = (long) biomeX * (long) biomeX; long i = (long) biomeX * (long) biomeX;
long j = (long) biomeZ * (long) biomeZ; long j = (long) biomeZ * (long) biomeZ;
long check = GeneratorOptions.isFarEndBiomes() ? 65536L : 625L; long farEndBiomes = GeneratorOptions.getFarEndBiomes();
long dist = i + j; long dist = i + j;
if ((biomeX & 63) == 0 && (biomeZ & 63) == 0) { if ((biomeX & 63) == 0 && (biomeZ & 63) == 0) {
@ -153,7 +153,7 @@ public class BCLibEndBiomeSource extends BiomeSource {
} }
if (endLandFunction == null) { if (endLandFunction == null) {
if (dist <= check) return centerBiome; if (dist <= farEndBiomes) return centerBiome;
float height = TheEndBiomeSource.getHeightValue( float height = TheEndBiomeSource.getHeightValue(
noise, noise,
(biomeX >> 1) + 1, (biomeX >> 1) + 1,
@ -165,19 +165,19 @@ public class BCLibEndBiomeSource extends BiomeSource {
} }
if (height < -10F) { if (height < -10F) {
return mapVoid.getBiome(biomeX << 2, biomeZ << 2).getActualBiome(); return mapVoid.getBiome(biomeX << 2, biomeY << 2, biomeZ << 2).getActualBiome();
} }
else { else {
return mapLand.getBiome(biomeX << 2, biomeZ << 2).getActualBiome(); return mapLand.getBiome(biomeX << 2, biomeY << 2, biomeZ << 2).getActualBiome();
} }
} }
else { else {
pos.setLocation(biomeX, biomeZ); pos.setLocation(biomeX, biomeZ);
if (endLandFunction.apply(pos)) { if (endLandFunction.apply(pos)) {
return dist <= check ? centerBiome : mapLand.getBiome(biomeX << 2, biomeZ << 2).getActualBiome(); return dist <= farEndBiomes ? centerBiome : mapLand.getBiome(biomeX << 2, biomeY << 2, biomeZ << 2).getActualBiome();
} }
else { else {
return dist <= check ? barrens : mapVoid.getBiome(biomeX << 2, biomeZ << 2).getActualBiome(); return dist <= farEndBiomes ? barrens : mapVoid.getBiome(biomeX << 2, biomeY << 2, biomeZ << 2).getActualBiome();
} }
} }
} }

View file

@ -9,12 +9,14 @@ import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.Biome.BiomeCategory;
import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.Climate;
import org.apache.commons.lang3.function.TriFunction;
import ru.bclib.BCLib; 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.interfaces.BiomeMap;
import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.BCLBiome;
import ru.bclib.world.generator.map.MapStack;
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 ru.bclib.world.generator.map.square.SquareBiomeMap;
@ -32,6 +34,7 @@ public class BCLibNetherBiomeSource extends BiomeSource {
private BiomeMap biomeMap; private BiomeMap biomeMap;
private final long seed; private final long seed;
private static boolean forceLegacyGenerator = false; private static boolean forceLegacyGenerator = false;
private static int worldHeight;
/** /**
* When true, the older square generator is used for the nether. * When true, the older square generator is used for the nether.
@ -44,6 +47,14 @@ public class BCLibNetherBiomeSource extends BiomeSource {
forceLegacyGenerator = val; forceLegacyGenerator = val;
} }
/**
* Set world height, used when Nether is larger than vanilla 128 blocks tall.
* @param worldHeight height of the Nether ceiling.
*/
public static void setWorldHeight(int worldHeight) {
BCLibNetherBiomeSource.worldHeight = worldHeight;
}
public BCLibNetherBiomeSource(Registry<Biome> biomeRegistry, long seed) { public BCLibNetherBiomeSource(Registry<Biome> biomeRegistry, long seed) {
super(getBiomes(biomeRegistry)); super(getBiomes(biomeRegistry));
@ -73,11 +84,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();
if (GeneratorOptions.useOldBiomeGenerator() || forceLegacyGenerator) { boolean useLegacy = GeneratorOptions.useOldBiomeGenerator() || forceLegacyGenerator;
this.biomeMap = new SquareBiomeMap(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER); TriFunction<Long, Integer, BiomePicker, BiomeMap> mapConstructor = useLegacy ? SquareBiomeMap::new : HexBiomeMap::new;
if (worldHeight > 128) {
this.biomeMap = new MapStack(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER, 86, worldHeight, mapConstructor);
} }
else { else {
this.biomeMap = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER); this.biomeMap = mapConstructor.apply(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER);
} }
this.biomeRegistry = biomeRegistry; this.biomeRegistry = biomeRegistry;
@ -114,7 +127,7 @@ public class BCLibNetherBiomeSource extends BiomeSource {
if ((biomeX & 63) == 0 && (biomeZ & 63) == 0) { if ((biomeX & 63) == 0 && (biomeZ & 63) == 0) {
biomeMap.clearCache(); biomeMap.clearCache();
} }
return biomeMap.getBiome(biomeX << 2, biomeZ << 2).getActualBiome(); return biomeMap.getBiome(biomeX << 2, biomeY << 2, biomeZ << 2).getActualBiome();
} }
@Override @Override

View file

@ -11,12 +11,12 @@ public class GeneratorOptions {
private static int biomeSizeEndLand; private static int biomeSizeEndLand;
private static int biomeSizeEndVoid; private static int biomeSizeEndVoid;
private static Function<Point, Boolean> endLandFunction; private static Function<Point, Boolean> endLandFunction;
private static boolean farEndBiomes = true;
private static boolean customNetherBiomeSource = true; private static boolean customNetherBiomeSource = true;
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; private static boolean useOldBiomeGenerator = false;
private static long farEndBiomesSqr = 1000000;
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);
@ -49,12 +49,16 @@ public class GeneratorOptions {
return endLandFunction; return endLandFunction;
} }
public static boolean isFarEndBiomes() { public static long getFarEndBiomes() {
return farEndBiomes; return farEndBiomesSqr;
} }
public static void setFarEndBiomes(boolean farEndBiomes) { /**
GeneratorOptions.farEndBiomes = farEndBiomes; * Set distance of far End biomes generation, in blocks
* @param distance
*/
public static void setFarEndBiomes(int distance) {
GeneratorOptions.farEndBiomesSqr = (long) distance * (long) distance;
} }
public static boolean customNetherBiomeSource() { public static boolean customNetherBiomeSource() {

View file

@ -0,0 +1,55 @@
package ru.bclib.world.generator.map;
import net.minecraft.util.Mth;
import org.apache.commons.lang3.function.TriFunction;
import ru.bclib.interfaces.BiomeMap;
import ru.bclib.noise.OpenSimplexNoise;
import ru.bclib.world.biomes.BCLBiome;
import ru.bclib.world.generator.BiomePicker;
import java.util.Random;
public class MapStack implements BiomeMap {
private final OpenSimplexNoise noise;
private final BiomeMap[] maps;
private final int worldHeight;
private final int minValue;
private final int maxValue;
public MapStack(long seed, int size, BiomePicker picker, int mapHeight, int worldHeight, TriFunction<Long, Integer, BiomePicker, BiomeMap> mapConstructor) {
final int mapCount = Mth.ceil((float) worldHeight / mapHeight);
this.worldHeight = worldHeight;
minValue = Mth.floor(mapHeight * 0.5F + 0.5F);
maxValue = Mth.floor(worldHeight - mapHeight * 0.5F + 0.5F);
maps = new BiomeMap[mapCount];
Random random = new Random(seed);
for (int i = 0; i < mapCount; i++) {
maps[i] = mapConstructor.apply(random.nextLong(), size, picker);
}
noise = new OpenSimplexNoise(random.nextInt());
}
@Override
public void clearCache() {
for (BiomeMap map: maps) {
map.clearCache();
}
}
@Override
public BCLBiome getBiome(double x, double y, double z) {
int mapIndex;
if (y < minValue) {
mapIndex = 0;
}
else if (y > maxValue) {
mapIndex = maps.length - 1;
}
else {
mapIndex = Mth.floor((y + noise.eval(x * 0.03, z * 0.03) * 8) / worldHeight * maps.length + 0.5F);
}
return maps[mapIndex].getBiome(x, y, z);
}
}

View file

@ -47,7 +47,7 @@ public class HexBiomeMap implements BiomeMap {
} }
@Override @Override
public BCLBiome getBiome(double x, double z) { public BCLBiome getBiome(double x, double y, double z) {
BCLBiome biome = getRawBiome(x, z); BCLBiome biome = getRawBiome(x, z);
BCLBiome edge = biome.getEdge(); BCLBiome edge = biome.getEdge();
float offset = biome.getEdgeSize(); float offset = biome.getEdgeSize();

View file

@ -19,7 +19,6 @@ public class SquareBiomeMap implements BiomeMap {
private final WorldgenRandom random; private final WorldgenRandom random;
private final BiomePicker picker; private final BiomePicker picker;
private final long seed;
private final int sizeXZ; private final int sizeXZ;
private final int depth; private final int depth;
private final int size; private final int size;
@ -33,7 +32,6 @@ public class SquareBiomeMap implements BiomeMap {
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;
this.picker = picker; this.picker = picker;
this.seed = seed;
} }
@Override @Override
@ -44,7 +42,7 @@ public class SquareBiomeMap implements BiomeMap {
} }
@Override @Override
public BCLBiome getBiome(double x, double z) { public BCLBiome getBiome(double x, double y, double 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)) {