The ender dragon is spawned by the BiomeEndDecorator for the chunk (0,0) during world population. It is placed at the coordinates (0,128,0) with a random rotation yaw.
After reducing the dragon's health to zero or less, the dragon will start its death animation. Also a deathTicks timer is started, which will be incremented every tick.
While the dragon is in this state, large explosion particles are continuously spawned. Also the dragon's motion is controlled by the deathUpdate method, moving it up by 0.1 blocks/tick but not horizontally.
1000 XP is dropped 10 times, every 5 ticks, while the deathTicks timer is between 150 and 200 (7.5 and 10 seconds).
While the deathTicks timer is between 180 and 200 (9 and 10 seconds) huge explosion particles are spawned.
When the timer reaches 200 (after 10 seconds) the dragon it set dead, 2000 XP are dropped and an end portal is spawned at the dragon's x and z coordinates but at y = 64.
The ender dragon chooses either a player or a location to fly to. If this player or location is less than 10 or more than 150 blocks radial distance away then a new player or location is chosen. A player is attempted to be chosen 50% of the time and may not be in spectator mode or be further than 150 blocks away. The location chosen otherwise is a random point in a 120×120×50 cuboid centered on (0,95,0).
Upon taking damage the ender dragon will choose a slightly random location close behind it (and upwards) as a target to fly to.
The ender dragon has noClip set to true meaning it cannot collide with any blocks or entities. However, it has its own version of collision management. Entities within a bounding box of its wings (expanded by 4 blocks vertically and down 2 blocks) are accelerated away from the centre of the corresponding bounding box and up by 0.2 blocks/tick². Entities within the bounding box of the dragon's head (expanded by 1 block) are dealt 10 damaged by the dragon (0 to players on peaceful, 6 on easy and 15 on hard difficulty).
If mobGriefing is true then any blocks within the bounding box of the dragon's head or body will be replaced with air, unless a block specifies otherwise. If any blocks are destroyed this way, then the dragon's speed is temporarily multiplied by 0.8 and large explosion particles are spawned.
Blocks that will not be destroyed are obsidian, end stone, bedrock, command blocks and barriers.
Attacking the Ender Dragon Edit
The ender dragon is immune to fire damage.
The dragon will only take damage from players and explosions.
When a part of the dragon other than it's head is damaged, then the damage dealt is recalculated using the following formula.
new damage = (damage / 4) + 1
This causes the dragon to take 1 damage (1/2 a heart) from sources that usually deal no damage (e.g. snowballs and eggs) after an indirect hit.