[Fix] DataPack Biomes from other mods are loaded after the WorldStem was first built. Our Biomes-Sources would not recognize that change (#16)

This commit is contained in:
Frank 2022-07-04 00:54:41 +02:00
parent 3b0f609776
commit a73bd23ddf
3 changed files with 39 additions and 2 deletions

View file

@ -1,6 +1,7 @@
package org.betterx.bclib.api.v2.generator; package org.betterx.bclib.api.v2.generator;
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI; 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.biomesource.MergeableBiomeSource;
import org.betterx.worlds.together.world.BiomeSourceWithNoiseRelatedSettings; import org.betterx.worlds.together.world.BiomeSourceWithNoiseRelatedSettings;
import org.betterx.worlds.together.world.BiomeSourceWithSeed; import org.betterx.worlds.together.world.BiomeSourceWithSeed;
@ -18,7 +19,7 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceWithSeed, MergeableBiomeSource<BCLBiomeSource>, BiomeSourceWithNoiseRelatedSettings { public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceWithSeed, MergeableBiomeSource<BCLBiomeSource>, BiomeSourceWithNoiseRelatedSettings, BiomeSourceFromRegistry {
protected final Registry<Biome> biomeRegistry; protected final Registry<Biome> biomeRegistry;
protected long currentSeed; protected long currentSeed;
protected int maxHeight; protected int maxHeight;
@ -117,4 +118,7 @@ public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceW
this.setMaxHeight(generator.noiseSettings().height()); this.setMaxHeight(generator.noiseSettings().height());
} }
public Registry<Biome> getBiomeRegistry() {
return biomeRegistry;
}
} }

View file

@ -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<Biome> getBiomeRegistry();
Set<Holder<Biome>> possibleBiomes();
default boolean sameRegistryButDifferentBiomes(BiomeSourceFromRegistry other) {
if (other.getBiomeRegistry() == getBiomeRegistry()) {
Set<Holder<Biome>> mySet = this.possibleBiomes();
Set<Holder<Biome>> otherSet = other.possibleBiomes();
if (otherSet.size() != mySet.size()) return true;
for (Holder<Biome> b : mySet) {
if (!otherSet.contains(b))
return true;
}
}
return false;
}
}

View file

@ -1,5 +1,6 @@
package org.betterx.worlds.together.chunkgenerator; package org.betterx.worlds.together.chunkgenerator;
import org.betterx.worlds.together.biomesource.BiomeSourceFromRegistry;
import org.betterx.worlds.together.biomesource.BiomeSourceWithConfig; import org.betterx.worlds.together.biomesource.BiomeSourceWithConfig;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
@ -28,8 +29,14 @@ public interface EnforceableChunkGenerator<G extends ChunkGenerator> {
if (one == two) return false; if (one == two) return false;
if (one instanceof BiomeSourceWithConfig<?, ?> ba && two instanceof BiomeSourceWithConfig<?, ?> bb) { 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()); return !one.getClass().isAssignableFrom(two.getClass()) && !two.getClass().isAssignableFrom(one.getClass());
} }
} }