## Ravager can knock back ("teleport") entities very far away after being stunned

XMLWordPrintable
• Bug
• Resolution: Won't Fix
• None
• Minecraft 1.14.2, Minecraft 1.14.3 Pre-Release 2, Minecraft 1.14.3 Pre-Release 3, Minecraft 1.14.3 Pre-Release 4, Minecraft 1.14.3, Minecraft 1.14.4 Pre-Release 1, Minecraft 1.14.4 Pre-Release 2, Minecraft 1.14.4 Pre-Release 3
• Entities

### The bug

After a ravager has been stunned, they occasionally scream. This scream will push entities away from the ravager. How far away the entity will be knocked back depends on the position of the entity relative to the ravager. For instance, an armor stand that is directly above a ravager can travel a large distance in a very short amount of time, just by the knockback of the ravager.

Players can use this mechanic as well if they're riding another entity.

### Video

This is the video by 'SimplySarc' (who found the bug) where he shows it off the first time.

### Code analysis

What is happening:
When the Ravager attacks an entity, and that entity is shielding, he has a 50% chance to roar.
For the first two seconds, he is stunned. After another 0.5 seconds, he roars, knocking back players within 4 blocks of him.

The math to apply the knockback is as follows:

```double d0 = entity.locX - this.locX;
double d1 = entity.locZ - this.locZ;
double d2 = d0 * d0 + d1 * d1;
entity.f(d0 / d2 * 4.0D, 0.2D, d1 / d2 * 4.0D);
```

(where "entity" is the entity being knocked back, "this" is the ravager, and entity#f is the function that applies knockback.

Due to this bad math (no clamping or divide by zero checks), our velocity can reach huge numbers.
Conditions are simple: both entities must have very similar x and z values. (aka +-0.01 difference)

If the x and y are exactly the same (+-0 difference), NaN is added as the velocity, which thankfully doesn't break anything.
Big enough values will crash a server (link), due to a too long tick / too many missed.
See this for the crash: https://content.jame.xyz/sharex/mQRiWi3MfN.mp4

Edit 1: Here's the plugin used in the videos to test: https://github.com/electricman226/RavagerBug

[Mojang] slicedlime
Austin