From 595063bf99d9ebd6f94714ab9e49390af845bd53 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Thu, 9 Dec 2021 12:01:53 +0300 Subject: [PATCH] MapStack fix --- .../generator/BCLibNetherBiomeSource.java | 25 +++++++++++++------ .../bclib/world/generator/map/MapStack.java | 7 ++++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index ade35ef6..45d53d3e 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -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 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 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); + } + } } diff --git a/src/main/java/ru/bclib/world/generator/map/MapStack.java b/src/main/java/ru/bclib/world/generator/map/MapStack.java index 48dd7472..43280b0e 100644 --- a/src/main/java/ru/bclib/world/generator/map/MapStack.java +++ b/src/main/java/ru/bclib/world/generator/map/MapStack.java @@ -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 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);