hassansyyid

Dragon

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