[Change] Prevent Crash when merging BiomeSources. A cought crash can result in modded biomes not getting loaded. (quiqueck/BetterNether#138)

This commit is contained in:
Frank 2023-06-18 00:32:09 +02:00
parent f0dd0e698d
commit fd9bac7484
2 changed files with 33 additions and 18 deletions

View file

@ -238,6 +238,7 @@ public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceW
final List<String> excludeList = Configs.BIOMES_CONFIG.getExcludeMatching(defaultBiomeType());
final Registry<BCLBiome> bclBiomes = access.registryOrThrow(BCLBiomeRegistry.BCL_BIOMES_REGISTRY);
try {
for (Holder<Biome> possibleBiome : inputBiomeSource.possibleBiomes()) {
ResourceKey<Biome> key = possibleBiome.unwrapKey().orElse(null);
if (key != null) {
@ -257,6 +258,11 @@ public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceW
}
}
}
} catch (RuntimeException e) {
BCLib.LOGGER.error("Error while rebuilding Biomesources!", e);
} catch (Exception e) {
BCLib.LOGGER.error("Error while rebuilding Biomesources!", e);
}
this.reloadBiomes();
return this;

View file

@ -1,5 +1,7 @@
package org.betterx.worlds.together.biomesource;
import org.betterx.bclib.BCLib;
import net.minecraft.core.Holder;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource;
@ -9,13 +11,20 @@ import java.util.Set;
public interface MergeableBiomeSource<B extends BiomeSource> {
default boolean togetherShouldMerge(BiomeSource inputBiomeSource) {
Set<Holder<Biome>> mySet = ((B) this).possibleBiomes();
try {
Set<Holder<Biome>> otherSet = inputBiomeSource.possibleBiomes();
if (otherSet.size() != mySet.size()) return true;
for (Holder<Biome> b : mySet) {
if (!otherSet.contains(b))
return true;
}
} catch (RuntimeException e) {
BCLib.LOGGER.error("Failed to merge BiomeSource", e);
} catch (Exception e) {
BCLib.LOGGER.error("Failed to merge BiomeSource", e);
}
return false;
}