--- a/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
+++ b/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
@@ -63,7 +_,7 @@
     private static final String DRAGON_PHASE_KEY = "DragonPhase";
     private static final int DEFAULT_DEATH_TIME = 0;
     public final DragonFlightHistory flightHistory = new DragonFlightHistory();
-    private final EnderDragonPart[] subEntities;
+    public final EnderDragonPart[] subEntities;
     public final EnderDragonPart head;
     private final EnderDragonPart neck;
     private final EnderDragonPart body;
@@ -88,6 +_,10 @@
     private final Node[] nodes = new Node[24];
     private final int[] nodeAdjacency = new int[24];
     private final BinaryHeap openSet = new BinaryHeap();
+    // Paper start
+    private final net.minecraft.world.level.Explosion explosionSource; // Paper - reusable source for CraftTNTPrimed.getSource()
+    @Nullable private BlockPos podium;
+    // Paper end
 
     public EnderDragon(EntityType<? extends EnderDragon> entityType, Level level) {
         super(EntityType.ENDER_DRAGON, level);
@@ -103,6 +_,7 @@
         this.setHealth(this.getMaxHealth());
         this.noPhysics = true;
         this.phaseManager = new EnderDragonPhaseManager(this);
+        this.explosionSource = new net.minecraft.world.level.ServerExplosion(level.getMinecraftWorld(), this, null, null, new Vec3(Double.NaN, Double.NaN, Double.NaN), Float.NaN, true, net.minecraft.world.level.Explosion.BlockInteraction.DESTROY); // Paper
     }
 
     public void setDragonFight(EndDragonFight dragonFight) {
@@ -121,6 +_,19 @@
         return Mob.createMobAttributes().add(Attributes.MAX_HEALTH, 200.0).add(Attributes.CAMERA_DISTANCE, 16.0);
     }
 
+    // Paper start - Allow changing the EnderDragon podium
+    public BlockPos getPodium() {
+        if (this.podium == null) {
+            return EndPodiumFeature.getLocation(this.getFightOrigin());
+        }
+        return this.podium;
+    }
+
+    public void setPodium(@Nullable BlockPos blockPos) {
+        this.podium = blockPos;
+    }
+    // Paper end - Allow changing the EnderDragon podium
+
     @Override
     public boolean isFlapping() {
         float cos = Mth.cos(this.flapTime * (float) (Math.PI * 2));
@@ -212,7 +_,7 @@
                     }
 
                     Vec3 flyTargetLocation = currentPhase.getFlyTargetLocation();
