Mojira Archive
MC-86836

Ender dragon can teleport through end_gateway

The bug

Ender dragons, like most entities, use end gateways when touching them. If, for some reason, the ender dragon flies through an end portal, it will be teleported through it, away from the main island and loaded chunks.

How to reproduce

/execute in minecraft:the_end run tp @p 0 80 5 180 -30
/setblock 0 ~5 0 minecraft:end_gateway{ExitPortal:{X:-100,Y:100,Z:0}} replace

Update: In 1.17 snapshots it requires several tries for this but to occur. It is inconsistent for some reason.

Code Analysis & Fix

Code Analysis done by [Mod] Anthony Cicinelli
The End Gateway allows all entities, including dragons to teleport through it. Simply doing a check in the canEntityTeleport method in the TheEndGatewayBlockEntity class for the ender dragon fixes this issue

Current Code

net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
   public static boolean canEntityTeleport(Entity p_59941_) {
          return EntitySelector.NO_SPECTATORS.test(p_59941_) && !p_59941_.getRootVehicle().isOnPortalCooldown();
   }

Fixed Code

net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
   public static boolean canEntityTeleport(Entity p_59941_) {
      //Check if the entity is the Ender Dragon fixes MC-86836 & MC-257097
      if(p_59941_ instanceof EnderDragon)
      {
         return false;
      }
      else {
         return EntitySelector.NO_SPECTATORS.test(p_59941_) && !p_59941_.getRootVehicle().isOnPortalCooldown();
      }
   }