Mojira Archive
MC-147476

Foxes do not stop sitting or sleeping when pulled by a lead

If the player attaches a lead to a fox that is either sittingor sleeping, the fox will not transition to the standing position.

Steps to Reproduce:

  1. Summon a sitting/sleeping fox:
    /summon fox ~ ~ ~ {Sitting:1b}
    /summon fox ~ ~ ~ {Sleeping:1b}
  2. Put a lead on it
  3. Pull the entity away from it's original position

Observed Results:

The fox will remain sitting/sleeping and appear to be dragged across the ground.

Expected Results:

The fox would properly stand up before being pulled by a lead.

Screenshots/Videos:

Code Analysis / Fix:

One way to fix the issue is inside the 'tick()' method of the fox, we check to see if the fox is leashed, and if the leash owner is a player. If both conditions are met, set the fox's sleeping and sitting state to false.

Class: net\minecraft\world\entity\animal\Fox.java - Method: tick()
   public void tick() {
      super.tick();
      if (this.isEffectiveAi()) {
         boolean flag = this.isInWater();
         if (flag || this.getTarget() != null || this.level().isThundering()) {
            this.wakeUp();
         }

         if (flag || this.isSleeping()) {
            this.setSitting(false);
         }
         
// FIX START
         Entity entity = this.getLeashHolder();
         if (this.isLeashed() && entity instanceof Player) {
            this.setSitting(false);
            this.wakeUp();
         }
// FIX END

         if (this.isFaceplanted() && this.level().random.nextFloat() < 0.2F) {
            BlockPos blockpos = this.blockPosition();
            BlockState blockstate = this.level().getBlockState(blockpos);
            this.level().levelEvent(2001, blockpos, Block.getId(blockstate));
         }
      }

      . . .
   }

Unresolved

[Mod] Jiingy

S

2019-04-05, 01:00 AM

2024-12-11, 04:12 PM

6

3

Confirmed

Mob behaviour

behavior, entity-data, fox, lead

Minecraft 19w14a - 1.21.4Minecraft 19w14a, 20w09a, 1.16.2, 20w51a, 1.16.5, 21w06a, 21w08b, 1.20.2, 23w41a, 23w42a, 23w43a, 23w46a, 1.20.3, 1.20.4 Release Candidate 1, 1.20.4, 24w09a, 1.20.5, 1.21.4

-