mojira.dev
MC-312831

Allays are invulnerable to damage with BYPASSES_INVULNERABILITY tag by player they are linked to.

Issue: Allays are invulnerable to damage with BYPASSES_INVULNERABILITY tag by player they are linked to.

Mechanism: In 26.3, the class net.minecraft.world.entity.animal.allay.Allay overrides the hurtServer method. Its implementation directly returns false if this.isLikedPlayer(source.getEntity()) without &&!source.is(DamageTypeTags.BYPASSES_INVULNERABILITY). As a result, even if the damage has the BYPASSES_INVULNERABILITY tag, “Target is invulnerable to the given damage type” may still occur. The decompiled code is as follows:

    public boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage) {
        return this.isLikedPlayer(source.getEntity()) ? false : super.hurtServer(level, source, damage);
    }

    private boolean isLikedPlayer(final @Nullable Entity other) {
        if (!(other instanceof Player player)) {
            return false;
        } else {
            Optional<UUID> likedPlayer = this.getBrain().getMemory(MemoryModuleType.LIKED_PLAYER);
            return likedPlayer.isPresent() && player.getUUID().equals(likedPlayer.get());
        }
    }

Steps to Reproduce:

  1. Give an Allay an item;

  2. Use /damage uuid 1000 minecraft:out_of_world by @p and /damage uuid 1000 minecraft:generic_kill by @p.

Expected: Damage types with the BYPASSES_INVULNERABILITY tag should live up to their name and must not be blocked by any form of damage invulnerability ability. Even if the damage comes from the player the Allay is linked to, the BYPASSES_INVULNERABILITY tag should not become a misnomer. This is a principle of mechanical design.

Fix: Add an additional check.

@Override
public boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage) {
    return this.isLikedPlayer(source.getEntity()) && !source.is(DamageTypeTags.BYPASSES_INVULNERABILITY) ? false : super.hurtServer(level, source, damage);
}

Attachments

Comments 1

Thank you for helping us improve Minecraft! We saved your files:

[media]

SekaiDorem

(Unassigned)

Unconfirmed

26.3

Retrieved