mojira.dev
MC-108592

Witches do not despawn correctly if they have a potion effect

The bug

Witches that have drank a fire resistant potion will no longer despawn if they are farther than 32m from a player but less than 128m from a player.

Hostile mobs normally despawn over time when farther than 32m but less than 128m from a player. Witches that have not drank a fire resistant potion will follow these rules. But if the witch drinks a fire resistant potions it will no longer follow these rules.

How to reproduce

  1. Place a witch inside a glass box with it standing on a magma block or lava. (see picture)

  2. Move the player 40m away from the witch.

  3. Wait indefinitely for the witch to despawn.

May also work with any potions the witch drinks.

These witches will still despawn if the player goes farther than 128m from them.

Code analysis

Code analysis by @unknown can be found in this comment.

Attachments

Comments 5

cannot reproduce: i lighted a witch on fire, went way above cloud level (140 blocks from the witch approx.), went back down, and the witch vanished.

u left the 128 block area so she despawned
u have to be more than 32 blocks from here and less than 128

I think this is working as intended(if unexpected).

Potion bottle being drunk counts as the mob holding an item. Interesting discovery though.

If the witch is holding an item similar to how a zombie hows a sword then it should despawn just as a zombie does. If the item that the witch is hold is picked off the ground then it should never despawn even if it's farther than 128m away from a player. It doesn't follow either rule.

This can be observed easiest with Witches as they drink their own potions, but it is affecting all mobs taking any damage they are not eligible to be taking for whatever reason (fire is the most obvious) (apart from general invulnerability, like blazes).

Reason:

Mobs despawn outside of the 32 block player radious randomly when their Entity.age (MCP 1.12 names) reaches 30s (600ticks) and RNG gods are against it. The reason why witches are not despawning is because in the EntityLivingBase.attackEntityFrom function the first thing that's set is Entity.age = 0 which I suppose is meant to refresh mobs AI tasks allowing them to wonder but as a side effect their despawn timer is reset as well. The problem is, that an entity damage can be voided within this function, yet still their age is reset. So a witch standing in fire, or magma blocks is attempting to take fire damage every tick which is voided due to their fire resistance effect, but this sets their age to 0 anyways. This is not desirable as the entity carries no sings of taking damage.

Solution:
I propose removing "this.entityAge = 0;" from beginnign of EntityLivingBase.attackEntityFrom and move it further down just after:

else if (flag1)
{
     this.playHurtSound(source);
}
this.entityAge = 0;

or even together with playHurtSound call. The reason is that's where entity takes a visual damage (tint is changed to red, hurt sound is played) which is much more intuitive that this entity woul not despawn for the next 30s from this point.

Ray

migrated

Confirmed

Minecraft 1.10.2, Minecraft 16w40a, Minecraft 16w41a, Minecraft 16w43a, Minecraft 1.11 Pre-Release 1, ..., Minecraft 1.12.1, Minecraft 1.12.2, Minecraft 17w48a, Minecraft 18w03b, Minecraft 18w16a

Minecraft 18w33a

Retrieved