Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author
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)

  • Author
Just now, diesieben07 said:

You'll have to use LivingDeathEvent. onKillEntity is not called by ServerPlayerEntity#onDeath, which is where it would normally be called from.

Great! Thanks.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.