EntityDragon .java

net.minecraft.entity.boss.EntityDragon (class, 782 lines): members: healingEnderCrystal, getMovementOffsets, attackDragonFrom, dragonPartArray, slowed.

net.minecraft.entity.bossclass782 linescommonextends EntityLiving30.4 KB

Implements

API Surface (16)

void applyEntityAttributes()
void entityInit()
double[] getMovementOffsets(int p_70974_1_, float p_70974_2_)
void onLivingUpdate()
boolean attackEntityFromPart(EntityDragonPart dragonPart, DamageSource source, float p_70965_3_)
boolean attackEntityFrom(DamageSource source, float amount)
boolean attackDragonFrom(DamageSource source, float amount)
void onKillCommand()
void onDeathUpdate()
void despawnEntity()
Entity[] getParts()
boolean canBeCollidedWith()
World getWorld()
String getLivingSound()
String getHurtSound()
float getSoundVolume()

Fields & Constants (20)

targetX
targetY
targetZ
ringBuffer
ringBufferIndex
dragonPartArray
dragonPartHead
dragonPartBody
dragonPartTail1
dragonPartTail2
dragonPartTail3
dragonPartWing1
dragonPartWing2
prevAnimTime
animTime
forceNewTarget
slowed
target
deathTicks
healingEnderCrystal

String literals (9)

"head"
"body"
"tail"
"wing"
"mob.enderdragon.wings"
"mobGriefing"
"doMobLoot"
"mob.enderdragon.growl"
"mob.enderdragon.hit"

Full Source

EntityDragon.java782 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.boss;
2
3
import com.google.common.collect.Lists;
4
import java.util.Iterator;
5
import java.util.List;
6
import net.minecraft.block.Block;
7
import net.minecraft.block.BlockTorch;
8
import net.minecraft.block.material.Material;
9
import net.minecraft.entity.Entity;
10
import net.minecraft.entity.EntityLiving;
11
import net.minecraft.entity.EntityLivingBase;
12
import net.minecraft.entity.IEntityMultiPart;
13
import net.minecraft.entity.SharedMonsterAttributes;
14
import net.minecraft.entity.item.EntityEnderCrystal;
15
import net.minecraft.entity.item.EntityXPOrb;
16
import net.minecraft.entity.monster.IMob;
17
import net.minecraft.entity.player.EntityPlayer;
18
import net.minecraft.init.Blocks;
19
import net.minecraft.util.AxisAlignedBB;
20
import net.minecraft.util.BlockPos;
21
import net.minecraft.util.DamageSource;
22
import net.minecraft.util.EntityDamageSource;
23
import net.minecraft.util.EnumFacing;
24
import net.minecraft.util.EnumParticleTypes;
25
import net.minecraft.util.MathHelper;
26
import net.minecraft.util.Vec3;
27
import net.minecraft.world.Explosion;
28
import net.minecraft.world.World;
29
30
public class EntityDragon extends EntityLiving implements IBossDisplayData, IEntityMultiPart, IMob
31
{
32
    public double targetX;
33
    public double targetY;
34
    public double targetZ;
35
36
    /**
37
     * Ring buffer array for the last 64 Y-positions and yaw rotations. Used to calculate offsets for the animations.
38
     */
39
    public double[][] ringBuffer = new double[64][3];
40
41
    /**
42
     * Index into the ring buffer. Incremented once per tick and restarts at 0 once it reaches the end of the buffer.
43
     */
44
    public int ringBufferIndex = -1;
45
46
    /** An array containing all body parts of this dragon */
47
    public EntityDragonPart[] dragonPartArray;
48
49
    /** The head bounding box of a dragon */
50
    public EntityDragonPart dragonPartHead;
51
52
    /** The body bounding box of a dragon */
53
    public EntityDragonPart dragonPartBody;
54
    public EntityDragonPart dragonPartTail1;
55
    public EntityDragonPart dragonPartTail2;
56
    public EntityDragonPart dragonPartTail3;
57
    public EntityDragonPart dragonPartWing1;
58
    public EntityDragonPart dragonPartWing2;
59
60
    /** Animation time at previous tick. */
61
    public float prevAnimTime;
62
63
    /**
64
     * Animation time, used to control the speed of the animation cycles (wings flapping, jaw opening, etc.)
65
     */
66
    public float animTime;
67
68
    /** Force selecting a new flight target at next tick if set to true. */
69
    public boolean forceNewTarget;
70
71
    /**
72
     * Activated if the dragon is flying though obsidian, white stone or bedrock. Slows movement and animation speed.
73
     */
74
    public boolean slowed;
75
    private Entity target;
76
    public int deathTicks;
77
78
    /** The current endercrystal that is healing this dragon */
79
    public EntityEnderCrystal healingEnderCrystal;
80
81
    public EntityDragon(World worldIn)
82
    {
83
        super(worldIn);
84
        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)};
