Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-272431

Ender Dragon incorrect vertical velocity causes erratic behavior

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.20.6, 24w21b, 1.21 Pre-Release 1, 1.21 Pre-Release 3, 1.21 Release Candidate 1, 1.21, 24w33a, 1.21.1, 1.21.2 Pre-Release 3, 1.21.3, 24w46a
    • None
    • Windows 11, Java 17, Java 21
    • Community Consensus
    • Mob behaviour
    • Normal
    • Gameplay

      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.

            Unassigned Unassigned
            Jukitsu Jukitsu
            Votes:
            10 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              CHK: