mojira.dev
MC-99785

You can leash entities in spectator mode

The Bug:

If you leash entities in creative mode, you can then switch to spectator and still be holding the leashed entity

Steps to Reproduce:

  1. Switch into creative mode, summon a cow, and obtain a lead.

  2. Attach the cow to the lead that you have.

  3. Switch into spectator mode and as you do this, take note as to whether the lead is still attached to the cow or not.

Observed Behavior:

Spectators can have leads attached to entities.

Expected Behavior:

Spectators would not be able to have leads attached to entities.

Code Analysis:

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

Linked issues

Attachments

Comments 27

This ticket is incomplete. Please review the guidelines before reporting issues.
For technical support please use the Mojang Support Center.

--- I am a robot. This action was performed automatically.

Confirmed for

  • 16w32a

Can confirm for MC 1.12.1. Related to MC-69216.

Affects 18w31a.

Confirmed in 1.16.1 and 20w27a.

17 more comments

Can confirm in 1.18.2.

Can confirm in 1.19.

Can confirm in 1.19.2.

Code Analysis:

The following is based on a decompiled version of Minecraft 1.20.1 using MCP-Reborn.

net.minecraft.world.entity.Mob.java // Original

public abstract class Mob extends LivingEntity implements Targeting {
   ...
   protected void tickLeash() {
      if (this.leashInfoTag != null) {
         this.restoreLeashFromSave();
      }      if (this.leashHolder != null) {
         if (!this.isAlive() || !this.leashHolder.isAlive()) {
            this.dropLeash(true, true);
         }
      }
   }
   ...
}

As you can see above, there is no check to see if this#leashHolder is in spectator mode.

Fix:

net.minecraft.world.entity.Mob.java // Updated

public abstract class Mob extends LivingEntity implements Targeting {
   ...
   protected void tickLeash() {
      if (this.leashInfoTag != null) {
         this.restoreLeashFromSave();
      }      if (this.leashHolder != null) {
         if (!this.isAlive() || !this.leashHolder.isAlive() || this.leashHolder.isSpectator()) {
            this.dropLeash(true, true);
         }
      }
   }
   ...
}

An easy solution is to add a check if the leashHolder is in spectator. If so, then we should drop the leash. 

Can confirm in 1.21 Pre-release 2.

Cameron H

(Unassigned)

Confirmed

Platform

Low

Items, Player

lead, leash, mob

Minecraft 1.9, Minecraft 1.10.2, Minecraft 16w32a, Minecraft 1.12.1, Minecraft 1.12.2, ..., 1.21 Pre-Release 4, 1.21, 24w46a, 1.21.4, 25w03a

Retrieved