Jump to content

[1.15.2] onKillEntity not being called on player death


SSilvamc

Recommended Posts

The onKillEntity method seems to work with any entity, but it doesn't seem to be activated when a player dies.

I figure I can get over this issue by using the LivingDeathEvent and checking whether the entity in question is a player, but i just want to know if this is an error or an intended feature (or, if there is another method I could use besides the event).

Link to comment
Share on other sites

5 hours ago, Animefan8888 said:

onKillEntity method in what class?

I was using it with FallingBlockEntity. Then again, that class does not override onKillEntity, it just takes it from the Entity class. 

 

This was my code:

Spoiler

public class BeheadingBladeEntity extends FallingBlockEntity {

	public BeheadingBladeEntity(World worldIn, double x, double y, double z, BlockState fallingBlockState) {
		super(worldIn, x, y, z, fallingBlockState);
	}

	public boolean onLivingFall(float distance, float damageMultiplier) {
		int i = MathHelper.ceil(distance - 1.0F);
		if (i > 0) {
			List<Entity> list = Lists.newArrayList(this.world.getEntitiesWithinAABBExcludingEntity(this, this.getBoundingBox()));
			for(Entity entity : list) {		
				Random rand = new Random();
				int val = rand.nextInt(5);
				IndirectEntityDamageSource source = new IndirectEntityDamageSource("guillotine" + Integer.toString(val), this, this);
				entity.attackEntityFrom(source, Float.MAX_VALUE);
			}
		}
		return false;
	}

	@Override
	public void onKillEntity(LivingEntity entityLivingIn) {
		System.out.println("Entity killed: " + entityLivingIn);
	}

}

 

This gets called whenever any entity is killed, but not when the player is killed.

I'm using an IndirectEntityDamageSource because the onDeath method in LivingEntity (which is where the onKillEntity method is triggered; it's the only reference to such method in the code, apart from the one in ZombieEntity which turns villagers to zombie villagers) gets the entity causing the damage with getTrueSource(), and if I use a simple DamageSource, this is set to null (and the onKillEntity method is never called)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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