    001    package net.minecraft.entity.boss;
    002
    003    import cpw.mods.fml.relauncher.Side;
    004    import cpw.mods.fml.relauncher.SideOnly;
    005    import java.util.Iterator;
    006    import java.util.List;
    007    import net.minecraft.block.Block;
    008    import net.minecraft.block.BlockEndPortal;
    009    import net.minecraft.entity.Entity;
    010    import net.minecraft.entity.EntityLiving;
    011    import net.minecraft.entity.IEntityMultiPart;
    012    import net.minecraft.entity.item.EntityEnderCrystal;
    013    import net.minecraft.entity.item.EntityXPOrb;
    014    import net.minecraft.entity.player.EntityPlayer;
    015    import net.minecraft.util.AxisAlignedBB;
    016    import net.minecraft.util.DamageSource;
    017    import net.minecraft.util.MathHelper;
    018    import net.minecraft.util.Vec3;
    019    import net.minecraft.world.World;
    020
    021    public class EntityDragon extends EntityLiving implements IBossDisplayData, IEntityMultiPart
    022    {
    023        public double targetX;
    024        public double targetY;
    025        public double targetZ;
    026
    027        /**
    028         * Ring buffer array for the last 64 Y-positions and yaw rotations. Used to calculate offsets for the animations.
    029         */
    030        public double[][] ringBuffer = new double[64][3];
    031
    032        /**
    033         * Index into the ring buffer. Incremented once per tick and restarts at 0 once it reaches the end of the buffer.
    034         */
    035        public int ringBufferIndex = -1;
    036
    037        /** An array containing all body parts of this dragon */
    038        public EntityDragonPart[] dragonPartArray;
    039
    040        /** The head bounding box of a dragon */
    041        public EntityDragonPart dragonPartHead;
    042
    043        /** The body bounding box of a dragon */
    044        public EntityDragonPart dragonPartBody;
    045        public EntityDragonPart dragonPartTail1;
    046        public EntityDragonPart dragonPartTail2;
    047        public EntityDragonPart dragonPartTail3;
    048        public EntityDragonPart dragonPartWing1;
    049        public EntityDragonPart dragonPartWing2;
    050
    051        /** Animation time at previous tick. */
    052        public float prevAnimTime = 0.0F;
    053
    054        /**
    055         * Animation time, used to control the speed of the animation cycles (wings flapping, jaw opening, etc.)
    056         */
    057        public float animTime = 0.0F;
    058
    059        /** Force selecting a new flight target at next tick if set to true. */
    060        public boolean forceNewTarget = false;
    061
    062        /**
    063         * Activated if the dragon is flying though obsidian, white stone or bedrock. Slows movement and animation speed.
    064         */
    065        public boolean slowed = false;
    066        private Entity target;
    067        public int deathTicks = 0;
    068
    069        /** The current endercrystal that is healing this dragon */
    070        public EntityEnderCrystal healingEnderCrystal = null;
    071
    072        public EntityDragon(World par1World)
    073        {
    074            super(par1World);
    075            this.dragonPartArray = new EntityDragonPart[] {this.dragonPartHead = new EntityDragonPart(this, "head", 6.0F, 6.0F), this.dragonPartBody = new EntityDragonPart(this, "body", 8.0F, 8.0F), this.dragonPartTail1 = new EntityDragonPart(this, "tail", 4.0F, 4.0F), this.dragonPartTail2 = new EntityDragonPart(this, "tail", 4.0F, 4.0F), this.dragonPartTail3 = new EntityDragonPart(this, "tail", 4.0F, 4.0F), this.dragonPartWing1 = new EntityDragonPart(this, "wing", 4.0F, 4.0F), this.dragonPartWing2 = new EntityDragonPart(this, "wing", 4.0F, 4.0F)};
    076            this.setEntityHealth(this.getMaxHealth());
    077            this.texture = "/mob/enderdragon/ender.png";
    078            this.setSize(16.0F, 8.0F);
    079            this.noClip = true;
    080            this.isImmuneToFire = true;
    081            this.targetY = 100.0D;
    082            this.ignoreFrustumCheck = true;
    083        }
    084
    085        public int getMaxHealth()
    086        {
    087            return 200;
    088        }
    089
    090        protected void entityInit()
    091        {
    092            super.entityInit();
    093            this.dataWatcher.addObject(16, new Integer(this.getMaxHealth()));
    094        }
    095
    096        /**
    097         * Returns a double[3] array with movement offsets, used to calculate trailing tail/neck positions. [0] = yaw
    098         * offset, [1] = y offset, [2] = unused, always 0. Parameters: buffer index offset, partial ticks.
    099         */
    100        public double[] getMovementOffsets(int par1, float par2)
    101        {
    102            if (this.health <= 0)
    103            {
    104                par2 = 0.0F;
    105            }
    106
    107            par2 = 1.0F - par2;
    108            int var3 = this.ringBufferIndex - par1 * 1 & 63;
    109            int var4 = this.ringBufferIndex - par1 * 1 - 1 & 63;
    110            double[] var5 = new double[3];
    111            double var6 = this.ringBuffer[var3][0];
    112            double var8 = MathHelper.wrapAngleTo180_double(this.ringBuffer[var4][0] - var6);
    113            var5[0] = var6 + var8 * (double)par2;
    114            var6 = this.ringBuffer[var3][1];
    115            var8 = this.ringBuffer[var4][1] - var6;
    116            var5[1] = var6 + var8 * (double)par2;
    117            var5[2] = this.ringBuffer[var3][2] + (this.ringBuffer[var4][2] - this.ringBuffer[var3][2]) * (double)par2;
    118            return var5;
    119        }
    120
    121        /**
    122         * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
    123         * use this to react to sunlight and start to burn.
    124         */
    125        public void onLivingUpdate()
    126        {
    127            float var1;
    128            float var2;
    129
    130            if (!this.worldObj.isRemote)
    131            {
    132                this.dataWatcher.updateObject(16, Integer.valueOf(this.health));
    133            }
    134            else
    135            {
    136                var1 = MathHelper.cos(this.animTime * (float)Math.PI * 2.0F);
    137                var2 = MathHelper.cos(this.prevAnimTime * (float)Math.PI * 2.0F);
    138
    139                if (var2 <= -0.3F && var1 >= -0.3F)
    140                {
    141                    this.worldObj.playSound(this.posX, this.posY, this.posZ, "mob.enderdragon.wings", 5.0F, 0.8F + this.rand.nextFloat() * 0.3F, false);
    142                }
    143            }
    144
    145            this.prevAnimTime = this.animTime;
    146            float var3;
    147
    148            if (this.health <= 0)
    149            {
    150                var1 = (this.rand.nextFloat() - 0.5F) * 8.0F;
    151                var2 = (this.rand.nextFloat() - 0.5F) * 4.0F;
    152                var3 = (this.rand.nextFloat() - 0.5F) * 8.0F;
    153                this.worldObj.spawnParticle("largeexplode", this.posX + (double)var1, this.posY + 2.0D + (double)var2, this.posZ + (double)var3, 0.0D, 0.0D, 0.0D);
    154            }
    155            else
    156            {
    157                this.updateDragonEnderCrystal();
    158                var1 = 0.2F / (MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ) * 10.0F + 1.0F);
    159                var1 *= (float)Math.pow(2.0D, this.motionY);
    160
    161                if (this.slowed)
    162                {
    163                    this.animTime += var1 * 0.5F;
    164                }
    165                else
    166                {
    167                    this.animTime += var1;
    168                }
    169
    170                this.rotationYaw = MathHelper.wrapAngleTo180_float(this.rotationYaw);
    171
    172                if (this.ringBufferIndex < 0)
    173                {
    174                    for (int var25 = 0; var25 < this.ringBuffer.length; ++var25)
    175                    {
    176                        this.ringBuffer[var25][0] = (double)this.rotationYaw;
    177                        this.ringBuffer[var25][1] = this.posY;
    178                    }
    179                }
    180
    181                if (++this.ringBufferIndex == this.ringBuffer.length)
    182                {
    183                    this.ringBufferIndex = 0;
    184                }
    185
    186                this.ringBuffer[this.ringBufferIndex][0] = (double)this.rotationYaw;
    187                this.ringBuffer[this.ringBufferIndex][1] = this.posY;
    188                double var4;
    189                double var6;
    190                double var8;
    191                double var26;
    192                float var33;
    193
    194                if (this.worldObj.isRemote)
    195                {
    196                    if (this.newPosRotationIncrements > 0)
    197                    {
    198                        var26 = this.posX + (this.newPosX - this.posX) / (double)this.newPosRotationIncrements;
    199                        var4 = this.posY + (this.newPosY - this.posY) / (double)this.newPosRotationIncrements;
    200                        var6 = this.posZ + (this.newPosZ - this.posZ) / (double)this.newPosRotationIncrements;
    201                        var8 = MathHelper.wrapAngleTo180_double(this.newRotationYaw - (double)this.rotationYaw);
    202                        this.rotationYaw = (float)((double)this.rotationYaw + var8 / (double)this.newPosRotationIncrements);
    203                        this.rotationPitch = (float)((double)this.rotationPitch + (this.newRotationPitch - (double)this.rotationPitch) / (double)this.newPosRotationIncrements);
    204                        --this.newPosRotationIncrements;
    205                        this.setPosition(var26, var4, var6);
    206                        this.setRotation(this.rotationYaw, this.rotationPitch);
    207                    }
    208                }
    209                else
    210                {
    211                    var26 = this.targetX - this.posX;
    212                    var4 = this.targetY - this.posY;
    213                    var6 = this.targetZ - this.posZ;
    214                    var8 = var26 * var26 + var4 * var4 + var6 * var6;
    215
    216                    if (this.target != null)
    217                    {
    218                        this.targetX = this.target.posX;
    219                        this.targetZ = this.target.posZ;
    220                        double var10 = this.targetX - this.posX;
    221                        double var12 = this.targetZ - this.posZ;
    222                        double var14 = Math.sqrt(var10 * var10 + var12 * var12);
    223                        double var16 = 0.4000000059604645D + var14 / 80.0D - 1.0D;
    224
    225                        if (var16 > 10.0D)
    226                        {
    227                            var16 = 10.0D;
    228                        }
    229
    230                        this.targetY = this.target.boundingBox.minY + var16;
    231                    }
    232                    else
    233                    {
    234                        this.targetX += this.rand.nextGaussian() * 2.0D;
    235                        this.targetZ += this.rand.nextGaussian() * 2.0D;
    236                    }
    237
    238                    if (this.forceNewTarget || var8 < 100.0D || var8 > 22500.0D || this.isCollidedHorizontally || this.isCollidedVertically)
    239                    {
    240                        this.setNewTarget();
    241                    }
    242
    243                    var4 /= (double)MathHelper.sqrt_double(var26 * var26 + var6 * var6);
    244                    var33 = 0.6F;
    245
    246                    if (var4 < (double)(-var33))
    247                    {
    248                        var4 = (double)(-var33);
    249                    }
    250
    251                    if (var4 > (double)var33)
    252                    {
    253                        var4 = (double)var33;
    254                    }
    255
    256                    this.motionY += var4 * 0.10000000149011612D;
    257                    this.rotationYaw = MathHelper.wrapAngleTo180_float(this.rotationYaw);
    258                    double var11 = 180.0D - Math.atan2(var26, var6) * 180.0D / Math.PI;
    259                    double var13 = MathHelper.wrapAngleTo180_double(var11 - (double)this.rotationYaw);
    260
    261                    if (var13 > 50.0D)
    262                    {
    263                        var13 = 50.0D;
    264                    }
    265
    266                    if (var13 < -50.0D)
    267                    {
    268                        var13 = -50.0D;
    269                    }
    270
    271                    Vec3 var15 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.targetX - this.posX, this.targetY - this.posY, this.targetZ - this.posZ).normalize();
    272                    Vec3 var40 = this.worldObj.getWorldVec3Pool().getVecFromPool((double)MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F), this.motionY, (double)(-MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F))).normalize();
    273                    float var17 = (float)(var40.dotProduct(var15) + 0.5D) / 1.5F;
    274
    275                    if (var17 < 0.0F)
    276                    {
    277                        var17 = 0.0F;
    278                    }
    279
    280                    this.randomYawVelocity *= 0.8F;
    281                    float var18 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ) * 1.0F + 1.0F;
    282                    double var19 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ) * 1.0D + 1.0D;
    283
    284                    if (var19 > 40.0D)
    285                    {
    286                        var19 = 40.0D;
    287                    }
    288
    289                    this.randomYawVelocity = (float)((double)this.randomYawVelocity + var13 * (0.699999988079071D / var19 / (double)var18));
    290                    this.rotationYaw += this.randomYawVelocity * 0.1F;
    291                    float var21 = (float)(2.0D / (var19 + 1.0D));
    292                    float var22 = 0.06F;
    293                    this.moveFlying(0.0F, -1.0F, var22 * (var17 * var21 + (1.0F - var21)));
    294
    295                    if (this.slowed)
    296                    {
    297                        this.moveEntity(this.motionX * 0.800000011920929D, this.motionY * 0.800000011920929D, this.motionZ * 0.800000011920929D);
    298                    }
    299                    else
    300                    {
    301                        this.moveEntity(this.motionX, this.motionY, this.motionZ);
    302                    }
    303
    304                    Vec3 var23 = this.worldObj.getWorldVec3Pool().getVecFromPool(this.motionX, this.motionY, this.motionZ).normalize();
    305                    float var24 = (float)(var23.dotProduct(var40) + 1.0D) / 2.0F;
    306                    var24 = 0.8F + 0.15F * var24;
    307                    this.motionX *= (double)var24;
    308                    this.motionZ *= (double)var24;
    309                    this.motionY *= 0.9100000262260437D;
    310                }
    311
    312                this.renderYawOffset = this.rotationYaw;
    313                this.dragonPartHead.width = this.dragonPartHead.height = 3.0F;
    314                this.dragonPartTail1.width = this.dragonPartTail1.height = 2.0F;
    315                this.dragonPartTail2.width = this.dragonPartTail2.height = 2.0F;
    316                this.dragonPartTail3.width = this.dragonPartTail3.height = 2.0F;
    317                this.dragonPartBody.height = 3.0F;
    318                this.dragonPartBody.width = 5.0F;
    319                this.dragonPartWing1.height = 2.0F;
    320                this.dragonPartWing1.width = 4.0F;
    321                this.dragonPartWing2.height = 3.0F;
    322                this.dragonPartWing2.width = 4.0F;
    323                var2 = (float)(this.getMovementOffsets(5, 1.0F)[1] - this.getMovementOffsets(10, 1.0F)[1]) * 10.0F / 180.0F * (float)Math.PI;
    324                var3 = MathHelper.cos(var2);
    325                float var28 = -MathHelper.sin(var2);
    326                float var5 = this.rotationYaw * (float)Math.PI / 180.0F;
    327                float var27 = MathHelper.sin(var5);
    328                float var7 = MathHelper.cos(var5);
    329                this.dragonPartBody.onUpdate();
    330                this.dragonPartBody.setLocationAndAngles(this.posX + (double)(var27 * 0.5F), this.posY, this.posZ - (double)(var7 * 0.5F), 0.0F, 0.0F);
    331                this.dragonPartWing1.onUpdate();
    332                this.dragonPartWing1.setLocationAndAngles(this.posX + (double)(var7 * 4.5F), this.posY + 2.0D, this.posZ + (double)(var27 * 4.5F), 0.0F, 0.0F);
    333                this.dragonPartWing2.onUpdate();
    334                this.dragonPartWing2.setLocationAndAngles(this.posX - (double)(var7 * 4.5F), this.posY + 2.0D, this.posZ - (double)(var27 * 4.5F), 0.0F, 0.0F);
    335
    336                if (!this.worldObj.isRemote && this.hurtTime == 0)
    337                {
    338                    this.collideWithEntities(this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.dragonPartWing1.boundingBox.expand(4.0D, 2.0D, 4.0D).offset(0.0D, -2.0D, 0.0D)));
    339                    this.collideWithEntities(this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.dragonPartWing2.boundingBox.expand(4.0D, 2.0D, 4.0D).offset(0.0D, -2.0D, 0.0D)));
    340                    this.attackEntitiesInList(this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.dragonPartHead.boundingBox.expand(1.0D, 1.0D, 1.0D)));
    341                }
    342
    343                double[] var29 = this.getMovementOffsets(5, 1.0F);
    344                double[] var9 = this.getMovementOffsets(0, 1.0F);
    345                var33 = MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F - this.randomYawVelocity * 0.01F);
    346                float var32 = MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F - this.randomYawVelocity * 0.01F);
    347                this.dragonPartHead.onUpdate();
    348                this.dragonPartHead.setLocationAndAngles(this.posX + (double)(var33 * 5.5F * var3), this.posY + (var9[1] - var29[1]) * 1.0D + (double)(var28 * 5.5F), this.posZ - (double)(var32 * 5.5F * var3), 0.0F, 0.0F);
    349
    350                for (int var30 = 0; var30 < 3; ++var30)
    351                {
    352                    EntityDragonPart var31 = null;
    353
    354                    if (var30 == 0)
    355                    {
    356                        var31 = this.dragonPartTail1;
    357                    }
    358
    359                    if (var30 == 1)
    360                    {
    361                        var31 = this.dragonPartTail2;
    362                    }
    363
    364                    if (var30 == 2)
    365                    {
    366                        var31 = this.dragonPartTail3;
    367                    }
    368
    369                    double[] var35 = this.getMovementOffsets(12 + var30 * 2, 1.0F);
    370                    float var34 = this.rotationYaw * (float)Math.PI / 180.0F + this.simplifyAngle(var35[0] - var29[0]) * (float)Math.PI / 180.0F * 1.0F;
    371                    float var38 = MathHelper.sin(var34);
    372                    float var37 = MathHelper.cos(var34);
    373                    float var36 = 1.5F;
    374                    float var39 = (float)(var30 + 1) * 2.0F;
    375                    var31.onUpdate();
    376                    var31.setLocationAndAngles(this.posX - (double)((var27 * var36 + var38 * var39) * var3), this.posY + (var35[1] - var29[1]) * 1.0D - (double)((var39 + var36) * var28) + 1.5D, this.posZ + (double)((var7 * var36 + var37 * var39) * var3), 0.0F, 0.0F);
    377                }
    378
    379                if (!this.worldObj.isRemote)
    380                {
    381                    this.slowed = this.destroyBlocksInAABB(this.dragonPartHead.boundingBox) | this.destroyBlocksInAABB(this.dragonPartBody.boundingBox);
    382                }
    383            }
    384        }
    385
    386        /**
    387         * Updates the state of the enderdragon's current endercrystal.
    388         */
    389        private void updateDragonEnderCrystal()
    390        {
    391            if (this.healingEnderCrystal != null)
    392            {
    393                if (this.healingEnderCrystal.isDead)
    394                {
    395                    if (!this.worldObj.isRemote)
    396                    {
    397                        this.attackEntityFromPart(this.dragonPartHead, DamageSource.explosion, 10);
    398                    }
    399
    400                    this.healingEnderCrystal = null;
    401                }
    402                else if (this.ticksExisted % 10 == 0 && this.health < this.getMaxHealth())
    403                {
    404                    ++this.health;
    405                }
    406            }
    407
    408            if (this.rand.nextInt(10) == 0)
    409            {
    410                float var1 = 32.0F;
    411                List var2 = this.worldObj.getEntitiesWithinAABB(EntityEnderCrystal.class, this.boundingBox.expand((double)var1, (double)var1, (double)var1));
    412                EntityEnderCrystal var3 = null;
    413                double var4 = Double.MAX_VALUE;
    414                Iterator var6 = var2.iterator();
    415
    416                while (var6.hasNext())
    417                {
    418                    EntityEnderCrystal var7 = (EntityEnderCrystal)var6.next();
    419                    double var8 = var7.getDistanceSqToEntity(this);
    420
    421                    if (var8 < var4)
    422                    {
    423                        var4 = var8;
    424                        var3 = var7;
    425                    }
    426                }
    427
    428                this.healingEnderCrystal = var3;
    429            }
    430        }
    431
    432        /**
    433         * Pushes all entities inside the list away from the enderdragon.
    434         */
    435        private void collideWithEntities(List par1List)
    436        {
    437            double var2 = (this.dragonPartBody.boundingBox.minX + this.dragonPartBody.boundingBox.maxX) / 2.0D;
    438            double var4 = (this.dragonPartBody.boundingBox.minZ + this.dragonPartBody.boundingBox.maxZ) / 2.0D;
    439            Iterator var6 = par1List.iterator();
    440
    441            while (var6.hasNext())
    442            {
    443                Entity var7 = (Entity)var6.next();
    444
    445                if (var7 instanceof EntityLiving)
    446                {
    447                    double var8 = var7.posX - var2;
    448                    double var10 = var7.posZ - var4;
    449                    double var12 = var8 * var8 + var10 * var10;
    450                    var7.addVelocity(var8 / var12 * 4.0D, 0.20000000298023224D, var10 / var12 * 4.0D);
    451                }
    452            }
    453        }
    454
    455        /**
    456         * Attacks all entities inside this list, dealing 5 hearts of damage.
    457         */
    458        private void attackEntitiesInList(List par1List)
    459        {
    460            for (int var2 = 0; var2 < par1List.size(); ++var2)
    461            {
    462                Entity var3 = (Entity)par1List.get(var2);
    463
    464                if (var3 instanceof EntityLiving)
    465                {
    466                    var3.attackEntityFrom(DamageSource.causeMobDamage(this), 10);
    467                }
    468            }
    469        }
    470
    471        /**
    472         * Sets a new target for the flight AI. It can be a random coordinate or a nearby player.
    473         */
    474        private void setNewTarget()
    475        {
    476            this.forceNewTarget = false;
    477
    478            if (this.rand.nextInt(2) == 0 && !this.worldObj.playerEntities.isEmpty())
    479            {
    480                this.target = (Entity)this.worldObj.playerEntities.get(this.rand.nextInt(this.worldObj.playerEntities.size()));
    481            }
    482            else
    483            {
    484                boolean var1 = false;
    485
    486                do
    487                {
    488                    this.targetX = 0.0D;
    489                    this.targetY = (double)(70.0F + this.rand.nextFloat() * 50.0F);
    490                    this.targetZ = 0.0D;
    491                    this.targetX += (double)(this.rand.nextFloat() * 120.0F - 60.0F);
    492                    this.targetZ += (double)(this.rand.nextFloat() * 120.0F - 60.0F);
    493                    double var2 = this.posX - this.targetX;
    494                    double var4 = this.posY - this.targetY;
    495                    double var6 = this.posZ - this.targetZ;
    496                    var1 = var2 * var2 + var4 * var4 + var6 * var6 > 100.0D;
    497                }
    498                while (!var1);
    499
    500                this.target = null;
    501            }
    502        }
    503
    504        /**
    505         * Simplifies the value of a number by adding/subtracting 180 to the point that the number is between -180 and 180.
    506         */
    507        private float simplifyAngle(double par1)
    508        {
    509            return (float)MathHelper.wrapAngleTo180_double(par1);
    510        }
    511
    512        /**
    513         * Destroys all blocks that aren't associated with 'The End' inside the given bounding box.
    514         */
    515        private boolean destroyBlocksInAABB(AxisAlignedBB par1AxisAlignedBB)
    516        {
    517            int var2 = MathHelper.floor_double(par1AxisAlignedBB.minX);
    518            int var3 = MathHelper.floor_double(par1AxisAlignedBB.minY);
    519            int var4 = MathHelper.floor_double(par1AxisAlignedBB.minZ);
    520            int var5 = MathHelper.floor_double(par1AxisAlignedBB.maxX);
    521            int var6 = MathHelper.floor_double(par1AxisAlignedBB.maxY);
    522            int var7 = MathHelper.floor_double(par1AxisAlignedBB.maxZ);
    523            boolean var8 = false;
    524            boolean var9 = false;
    525
    526            for (int var10 = var2; var10 <= var5; ++var10)
    527            {
    528                for (int var11 = var3; var11 <= var6; ++var11)
    529                {
    530                    for (int var12 = var4; var12 <= var7; ++var12)
    531                    {
    532                        int var13 = this.worldObj.getBlockId(var10, var11, var12);
    533                        Block block = Block.blocksList[var13];
    534
    535                        if (block != null)
    536                        {
    537                            if (block.canDragonDestroy(worldObj, var10, var11, var12))
    538                            {
    539                                var9 = true;
    540                                this.worldObj.setBlockWithNotify(var10, var11, var12, 0);
    541                            }
    542                            else
    543                            {
    544                                var8 = true;
    545                            }
    546                        }
    547                    }
    548                }
    549            }
    550
    551            if (var9)
    552            {
    553                double var16 = par1AxisAlignedBB.minX + (par1AxisAlignedBB.maxX - par1AxisAlignedBB.minX) * (double)this.rand.nextFloat();
    554                double var17 = par1AxisAlignedBB.minY + (par1AxisAlignedBB.maxY - par1AxisAlignedBB.minY) * (double)this.rand.nextFloat();
    555                double var14 = par1AxisAlignedBB.minZ + (par1AxisAlignedBB.maxZ - par1AxisAlignedBB.minZ) * (double)this.rand.nextFloat();
    556                this.worldObj.spawnParticle("largeexplode", var16, var17, var14, 0.0D, 0.0D, 0.0D);
    557            }
    558
    559            return var8;
    560        }
    561
    562        public boolean attackEntityFromPart(EntityDragonPart par1EntityDragonPart, DamageSource par2DamageSource, int par3)
    563        {
    564            if (par1EntityDragonPart != this.dragonPartHead)
    565            {
    566                par3 = par3 / 4 + 1;
    567            }
    568
    569            float var4 = this.rotationYaw * (float)Math.PI / 180.0F;
    570            float var5 = MathHelper.sin(var4);
    571            float var6 = MathHelper.cos(var4);
    572            this.targetX = this.posX + (double)(var5 * 5.0F) + (double)((this.rand.nextFloat() - 0.5F) * 2.0F);
    573            this.targetY = this.posY + (double)(this.rand.nextFloat() * 3.0F) + 1.0D;
    574            this.targetZ = this.posZ - (double)(var6 * 5.0F) + (double)((this.rand.nextFloat() - 0.5F) * 2.0F);
    575            this.target = null;
    576
    577            if (par2DamageSource.getEntity() instanceof EntityPlayer || par2DamageSource == DamageSource.explosion)
    578            {
    579                this.func_82195_e(par2DamageSource, par3);
    580            }
    581
    582            return true;
    583        }
    584
    585        /**
    586         * Called when the entity is attacked.
    587         */
    588        public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
    589        {
    590            return false;
    591        }
    592
    593        protected boolean func_82195_e(DamageSource par1DamageSource, int par2)
    594        {
    595            return super.attackEntityFrom(par1DamageSource, par2);
    596        }
    597
    598        /**
    599         * handles entity death timer, experience orb and particle creation
    600         */
    601        protected void onDeathUpdate()
    602        {
    603            ++this.deathTicks;
    604
    605            if (this.deathTicks >= 180 && this.deathTicks <= 200)
    606            {
    607                float var1 = (this.rand.nextFloat() - 0.5F) * 8.0F;
    608                float var2 = (this.rand.nextFloat() - 0.5F) * 4.0F;
    609                float var3 = (this.rand.nextFloat() - 0.5F) * 8.0F;
    610                this.worldObj.spawnParticle("hugeexplosion", this.posX + (double)var1, this.posY + 2.0D + (double)var2, this.posZ + (double)var3, 0.0D, 0.0D, 0.0D);
    611            }
    612
    613            int var4;
    614            int var5;
    615
    616            if (!this.worldObj.isRemote)
    617            {
    618                if (this.deathTicks > 150 && this.deathTicks % 5 == 0)
    619                {
    620                    var4 = 1000;
    621
    622                    while (var4 > 0)
    623                    {
    624                        var5 = EntityXPOrb.getXPSplit(var4);
    625                        var4 -= var5;
    626                        this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, var5));
    627                    }
    628                }
    629
    630                if (this.deathTicks == 1)
    631                {
    632                    this.worldObj.func_82739_e(1018, (int)this.posX, (int)this.posY, (int)this.posZ, 0);
    633                }
    634            }
    635
    636            this.moveEntity(0.0D, 0.10000000149011612D, 0.0D);
    637            this.renderYawOffset = this.rotationYaw += 20.0F;
    638
    639            if (this.deathTicks == 200 && !this.worldObj.isRemote)
    640            {
    641                var4 = 2000;
    642
    643                while (var4 > 0)
    644                {
    645                    var5 = EntityXPOrb.getXPSplit(var4);
    646                    var4 -= var5;
    647                    this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, var5));
    648                }
    649
    650                this.createEnderPortal(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posZ));
    651                this.setDead();
    652            }
    653        }
    654
    655        /**
    656         * Creates the ender portal leading back to the normal world after defeating the enderdragon.
    657         */
    658        private void createEnderPortal(int par1, int par2)
    659        {
    660            byte var3 = 64;
    661            BlockEndPortal.bossDefeated = true;
    662            byte var4 = 4;
    663
    664            for (int var5 = var3 - 1; var5 <= var3 + 32; ++var5)
    665            {
    666                for (int var6 = par1 - var4; var6 <= par1 + var4; ++var6)
    667                {
    668                    for (int var7 = par2 - var4; var7 <= par2 + var4; ++var7)
    669                    {
    670                        double var8 = (double)(var6 - par1);
    671                        double var10 = (double)(var7 - par2);
    672                        double var12 = var8 * var8 + var10 * var10;
    673
    674                        if (var12 <= ((double)var4 - 0.5D) * ((double)var4 - 0.5D))
    675                        {
    676                            if (var5 < var3)
    677                            {
    678                                if (var12 <= ((double)(var4 - 1) - 0.5D) * ((double)(var4 - 1) - 0.5D))
    679                                {
    680                                    this.worldObj.setBlockWithNotify(var6, var5, var7, Block.bedrock.blockID);
    681                                }
    682                            }
    683                            else if (var5 > var3)
    684                            {
    685                                this.worldObj.setBlockWithNotify(var6, var5, var7, 0);
    686                            }
    687                            else if (var12 > ((double)(var4 - 1) - 0.5D) * ((double)(var4 - 1) - 0.5D))
    688                            {
    689                                this.worldObj.setBlockWithNotify(var6, var5, var7, Block.bedrock.blockID);
    690                            }
    691                            else
    692                            {
    693                                this.worldObj.setBlockWithNotify(var6, var5, var7, Block.endPortal.blockID);
    694                            }
    695                        }
    696                    }
    697                }
    698            }
    699
    700            this.worldObj.setBlockWithNotify(par1, var3 + 0, par2, Block.bedrock.blockID);
    701            this.worldObj.setBlockWithNotify(par1, var3 + 1, par2, Block.bedrock.blockID);
    702            this.worldObj.setBlockWithNotify(par1, var3 + 2, par2, Block.bedrock.blockID);
    703            this.worldObj.setBlockWithNotify(par1 - 1, var3 + 2, par2, Block.torchWood.blockID);
    704            this.worldObj.setBlockWithNotify(par1 + 1, var3 + 2, par2, Block.torchWood.blockID);
    705            this.worldObj.setBlockWithNotify(par1, var3 + 2, par2 - 1, Block.torchWood.blockID);
    706            this.worldObj.setBlockWithNotify(par1, var3 + 2, par2 + 1, Block.torchWood.blockID);
    707            this.worldObj.setBlockWithNotify(par1, var3 + 3, par2, Block.bedrock.blockID);
    708            this.worldObj.setBlockWithNotify(par1, var3 + 4, par2, Block.dragonEgg.blockID);
    709            BlockEndPortal.bossDefeated = false;
    710        }
    711
    712        /**
    713         * Makes the entity despawn if requirements are reached
    714         */
    715        protected void despawnEntity() {}
    716
    717        /**
    718         * Return the Entity parts making up this Entity (currently only for dragons)
    719         */
    720        public Entity[] getParts()
    721        {
    722            return this.dragonPartArray;
    723        }
    724
    725        /**
    726         * Returns true if other Entities should be prevented from moving through this Entity.
    727         */
    728        public boolean canBeCollidedWith()
    729        {
    730            return false;
    731        }
    732
    733        @SideOnly(Side.CLIENT)
    734
    735        /**
    736         * Returns the health points of the dragon.
    737         */
    738        public int getDragonHealth()
    739        {
    740            return this.dataWatcher.getWatchableObjectInt(16);
    741        }
    742
    743        public World func_82194_d()
    744        {
    745            return this.worldObj;
    746        }
    747
    748        /**
    749         * Returns the sound this mob makes while it's alive.
    750         */
    751        protected String getLivingSound()
    752        {
    753            return "mob.enderdragon.growl";
    754        }
    755
    756        /**
    757         * Returns the sound this mob makes when it is hurt.
    758         */
    759        protected String getHurtSound()
    760        {
    761            return "mob.enderdragon.hit";
    762        }
    763
    764        /**
    765         * Returns the volume for the sounds this mob makes.
    766         */
    767        protected float getSoundVolume()
    768        {
    769            return 5.0F;
    770        }
    771    }