mojira.dev
MC-265381

Tamed cats panic when receiving damage

The Bug:

Tamed cats panic when receiving damage.

This behavior is inconsistent with wolves. Since the said cat is tamed, one would expect it not to panic when being attacked. This problem first appeared in 23w07a.

Steps to Reproduce:

  1. Tame a wolf, make it sit, and attack it.

  2. Take note of how the wolf begins standing but does not begin panicking.

  3. Tame a cat, make it sit, and attack it.

  4. Take note as to whether or not tamed cats panic when receiving damage.

Observed Behavior:

Tamed cats panic when receiving damage, which is inconsistent with the behavior of tamed wolves.

Expected Behavior:

Tamed cats would not panic when receiving damage, therefore maintaining consistency with the behavior of tamed wolves.

Code Analysis:

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

Linked issues

Comments 1

Apollo30

Fix:

The following is based on a decompiled version of Minecraft 1.20.1 using MCP-Reborn.
This is a solution to fix the problem of tamed cats panicking whenever their owner attacked it.   

net.minecraft.world.entity.animal.Cat.java

protected void registerGoals() {
   this.temptGoal = new Cat.CatTemptGoal(this, 0.6D, TEMPT_INGREDIENT, true);
   this.goalSelector.addGoal(1, new FloatGoal(this));
   this.goalSelector.addGoal(1, new CatPanicGoal(1.5D));
   ...
}

...

class CatPanicGoal extends PanicGoal {
   public CatPanicGoal(double p_203124_) {
      super(Cat.this, p_203124_);
   }

   protected boolean shouldPanic() {
      return (this.mob.getLastHurtByMob() != null && !this.mob.getLastHurtByMob().equals(Cat.this.getOwner())) || this.mob.isFreezing() || this.mob.isOnFire();
   }
}

The old Cat.java file used the normal PanicGoal which determines if the entity should panic.

In it, it checked if this.mob.getLastHurtByMob() != null but never checked if the damager is the owner.

Avoma

(Unassigned)

Confirmed

Gameplay

Normal

Mob behaviour

cat

1.20.1, 1.20.2 Pre-Release 3, 1.20.2, 23w51b, 24w10a, ..., 24w21b, 1.21, 1.21.4, 1.21.5, 25w21a

Retrieved