/// <summary>
        /// Called when the throwable hits a block or entity.
        /// </summary>
        protected override void OnImpact(MovingObjectPosition par1MovingObjectPosition)
        {
            if (!WorldObj.IsRemote)
            {
                List <PotionEffect> list = Item.Potion.GetEffects(PotionDamage);

                if (list != null && list.Count > 0)
                {
                    AxisAlignedBB axisalignedbb = BoundingBox.Expand(4, 2, 4);
                    List <Entity> list1         = WorldObj.GetEntitiesWithinAABB(typeof(net.minecraft.src.EntityLiving), axisalignedbb);

                    if (list1 != null && list1.Count > 0)
                    {
                        for (IEnumerator <Entity> iterator = list1.GetEnumerator(); iterator.MoveNext();)
                        {
                            Entity entity = iterator.Current;
                            double d      = GetDistanceSqToEntity(entity);

                            if (d < 16D)
                            {
                                double d1 = 1.0D - Math.Sqrt(d) / 4D;

                                if (entity == par1MovingObjectPosition.EntityHit)
                                {
                                    d1 = 1.0D;
                                }

                                IEnumerator <PotionEffect> iterator1 = list.GetEnumerator();

                                while (iterator1.MoveNext())
                                {
                                    PotionEffect potioneffect = iterator1.Current;
                                    int          i            = potioneffect.GetPotionID();

                                    if (Potion.PotionTypes[i].IsInstant())
                                    {
                                        Potion.PotionTypes[i].AffectEntity(Thrower, (EntityLiving)entity, potioneffect.GetAmplifier(), d1);
                                    }
                                    else
                                    {
                                        int j = (int)(d1 * (double)potioneffect.GetDuration() + 0.5D);

                                        if (j > 20)
                                        {
                                            ((EntityLiving)entity).AddPotionEffect(new PotionEffect(i, j, potioneffect.GetAmplifier()));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                WorldObj.PlayAuxSFX(2002, (int)Math.Round(PosX), (int)Math.Round(PosY), (int)Math.Round(PosZ), PotionDamage);
                SetDead();
            }
        }
        /// <summary>
        /// Finds the closest player within 16 blocks to attack, or null if this Entity isn't interested in attacking
        /// (Animals, Spiders at day, peaceful PigZombies).
        /// </summary>
        protected override Entity FindPlayerToAttack()
        {
            if (FleeingTick > 0)
            {
                return(null);
            }

            float f = 8F;

            if (InLove > 0)
            {
                List <Entity> list = WorldObj.GetEntitiesWithinAABB(this.GetType(), BoundingBox.Expand(f, f, f));

                for (int i = 0; i < list.Count; i++)
                {
                    EntityAnimal entityanimal = (EntityAnimal)list[i];

                    if (entityanimal != this && entityanimal.InLove > 0)
                    {
                        return(entityanimal);
                    }
                }
            }
            else if (GetGrowingAge() == 0)
            {
                List <Entity> list1 = WorldObj.GetEntitiesWithinAABB(typeof(net.minecraft.src.EntityPlayer), BoundingBox.Expand(f, f, f));

                for (int j = 0; j < list1.Count; j++)
                {
                    EntityPlayer entityplayer = (EntityPlayer)list1[j];

                    if (entityplayer.GetCurrentEquippedItem() != null && IsWheat(entityplayer.GetCurrentEquippedItem()))
                    {
                        return(entityplayer);
                    }
                }
            }
            else if (GetGrowingAge() > 0)
            {
                List <Entity> list2 = WorldObj.GetEntitiesWithinAABB(this.GetType(), BoundingBox.Expand(f, f, f));

                for (int k = 0; k < list2.Count; k++)
                {
                    EntityAnimal entityanimal1 = (EntityAnimal)list2[k];

                    if (entityanimal1 != this && entityanimal1.GetGrowingAge() < 0)
                    {
                        return(entityanimal1);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the state of the enderdragon's current endercrystal.
        /// </summary>
        private void UpdateDragonEnderCrystal()
        {
            if (HealingEnderCrystal != null)
            {
                if (HealingEnderCrystal.IsDead)
                {
                    if (!WorldObj.IsRemote)
                    {
                        AttackEntityFromPart(DragonPartHead, DamageSource.Explosion, 10);
                    }

                    HealingEnderCrystal = null;
                }
                else if (TicksExisted % 10 == 0 && Health < MaxHealth)
                {
                    Health++;
                }
            }

            if (Rand.Next(10) == 0)
            {
                float                f    = 32F;
                List <Entity>        list = WorldObj.GetEntitiesWithinAABB(typeof(net.minecraft.src.EntityEnderCrystal), BoundingBox.Expand(f, f, f));
                EntityEnderCrystal   entityendercrystal = null;
                double               d        = double.MaxValue;
                IEnumerator <Entity> iterator = list.GetEnumerator();

                do
                {
                    if (!iterator.MoveNext())
                    {
                        break;
                    }

                    Entity entity = iterator.Current;
                    double d1     = entity.GetDistanceSqToEntity(this);

                    if (d1 < d)
                    {
                        d = d1;
                        entityendercrystal = (EntityEnderCrystal)entity;
                    }
                }while (true);

                HealingEnderCrystal = entityendercrystal;
            }
        }
        /// <summary>
        /// Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner uses this to count
        /// ticks and creates a new spawn inside its implementation.
        /// </summary>
        public override void UpdateEntity()
        {
            Yaw2 = Yaw;

            if (!AnyPlayerInRange())
            {
                return;
            }

            double d  = (float)XCoord + WorldObj.Rand.NextFloat();
            double d1 = (float)YCoord + WorldObj.Rand.NextFloat();
            double d2 = (float)ZCoord + WorldObj.Rand.NextFloat();

            WorldObj.SpawnParticle("smoke", d, d1, d2, 0.0F, 0.0F, 0.0F);
            WorldObj.SpawnParticle("flame", d, d1, d2, 0.0F, 0.0F, 0.0F);

            for (Yaw += 1000F / ((float)Delay + 200F); Yaw > 360D;)
            {
                Yaw  -= 360D;
                Yaw2 -= 360D;
            }

            if (!WorldObj.IsRemote)
            {
                if (Delay == -1)
                {
                    UpdateDelay();
                }

                if (Delay > 0)
                {
                    Delay--;
                    return;
                }

                sbyte byte0 = 4;

                for (int i = 0; i < byte0; i++)
                {
                    EntityLiving entityliving = (EntityLiving)EntityList.CreateEntityByName(MobID, WorldObj);

                    if (entityliving == null)
                    {
                        return;
                    }

                    int j = WorldObj.GetEntitiesWithinAABB(entityliving.GetType(), AxisAlignedBB.GetBoundingBoxFromPool(XCoord, YCoord, ZCoord, XCoord + 1, YCoord + 1, ZCoord + 1).Expand(8F, 4F, 8F)).Count;

                    if (j >= 6)
                    {
                        UpdateDelay();
                        return;
                    }

                    if (entityliving == null)
                    {
                        continue;
                    }

                    float d3 = XCoord + (WorldObj.Rand.NextFloat() - WorldObj.Rand.NextFloat()) * 4F;
                    float d4 = (YCoord + WorldObj.Rand.Next(3)) - 1;
                    float d5 = ZCoord + (WorldObj.Rand.NextFloat() - WorldObj.Rand.NextFloat()) * 4F;
                    entityliving.SetLocationAndAngles(d3, d4, d5, WorldObj.Rand.NextFloat() * 360F, 0.0F);

                    if (entityliving.GetCanSpawnHere())
                    {
                        WorldObj.SpawnEntityInWorld(entityliving);
                        WorldObj.PlayAuxSFX(2004, XCoord, YCoord, ZCoord, 0);
                        entityliving.SpawnExplosionParticle();
                        UpdateDelay();
                    }
                }
            }

            base.UpdateEntity();
        }