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