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:
Switch into creative mode, summon a cow, and obtain a lead.
Attach the cow to the lead that you have.
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
is duplicated by 6
relates to 2
Attachments
Comments 27
Can confirm for MC 1.12.1. Related to MC-69216.
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.
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.