Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-147476

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • Minecraft 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
    • Confirmed
    • Mob behaviour

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

            Unassigned Unassigned
            Jingy [Helper] Jiingy
            Votes:
            6 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              CHK: