From a73bd23ddf04e8933196e33a904f00fafb4696e9 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 4 Jul 2022 00:54:41 +0200 Subject: [PATCH] [Fix] DataPack Biomes from other mods are loaded after the WorldStem was first built. Our Biomes-Sources would not recognize that change (#16) --- .../api/v2/generator/BCLBiomeSource.java | 6 ++++- .../biomesource/BiomeSourceFromRegistry.java | 26 +++++++++++++++++++ .../EnforceableChunkGenerator.java | 9 ++++++- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/betterx/worlds/together/biomesource/BiomeSourceFromRegistry.java diff --git a/src/main/java/org/betterx/bclib/api/v2/generator/BCLBiomeSource.java b/src/main/java/org/betterx/bclib/api/v2/generator/BCLBiomeSource.java index 6e01ee27..8c406bb8 100644 --- a/src/main/java/org/betterx/bclib/api/v2/generator/BCLBiomeSource.java +++ b/src/main/java/org/betterx/bclib/api/v2/generator/BCLBiomeSource.java @@ -1,6 +1,7 @@ package org.betterx.bclib.api.v2.generator; import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI; +import org.betterx.worlds.together.biomesource.BiomeSourceFromRegistry; import org.betterx.worlds.together.biomesource.MergeableBiomeSource; import org.betterx.worlds.together.world.BiomeSourceWithNoiseRelatedSettings; import org.betterx.worlds.together.world.BiomeSourceWithSeed; @@ -18,7 +19,7 @@ import java.util.Comparator; import java.util.List; import java.util.Set; -public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceWithSeed, MergeableBiomeSource, BiomeSourceWithNoiseRelatedSettings { +public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceWithSeed, MergeableBiomeSource, BiomeSourceWithNoiseRelatedSettings, BiomeSourceFromRegistry { protected final Registry biomeRegistry; protected long currentSeed; protected int maxHeight; @@ -117,4 +118,7 @@ public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceW this.setMaxHeight(generator.noiseSettings().height()); } + public Registry getBiomeRegistry() { + return biomeRegistry; + } } diff --git a/src/main/java/org/betterx/worlds/together/biomesource/BiomeSourceFromRegistry.java b/src/main/java/org/betterx/worlds/together/biomesource/BiomeSourceFromRegistry.java new file mode 100644 index 00000000..dd908026 --- /dev/null +++ b/src/main/java/org/betterx/worlds/together/biomesource/BiomeSourceFromRegistry.java @@ -0,0 +1,26 @@ +package org.betterx.worlds.together.biomesource; + +import net.minecraft.core.Holder; +import net.minecraft.core.Registry; +import net.minecraft.world.level.biome.Biome; + +import java.util.Set; + +public interface BiomeSourceFromRegistry { + Registry getBiomeRegistry(); + Set> possibleBiomes(); + + default boolean sameRegistryButDifferentBiomes(BiomeSourceFromRegistry other) { + if (other.getBiomeRegistry() == getBiomeRegistry()) { + Set> mySet = this.possibleBiomes(); + Set> otherSet = other.possibleBiomes(); + if (otherSet.size() != mySet.size()) return true; + for (Holder b : mySet) { + if (!otherSet.contains(b)) + return true; + } + } + + return false; + } +} diff --git a/src/main/java/org/betterx/worlds/together/chunkgenerator/EnforceableChunkGenerator.java b/src/main/java/org/betterx/worlds/together/chunkgenerator/EnforceableChunkGenerator.java index f43e5ed5..505b3bbb 100644 --- a/src/main/java/org/betterx/worlds/together/chunkgenerator/EnforceableChunkGenerator.java +++ b/src/main/java/org/betterx/worlds/together/chunkgenerator/EnforceableChunkGenerator.java @@ -1,5 +1,6 @@ package org.betterx.worlds.together.chunkgenerator; +import org.betterx.worlds.together.biomesource.BiomeSourceFromRegistry; import org.betterx.worlds.together.biomesource.BiomeSourceWithConfig; import net.minecraft.core.RegistryAccess; @@ -28,8 +29,14 @@ public interface EnforceableChunkGenerator { if (one == two) return false; if (one instanceof BiomeSourceWithConfig ba && two instanceof BiomeSourceWithConfig bb) { - return !ba.getTogetherConfig().couldSetWithoutRepair(bb.getTogetherConfig()); + if (!ba.getTogetherConfig().couldSetWithoutRepair(bb.getTogetherConfig())) + return true; } + if (one instanceof BiomeSourceFromRegistry ba && two instanceof BiomeSourceFromRegistry bb) { + if (ba.sameRegistryButDifferentBiomes(bb)) + return true; + } + return !one.getClass().isAssignableFrom(two.getClass()) && !two.getClass().isAssignableFrom(one.getClass()); } }