@SubscribeEvent
public void onSpecialSpawn(SpecialSpawn event) {
// When a mob spawns naturally, see if it has a chance to spawn with a backpack.
EntityLivingBase entity = event.entityLiving;
World world = entity.worldObj;
double probability = 0.0;
for (BetterStorageBackpack.BackpackSpawnEntry entry : BetterStorageBackpack.spawnWithBackpack) {
if (!entity.getClass().equals(entry.entityClass)) continue;
probability = entry.probability;
break;
}
if (!RandomUtils.getBoolean(probability) || entity.isChild()) return;
// If entity is a vanilla enderman, replace it with a friendly one.
if (entity.getClass().equals(EntityEnderman.class)) {
if ((BetterStorageTiles.enderBackpack != null) &&
// Don't spawn friendly endermen in the end or end biome, would make them too easy to get.
(world.provider.dimensionId != 1) &&
(world.getBiomeGenForCoords((int)entity.posX, (int)entity.posZ) != BiomeGenBase.sky)) {
EntityFrienderman frienderman = new EntityFrienderman(world);
frienderman.setPositionAndRotation(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, 0);
world.spawnEntityInWorld(frienderman);
ItemBackpack.getBackpackData(frienderman).spawnsWithBackpack = true;
entity.setDead();
}
// Otherwise, just mark it to spawn with a backpack.
} else if (BetterStorageTiles.backpack != null)
ItemBackpack.getBackpackData(entity).spawnsWithBackpack = true;