mojira.dev
MC-176758

Tamed mules show heart particles after being fed, even though they cant breed

Tamed mules will show heart particles after being fed, despite the fact that they are not able to breed.

Steps to Reproduce:

  1. Run this command twice to summon two tamed mules

    /summon mule ~ ~ ~ {Tame:1b}
  2. Feed both mules an item they like

    /give @p golden_carrot

Observed Results:

The mules will both display heart particles.

Expected Results:

The mules would not show heart particles, as they are not in love and will not breed.

Screenshots/Videos:

[media]

Code Analysis / MCP-Reborn 1.20.2

Here in the handleEntityEvent() method of Animal.java, the game first checks to see if the event id is equal to 18 (18 is the "IN_LOVE_HEARTS" event) and if that is true, then the heart particles are displayed around the entity. However, it never checks to see if that entity is capable of breeding.

Class: net\minecraft\world\entity\animal\Animal.java - Method: handleEntityEvent()
public void handleEntityEvent(byte eventId) {
      if (eventId == 18) {
         for(int i = 0; i < 7; ++i) {
            double z1 = this.random.nextGaussian() * 0.02D;
            double z2 = this.random.nextGaussian() * 0.02D;
            double z3 = this.random.nextGaussian() * 0.02D;
            this.level().addParticle(ParticleTypes.HEART, this.getRandomX(1.0D), this.getRandomY() + 0.5D, this.getRandomZ(1.0D), z1, z2, z3);
         }
      } else {
         super.handleEntityEvent(eventId);
      }
   }

Possible Fix

A possible fix for this issue, is to do the following two things:

  1. Add an extra check inside of the handleEntityEvent() method to see if the entity is capable of falling in love before displaying the particles

public void handleEntityEvent(byte eventId) {
Fix Start
      if (eventId == 18 && this.canFallInLove()) {
Fix End
         for(int i = 0; i < 7; ++i) {
            double d0 = this.random.nextGaussian() * 0.02D;
            double d1 = this.random.nextGaussian() * 0.02D;double d2 = this.random.nextGaussian() * 0.02D;
            this.level().addParticle(ParticleTypes.HEART, this.getRandomX(1.0D), this.getRandomY() + 0.5D, this.getRandomZ(1.0D), d0, d1, d2);
         }
      } else {
         super.handleEntityEvent(eventId);
      }
   }
  1. Inside the Mule.java class, override the "canFallInLove()" method, and return false.

public boolean canFallInLove() {
      return false;
   }

This fix provides the following behavior:

[media]

Attachments

Comments 3

Some NBT tags for mobs that can breed are kept in the mule, which is LoveCause and InLove. Can confirm, but not sure if heart particles are suppose to appear. But hearts do appear if the mule has taken damage and healed by golden apples and enchanted apples.

Requesting ownership of this issue

[Mod] Jingy

(Unassigned)

Confirmed

Gameplay

Low

Mob behaviour

breeding, mule, particle

20w13b, 1.16.4 Release Candidate 1, 1.16.4, 1.20.2, 23w40a, 23w42a, 1.20.3, 1.20.4, 1.20.5

Retrieved