85
        this.setHealth(this.getMaxHealth());
86
        this.setSize(16.0F, 8.0F);
87
        this.noClip = true;
88
        this.isImmuneToFire = true;
89
        this.targetY = 100.0D;
90
        this.ignoreFrustumCheck = true;
91
    }
92
93
    protected void applyEntityAttributes()
94
    {
95
        super.applyEntityAttributes();
96
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(200.0D);
97
    }
98
99
    protected void entityInit()
100
    {
101
        super.entityInit();
102
    }
103
104
    /**
105
     * Returns a double[3] array with movement offsets, used to calculate trailing tail/neck positions. [0] = yaw
106
     * offset, [1] = y offset, [2] = unused, always 0. Parameters: buffer index offset, partial ticks.
107
     */
108
    public double[] getMovementOffsets(int p_70974_1_, float p_70974_2_)
109
    {
110
        if (this.getHealth() <= 0.0F)
111
        {
112
            p_70974_2_ = 0.0F;
113
        }
114
115
        p_70974_2_ = 1.0F - p_70974_2_;
116
        int i = this.ringBufferIndex - p_70974_1_ * 1 & 63;
117
        int j = this.ringBufferIndex - p_70974_1_ * 1 - 1 & 63;
118
        double[] adouble = new double[3];
119
        double d0 = this.ringBuffer[i][0];
120
        double d1 = MathHelper.wrapAngleTo180_double(this.ringBuffer[j][0] - d0);
121
        adouble[0] = d0 + d1 * (double)p_70974_2_;
122
        d0 = this.ringBuffer[i][1];
123
        d1 = this.ringBuffer[j][1] - d0;
124
        adouble[1] = d0 + d1 * (double)p_70974_2_;
125
        adouble[2] = this.ringBuffer[i][2] + (this.ringBuffer[j][2] - this.ringBuffer[i][2]) * (double)p_70974_2_;
126
        return adouble;
127
    }
128
129
    /**
130
     * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
131
     * use this to react to sunlight and start to burn.
132
     */
133
    public void onLivingUpdate()
134
    {
135
        if (this.worldObj.isRemote)
136
        {
137
            float f = MathHelper.cos(this.animTime * (float)Math.PI * 2.0F);
138
            float f1 = MathHelper.cos(this.prevAnimTime * (float)Math.PI * 2.0F);
139
140
            if (f1 <= -0.3F && f >= -0.3F && !this.isSilent())
141
            {
142
                this.worldObj.playSound(this.posX, this.posY, this.posZ, "mob.enderdragon.wings", 5.0F, 0.8F + this.rand.nextFloat() * 0.3F, false);
143
            }
144
        }
145
146
        this.prevAnimTime = this.animTime;
147
148
        if (this.getHealth() <= 0.0F)
149
        {
150
            float f11 = (this.rand.nextFloat() - 0.5F) * 8.0F;
151
            float f13 = (this.rand.nextFloat() - 0.5F) * 4.0F;
152
            float f14 = (this.rand.nextFloat() - 0.5F) * 8.0F;
153
            this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, this.posX + (double)f11, this.posY + 2.0D + (double)f13, this.posZ + (double)f14, 0.0D, 0.0D, 0.0D, new int[0]);
154
        }
155
        else
156
        {
157
            this.updateDragonEnderCrystal();
158
            float f10 = 0.2F / (MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ) * 10.0F + 1.0F);
159
            f10 = f10 * (float)Math.pow(2.0D, this.motionY);
160
161
            if (this.slowed)
162
            {
163
                this.animTime += f10 * 0.5F;
164
            }
165
            else
166
            {
167
                this.animTime += f10;
168
            }
169
170
            this.rotationYaw = MathHelper.wrapAngleTo180_float(this.rotationYaw);
171
172
            if (this.isAIDisabled())
173
            {
174
                this.animTime = 0.5F;
175
            }
