Death by Explosion?

Hi, trying to capture Explosions that cause entity death.

    public void MobDeath(DestructEntityEvent.Death event, @First EntityDamageSource src){
        Entity killer = src.getSource();
        Sponge.getGame().getServer().getBroadcastChannel().send(Text.of(killer));
    }

However no matter what combination i’ve tried nothing returns for when an explosion kills something…can someone point me in the right direction?

you mean src.isExplosive()?

ummm no that’s a boolean right?
I’m looking more for a way to target the player that caused the explosion? sort of like how in this below I identify what player killed the entity.

        if (src.getSource() instanceof Projectile){
    	Projectile projectile = (Projectile) src.getSource();
    	Optional<UUID> arrow = projectile.getCreator();

Does that make a bit more sense?

Also just another heads up i tried that just to see if it was captureing the explosion as the cause of death…and it doesn’t seem to pick up the explosion caused by tnt

    public void MobDeath(DestructEntityEvent.Death event, @First EntityDamageSource src){
    Entity killer = src.getSource();
    Sponge.getGame().getServer().getBroadcastChannel().send(Text.of(killer));
    
    if(src.isExplosive() == true) {
    	Sponge.getGame().getServer().getBroadcastChannel().send(Text.of("well ok then"));
    }

So the src.explosive part never actually sends the well…ok then message…

But when i change that to false and …it picks up the arrow that i use to kill it and says well ok then…is the tnt not under the isExplosive?

I don’t know off the top of my head what the cause stack at that point would be, or what type of DamageSource it would be. Why don’t you tell it to print out the entire cause on every damage event, and then explode yourself and see what the cause ends up being?

yea…that’s a good idea…if that doesn’t work i’ll repost on here…thanks!

so yea i’m sure you’re busy but even that isn’t working…I’ll try fiddling with it a bit more. But i’m not getting any information from it.

k…So here’s the code i used to find this info…

public void Destruction(DamageEntityEvent event) {
	Sponge.getGame().getServer().getBroadcastChannel().send(Text.of(event.getCause()));
	
}

then the stack i get back is this

Cause[Context=Context[], Stack={DamageSource{Name=explosion, Type=custom}, net.minecraft.world.Explosion@36abfa76, EntityTNTPrimed['Block of TNT'/565, l='world', x=-319.54, y=67.00, z=139.51]}]

So because I’m fairly new at deconstructing one of these…I see that the the cause is primed tnt…but how would i check for this from EntityDamageSource and not soley from the DamageSource?

Well, you wouldn’t. You’d just get the TNT directly from the Cause, because it’s right there.

ok lol then i’m soo lost

@First PrimedTNT tnt
1 Like