Solved EntityDeathEvent not being fired

dominikremes

New member
Sep 11, 2023
2
0
1
I'm working on a minigame, where the game throws in hoards of mobs (mostly zombies) for the players to fight off. I would like to have a counter, which counts down how many of the mobs are still alive, however I find the "check it on every x tick method" very unoptimized and for some reason counting down with the EntityDeathEvent is unreliable. I've found, that after fighting with tens or hundreds of mobs in a short time, sometimes, for some unknown reason the EntityDeathEvent is not triggered for a few mobs that when checked with the isDeath method report true.

I'm however not sure if the player is the one killing the mobs, a skeleton shoots them, a creeper kills some by exploding, or something else happens, but at the time that we get to the point, that there have been 200-300 mobs killed, I have 4-10 mobs that no longer exist, however the EntityDeathEvent was not fired for them. I've tried to find out what killed it by printing out the last cause of damage, but it gives null. When spawning the entities, I set them to be persistent, so they shouldn't despawn, also there isn't enough room for them to get far enough from the players to despawn.

I for sure know, that most of the times, when a player, skeleton, creeper or a zombie kills an another mob, it gets registered, however I wasn't able to notice an incident, when I could say for definite, that the kill was not registered (I'm not killing them 1 by 1, but in bulk, as they come, so it's hard to keep track of it).

Did anyone notice anything similar? Is there a fix to this?
 
Version Output
This server is running Paper version git-Paper-170 (MC: 1.20.1) (Implementing API version 1.20.1-R0.1-SNAPSHOT) (Git: 39953cf)
You are 24 version(s) behind
Download the new version at: https://papermc.io/downloads/paper

dominikremes

New member
Sep 11, 2023
2
0
1
Nevermind, found a solution. If anyone would have a similar problem in the future, try using the setRemoveWhenFarAway function and set it to false. If this is not set to false, it seems like the setPersistant is just ignored.