176
            else
177
            {
178
                if (this.ringBufferIndex < 0)
179
                {
180
                    for (int i = 0; i < this.ringBuffer.length; ++i)
181
                    {
182
                        this.ringBuffer[i][0] = (double)this.rotationYaw;
183
                        this.ringBuffer[i][1] = this.posY;
184
                    }
185
                }
186
187
                if (++this.ringBufferIndex == this.ringBuffer.length)
188
                {
189
                    this.ringBufferIndex = 0;
190
                }
191
192
                this.ringBuffer[this.ringBufferIndex][0] = (double)this.rotationYaw;
193
                this.ringBuffer[this.ringBufferIndex][1] = this.posY;
194
195
                if (this.worldObj.isRemote)
196
                {
197
                    if (this.newPosRotationIncrements > 0)
198
                    {
199
                        double d10 = this.posX + (this.newPosX - this.posX) / (double)this.newPosRotationIncrements;
200
                        double d0 = this.posY + (this.newPosY - this.posY) / (double)this.newPosRotationIncrements;
201
                        double d1 = this.posZ + (this.newPosZ - this.posZ) / (double)this.newPosRotationIncrements;
202
                        double d2 = MathHelper.wrapAngleTo180_double(this.newRotationYaw - (double)this.rotationYaw);
203
                        this.rotationYaw = (float)((double)this.rotationYaw + d2 / (double)this.newPosRotationIncrements);
204
                        this.rotationPitch = (float)((double)this.rotationPitch + (this.newRotationPitch - (double)this.rotationPitch) / (double)this.newPosRotationIncrements);
205
                        --this.newPosRotationIncrements;
206
                        this.setPosition(d10, d0, d1);
207
                        this.setRotation(this.rotationYaw, this.rotationPitch);
208
                    }
209
                }
210
                else
211
                {
212
                    double d11 = this.targetX - this.posX;
213
                    double d12 = this.targetY - this.posY;
214
                    double d13 = this.targetZ - this.posZ;
215
                    double d14 = d11 * d11 + d12 * d12 + d13 * d13;
216
217
                    if (this.target != null)
218
                    {
219
                        this.targetX = this.target.posX;
220
                        this.targetZ = this.target.posZ;
221
                        double d3 = this.targetX - this.posX;
222
                        double d5 = this.targetZ - this.posZ;
223
                        double d7 = Math.sqrt(d3 * d3 + d5 * d5);
224
                        double d8 = 0.4000000059604645D + d7 / 80.0D - 1.0D;
225
226
                        if (d8 > 10.0D)
227
                        {
228
                            d8 = 10.0D;
229
                        }
230
231
                        this.targetY = this.target.getEntityBoundingBox().minY + d8;
232
                    }
233
                    else
234
                    {
235
                        this.targetX += this.rand.nextGaussian() * 2.0D;
236
                        this.targetZ += this.rand.nextGaussian() * 2.0D;
237
                    }
238
239
                    if (this.forceNewTarget || d14 < 100.0D || d14 > 22500.0D || this.isCollidedHorizontally || this.isCollidedVertically)
240
                    {
241
                        this.setNewTarget();
242
                    }
243
244
                    d12 = d12 / (double)MathHelper.sqrt_double(d11 * d11 + d13 * d13);
245
                    float f17 = 0.6F;
246
                    d12 = MathHelper.clamp_double(d12, (double)(-f17), (double)f17);
247
                    this.motionY += d12 * 0.10000000149011612D;
248
                    this.rotationYaw = MathHelper.wrapAngleTo180_float(this.rotationYaw);
249
                    double d4 = 180.0D - MathHelper.atan2(d11, d13) * 180.0D / Math.PI;
250
                    double d6 = MathHelper.wrapAngleTo180_double(d4 - (double)this.rotationYaw);
251
252
                    if (d6 > 50.0D)
253
                    {
254
                        d6 = 50.0D;
255
                    }
256
257
                    if (d6 < -50.0D)
258
                    {
259
                        d6 = -50.0D;
260
                    }
261
262
                    Vec3 vec3 = (new Vec3(this.targetX - this.posX, this.targetY - this.posY, this.targetZ - this.posZ)).normalize();
263
                    double d15 = (double)(-MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F));
264
                    Vec3 vec31 = (new Vec3((double)MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F), this.motionY, d15)).normalize();