-                    if (flyTargetLocation != null) {
+                    if (flyTargetLocation != null && currentPhase.getPhase() != EnderDragonPhase.HOVERING) { // CraftBukkit - Don't move when hovering
                         double d = flyTargetLocation.x - this.getX();
                         double d1 = flyTargetLocation.y - this.getY();
                         double d2 = flyTargetLocation.z - this.getZ();
@@ -367,7 +_,12 @@
             if (this.nearestCrystal.isRemoved()) {
                 this.nearestCrystal = null;
             } else if (this.tickCount % 10 == 0 && this.getHealth() < this.getMaxHealth()) {
-                this.setHealth(this.getHealth() + 1.0F);
+                // CraftBukkit start
+                org.bukkit.event.entity.EntityRegainHealthEvent event = new org.bukkit.event.entity.EntityRegainHealthEvent(this.getBukkitEntity(), 1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL);
+                if (event.callEvent()) {
+                    this.setHealth((float) (this.getHealth() + event.getAmount()));
+                }
+                // CraftBukkit end
             }
         }
 
@@ -397,7 +_,7 @@
                 double d2 = entity.getX() - d;
                 double d3 = entity.getZ() - d1;
                 double max = Math.max(d2 * d2 + d3 * d3, 0.1);
-                entity.push(d2 / max * 4.0, 0.2F, d3 / max * 4.0);
+                entity.push(d2 / max * 4.0, 0.2F, d3 / max * 4.0, this); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
                 if (!this.phaseManager.getCurrentPhase().isSitting() && livingEntity.getLastHurtByMobTimestamp() < entity.tickCount - 2) {
                     DamageSource damageSource = this.damageSources().mobAttack(this);
                     entity.hurtServer(level, damageSource, 5.0F);
@@ -430,6 +_,7 @@
         int floor5 = Mth.floor(box.maxZ);
         boolean flag = false;
         boolean flag1 = false;
+        List<org.bukkit.block.Block> destroyedBlocks = new java.util.ArrayList<>(); // Paper - Create a list to hold all the destroyed blocks
 
         for (int i = floor; i <= floor3; i++) {
             for (int i1 = floor1; i1 <= floor4; i1++) {
@@ -438,7 +_,11 @@
                     BlockState blockState = level.getBlockState(blockPos);
                     if (!blockState.isAir() && !blockState.is(BlockTags.DRAGON_TRANSPARENT)) {
                         if (level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) && !blockState.is(BlockTags.DRAGON_IMMUNE)) {
-                            flag1 = level.removeBlock(blockPos, false) || flag1;
+                            // CraftBukkit start - Add blocks to list rather than destroying them
+                            //flag1 = level.removeBlock(blockPos, false) || flag1;
+                            flag1 = true;
+                            destroyedBlocks.add(org.bukkit.craftbukkit.block.CraftBlock.at(level, blockPos));
+                            // CraftBukkit end
                         } else {
                             flag = true;
                         }
@@ -447,6 +_,58 @@
             }
         }
 
+        // CraftBukkit start - Set off an EntityExplodeEvent for the dragon exploding all these blocks
+        // SPIGOT-4882: don't fire event if nothing hit
+        if (!flag1) {
+            return flag;
+        }
+
+        org.bukkit.event.entity.EntityExplodeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityExplodeEvent(this, destroyedBlocks, 0F, this.explosionSource.getBlockInteraction());
+        if (event.isCancelled()) {
+            // This flag literally means 'Dragon hit something hard' (Obsidian, White Stone or Bedrock) and will cause the dragon to slow down.
+            // We should consider adding an event extension for it, or perhaps returning true if the event is cancelled.
+            return flag;
+        } else if (event.getYield() == 0F) {
+            // Yield zero ==> no drops
+            for (org.bukkit.block.Block block : event.blockList()) {
+                this.level().removeBlock(new BlockPos(block.getX(), block.getY(), block.getZ()), false);
+            }
+        } else {
+            for (org.bukkit.block.Block block : event.blockList()) {
+                org.bukkit.Material blockType = block.getType();
+                if (blockType.isAir()) {
+                    continue;
+                }
+
+                org.bukkit.craftbukkit.block.CraftBlock craftBlock = ((org.bukkit.craftbukkit.block.CraftBlock) block);
+                BlockPos pos = craftBlock.getPosition();
+
+                net.minecraft.world.level.block.Block nmsBlock = craftBlock.getNMS().getBlock();
+                if (nmsBlock.dropFromExplosion(this.explosionSource)) {
+                    net.minecraft.world.level.block.entity.BlockEntity blockEntity = craftBlock.getNMS().hasBlockEntity() ? this.level().getBlockEntity(pos) : null;
+                    net.minecraft.world.level.storage.loot.LootParams.Builder builder = new net.minecraft.world.level.storage.loot.LootParams.Builder((ServerLevel) this.level())
+                        .withParameter(net.minecraft.world.level.storage.loot.parameters.LootContextParams.ORIGIN, Vec3.atCenterOf(pos))
+                        .withParameter(net.minecraft.world.level.storage.loot.parameters.LootContextParams.TOOL, net.minecraft.world.item.ItemStack.EMPTY)
+                        .withParameter(net.minecraft.world.level.storage.loot.parameters.LootContextParams.EXPLOSION_RADIUS, 1.0F / event.getYield())
+                        .withOptionalParameter(net.minecraft.world.level.storage.loot.parameters.LootContextParams.BLOCK_ENTITY, blockEntity);
+
+                    craftBlock.getNMS().getDrops(builder).forEach((stack) -> {
+                        net.minecraft.world.level.block.Block.popResource(this.level(), pos, stack);
+                    });
+                    craftBlock.getNMS().spawnAfterBreak((ServerLevel) this.level(), pos, net.minecraft.world.item.ItemStack.EMPTY, false);
+                }
+                // Paper start - TNTPrimeEvent
+                org.bukkit.block.Block tntBlock = org.bukkit.craftbukkit.block.CraftBlock.at(this.level(), pos);
+                if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.EXPLOSION, explosionSource.getIndirectSourceEntity().getBukkitEntity()).callEvent())
+                    continue;
+                // Paper end - TNTPrimeEvent
+                nmsBlock.wasExploded((ServerLevel) this.level(), pos, this.explosionSource);
+
+                this.level().removeBlock(pos, false);
+            }
+        }
+        // CraftBukkit end
+
         if (flag1) {
             BlockPos blockPos1 = new BlockPos(
                 floor + this.random.nextInt(floor3 - floor + 1),
@@ -504,7 +_,15 @@
 
     @Override
     public void kill(ServerLevel level) {
-        this.remove(Entity.RemovalReason.KILLED);
+        // Paper start - Fire entity death event
+        this.silentDeath = true;
+        org.bukkit.event.entity.EntityDeathEvent deathEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDeathEvent(this, this.damageSources().genericKill());
+        if (deathEvent.isCancelled()) {
+            this.silentDeath = false; // Reset to default if event was cancelled
+            return;
+        }
+        this.remove(Entity.RemovalReason.KILLED, org.bukkit.event.entity.EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause
+        // Paper end - Fire entity death event
         this.gameEvent(GameEvent.ENTITY_DIE);
         if (this.dragonFight != null) {
             this.dragonFight.updateDragon(this);
@@ -526,18 +_,41 @@
             this.level().addParticle(ParticleTypes.EXPLOSION_EMITTER, this.getX() + f, this.getY() + 2.0 + f1, this.getZ() + f2, 0.0, 0.0, 0.0);
         }
 
+        // CraftBukkit start - SPIGOT-2420: Moved up to #getExpReward method
+        /*
         int i = 500;
         if (this.dragonFight != null && !this.dragonFight.hasPreviouslyKilledDragon()) {
             i = 12000;
         }
+         */
+        int i = this.expToDrop;
+        // CraftBukkit end
 
         if (this.level() instanceof ServerLevel serverLevel) {
-            if (this.dragonDeathTime > 150 && this.dragonDeathTime % 5 == 0 && serverLevel.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
-                ExperienceOrb.award(serverLevel, this.position(), Mth.floor(i * 0.08F));
+            if (this.dragonDeathTime > 150 && this.dragonDeathTime % 5 == 0) { // CraftBukkit - SPIGOT-2420: Already checked for the game rule when calculating the xp
+                ExperienceOrb.awardWithDirection(serverLevel, this.position(), net.minecraft.world.phys.Vec3.ZERO, Mth.floor(i * 0.08F), org.bukkit.entity.ExperienceOrb.SpawnReason.ENTITY_DEATH, net.minecraft.world.entity.EntityReference.get(this.lastHurtByPlayer, this.level(), Player.class), this); // Paper
             }
 
             if (this.dragonDeathTime == 1 && !this.isSilent()) {
-                serverLevel.globalLevelEvent(1028, this.blockPosition(), 0);
+                // CraftBukkit start - Use relative location for far away sounds
+                // serverLevel.globalLevelEvent(1028, this.blockPosition(), 0);
+                int viewDistance = serverLevel.getCraftServer().getViewDistance() * 16;
+                for (net.minecraft.server.level.ServerPlayer player : serverLevel.getPlayersForGlobalSoundGamerule()) { // Paper - respect global sound events gamerule
+                    double deltaX = this.getX() - player.getX();
+                    double deltaZ = this.getZ() - player.getZ();
+                    double distanceSquared = Mth.square(deltaX) + Mth.square(deltaZ);
+                    final double soundRadiusSquared = serverLevel.getGlobalSoundRangeSquared(config -> config.dragonDeathSoundRadius); // Paper - respect global sound events gamerule
+                    if (!serverLevel.getGameRules().getBoolean(GameRules.RULE_GLOBAL_SOUND_EVENTS) && distanceSquared > soundRadiusSquared) continue; // Paper - respect global sound events gamerule
+                    if (distanceSquared > Mth.square(viewDistance)) {
+                        double deltaLength = Math.sqrt(distanceSquared);
+                        double relativeX = player.getX() + (deltaX / deltaLength) * viewDistance;
+                        double relativeZ = player.getZ() + (deltaZ / deltaLength) * viewDistance;
+                        player.connection.send(new net.minecraft.network.protocol.game.ClientboundLevelEventPacket(net.minecraft.world.level.block.LevelEvent.SOUND_DRAGON_DEATH, new BlockPos((int) relativeX, (int) this.getY(), (int) relativeZ), 0, true));
+                    } else {
+                        player.connection.send(new net.minecraft.network.protocol.game.ClientboundLevelEventPacket(net.minecraft.world.level.block.LevelEvent.SOUND_DRAGON_DEATH, new BlockPos((int) this.getX(), (int) this.getY(), (int) this.getZ()), 0, true));
+                    }
+                }
+                // CraftBukkit end
             }
         }
 
@@ -550,15 +_,15 @@
         }
 
         if (this.dragonDeathTime == 200 && this.level() instanceof ServerLevel serverLevel1) {
-            if (serverLevel1.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
-                ExperienceOrb.award(serverLevel1, this.position(), Mth.floor(i * 0.2F));
+            if (true) { // Paper - SPIGOT-2420: Already checked for the game rule when calculating the xp
+                ExperienceOrb.awardWithDirection(serverLevel1, this.position(), net.minecraft.world.phys.Vec3.ZERO, Mth.floor(i * 0.2F), org.bukkit.entity.ExperienceOrb.SpawnReason.ENTITY_DEATH, net.minecraft.world.entity.EntityReference.get(this.lastHurtByPlayer, this.level(), Player.class), this); // Paper
             }
 
             if (this.dragonFight != null) {
                 this.dragonFight.setDragonKilled(this);
             }
 
-            this.remove(Entity.RemovalReason.KILLED);
+            this.remove(Entity.RemovalReason.KILLED, org.bukkit.event.entity.EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause
             this.gameEvent(GameEvent.ENTITY_DIE);
         }
     }
@@ -740,6 +_,7 @@
         super.addAdditionalSaveData(output);
         output.putInt("DragonPhase", this.phaseManager.getCurrentPhase().getPhase().getId());
         output.putInt("DragonDeathTime", this.dragonDeathTime);
+        output.putInt("Bukkit.expToDrop", this.expToDrop); // CraftBukkit - SPIGOT-2420: The ender dragon drops xp over time which can also happen between server starts
     }
 
     @Override
@@ -747,6 +_,7 @@
         super.readAdditionalSaveData(input);
         input.getInt("DragonPhase").ifPresent(integer -> this.phaseManager.setPhase(EnderDragonPhase.getById(integer)));
         this.dragonDeathTime = input.getIntOr("DragonDeathTime", 0);
+        this.expToDrop = input.getIntOr("Bukkit.expToDrop", 0); // CraftBukkit - SPIGOT-2420: The ender dragon drops xp over time which can also happen between server starts
     }
 
     @Override
@@ -768,17 +_,17 @@
     }
 
     @Override
-    protected SoundEvent getAmbientSound() {
+    public SoundEvent getAmbientSound() {
         return SoundEvents.ENDER_DRAGON_AMBIENT;
     }
 
     @Override
-    protected SoundEvent getHurtSound(DamageSource damageSource) {
+    public SoundEvent getHurtSound(DamageSource damageSource) {
         return SoundEvents.ENDER_DRAGON_HURT;
     }
 
     @Override
-    protected float getSoundVolume() {
+    public float getSoundVolume() {
         return 5.0F;
     }
 
@@ -787,7 +_,7 @@
         EnderDragonPhase<? extends DragonPhaseInstance> phase = currentPhase.getPhase();
         Vec3 viewVector;
         if (phase == EnderDragonPhase.LANDING || phase == EnderDragonPhase.TAKEOFF) {
-            BlockPos heightmapPos = this.level().getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, EndPodiumFeature.getLocation(this.fightOrigin));
+            BlockPos heightmapPos = this.level().getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, this.getPodium()); // Paper - Allow changing the EnderDragon podium
             float max = Math.max((float)Math.sqrt(heightmapPos.distToCenterSqr(this.position())) / 4.0F, 1.0F);
             float f = 6.0F / max;
             float xRot = this.getXRot();
@@ -875,4 +_,19 @@
     protected float sanitizeScale(float scale) {
         return 1.0F;
     }
+
+    // CraftBukkit start - SPIGOT-2420: Special case, the ender dragon drops 12000 xp for the first kill and 500 xp for every other kill and this over time.
+    @Override
+    public int getExpReward(ServerLevel level, Entity entity) {
+        // CraftBukkit - Moved from #tickDeath method
+        boolean flag = level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT);
+        int i = 500;
+
+        if (this.dragonFight != null && !this.dragonFight.hasPreviouslyKilledDragon()) {
+            i = 12000;
+        }
+
+        return flag ? i : 0;
+    }
+    // CraftBukkit end
 }
