The bug
Puffed pufferfish can hurt the player even if it's dead.
How to reproduce
Summon a dying puffed pufferfish:
/summon minecraft:pufferfish ~ ~ ~ {Health:0f,PuffState:1}
→ ❌ Pufferfish can hurt the player while dying
Code analysis
Code analysis can be found in this comment.
Linked issues
Attachments
Comments 8
Code analysis (Mojang mappings, 21w11a): Pufferfish#playerTouch(Player)
does not check if the pufferfish is alive before hurting the player. A potential fix would just require this check:
...
@Override
public void playerTouch(Player $$0) {
if (this.isAlive()) {
int $$1 = this.getPuffState();
if ($$0 instanceof ServerPlayer && $$1 > 0 && $$0.hurt(DamageSource.mobAttack(this), (float)(1 + $$1))) {
if (!this.isSilent()) {
((ServerPlayer)$$0).connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.PUFFER_FISH_STING, 0.0f));
}
$$0.addEffect(new MobEffectInstance(MobEffects.POISON, 60 * $$1, 0), this);
}
}
}
...
Confirmed in 1.16.1 and 20w28a.