265
                    float f5 = ((float)vec31.dotProduct(vec3) + 0.5F) / 1.5F;
266
267
                    if (f5 < 0.0F)
268
                    {
269
                        f5 = 0.0F;
270
                    }
271
272
                    this.randomYawVelocity *= 0.8F;
273
                    float f6 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ) * 1.0F + 1.0F;
274
                    double d9 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ) * 1.0D + 1.0D;
275
276
                    if (d9 > 40.0D)
277
                    {
278
                        d9 = 40.0D;
279
                    }
280
281
                    this.randomYawVelocity = (float)((double)this.randomYawVelocity + d6 * (0.699999988079071D / d9 / (double)f6));
282
                    this.rotationYaw += this.randomYawVelocity * 0.1F;
283
                    float f7 = (float)(2.0D / (d9 + 1.0D));
284
                    float f8 = 0.06F;
285
                    this.moveFlying(0.0F, -1.0F, f8 * (f5 * f7 + (1.0F - f7)));
286
287
                    if (this.slowed)
288
                    {
289
                        this.moveEntity(this.motionX * 0.800000011920929D, this.motionY * 0.800000011920929D, this.motionZ * 0.800000011920929D);
290
                    }
291
                    else
292
                    {
293
                        this.moveEntity(this.motionX, this.motionY, this.motionZ);
294
                    }
295
296
                    Vec3 vec32 = (new Vec3(this.motionX, this.motionY, this.motionZ)).normalize();
297
                    float f9 = ((float)vec32.dotProduct(vec31) + 1.0F) / 2.0F;
298
                    f9 = 0.8F + 0.15F * f9;
299
                    this.motionX *= (double)f9;
300
                    this.motionZ *= (double)f9;
301
                    this.motionY *= 0.9100000262260437D;
302
                }
303
304
                this.renderYawOffset = this.rotationYaw;
305
                this.dragonPartHead.width = this.dragonPartHead.height = 3.0F;
306
                this.dragonPartTail1.width = this.dragonPartTail1.height = 2.0F;
307
                this.dragonPartTail2.width = this.dragonPartTail2.height = 2.0F;
308
                this.dragonPartTail3.width = this.dragonPartTail3.height = 2.0F;
309
                this.dragonPartBody.height = 3.0F;
310
                this.dragonPartBody.width = 5.0F;
311
                this.dragonPartWing1.height = 2.0F;
312
                this.dragonPartWing1.width = 4.0F;
313
                this.dragonPartWing2.height = 3.0F;
314
                this.dragonPartWing2.width = 4.0F;
315
                float f12 = (float)(this.getMovementOffsets(5, 1.0F)[1] - this.getMovementOffsets(10, 1.0F)[1]) * 10.0F / 180.0F * (float)Math.PI;
316
                float f2 = MathHelper.cos(f12);
317
                float f15 = -MathHelper.sin(f12);
318
                float f3 = this.rotationYaw * (float)Math.PI / 180.0F;
319
                float f16 = MathHelper.sin(f3);
320
                float f4 = MathHelper.cos(f3);
321
                this.dragonPartBody.onUpdate();
322
                this.dragonPartBody.setLocationAndAngles(this.posX + (double)(f16 * 0.5F), this.posY, this.posZ - (double)(f4 * 0.5F), 0.0F, 0.0F);
323
                this.dragonPartWing1.onUpdate();
324
                this.dragonPartWing1.setLocationAndAngles(this.posX + (double)(f4 * 4.5F), this.posY + 2.0D, this.posZ + (double)(f16 * 4.5F), 0.0F, 0.0F);
325
                this.dragonPartWing2.onUpdate();
326
                this.dragonPartWing2.setLocationAndAngles(this.posX - (double)(f4 * 4.5F), this.posY + 2.0D, this.posZ - (double)(f16 * 4.5F), 0.0F, 0.0F);
327
328
                if (!this.worldObj.isRemote && this.hurtTime == 0)
329
                {
330
                    this.collideWithEntities(this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.dragonPartWing1.getEntityBoundingBox().expand(4.0D, 2.0D, 4.0D).offset(0.0D, -2.0D, 0.0D)));
331
                    this.collideWithEntities(this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.dragonPartWing2.getEntityBoundingBox().expand(4.0D, 2.0D, 4.0D).offset(0.0D, -2.0D, 0.0D)));
332
                    this.attackEntitiesInList(this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.dragonPartHead.getEntityBoundingBox().expand(1.0D, 1.0D, 1.0D)));
