mojira.dev
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:

[media]

[media]

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));
         }
      }

      . . .
   }

Linked issues

Attachments

Comments 6

Foxes can sometimes be dragged when sitting and facing you. They can be dragged when sleeping also until they are out of shade then they wake. Cannot reproduce issue of sitting in middair or the fox sliding away from player when attached to lead.

Can confirm in 20w51a.

Can confirm in 21w05b.

Can confirm in 21w06a.

Can confirm in 1.16.5 and 21w08b.

I would like to request ownership of this issue as I can confirm it in 23w41a, and noticed that the original poster has not kept up with this issue (inactive since 2019)

S

[Mod] Jingy

(Unassigned)

Confirmed

Mob behaviour

behavior, entity-data, fox, lead

Minecraft 19w14a, 20w09a, 1.16.2, 20w51a, 1.16.5, ..., 1.20.4 Release Candidate 1, 1.20.4, 24w09a, 1.20.5, 1.21.4

Retrieved