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