333
                }
334
335
                double[] adouble1 = this.getMovementOffsets(5, 1.0F);
336
                double[] adouble = this.getMovementOffsets(0, 1.0F);
337
                float f18 = MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F - this.randomYawVelocity * 0.01F);
338
                float f19 = MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F - this.randomYawVelocity * 0.01F);
339
                this.dragonPartHead.onUpdate();
340
                this.dragonPartHead.setLocationAndAngles(this.posX + (double)(f18 * 5.5F * f2), this.posY + (adouble[1] - adouble1[1]) * 1.0D + (double)(f15 * 5.5F), this.posZ - (double)(f19 * 5.5F * f2), 0.0F, 0.0F);
341
342
                for (int j = 0; j < 3; ++j)
343
                {
344
                    EntityDragonPart entitydragonpart = null;
345
346
                    if (j == 0)
347
                    {
348
                        entitydragonpart = this.dragonPartTail1;
349
                    }
350
351
                    if (j == 1)
352
                    {
353
                        entitydragonpart = this.dragonPartTail2;
354
                    }
355
356
                    if (j == 2)
357
                    {
358
                        entitydragonpart = this.dragonPartTail3;
359
                    }
360
361
                    double[] adouble2 = this.getMovementOffsets(12 + j * 2, 1.0F);
362
                    float f20 = this.rotationYaw * (float)Math.PI / 180.0F + this.simplifyAngle(adouble2[0] - adouble1[0]) * (float)Math.PI / 180.0F * 1.0F;
363
                    float f21 = MathHelper.sin(f20);
364
                    float f22 = MathHelper.cos(f20);
365
                    float f23 = 1.5F;
366
                    float f24 = (float)(j + 1) * 2.0F;
367
                    entitydragonpart.onUpdate();
368
                    entitydragonpart.setLocationAndAngles(this.posX - (double)((f16 * f23 + f21 * f24) * f2), this.posY + (adouble2[1] - adouble1[1]) * 1.0D - (double)((f24 + f23) * f15) + 1.5D, this.posZ + (double)((f4 * f23 + f22 * f24) * f2), 0.0F, 0.0F);
369
                }
370
371
                if (!this.worldObj.isRemote)
372
                {
373
                    this.slowed = this.destroyBlocksInAABB(this.dragonPartHead.getEntityBoundingBox()) | this.destroyBlocksInAABB(this.dragonPartBody.getEntityBoundingBox());
374
                }
375
            }
376
        }
377
    }
378
379
    /**
380
     * Updates the state of the enderdragon's current endercrystal.
381
     */
382
    private void updateDragonEnderCrystal()
383
    {
384
        if (this.healingEnderCrystal != null)
385
        {
386
            if (this.healingEnderCrystal.isDead)
387
            {
388
                if (!this.worldObj.isRemote)
389
                {
390
                    this.attackEntityFromPart(this.dragonPartHead, DamageSource.setExplosionSource((Explosion)null), 10.0F);
391
                }
392
393
                this.healingEnderCrystal = null;
394
            }
395
            else if (this.ticksExisted % 10 == 0 && this.getHealth() < this.getMaxHealth())
396
            {
397
                this.setHealth(this.getHealth() + 1.0F);
398
            }
399
        }
400
401
        if (this.rand.nextInt(10) == 0)
402
        {
403
            float f = 32.0F;
404
            List<EntityEnderCrystal> list = this.worldObj.<EntityEnderCrystal>getEntitiesWithinAABB(EntityEnderCrystal.class, this.getEntityBoundingBox().expand((double)f, (double)f, (double)f));
405
            EntityEnderCrystal entityendercrystal = null;
406
            double d0 = Double.MAX_VALUE;
407
408
            for (EntityEnderCrystal entityendercrystal1 : list)
409
            {
410
                double d1 = entityendercrystal1.getDistanceSqToEntity(this);
411
412
                if (d1 < d0)
413
                {
414
                    d0 = d1;
415
                    entityendercrystal = entityendercrystal1;
416
                }
417
            }
418
419
            this.healingEnderCrystal = entityendercrystal;
420
        }
421
    }
422
423
    /**
424
     * Pushes all entities inside the list away from the enderdragon.
425
     */
426
    private void collideWithEntities(List<Entity> p_70970_1_)
