/// <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);
        }
 /// <summary>
 /// Called upon block activation (left or right click on the block.). The three integers represent x,y,z of the
 /// block.
 /// </summary>
 public override bool BlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
 {
     if (par5EntityPlayer.GetCurrentEquippedItem() != null && par5EntityPlayer.GetCurrentEquippedItem().ItemID == Item.FlintAndSteel.ShiftedIndex)
     {
         OnBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
         par1World.SetBlockWithNotify(par2, par3, par4, 0);
         return(true);
     }
     else
     {
         return(base.BlockActivated(par1World, par2, par3, par4, par5EntityPlayer));
     }
 }
 /// <summary>
 /// Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the
 /// block and l is the block's subtype/damage.
 /// </summary>
 public override void HarvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6)
 {
     if (!par1World.IsRemote && par2EntityPlayer.GetCurrentEquippedItem() != null && par2EntityPlayer.GetCurrentEquippedItem().ItemID == Item.Shears.ShiftedIndex)
     {
         par2EntityPlayer.AddStat(StatList.MineBlockStatArray[BlockID], 1);
         DropBlockAsItem_do(par1World, par3, par4, par5, new ItemStack(Block.Leaves.BlockID, 1, par6 & 3));
     }
     else
     {
         base.HarvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6);
     }
 }
        /// <summary>
        /// Returns whether the EntityAIBase should begin execution.
        /// </summary>
        public override bool ShouldExecute()
        {
            if (DelayTemptCounter > 0)
            {
                DelayTemptCounter--;
                return(false);
            }

            TemptingPlayer = TemptedEntity.WorldObj.GetClosestPlayerToEntity(TemptedEntity, 10);

            if (TemptingPlayer == null)
            {
                return(false);
            }

            ItemStack itemstack = TemptingPlayer.GetCurrentEquippedItem();

            if (itemstack == null)
            {
                return(false);
            }

            return(itemstack.ItemID == BreedingFood);
        }
        /// <summary>
        /// Basic mob attack. Default to touch of death in EntityCreature. Overridden by each mob to define their attack.
        /// </summary>
        protected override void AttackEntity(Entity par1Entity, float par2)
        {
            if (par1Entity is EntityPlayer)
            {
                if (par2 < 3F)
                {
                    double d  = par1Entity.PosX - PosX;
                    double d1 = par1Entity.PosZ - PosZ;
                    RotationYaw = (float)((Math.Atan2(d1, d) * 180D) / Math.PI) - 90F;
                    HasAttacked = true;
                }

                EntityPlayer entityplayer = (EntityPlayer)par1Entity;

                if (entityplayer.GetCurrentEquippedItem() == null || !IsWheat(entityplayer.GetCurrentEquippedItem()))
                {
                    EntityToAttack = null;
                }
            }
            else if (par1Entity is EntityAnimal)
            {
                EntityAnimal entityanimal = (EntityAnimal)par1Entity;

                if (GetGrowingAge() > 0 && entityanimal.GetGrowingAge() < 0)
                {
                    if ((double)par2 < 2.5D)
                    {
                        HasAttacked = true;
                    }
                }
                else if (InLove > 0 && entityanimal.InLove > 0)
                {
                    if (entityanimal.EntityToAttack == null)
                    {
                        entityanimal.EntityToAttack = this;
                    }

                    if (entityanimal.EntityToAttack == this && (double)par2 < 3.5D)
                    {
                        entityanimal.InLove++;
                        InLove++;
                        Breeding++;

                        if (Breeding % 4 == 0)
                        {
                            WorldObj.SpawnParticle("heart", (PosX + (double)(Rand.NextFloat() * Width * 2.0F)) - (double)Width, PosY + 0.5D + (double)(Rand.NextFloat() * Height), (PosZ + (double)(Rand.NextFloat() * Width * 2.0F)) - (double)Width, 0.0F, 0.0F, 0.0F);
                        }

                        if (Breeding == 60)
                        {
                            Procreate((EntityAnimal)par1Entity);
                        }
                    }
                    else
                    {
                        Breeding = 0;
                    }
                }
                else
                {
                    Breeding       = 0;
                    EntityToAttack = null;
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Called to update the entity's position/logic.
        /// </summary>
        public override void OnUpdate()
        {
            base.OnUpdate();

            if (FishPosRotationIncrements > 0)
            {
                float  d  = PosX + (FishX - PosX) / FishPosRotationIncrements;
                float  d1 = PosY + (FishY - PosY) / FishPosRotationIncrements;
                float  d2 = PosZ + (FishZ - PosZ) / FishPosRotationIncrements;
                double d4;

                for (d4 = FishYaw - RotationYaw; d4 < -180D; d4 += 360D)
                {
                }

                for (; d4 >= 180D; d4 -= 360D)
                {
                }

                RotationYaw   += (float)d4 / FishPosRotationIncrements;
                RotationPitch += (float)(FishPitch - RotationPitch) / FishPosRotationIncrements;
                FishPosRotationIncrements--;
                SetPosition(d, d1, d2);
                SetRotation(RotationYaw, RotationPitch);
                return;
            }

            if (!WorldObj.IsRemote)
            {
                ItemStack itemstack = Angler.GetCurrentEquippedItem();

                if (Angler.IsDead || !Angler.IsEntityAlive() || itemstack == null || itemstack.GetItem() != Item.FishingRod || GetDistanceSqToEntity(Angler) > 1024D)
                {
                    SetDead();
                    Angler.FishEntity = null;
                    return;
                }

                if (Bobber != null)
                {
                    if (Bobber.IsDead)
                    {
                        Bobber = null;
                    }
                    else
                    {
                        PosX = Bobber.PosX;
                        PosY = Bobber.BoundingBox.MinY + Bobber.Height * 0.80000000000000004F;
                        PosZ = Bobber.PosZ;
                        return;
                    }
                }
            }

            if (Shake > 0)
            {
                Shake--;
            }

            if (InGround)
            {
                int i = WorldObj.GetBlockId(XTile, YTile, ZTile);

                if (i != InTile)
                {
                    InGround      = false;
                    MotionX      *= Rand.NextFloat() * 0.2F;
                    MotionY      *= Rand.NextFloat() * 0.2F;
                    MotionZ      *= Rand.NextFloat() * 0.2F;
                    TicksInGround = 0;
                    TicksInAir    = 0;
                }
                else
                {
                    TicksInGround++;

                    if (TicksInGround == 1200)
                    {
                        SetDead();
                    }

                    return;
                }
            }
            else
            {
                TicksInAir++;
            }

            Vec3D vec3d  = Vec3D.CreateVector(PosX, PosY, PosZ);
            Vec3D vec3d1 = Vec3D.CreateVector(PosX + MotionX, PosY + MotionY, PosZ + MotionZ);
            MovingObjectPosition movingobjectposition = WorldObj.RayTraceBlocks(vec3d, vec3d1);

            vec3d  = Vec3D.CreateVector(PosX, PosY, PosZ);
            vec3d1 = Vec3D.CreateVector(PosX + MotionX, PosY + MotionY, PosZ + MotionZ);

            if (movingobjectposition != null)
            {
                vec3d1 = Vec3D.CreateVector(movingobjectposition.HitVec.XCoord, movingobjectposition.HitVec.YCoord, movingobjectposition.HitVec.ZCoord);
            }

            Entity        entity = null;
            List <Entity> list   = WorldObj.GetEntitiesWithinAABBExcludingEntity(this, BoundingBox.AddCoord(MotionX, MotionY, MotionZ).Expand(1.0F, 1.0F, 1.0F));
            double        d3     = 0.0F;

            for (int j = 0; j < list.Count; j++)
            {
                Entity entity1 = list[j];

                if (!entity1.CanBeCollidedWith() || entity1 == Angler && TicksInAir < 5)
                {
                    continue;
                }

                float                f2                    = 0.3F;
                AxisAlignedBB        axisalignedbb         = entity1.BoundingBox.Expand(f2, f2, f2);
                MovingObjectPosition movingobjectposition1 = axisalignedbb.CalculateIntercept(vec3d, vec3d1);

                if (movingobjectposition1 == null)
                {
                    continue;
                }

                double d6 = vec3d.DistanceTo(movingobjectposition1.HitVec);

                if (d6 < d3 || d3 == 0.0F)
                {
                    entity = entity1;
                    d3     = d6;
                }
            }

            if (entity != null)
            {
                movingobjectposition = new MovingObjectPosition(entity);
            }

            if (movingobjectposition != null)
            {
                if (movingobjectposition.EntityHit != null)
                {
                    if (movingobjectposition.EntityHit.AttackEntityFrom(DamageSource.CauseThrownDamage(this, Angler), 0))
                    {
                        Bobber = movingobjectposition.EntityHit;
                    }
                }
                else
                {
                    InGround = true;
                }
            }

            if (InGround)
            {
                return;
            }

            MoveEntity(MotionX, MotionY, MotionZ);
            float f = MathHelper2.Sqrt_double(MotionX * MotionX + MotionZ * MotionZ);

            RotationYaw = (float)((Math.Atan2(MotionX, MotionZ) * 180D) / Math.PI);

            for (RotationPitch = (float)((Math.Atan2(MotionY, f) * 180D) / Math.PI); RotationPitch - PrevRotationPitch < -180F; PrevRotationPitch -= 360F)
            {
            }

            for (; RotationPitch - PrevRotationPitch >= 180F; PrevRotationPitch += 360F)
            {
            }

            for (; RotationYaw - PrevRotationYaw < -180F; PrevRotationYaw -= 360F)
            {
            }

            for (; RotationYaw - PrevRotationYaw >= 180F; PrevRotationYaw += 360F)
            {
            }

            RotationPitch = PrevRotationPitch + (RotationPitch - PrevRotationPitch) * 0.2F;
            RotationYaw   = PrevRotationYaw + (RotationYaw - PrevRotationYaw) * 0.2F;
            float f1 = 0.92F;

            if (OnGround || IsCollidedHorizontally)
            {
                f1 = 0.5F;
            }

            int   k  = 5;
            float d5 = 0.0F;

            for (int l = 0; l < k; l++)
            {
                float         d8             = ((BoundingBox.MinY + ((BoundingBox.MaxY - BoundingBox.MinY) * (l + 0)) / k) - 0.125F) + 0.125F;
                float         d9             = ((BoundingBox.MinY + ((BoundingBox.MaxY - BoundingBox.MinY) * (l + 1)) / k) - 0.125F) + 0.125F;
                AxisAlignedBB axisalignedbb1 = AxisAlignedBB.GetBoundingBoxFromPool(BoundingBox.MinX, d8, BoundingBox.MinZ, BoundingBox.MaxX, d9, BoundingBox.MaxZ);

                if (WorldObj.IsAABBInMaterial(axisalignedbb1, Material.Water))
                {
                    d5 += 1.0F / k;
                }
            }

            if (d5 > 0.0F)
            {
                if (TicksCatchable > 0)
                {
                    TicksCatchable--;
                }
                else
                {
                    int c = 500;

                    if (WorldObj.CanLightningStrikeAt(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(PosY) + 1, MathHelper2.Floor_double(PosZ)))
                    {
                        c = 300;
                    }

                    if (Rand.Next(c) == 0)
                    {
                        TicksCatchable = Rand.Next(30) + 10;
                        MotionY       -= 0.20000000298023224F;
                        WorldObj.PlaySoundAtEntity(this, "random.splash", 0.25F, 1.0F + (Rand.NextFloat() - Rand.NextFloat()) * 0.4F);
                        float f3 = MathHelper2.Floor_double(BoundingBox.MinY);

                        for (int i1 = 0; (float)i1 < 1.0F + Width * 20F; i1++)
                        {
                            float f4 = (Rand.NextFloat() * 2.0F - 1.0F) * Width;
                            float f6 = (Rand.NextFloat() * 2.0F - 1.0F) * Width;
                            WorldObj.SpawnParticle("bubble", PosX + f4, f3 + 1.0F, PosZ + f6, MotionX, MotionY - (Rand.NextFloat() * 0.2F), MotionZ);
                        }

                        for (int j1 = 0; (float)j1 < 1.0F + Width * 20F; j1++)
                        {
                            float f5 = (Rand.NextFloat() * 2.0F - 1.0F) * Width;
                            float f7 = (Rand.NextFloat() * 2.0F - 1.0F) * Width;
                            WorldObj.SpawnParticle("splash", PosX + f5, f3 + 1.0F, PosZ + f7, MotionX, MotionY, MotionZ);
                        }
                    }
                }
            }

            if (TicksCatchable > 0)
            {
                MotionY -= (Rand.NextFloat() * Rand.NextFloat() * Rand.NextFloat()) * 0.20000000000000001F;
            }

            float d7 = d5 * 2F - 1.0F;

            MotionY += 0.039999999105930328F * d7;

            if (d5 > 0.0F)
            {
                f1       = (float)((double)f1 * 0.90000000000000002D);
                MotionY *= 0.80000000000000004F;
            }

            MotionX *= f1;
            MotionY *= f1;
            MotionZ *= f1;
            SetPosition(PosX, PosY, PosZ);
        }