[Fix] Crash when a second world is loaded

This commit is contained in:
Frank 2022-07-01 20:18:10 +02:00
parent 4259c704a2
commit a2956a4cba
2 changed files with 39 additions and 24 deletions

View file

@ -1210,38 +1210,44 @@ public class EndFeatures {
} }
public static void addBiomeFeatures(ResourceLocation id, Holder<Biome> biome) { public static void addBiomeFeatures(ResourceLocation id, Holder<Biome> biome) {
BiomeAPI.addBiomeFeature(biome, FLAVOLITE_LAYER); if (!BetterEnd.MOD_ID.equals(id.getNamespace())) {
BiomeAPI.addBiomeFeature(biome, THALLASIUM_ORE); BiomeAPI.addBiomeFeature(biome, FLAVOLITE_LAYER);
BiomeAPI.addBiomeFeature(biome, ENDER_ORE); BiomeAPI.addBiomeFeature(biome, THALLASIUM_ORE);
BiomeAPI.addBiomeFeature(biome, CRASHED_SHIP); BiomeAPI.addBiomeFeature(biome, ENDER_ORE);
BiomeAPI.addBiomeFeature(biome, CRASHED_SHIP);
BCLBiome bclbiome = BiomeAPI.getBiome(id); BCLBiome bclbiome = BiomeAPI.getBiome(id);
BCLFeature feature = getBiomeStructures(bclbiome); BCLFeature feature = getBiomeStructures(bclbiome);
if (feature != null) { if (feature != null) {
BiomeAPI.addBiomeFeature(biome, feature); BiomeAPI.addBiomeFeature(biome, feature);
} }
if (id.getNamespace().equals(BetterEnd.MOD_ID)) { boolean hasCaves = bclbiome.getCustomData("has_caves", true) && !(bclbiome instanceof EndCaveBiome);
return; //TODO: 1.19 Test Cave generation
} if (hasCaves && !BiomeAPI.wasRegisteredAsEndVoidBiome(id) /*!BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(id)*/) {
if (Configs.BIOME_CONFIG.getBoolean(id, "hasCaves", true)) {
boolean hasCaves = bclbiome.getCustomData("has_caves", true) && !(bclbiome instanceof EndCaveBiome); BiomeAPI.addBiomeFeature(biome, ROUND_CAVE);
//TODO: 1.19 Test Cave generation BiomeAPI.addBiomeFeature(biome, TUNEL_CAVE);
if (hasCaves && !BiomeAPI.wasRegisteredAsEndVoidBiome(id) /*!BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(id)*/) { }
if (Configs.BIOME_CONFIG.getBoolean(id, "hasCaves", true)) {
BiomeAPI.addBiomeFeature(biome, ROUND_CAVE);
BiomeAPI.addBiomeFeature(biome, TUNEL_CAVE);
} }
} }
} }
private static BCLFeature<BuildingListFeature, BuildingListFeatureConfig> getBiomeStructures(BCLBiome biome) { private static BCLFeature<BuildingListFeature, BuildingListFeatureConfig> getBiomeStructures(BCLBiome biome) {
String ns = biome.getID().getNamespace(); return getBiomeStructures(biome.getID());
String nm = biome.getID().getPath(); }
private static BCLFeature<BuildingListFeature, BuildingListFeatureConfig> getBiomeStructures(ResourceLocation loc) {
String ns = loc.getNamespace();
String nm = loc.getPath();
return getBiomeStructures(ns, nm);
}
private static BCLFeature<BuildingListFeature, BuildingListFeatureConfig> getBiomeStructures(String ns, String nm) {
ResourceLocation id = new ResourceLocation(ns, nm + "_structures"); ResourceLocation id = new ResourceLocation(ns, nm + "_structures");
if (BuiltinRegistries.PLACED_FEATURE.containsKey(id)) { if (BuiltinRegistries.PLACED_FEATURE.containsKey(id)) {
throw new IllegalStateException("Feature for " + id + "was already build"); throw new IllegalStateException("Feature for " + id + " was already build");
} }
String path = "/data/" + ns + "/structures/biome/" + nm + "/"; String path = "/data/" + ns + "/structures/biome/" + nm + "/";
@ -1282,12 +1288,21 @@ public class EndFeatures {
return null; return null;
} }
public static BCLBiomeBuilder addDefaultFeatures(BCLBiomeBuilder builder, boolean hasCaves) { public static BCLBiomeBuilder addDefaultFeatures(
ResourceLocation biomeID,
BCLBiomeBuilder builder,
boolean hasCaves
) {
builder.feature(FLAVOLITE_LAYER); builder.feature(FLAVOLITE_LAYER);
builder.feature(THALLASIUM_ORE); builder.feature(THALLASIUM_ORE);
builder.feature(ENDER_ORE); builder.feature(ENDER_ORE);
builder.feature(CRASHED_SHIP); builder.feature(CRASHED_SHIP);
BCLFeature<BuildingListFeature, BuildingListFeatureConfig> feature = getBiomeStructures(biomeID);
if (feature != null) {
builder.feature(feature);
}
if (hasCaves) { if (hasCaves) {
builder.feature(ROUND_CAVE); builder.feature(ROUND_CAVE);
builder.feature(TUNEL_CAVE); builder.feature(TUNEL_CAVE);

View file

@ -117,7 +117,7 @@ public class EndBiome extends BCLBiome implements SurfaceMaterialProvider {
.surface(biomeConfig.surfaceMaterial().surface().build()); .surface(biomeConfig.surfaceMaterial().surface().build());
biomeConfig.addCustomBuildData(builder); biomeConfig.addCustomBuildData(builder);
EndFeatures.addDefaultFeatures(builder, biomeConfig.hasCaves()); EndFeatures.addDefaultFeatures(biomeConfig.ID, builder, biomeConfig.hasCaves());
EndBiome biome = builder.build(biomeConfig.getSupplier()); EndBiome biome = builder.build(biomeConfig.getSupplier());