427
    {
428
        double d0 = (this.dragonPartBody.getEntityBoundingBox().minX + this.dragonPartBody.getEntityBoundingBox().maxX) / 2.0D;
429
        double d1 = (this.dragonPartBody.getEntityBoundingBox().minZ + this.dragonPartBody.getEntityBoundingBox().maxZ) / 2.0D;
430
431
        for (Entity entity : p_70970_1_)
432
        {
433
            if (entity instanceof EntityLivingBase)
434
            {
435
                double d2 = entity.posX - d0;
436
                double d3 = entity.posZ - d1;
437
                double d4 = d2 * d2 + d3 * d3;
438
                entity.addVelocity(d2 / d4 * 4.0D, 0.20000000298023224D, d3 / d4 * 4.0D);
439
            }
440
        }
441
    }
442
443
    /**
444
     * Attacks all entities inside this list, dealing 5 hearts of damage.
445
     */
446
    private void attackEntitiesInList(List<Entity> p_70971_1_)
447
    {
448
        for (int i = 0; i < p_70971_1_.size(); ++i)
449
        {
450
            Entity entity = (Entity)p_70971_1_.get(i);
451
452
            if (entity instanceof EntityLivingBase)
453
            {
454
                entity.attackEntityFrom(DamageSource.causeMobDamage(this), 10.0F);
455
                this.applyEnchantments(this, entity);
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
        List<EntityPlayer> list = Lists.newArrayList(this.worldObj.playerEntities);
467
        Iterator<EntityPlayer> iterator = list.iterator();
468
469
        while (iterator.hasNext())
470
        {
471
            if (((EntityPlayer)iterator.next()).isSpectator())
472
            {
473
                iterator.remove();
474
            }
475
        }
476
477
        if (this.rand.nextInt(2) == 0 && !list.isEmpty())
478
        {
479
            this.target = (Entity)list.get(this.rand.nextInt(list.size()));
480
        }
481
        else
482
        {
483
            while (true)
484
            {
485
                this.targetX = 0.0D;
486
                this.targetY = (double)(70.0F + this.rand.nextFloat() * 50.0F);
487
                this.targetZ = 0.0D;
488
                this.targetX += (double)(this.rand.nextFloat() * 120.0F - 60.0F);
489
                this.targetZ += (double)(this.rand.nextFloat() * 120.0F - 60.0F);
490
                double d0 = this.posX - this.targetX;
491
                double d1 = this.posY - this.targetY;
492
                double d2 = this.posZ - this.targetZ;
493
                boolean flag = d0 * d0 + d1 * d1 + d2 * d2 > 100.0D;
494
495
                if (flag)
496
                {
497
                    break;
498
                }
499
            }
500
501
            this.target = null;
502
        }
503
    }
504
505
    /**
506
     * Simplifies the value of a number by adding/subtracting 180 to the point that the number is between -180 and 180.
507
     */
508
    private float simplifyAngle(double p_70973_1_)
509
    {
510
        return (float)MathHelper.wrapAngleTo180_double(p_70973_1_);
511
    }
512
513
    /**
514
     * Destroys all blocks that aren't associated with 'The End' inside the given bounding box.
515
     */
516
    private boolean destroyBlocksInAABB(AxisAlignedBB p_70972_1_)
517
    {
518
        int i = MathHelper.floor_double(p_70972_1_.minX);
519
        int j = MathHelper.floor_double(p_70972_1_.minY);
520
        int k = MathHelper.floor_double(p_70972_1_.minZ);
521
        int l = MathHelper.floor_double(p_70972_1_.maxX);
522
        int i1 = MathHelper.floor_double(p_70972_1_.maxY);
523
        int j1 = MathHelper.floor_double(p_70972_1_.maxZ);
524
        boolean flag = false;
525
        boolean flag1 = false;
526
527
        for (int k1 = i; k1 <= l; ++k1)
528
        {
529
            for (int l1 = j; l1 <= i1; ++l1)
530
            {
531
                for (int i2 = k; i2 <= j1; ++i2)
532
                {
533
                    BlockPos blockpos = new BlockPos(k1, l1, i2);
534
                    Block block = this.worldObj.getBlockState(blockpos).getBlock();
535
536
                    if (block.getMaterial() != Material.air)
537
                    {
538
                        if (block != Blocks.barrier && block != Blocks.obsidian && block != Blocks.end_stone && block != Blocks.bedrock && block != Blocks.command_block && this.worldObj.getGameRules().getBoolean("mobGriefing"))
539
                        {
540
                            flag1 = this.worldObj.setBlockToAir(blockpos) || flag1;
541
                        }
542
                        else
543
                        {
544
                            flag = true;
545
                        }
546
                    }
547
                }
548
            }
549
        }
550
551
        if (flag1)
552
        {
553
            double d0 = p_70972_1_.minX + (p_70972_1_.maxX - p_70972_1_.minX) * (double)this.rand.nextFloat();
554
            double d1 = p_70972_1_.minY + (p_70972_1_.maxY - p_70972_1_.minY) * (double)this.rand.nextFloat();
555
            double d2 = p_70972_1_.minZ + (p_70972_1_.maxZ - p_70972_1_.minZ) * (double)this.rand.nextFloat();
556
            this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, d0, d1, d2, 0.0D, 0.0D, 0.0D, new int[0]);
557
        }
558
559
        return flag;
560
    }
561
562
    public boolean attackEntityFromPart(EntityDragonPart dragonPart, DamageSource source, float p_70965_3_)
563
    {
564
        if (dragonPart != this.dragonPartHead)
565
        {
566
            p_70965_3_ = p_70965_3_ / 4.0F + 1.0F;
567
        }
568
569
        float f = this.rotationYaw * (float)Math.PI / 180.0F;
570
        float f1 = MathHelper.sin(f);
571
        float f2 = MathHelper.cos(f);
572
        this.targetX = this.posX + (double)(f1 * 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)(f2 * 5.0F) + (double)((this.rand.nextFloat() - 0.5F) * 2.0F);
575
        this.target = null;
576
577
        if (source.getEntity() instanceof EntityPlayer || source.isExplosion())
578
        {
579
            this.attackDragonFrom(source, p_70965_3_);
580
        }
581
582
        return true;
583
    }
584
585
    /**
586
     * Called when the entity is attacked.
587
     */
588
    public boolean attackEntityFrom(DamageSource source, float amount)
589
    {
590
        if (source instanceof EntityDamageSource && ((EntityDamageSource)source).getIsThornsDamage())
591
        {
592
            this.attackDragonFrom(source, amount);
593
        }
594
595
        return false;
596
    }
597
598
    /**
599
     * Provides a way to cause damage to an ender dragon.
600
     */
601
    protected boolean attackDragonFrom(DamageSource source, float amount)
602
    {
603
        return super.attackEntityFrom(source, amount);
604
    }
605
606
    /**
607
     * Called by the /kill command.
608
     */
609
    public void onKillCommand()
610
    {
611
        this.setDead();
612
    }
613
614
    /**
615
     * handles entity death timer, experience orb and particle creation
616
     */
617
    protected void onDeathUpdate()
618
    {
619
        ++this.deathTicks;
620
621
        if (this.deathTicks >= 180 && this.deathTicks <= 200)
622
        {
623
            float f = (this.rand.nextFloat() - 0.5F) * 8.0F;
624
            float f1 = (this.rand.nextFloat() - 0.5F) * 4.0F;
625
            float f2 = (this.rand.nextFloat() - 0.5F) * 8.0F;
626
            this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, this.posX + (double)f, this.posY + 2.0D + (double)f1, this.posZ + (double)f2, 0.0D, 0.0D, 0.0D, new int[0]);
627
        }
628
629
        boolean flag = this.worldObj.getGameRules().getBoolean("doMobLoot");
630
631
        if (!this.worldObj.isRemote)
632
        {
633
            if (this.deathTicks > 150 && this.deathTicks % 5 == 0 && flag)
634
            {
635
                int i = 1000;
636
637
                while (i > 0)
638
                {
639
                    int k = EntityXPOrb.getXPSplit(i);
640
                    i -= k;
641
                    this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, k));
642
                }
643
            }
