NPC Natural Spawning:

-Further small fixes to natural spawning.
-Fixed "Skipping Entity with id " console spam.
-Entity entries can now be set to null.
-Fixed incorrect event bus logic.
This commit is contained in:
Luis C.M committed 2022-10-31 17:48:53 -05:00
1 parent 62c54e24e8
commit 45bda8ffe1
2 files changed
+13 -4

No files matched your search

+12 -3
View File
@@ -156,6 +156,10 @@ public class NPCSpawning {
for (NBTTagCompound compound : allCompoundList) {
Entity entity;
try {
Class<?> oclass = (Class<?>)EntityList.stringToClassMapping.get(compound.getString("id"));
if (oclass == null) {
continue;
}
entity = EntityList.createEntityFromNBT(compound, world);
} catch (Exception e) {
continue;
@@ -165,10 +169,15 @@ public class NPCSpawning {
}
}
if (entities.size() == 0) {
return false;
}
Entity spawnEntity = entities.get((int)Math.floor(Math.random()*entities.size()));
if(!(spawnEntity instanceof EntityLiving))
return false;
if (!(spawnEntity instanceof EntityLiving)) {
return false;
}
entityliving = (EntityLiving) spawnEntity;
@@ -192,7 +201,7 @@ public class NPCSpawning {
if (canSpawn == Result.DENY || (canSpawn == Result.DEFAULT && !canEntitySpawn(data,entityliving)))
return false;
if (!EventHooks.onCNPCNaturalSpawn(data, new BlockPos(x,y,z), NPCSpawning.animalSpawn, NPCSpawning.monsterSpawn, NPCSpawning.liquidSpawn, NPCSpawning.airSpawn)) {
if (EventHooks.onCNPCNaturalSpawn(data, new BlockPos(x,y,z), NPCSpawning.animalSpawn, NPCSpawning.monsterSpawn, NPCSpawning.liquidSpawn, NPCSpawning.airSpawn)) {
return false;
}
@@ -104,7 +104,7 @@ public class SpawnData extends WeightedRandom.Item implements INaturalSpawn {
slot = 5;
NBTTagCompound compound = new NBTTagCompound();
if (!entity.getMCEntity().writeToNBTOptional(compound)) {
if (entity != null && !entity.getMCEntity().writeToNBTOptional(compound)) {
throw new CustomNPCsException("Entity could not be written to NBT");
} else {
switch (slot) {