The Bug
Suspending mobs from leashes in the air then moving the fence post with a piston causes the mob to die when they hit the ground regardless of the height they fall.
I expected the mob to survive a fall of 1-3 blocks in height, but to die from long falls.
Instead the mob dies even if it only falls one block to the ground.
Put a fence post up in the air at least high enough that it holds the mob off the ground by one or more blocks.
Put a piston up against the fence post.
Attach a mob to the fence post with a leash.
Activate the piston moving the post.
The leash will break.
The mob will die.
Additionally a player riding a saddled mob will die too (from MC-100443)
This works at any fall height of 1 or greater.
Code analysis and fix
Code analysis and fix by @unknown in this comment.
The problem lies in the method checkFallDamage()
in net.minecraft.world.entity.Entity.java
:
net.minecraft.world.entity.Entity.java (Mojang mappings, 1.18-pre5, variable renamings)
protected void checkFallDamage(double heightDifference, boolean onGround, BlockState landedState, BlockPos landedPosition) {
if (onGround) {
...
}
this.resetFallDistance();
} else if (heightDifference < 0.0) {
this.fallDistance = (float)((double)this.fallDistance - heightDifference);
}
}
Fixed code:
protected void checkFallDamage(...) {
if (onGround) {
...
}
this.resetFallDistance();
} else if (heightDifference < 0.0D) {
this.fallDistance = (float)((double)this.fallDistance - heightDifference);
} else if (heightDifference > 0.0D) {
//Add back in the heightDifference if going upwards
this.fallDistance = Math.max((float)((double) this.fallDistance - heightDifference),0);
}
}
Linked issues
relates to 2
Comments 30
I speculate that this happens because of suspended mobs accumulating fall distance (Like zombie pigman in lava lakes before)
Confirmed, but it does not only happen when you break leads, when you fly around with a tied mob, and you get the mob to the floor, it gets fall damage (and it mostly dies).
Confirmed for 1.18 pre-5
I added @unknown's fix to the bug description, using Mojang mappings. If I overlooked something, please let me know as I'm not a programmer.
In my opinion, this way of calculating fall damage is flawed and not realistic.
Instead, I propose calculating fall damage based on the velocity of the entity before hitting the ground. You can tune this calculation to replicate the current behaviour of 3 blocks = damage knowing Minecraft's gravitational constant.
This technique also allows Mojang to remove any specific slow-falling conditions as the impact velocity would not be high enough to inflict damage.
I've experimented this too.