644
645
            if (this.deathTicks == 1)
646
            {
647
                this.worldObj.playBroadcastSound(1018, new BlockPos(this), 0);
648
            }
649
        }
650
651
        this.moveEntity(0.0D, 0.10000000149011612D, 0.0D);
652
        this.renderYawOffset = this.rotationYaw += 20.0F;
653
654
        if (this.deathTicks == 200 && !this.worldObj.isRemote)
655
        {
656
            if (flag)
657
            {
658
                int j = 2000;
659
660
                while (j > 0)
661
                {
662
                    int l = EntityXPOrb.getXPSplit(j);
663
                    j -= l;
664
                    this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, l));
665
                }
666
            }
667
668
            this.generatePortal(new BlockPos(this.posX, 64.0D, this.posZ));
669
            this.setDead();
670
        }
671
    }
672
673
    /**
674
     * Generate the portal when the dragon dies
675
     */
676
    private void generatePortal(BlockPos pos)
677
    {
678
        int i = 4;
679
        double d0 = 12.25D;
680
        double d1 = 6.25D;
681
682
        for (int j = -1; j <= 32; ++j)
683
        {
684
            for (int k = -4; k <= 4; ++k)
685
            {
686
                for (int l = -4; l <= 4; ++l)
687
                {
688
                    double d2 = (double)(k * k + l * l);
689
690
                    if (d2 <= 12.25D)
691
                    {
692
                        BlockPos blockpos = pos.add(k, j, l);
693
694
                        if (j < 0)
695
                        {
696
                            if (d2 <= 6.25D)
697
                            {
698
                                this.worldObj.setBlockState(blockpos, Blocks.bedrock.getDefaultState());
699
                            }
700
                        }
701
                        else if (j > 0)
702
                        {
703
                            this.worldObj.setBlockState(blockpos, Blocks.air.getDefaultState());
704
                        }
705
                        else if (d2 > 6.25D)
706
                        {
707
                            this.worldObj.setBlockState(blockpos, Blocks.bedrock.getDefaultState());
708
                        }
709
                        else
710
                        {
711
                            this.worldObj.setBlockState(blockpos, Blocks.end_portal.getDefaultState());
712
                        }
713
                    }
714
                }
715
            }
716
        }
717
718
        this.worldObj.setBlockState(pos, Blocks.bedrock.getDefaultState());
719
        this.worldObj.setBlockState(pos.up(), Blocks.bedrock.getDefaultState());
720
        BlockPos blockpos1 = pos.up(2);
721
        this.worldObj.setBlockState(blockpos1, Blocks.bedrock.getDefaultState());
722
        this.worldObj.setBlockState(blockpos1.west(), Blocks.torch.getDefaultState().withProperty(BlockTorch.FACING, EnumFacing.EAST));
723
        this.worldObj.setBlockState(blockpos1.east(), Blocks.torch.getDefaultState().withProperty(BlockTorch.FACING, EnumFacing.WEST));
724
        this.worldObj.setBlockState(blockpos1.north(), Blocks.torch.getDefaultState().withProperty(BlockTorch.FACING, EnumFacing.SOUTH));
725
        this.worldObj.setBlockState(blockpos1.south(), Blocks.torch.getDefaultState().withProperty(BlockTorch.FACING, EnumFacing.NORTH));
726
        this.worldObj.setBlockState(pos.up(3), Blocks.bedrock.getDefaultState());
727
        this.worldObj.setBlockState(pos.up(4), Blocks.dragon_egg.getDefaultState());
728
    }
