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