Jump to content

[SOLVED][1.12.2] onLivingDeath Event Multiple Calls For Ender Dragon


Recommended Posts

In my mod I use the onLivingDeath event to decide if a user has killed enough of a specific mob for something to occur.

I recently had an issue raised on GitHub where the user said that they could keep hitting the Dragon with arrows while it was dying and they could register multiple deaths.


I've added some debug to my event handler and sure enough, if I was quick enough with a bow I could get multiple events raised until a point in the EnderDragon death sequence



public class HandlerLivingDeathEvent {

    public void onLivingDeathEvent(LivingDeathEvent event) {

        LogHelper.info("onLivingDeathEvent: " + event.getSource() + "/" + event.getEntity() + "/" + event.getEntity().isDead);
        new Exception().printStackTrace();


Gave the output


[12:26:23] [Server thread/INFO]: Woot: onLivingDeathEvent: net.minecraft.util.EntityDamageSourceIndirect@70bea580/EntityDragon['Ender Dragon'/277010, l='Mob Test', x=7.20, y=84.56, z=-28.32]/false
[12:26:23] [main/INFO]: Woot: onLivingDeathEvent: net.minecraft.util.DamageSource@369d50fa/EntityDragon['Ender Dragon'/277010, l='MpServer', x=7.50, y=84.50, z=-29.54]/false
[12:26:24] [Server thread/INFO]: Woot: onLivingDeathEvent: net.minecraft.util.EntityDamageSourceIndirect@764bce76/EntityDragon['Ender Dragon'/277010, l='Mob Test', x=7.99, y=80.26, z=-24.57]/false
[12:26:25] [Server thread/INFO]: Woot: onLivingDeathEvent: net.minecraft.util.EntityDamageSourceIndirect@4a8c7eaa/EntityDragon['Ender Dragon'/277010, l='Mob Test', x=9.94, y=68.92, z=-15.77]/false


So I managed three server events for onLivingDeath and one client event.

On another run I managed to get six server events and one client event.

I'm only summoning one EnderDragon so it can only be for the one mob.


Dumping the stack for the server event showed the same path for each event

[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at ipsis.woot.event.HandlerLivingDeathEvent.onLivingDeathEvent(HandlerLivingDeathEvent.java:21)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_188_HandlerLivingDeathEvent_onLivingDeathEvent_LivingDeathEvent.invoke(.dynamic)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraftforge.common.ForgeHooks.onLivingDeath(ForgeHooks.java:600)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraft.entity.EntityLivingBase.onDeath(EntityLivingBase.java:1282)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:1127)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraft.entity.boss.EntityDragon.attackDragonFrom(EntityDragon.java:643)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraft.entity.boss.EntityDragon.attackEntityFromPart(EntityDragon.java:601)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraft.entity.MultiPartEntityPart.attackEntityFrom(MultiPartEntityPart.java:51)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraft.entity.projectile.EntityArrow.onHit(EntityArrow.java:391)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraft.entity.projectile.EntityArrow.onUpdate(EntityArrow.java:286)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraft.entity.projectile.EntityTippedArrow.onUpdate(EntityTippedArrow.java:110)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2168)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:871)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraft.world.World.updateEntity(World.java:2127)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraft.world.World.updateEntities(World.java:1928)
[12:29:54] [Server thread/INFO]: [ipsis.woot.event.HandlerLivingDeathEvent:onLivingDeathEvent:21]: 	at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:643)


This is using Forge 1.12.2-

I have a few mods in my dev environment for testing, but nothing is jumping out as having any impact on the Dragon death sequence.

Looking at the methods in the stack trace I'm not seeing any obvious path that allows this.


attackEntityFromPart(dragonPart, source, damage)
	damage = modify damage if neede
	attackDragonFrom(source, damage)
		attackEntityFrom(source, damage)	
			raise onLivingAttack event
			if health <= 0.0F
			if health <= 0.0F
					raise onLivingDeath event


So am I just using the wrong event to register the death occurring in my code, or is this a known "quirk" of the Dragon death and the fact that it is a multi-part mob?

Edited by Ipsissimus418
Add clarification of Dragon quirk thoughts.
Link to comment
Share on other sites

Dragons stay alive after death to show their death beaming thing. You can see this by shooting them with projectiles very fast when they are "dead", they will still get knocked back, and if knocked back far enough will start moving around again. They also start rotating in apparently random directions when hit at this stage. 

Hope this helps

  • Like 1

About Me


My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

That actually fits in with a piece of code in EntityDragon


if health <= 0.0F && !currentphase.isStationary


That seems to tick the Dragon back up by 1 health if you attack it while it is dying, but still moving.

It would therefore be allowed to reach the onDeath multiple times as the health > 0.0F.


If that is the case, I might try caching the last EntityID in my event handler to try and filter out the duplicate Dragon ones. It wont be 100% successful, but it should cut them down a bit.

Link to comment
Share on other sites

I've started to cache the last few entity.getCachedUniqueIdString and then used that to compare incoming event, then dropping the event if I've already seen that id.

This seems to filter out the multiple Dragon ones without having any obvious impact on other entity deaths.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.