mojira.dev
MC-272431

Ender Dragon incorrect vertical velocity causes erratic behavior

Since 19w08b, the Ender Dragon's vertical velocity when flying to a target node has been incorrect, causing erratic behavior and difficulties flying towards its target, flying back and forth around it. This is most obvious on its perching phase, but also during its hover phase, when it is seen flying back and forth repetitively around its nodes.

This issue is responsible of MC-271336, MC-271337, and in some ways to MC-197201 as the dragon would often fail to reach the player when charging it after a perch. Contrary to what those reports suggest, it is unrelated to the dragon phase mechanic or to any fix given in 19w08b, and must have been introduced in an internal rewrite.

An earlier report,  MC-201937 described the same issue but was wrongfully ruled as invalid.

Expected behavior:
The dragon is able to fly up and dive down at the proper vertical velocity and reach its target with the shortest path possible, without needing to fly back and forth.

Steps to Reproduce:
There are several ways to reproduce it:

First way:
1. Go to the End, break all crystals and wait for the dragon to perch on the end podium
-> Notice how it roams back and forth while slowly descending to the podium

Second way:
1. Go to the End, break all crystals
2. Wait for it to perch, build a pillar with a significant height with respect to the end podium, several dozens of blocks away from the dragon, sufficiently far and close to it to charge you at the end of the perch
3. Stand on the pillar and Switch to survival mode
-> Notice how the dragon often fails to charge at the player and glides below the player

Third way (if you have sufficient knowledge of the Ender Dragon's AI):
1. Go to the End
2. Stand by a dragon AI pathfinding node
3. Wait until the dragon pathfinds to it
-> Notice how the dragon circles back and forth and around the target node

Code Analysis:
Before 19w08b, there is a portion of code in the method directing the dragon's movement towards its target (called "aiStep" in mojmaps) which adjusted the vertical velocity of the ender dragon by a certain amount:

(Decompiled from Release 1.12, MCP mappings)

Vec3d vec3d = iphase.getTargetLocation();
if (vec3d != null)
{
    double d6 = vec3d.xCoord - this.posX;
    double d7 = vec3d.yCoord - this.posY;
    double d8 = vec3d.zCoord - this.posZ;
    double d3 = d6 * d6 + d7 * d7 + d8 * d8;
    float f5 = iphase.getMaxRiseOrFall();
    d7 = MathHelper.clamp(d7 / (double)MathHelper.sqrt(d6 * d6 + d8 * d8), (double)(-f5), (double)f5);
    this.motionY += d7 * 0.10000000149011612D;
    ....

However, in versions after 19w08b, the same portion of code shows a tiny mistake:

(Decompiled from Release 1.20.6, Mojmaps, in EnderDragon::aiStep)

Vec3 vec32 = dragonPhaseInstance.getFlyTargetLocation();
if (vec32 != null) {
    double d = vec32.x - this.getX();
    double e = vec32.y - this.getY();
    double j = vec32.z - this.getZ();
    double k = d * d + e * e + j * j;
    float l = dragonPhaseInstance.getFlySpeed();
    double m = Math.sqrt(d * d + j * j);
    if (m > 0.0) {
        e = Mth.clamp(e / m, (double)(-l), (double)l);
    }

    this.setDeltaMovement(this.getDeltaMovement().add(0.0, e * 0.01, 0.0));
    ....

As shown here, the last line which modifies its vertical velocity, shows a mistake on the scaling factor (0.01 instead of 0.1).

The fix would be to change that scaling factor back to 0.1, which would fix all aforementioned issues related to the dragon behavior.

Linked issues

Comments

migrated

can confirm for 1.20.6

migrated

Can confirm for 24w21b

SeaOfPixels

Can confirm in 1.21.3 and 24w44a, it's worth noting that MC-158205, fixed in yesterday's snapshot, appeared in the same version as this bug.

Jukitsu

Note that the ramifications of this bug are quite large. Fixing this typo would virtually invalidate all strategies of speedrunning and one cycling.

SeaOfPixels

One cycling was possible before the bug was introduced, it may actually be faster to do even though it's more difficult, since you wouldn't have to wait for the dragon all the time, and the dragon would descend to the portal more often thanks to the fixed AI.

Jukitsu

Can confirm for 1.21.5

Jukitsu

(Unassigned)

Community Consensus

Gameplay

Normal

Mob behaviour

1.20.6, 24w21b, 1.21 Pre-Release 1, 1.21 Pre-Release 3, 1.21, ..., 1.21.2 Pre-Release 3, 1.21.3, 24w46a, 1.21.4, 25w03a

Retrieved