When tamed animals fall from high place, they can teleport to the player but not reset their fall distance, leading to death.
Steps to Reproduce:
Build a platform high in the air
Summon wolf on top of it
Punch the wolf off
→❌ It will teleport to the player and take a lot of damage/die because of fall damage.
Code analysis
Refer to this comment:
Attachments
Comments 23
Present in 1.13.2.
Tamed wolves are particularly strange. They will fall, die from fall damage while falling but then teleport to the player with low health.
Confirmed for 19w12b. I think the real bug here is that wolves take fall damage after teleporting, which doesn't happen when players are falling and then use an ender pearl. The same should happen with players when eating chorus fruit, which is why this might relate to MC-112133.
I feel like pet teleportation should simply reset fall damage the way other forms of survival teleportation (eg. ender pearls) do. That's the intuitive mechanic, and it makes the came more fun as a result.
Code Analysis (MCP):
Tamed mobs teleporting to their owners is handled inside the 'tick()' method of the FollowOwnerGoal class. Here, the game checks only the distanceToSqr of the owner before teleporting the Cat or Wolf pet to the player. There is no behavior as described in the issue to handle if the entity is falling, and how far.
net.minecraft.world.entity.ai.goal (1.20.1 Mojang Mappings)
public void tick() {
this.tamable.getLookControl().setLookAt(this.owner, 10.0F, (float)this.tamable.getMaxHeadXRot());
if (--this.timeToRecalcPath <= 0) {
this.timeToRecalcPath = this.adjustedTickDelay(10);
if (this.tamable.distanceToSqr(this.owner) >= 144.0D) {
this.teleportToOwner();
} else {
this.navigation.moveTo(this.owner, this.speedModifier);
}
}
}
Possible Fix:
To fix this behavior, the following can be done:
Check if the entity is not a flying entity (no need to reset fall damage of an entity that cannot take fall damage)
Check if the entity has at least fallen > 3.0 blocks distance downward (the maximum distance an entity can fall before taking fall damage)
If both checks are true, reset the entities fall damage.
(If I have missed any additional checks, let me know and I will update it)public void tick() { this.tamable.getLookControl().setLookAt(this.owner, 10.0F, (float)this.tamable.getMaxHeadXRot()); if (--this.timeToRecalcPath <= 0) { this.timeToRecalcPath = this.adjustedTickDelay(10); if (this.tamable.distanceToSqr(this.owner) >= 144.0D) { if (!(this.tamable instanceof FlyingAnimal) && this.tamable.fallDistance > 3.0F) { this.tamable.resetFallDistance(); } this.teleportToOwner(); } else { this.navigation.moveTo(this.owner, this.speedModifier); } } }
The fix provides the following expected behavior:
[media]
Still present in 1.13.1.