729
730
    /**
731
     * Makes the entity despawn if requirements are reached
732
     */
733
    protected void despawnEntity()
734
    {
735
    }
736
737
    /**
738
     * Return the Entity parts making up this Entity (currently only for dragons)
739
     */
740
    public Entity[] getParts()
741
    {
742
        return this.dragonPartArray;
743
    }
744
745
    /**
746
     * Returns true if other Entities should be prevented from moving through this Entity.
747
     */
748
    public boolean canBeCollidedWith()
749
    {
750
        return false;
751
    }
752
753
    public World getWorld()
754
    {
755
        return this.worldObj;
756
    }
757
758
    /**
759
     * Returns the sound this mob makes while it's alive.
760
     */
761
    protected String getLivingSound()
762
    {
763
        return "mob.enderdragon.growl";
764
    }
765
766
    /**
767
     * Returns the sound this mob makes when it is hurt.
768
     */
769
    protected String getHurtSound()
770
    {
771
        return "mob.enderdragon.hit";
772
    }
773
774
    /**
775
     * Returns the volume for the sounds this mob makes.
776
     */
777
    protected float getSoundVolume()
778
    {
779
        return 5.0F;
780
    }
781
}
782

Deobfuscated MCP 1.8.9 source of EntityDragon from Marcelektro/MavenMCP-1.8.9 (net/minecraft/entity/boss/EntityDragon.java), stored verbatim.