mojira.dev
MC-270793

Mobs with multiple entity type tags corresponding to effect immunity only respect one

Mobs with multiple entity type tags corresponding to effect immunity only respect one. This issue can be observed in 26.3 using datapacks, and can also be observed without datapacks in 26.4 Snapshot 3 & Snapshot 4, where Strays are now affected by Poison and Regeneration.

26.4 Snapshot 4 overview

Review the following method in LivingEntity.class:

public boolean canBeAffected(final MobEffectInstance newEffect) {
    if (this.is(EntityTypeTags.IMMUNE_TO_INFESTED)) {
         return !newEffect.is(MobEffects.INFESTED);
    } else if (this.is(EntityTypeTags.FREEZE_IMMUNE_ENTITY_TYPES)) {
       return !newEffect.is(MobEffects.FREEZING);
    } else if (this.is(EntityTypeTags.IMMUNE_TO_OOZING)) {
       return !newEffect.is(MobEffects.OOZING);
    } else {
       return !this.is(EntityTypeTags.IGNORES_POISON_AND_REGEN) ? true : !newEffect.is(MobEffects.REGENERATION) && !newEffect.is(MobEffects.POISON);
    }
}

It takes no great effort to see the problem: mobs which have multiple entity type tags granting them immunity to specific effects will only check the if clause of the first such tag. The logic of this method is backwards. It should be (I’ve also reordered the list so that it is alphabetical):

public boolean canBeAffected(final MobEffectInstance newEffect) {
    if (newEffect.is(MobEffects.FREEZING)) {
        return !this.is(EntityTypeTags.FREEZE_IMMUNE_ENTITY_TYPES);
    } else if (newEffects.is(MobEffects.INFESTED)) {
        return !this.is(EntityTypeTags.IMMUNE_TO_INFESTED);
    } else if (newEffects.is(MobEffects.OOZING)) {
        return !this.is(EntityTypeTags.IMMUNE_TO_OOZING);
    } else if (newEffects.is(MobEffects.POISON) || newEffects.is(MobEffects.REGENERATION)) {
        return !this.is(EntityTypeTags.IGNORES_POISON_AND_REGEN);
    }
    return true;
}

Impact on 26.3

In 26.3, Freezing does not yet exist, so no mobs have multiple of these tags by default. Reproducing the issue therefore requires a datapack:

  1. Enable the attached datapack, which adds chickens to the #immune_to_oozing and #immune_to_infested entity type tags

  2. Spawn a chicken

  3. Enable looking_at_entity_tags in debug options and confirm that the chicken you spawned has the minecraft:immune_to_oozing tag

  4. Splash the chicken with Oozing

  5. Kill the chicken
    ❌ Slimes spawn even though chickens are immune to Oozing through the datapack

Linked issues

Attachments

Comments 0

No comments.

Tis_awesomeness

Nathan Wolf

1222733

Confirmed

Platform HC

Normal

Data Packs

1.20.5 Pre-Release 2, 1.20.5 Pre-Release 3, 1.20.5 Pre-Release 4, 1.20.5 Release Candidate 1, 1.20.5 Release Candidate 2, , 25w43a, 1.21.11, 26.2, 26.3, 26.4 Snapshot 4

Retrieved