Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[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

 

eg.

public class HandlerLivingDeathEvent {

    @SubscribeEvent
    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-14.23.3.2655.

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
				return
			damageEntity
			if health <= 0.0F
				onDeath
					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 post
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

Spoiler

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 post
Share on other sites

That actually fits in with a piece of code in EntityDragon

 

attackDragonFrom
if health <= 0.0F && !currentphase.isStationary
	setHealth(1.0F)
	setPhase(DYING)

 

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 post
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 post
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.

Guest
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.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Hello everyone!   I'm working on a tree model visualizer object, that can draw a tree dynamically to the screen regardless of how many nodes or subtrees there are. The user can move the display with dragging, and here comes the problem I have. I need every object that is outside of the object to be hidden, like on the advancement screen in vanilla, however, no matter how hard I looked at the vanilla code, I wasn't being able to figure out a way to do this. Right now, my objects are visible outside of the object. That is what I don't want to happen How would I be able to make this happen? Any help is appreciated!
    • sorry i will talk in english. there is the debug.log of server and the client debug.log debug.log
    • Aww thanks i guess... Makes sense now.
    • I showed you that code...    it was this, and your 'complained' about the deferred register name, then went on about Objectholder (which to be fair was only there because the ONLY other example of doing this wasn't exactly knowledgeable as to what was happening or why. I'm trying to figure out why the following works, and the example wasn't exactly updated, so i had to use IDE feedback to get it to work properly, and I used setRegistryName as a way to prevent it from using my own name space....    -- To be clear i'm not sure what i did that caused it to work..  but it does Just to be clear  This is sitting where the package says it's sitting.   -mine are sitting in com.dephoegon.reclaim....   package net.minecraft; import com.dephoegon.reclaim.aid.block.sand; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.material.MaterialColor; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraftforge.common.ToolType; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.registries.ObjectHolder; @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) public class blockoverrides { public static final Block SAND = new sand(14406560, AbstractBlock.Properties.create(Material.SAND, MaterialColor.SAND) .harvestTool(ToolType.SHOVEL).harvestLevel(0) .hardnessAndResistance(0.5F).sound(SoundType.SAND) , "", "", "", true).setRegistryName("minecraft", "sand"); @SubscribeEvent public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) { blockRegistryEvent.getRegistry().registerAll ( SAND ); } public static final Item SAND_ITEM = new BlockItem(SAND, new Item.Properties().group(ItemGroup.BUILDING_BLOCKS)).setRegistryName("minecraft","sand"); @SubscribeEvent public static void registerItems(RegistryEvent.Register<Item> event) { event.getRegistry().registerAll ( SAND_ITEM ); } }  
    • From what I can .. gather, and I'm sure this is my confusion going on..        It has public Objects that are effectively the block registry calls. Wait?  Would it be possible to actually override a public object, and have it use it? ---      I'm not sure I understand,   though the only bit I can honestly gather from that is a string name key, & the block object calling a new instance of a block (sand, log, etc) with properties defined in those block classes, which are often calling abstractblocks for properties, and extending special classes (like fallingblock) which tend to fall onto blocks, then abstract blocks themselves.   perhaps I'm missing the forest for the trees (or missing the trees for the forest), but  I'm not getting how you meant that.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.