MapStack fix

This commit is contained in:
paulevsGitch 2021-12-09 12:01:53 +03:00
parent 0868d8bd2b
commit 595063bf99
2 changed files with 22 additions and 10 deletions

View file

@ -34,6 +34,7 @@ public class BCLibNetherBiomeSource extends BiomeSource {
private BiomeMap biomeMap;
private final long seed;
private static boolean forceLegacyGenerator = false;
private static int lastWorldHeight;
private static int worldHeight;
/**
@ -84,14 +85,7 @@ public class BCLibNetherBiomeSource extends BiomeSource {
BiomeAPI.NETHER_BIOME_PICKER.getBiomes().forEach(biome -> biome.updateActualBiomes(biomeRegistry));
BiomeAPI.NETHER_BIOME_PICKER.rebuild();
boolean useLegacy = GeneratorOptions.useOldBiomeGenerator() || forceLegacyGenerator;
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 {
this.biomeMap = mapConstructor.apply(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER);
}
initMap();
this.biomeRegistry = biomeRegistry;
this.seed = seed;
@ -124,6 +118,10 @@ public class BCLibNetherBiomeSource extends BiomeSource {
@Override
public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler var4) {
if (lastWorldHeight != worldHeight) {
lastWorldHeight = worldHeight;
initMap();
}
if ((biomeX & 63) == 0 && (biomeZ & 63) == 0) {
biomeMap.clearCache();
}
@ -143,4 +141,15 @@ public class BCLibNetherBiomeSource extends BiomeSource {
public static void register() {
Registry.register(Registry.BIOME_SOURCE, BCLib.makeID("nether_biome_source"), CODEC);
}
private void initMap() {
boolean useLegacy = GeneratorOptions.useOldBiomeGenerator() || forceLegacyGenerator;
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 {
this.biomeMap = mapConstructor.apply(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER);
}
}
}

View file

@ -15,9 +15,11 @@ public class MapStack implements BiomeMap {
private final int worldHeight;
private final int minValue;
private final int maxValue;
private final int maxIndex;
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.maxIndex = mapCount - 1;
this.worldHeight = worldHeight;
minValue = Mth.floor(mapHeight * 0.5F + 0.5F);
maxValue = Mth.floor(worldHeight - mapHeight * 0.5F + 0.5F);
@ -44,10 +46,11 @@ public class MapStack implements BiomeMap {
mapIndex = 0;
}
else if (y > maxValue) {
mapIndex = maps.length - 1;
mapIndex = maxIndex;
}
else {
mapIndex = Mth.floor((y + noise.eval(x * 0.03, z * 0.03) * 8) / worldHeight * maps.length + 0.5F);
mapIndex = Mth.floor((y + noise.eval(x * 0.03, z * 0.03) * 8) / worldHeight * maxIndex + 0.5F);
mapIndex = Mth.clamp(mapIndex, 0, maxIndex);
}
return maps[mapIndex].getBiome(x, y, z);