mojira.dev
MC-313782

`/kill` fails to kill the target if it is blocking with an item with a `blocks_attacks` component that reduces damage from the `generic_kill` type

Steps to Reproduce:

  1. run /give @p shield[unbreakable={},blocks_attacks={damage_reductions:[{type:["minecraft:generic_kill"],base:0,factor:1,horizontal_blocking_angle:180}]}] to get a Special Shield;

  2. place a Command Block and a Pressure Plate;

  3. step on the Pressure Plate while using Special Shield to block;

  4. You can see “Killed Player“ but you are still alive.

How to Fix:

The current implementation of the LivingEntity#kill method is:

@Override
public void kill(final ServerLevel level) {
    this.hurtServer(level, this.damageSources().genericKill(), Float.MAX_VALUE);
}

It only needs to be changed to:

@Override
public void kill(final ServerLevel level) {
    this.killLivingEntity(level);
}

private final void killLivingEntity(final ServerLevel level) {
    float originalDamage = Float.MAX_VALUE;
    float damage = Float.MAX_VALUE;
    DamageSource source = this.damageSources().genericKill();
    boolean blocked = false;
    this.stopSleeping();
    this.noActionTime = 0;
    this.lastHurt = damage;
    this.damageCooldownTime = 20;
    this.setAbsorptionAmount(0.0F);
    this.getCombatTracker().recordDamage(source, dmg);
    this.setHealth(0.0F);
    this.gameEvent(GameEvent.ENTITY_DAMAGE);
    this.hurtDuration = 10;
    this.hurtTime = this.hurtDuration;
    this.resolveMobResponsibleForDamage(source);
    this.resolvePlayerResponsibleForDamage(source);
    level.broadcastDamageEvent(this, source);
    this.markHurt();
    this.makeSound(this.getDeathSound());
    this.playSecondaryHurtSound(source);
    this.die(this.damageSources().genericKill());
    this.setLastDamageSource(source);
    for (MobEffectInstance effect : this.getActiveEffects()) {
        effect.onMobHurt(level, this, source, damage);
    }
    if (this instanceof ServerPlayer serverPlayer) {
        CriteriaTriggers.ENTITY_HURT_PLAYER.trigger(serverPlayer, source, originalDamage, damage, blocked);
    }
}

and it will be fixed.

Comments 0

No comments.

SekaiDorem

(Unassigned)

Confirmed

26.3, 26.4 Pre-Release 3

Retrieved