[Fix] Empty Biomes in world generation and mob spawn could crash the game (quiqueck/BCLib#105)

This commit is contained in:
Frank 2023-06-23 08:14:31 +02:00
parent 3055ab1efa
commit 54f92ff686
12 changed files with 73 additions and 43 deletions

View file

@ -1,5 +1,7 @@
package org.betterx.betterend.entity;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
import org.betterx.betterend.registry.EndBiomes;
import org.betterx.betterend.registry.EndItems;
@ -51,7 +53,8 @@ public class CubozoaEntity extends AbstractSchoolingFish {
) {
SpawnGroupData data = super.finalizeSpawn(world, difficulty, spawnReason, entityData, entityTag);
if (BiomeAPI.getBiome(world.getBiome(blockPosition())).is(EndBiomes.SULPHUR_SPRINGS)) {
BCLBiome biome = BiomeAPI.getBiome(world.getBiome(blockPosition()));
if (!BCLBiomeRegistry.isEmptyBiome(biome) && biome.is(EndBiomes.SULPHUR_SPRINGS)) {
this.entityData.set(VARIANT, (byte) 1);
}

View file

@ -1,5 +1,7 @@
package org.betterx.betterend.entity;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
import org.betterx.betterend.registry.EndBiomes;
import org.betterx.betterend.registry.EndItems;
@ -59,7 +61,8 @@ public class EndFishEntity extends AbstractSchoolingFish {
) {
SpawnGroupData data = super.finalizeSpawn(world, difficulty, spawnReason, entityData, entityTag);
if (BiomeAPI.getBiome(world.getBiome(blockPosition())).equals(EndBiomes.SULPHUR_SPRINGS)) {
BCLBiome biome = BiomeAPI.getBiome(world.getBiome(blockPosition()));
if (!BCLBiomeRegistry.isEmptyBiome(biome) && biome.equals(EndBiomes.SULPHUR_SPRINGS)) {
this.entityData.set(VARIANT, (byte) (random.nextInt(VARIANTS_SULPHUR) + VARIANTS_NORMAL));
}

View file

@ -1,6 +1,7 @@
package org.betterx.betterend.entity;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
@ -95,14 +96,16 @@ public class EndSlimeEntity extends Slime {
) {
SpawnGroupData data = super.finalizeSpawn(world, difficulty, spawnReason, entityData, entityTag);
BCLBiome biome = BiomeAPI.getBiome(world.getBiome(blockPosition()));
if (biome.equals(EndBiomes.FOGGY_MUSHROOMLAND)) {
this.setMossy();
} else if (biome.equals(EndBiomes.MEGALAKE) || biome.equals(EndBiomes.MEGALAKE_GROVE)) {
this.setLake();
} else if (biome.equals(EndBiomes.AMBER_LAND)) {
this.setAmber();
if (!BCLBiomeRegistry.isEmptyBiome(biome)) {
if (biome.equals(EndBiomes.FOGGY_MUSHROOMLAND)) {
this.setMossy();
} else if (biome.equals(EndBiomes.MEGALAKE) || biome.equals(EndBiomes.MEGALAKE_GROVE)) {
this.setLake();
} else if (biome.equals(EndBiomes.AMBER_LAND)) {
this.setAmber();
}
this.refreshDimensions();
}
this.refreshDimensions();
return data;
}
@ -233,11 +236,13 @@ public class EndSlimeEntity extends Slime {
return false;
}
BCLBiome biome = BiomeAPI.getBiome(world.getBiome(pos));
if (biome.equals(EndBiomes.CHORUS_FOREST) || biome.equals(EndBiomes.MEGALAKE)) {
return true;
}
if (biome.equals(EndBiomes.MEGALAKE_GROVE) && random.nextBoolean()) {
return true;
if (!BCLBiomeRegistry.isEmptyBiome(biome)) {
if (biome.equals(EndBiomes.CHORUS_FOREST) || biome.equals(EndBiomes.MEGALAKE)) {
return true;
}
if (biome.equals(EndBiomes.MEGALAKE_GROVE) && random.nextBoolean()) {
return true;
}
}
return random.nextInt(4) == 0 && isWaterNear(world, pos);
}