/// <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>
        /// Called when the throwable hits a block or entity.
        /// </summary>
        protected override void OnImpact(MovingObjectPosition par1MovingObjectPosition)
        {
            if (!WorldObj.IsRemote)
            {
                WorldObj.PlayAuxSFX(2002, (int)Math.Round(PosX), (int)Math.Round(PosY), (int)Math.Round(PosZ), 0);

                for (int i = 3 + WorldObj.Rand.Next(5) + WorldObj.Rand.Next(5); i > 0;)
                {
                    int j = EntityXPOrb.GetXPSplit(i);
                    i -= j;
                    WorldObj.SpawnEntityInWorld(new EntityXPOrb(WorldObj, PosX, PosY, PosZ, j));
                }

                SetDead();
            }
        }
Esempio n. 3
0
        protected virtual void Func_40071_a(MovingObjectPosition par1MovingObjectPosition)
        {
            if (!WorldObj.IsRemote)
            {
                if (par1MovingObjectPosition.EntityHit != null)
                {
                    if (!par1MovingObjectPosition.EntityHit.AttackEntityFrom(DamageSource.CauseFireballDamage(this, ShootingEntity), 4))
                    {
                        ;
                    }
                }

                WorldObj.NewExplosion(null, PosX, PosY, PosZ, 1.0F, true);
                SetDead();
            }
        }
Esempio n. 4
0
        protected virtual MovingObjectPosition GetMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, bool par3)
        {
            float  f      = 1.0F;
            float  f1     = par2EntityPlayer.PrevRotationPitch + (par2EntityPlayer.RotationPitch - par2EntityPlayer.PrevRotationPitch) * f;
            float  f2     = par2EntityPlayer.PrevRotationYaw + (par2EntityPlayer.RotationYaw - par2EntityPlayer.PrevRotationYaw) * f;
            double d      = par2EntityPlayer.PrevPosX + (par2EntityPlayer.PosX - par2EntityPlayer.PrevPosX) * (double)f;
            double d1     = (par2EntityPlayer.PrevPosY + (par2EntityPlayer.PosY - par2EntityPlayer.PrevPosY) * (double)f + 1.6200000000000001D) - (double)par2EntityPlayer.YOffset;
            double d2     = par2EntityPlayer.PrevPosZ + (par2EntityPlayer.PosZ - par2EntityPlayer.PrevPosZ) * (double)f;
            Vec3D  vec3d  = Vec3D.CreateVector(d, d1, d2);
            float  f3     = MathHelper2.Cos(-f2 * 0.01745329F - (float)Math.PI);
            float  f4     = MathHelper2.Sin(-f2 * 0.01745329F - (float)Math.PI);
            float  f5     = -MathHelper2.Cos(-f1 * 0.01745329F);
            float  f6     = MathHelper2.Sin(-f1 * 0.01745329F);
            float  f7     = f4 * f5;
            float  f8     = f6;
            float  f9     = f3 * f5;
            double d3     = 5D;
            Vec3D  vec3d1 = vec3d.AddVector((double)f7 * d3, (double)f8 * d3, (double)f9 * d3);
            MovingObjectPosition movingobjectposition = par1World.RayTraceBlocks_do_do(vec3d, vec3d1, par3, !par3);

            return(movingobjectposition);
        }
 /// <summary>
 /// Called when the throwable hits a block or entity.
 /// </summary>
 protected abstract void OnImpact(MovingObjectPosition movingobjectposition);
        /// <summary>
        /// Called to update the entity's position/logic.
        /// </summary>
        public override void OnUpdate()
        {
            LastTickPosX = PosX;
            LastTickPosY = PosY;
            LastTickPosZ = PosZ;
            base.OnUpdate();

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

            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);
            }

            if (!WorldObj.IsRemote)
            {
                Entity        entity = null;
                List <Entity> list   = WorldObj.GetEntitiesWithinAABBExcludingEntity(this, BoundingBox.AddCoord(MotionX, MotionY, MotionZ).Expand(1.0F, 1.0F, 1.0F));
                float         d      = 0.0F;

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

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

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

                    if (movingobjectposition1 == null)
                    {
                        continue;
                    }

                    float d1 = (float)vec3d.DistanceTo(movingobjectposition1.HitVec);

                    if (d1 < d || d == 0.0F)
                    {
                        entity = entity1;
                        d      = d1;
                    }
                }

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

            if (movingobjectposition != null)
            {
                OnImpact(movingobjectposition);
            }

            PosX += MotionX;
            PosY += MotionY;
            PosZ += 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.99F;
            float f2 = Func_40075_e();

            if (IsInWater())
            {
                for (int j = 0; j < 4; j++)
                {
                    float f3 = 0.25F;
                    WorldObj.SpawnParticle("bubble", PosX - MotionX * f3, PosY - MotionY * f3, PosZ - MotionZ * f3, MotionX, MotionY, MotionZ);
                }

                f1 = 0.8F;
            }

            MotionX *= f1;
            MotionY *= f1;
            MotionZ *= f1;
            MotionY -= f2;
            SetPosition(PosX, PosY, PosZ);
        }
Esempio n. 7
0
        /// <summary>
        /// Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
        /// </summary>
        public override ItemStack OnItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
        {
            float  f      = 1.0F;
            float  f1     = par3EntityPlayer.PrevRotationPitch + (par3EntityPlayer.RotationPitch - par3EntityPlayer.PrevRotationPitch) * f;
            float  f2     = par3EntityPlayer.PrevRotationYaw + (par3EntityPlayer.RotationYaw - par3EntityPlayer.PrevRotationYaw) * f;
            double d      = par3EntityPlayer.PrevPosX + (par3EntityPlayer.PosX - par3EntityPlayer.PrevPosX) * (double)f;
            double d1     = (par3EntityPlayer.PrevPosY + (par3EntityPlayer.PosY - par3EntityPlayer.PrevPosY) * (double)f + 1.6200000000000001D) - (double)par3EntityPlayer.YOffset;
            double d2     = par3EntityPlayer.PrevPosZ + (par3EntityPlayer.PosZ - par3EntityPlayer.PrevPosZ) * (double)f;
            Vec3D  vec3d  = Vec3D.CreateVector(d, d1, d2);
            float  f3     = MathHelper2.Cos(-f2 * 0.01745329F - (float)Math.PI);
            float  f4     = MathHelper2.Sin(-f2 * 0.01745329F - (float)Math.PI);
            float  f5     = -MathHelper2.Cos(-f1 * 0.01745329F);
            float  f6     = MathHelper2.Sin(-f1 * 0.01745329F);
            float  f7     = f4 * f5;
            float  f8     = f6;
            float  f9     = f3 * f5;
            float  d3     = 5;
            Vec3D  vec3d1 = vec3d.AddVector((double)f7 * d3, (double)f8 * d3, (double)f9 * d3);
            MovingObjectPosition movingobjectposition = par2World.RayTraceBlocks_do(vec3d, vec3d1, true);

            if (movingobjectposition == null)
            {
                return(par1ItemStack);
            }

            Vec3D         vec3d2 = par3EntityPlayer.GetLook(f);
            bool          flag   = false;
            float         f10    = 1.0F;
            List <Entity> list   = par2World.GetEntitiesWithinAABBExcludingEntity(par3EntityPlayer, par3EntityPlayer.BoundingBox.AddCoord((float)vec3d2.XCoord * d3, (float)vec3d2.YCoord * d3, (float)vec3d2.ZCoord * d3).Expand(f10, f10, f10));

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

                if (!entity.CanBeCollidedWith())
                {
                    continue;
                }

                float         f11           = entity.GetCollisionBorderSize();
                AxisAlignedBB axisalignedbb = entity.BoundingBox.Expand(f11, f11, f11);

                if (axisalignedbb.IsVecInside(vec3d))
                {
                    flag = true;
                }
            }

            if (flag)
            {
                return(par1ItemStack);
            }

            if (movingobjectposition.TypeOfHit == EnumMovingObjectType.TILE)
            {
                int i = movingobjectposition.BlockX;
                int j = movingobjectposition.BlockY;
                int k = movingobjectposition.BlockZ;

                if (!par2World.IsRemote)
                {
                    if (par2World.GetBlockId(i, j, k) == Block.Snow.BlockID)
                    {
                        j--;
                    }

                    par2World.SpawnEntityInWorld(new EntityBoat(par2World, (float)i + 0.5F, (float)j + 1.0F, (float)k + 0.5F));
                }

                if (!par3EntityPlayer.Capabilities.IsCreativeMode)
                {
                    par1ItemStack.StackSize--;
                }
            }

            return(par1ItemStack);
        }
Esempio n. 8
0
        /// <summary>
        /// Called to update the entity's position/logic.
        /// </summary>
        public override void OnUpdate()
        {
            if (!WorldObj.IsRemote && (ShootingEntity != null && ShootingEntity.IsDead || !WorldObj.BlockExists((int)PosX, (int)PosY, (int)PosZ)))
            {
                SetDead();
                return;
            }

            base.OnUpdate();
            SetFire(1);

            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;
                    TicksAlive = 0;
                    TicksInAir = 0;
                }
                else
                {
                    TicksAlive++;

                    if (TicksAlive == 600)
                    {
                        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        d      = 0.0F;

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

                if (!entity1.CanBeCollidedWith() || entity1.IsEntityEqual(ShootingEntity) && TicksInAir < 25)
                {
                    continue;
                }

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

                if (movingobjectposition1 == null)
                {
                    continue;
                }

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

                if (d1 < d || d == 0.0F)
                {
                    entity = entity1;
                    d      = d1;
                }
            }

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

            if (movingobjectposition != null)
            {
                Func_40071_a(movingobjectposition);
            }

            PosX += MotionX;
            PosY += MotionY;
            PosZ += 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.95F;

            if (IsInWater())
            {
                for (int k = 0; k < 4; k++)
                {
                    float f3 = 0.25F;
                    WorldObj.SpawnParticle("bubble", PosX - MotionX * (double)f3, PosY - MotionY * (double)f3, PosZ - MotionZ * (double)f3, MotionX, MotionY, MotionZ);
                }

                f1 = 0.8F;
            }

            MotionX += AccelerationX;
            MotionY += AccelerationY;
            MotionZ += AccelerationZ;
            MotionX *= f1;
            MotionY *= f1;
            MotionZ *= f1;
            WorldObj.SpawnParticle("smoke", PosX, PosY + 0.5D, PosZ, 0.0F, 0.0F, 0.0F);
            SetPosition(PosX, PosY, PosZ);
        }
Esempio n. 9
0
        /// <summary>
        /// Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
        /// </summary>
        public override ItemStack OnItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
        {
            float  f    = 1.0F;
            double d    = par3EntityPlayer.PrevPosX + (par3EntityPlayer.PosX - par3EntityPlayer.PrevPosX) * (double)f;
            double d1   = (par3EntityPlayer.PrevPosY + (par3EntityPlayer.PosY - par3EntityPlayer.PrevPosY) * (double)f + 1.6200000000000001D) - (double)par3EntityPlayer.YOffset;
            double d2   = par3EntityPlayer.PrevPosZ + (par3EntityPlayer.PosZ - par3EntityPlayer.PrevPosZ) * (double)f;
            bool   flag = IsFull == 0;
            MovingObjectPosition movingobjectposition = GetMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, flag);

            if (movingobjectposition == null)
            {
                return(par1ItemStack);
            }

            if (movingobjectposition.TypeOfHit == EnumMovingObjectType.TILE)
            {
                int i = movingobjectposition.BlockX;
                int j = movingobjectposition.BlockY;
                int k = movingobjectposition.BlockZ;

                if (!par2World.CanMineBlock(par3EntityPlayer, i, j, k))
                {
                    return(par1ItemStack);
                }

                if (IsFull == 0)
                {
                    if (!par3EntityPlayer.CanPlayerEdit(i, j, k))
                    {
                        return(par1ItemStack);
                    }

                    if (par2World.GetBlockMaterial(i, j, k) == Material.Water && par2World.GetBlockMetadata(i, j, k) == 0)
                    {
                        par2World.SetBlockWithNotify(i, j, k, 0);

                        if (par3EntityPlayer.Capabilities.IsCreativeMode)
                        {
                            return(par1ItemStack);
                        }
                        else
                        {
                            return(new ItemStack(Item.BucketWater));
                        }
                    }

                    if (par2World.GetBlockMaterial(i, j, k) == Material.Lava && par2World.GetBlockMetadata(i, j, k) == 0)
                    {
                        par2World.SetBlockWithNotify(i, j, k, 0);

                        if (par3EntityPlayer.Capabilities.IsCreativeMode)
                        {
                            return(par1ItemStack);
                        }
                        else
                        {
                            return(new ItemStack(Item.BucketLava));
                        }
                    }
                }
                else
                {
                    if (IsFull < 0)
                    {
                        return(new ItemStack(Item.BucketEmpty));
                    }

                    if (movingobjectposition.SideHit == 0)
                    {
                        j--;
                    }

                    if (movingobjectposition.SideHit == 1)
                    {
                        j++;
                    }

                    if (movingobjectposition.SideHit == 2)
                    {
                        k--;
                    }

                    if (movingobjectposition.SideHit == 3)
                    {
                        k++;
                    }

                    if (movingobjectposition.SideHit == 4)
                    {
                        i--;
                    }

                    if (movingobjectposition.SideHit == 5)
                    {
                        i++;
                    }

                    if (!par3EntityPlayer.CanPlayerEdit(i, j, k))
                    {
                        return(par1ItemStack);
                    }

                    if (par2World.IsAirBlock(i, j, k) || !par2World.GetBlockMaterial(i, j, k).IsSolid())
                    {
                        if (par2World.WorldProvider.IsHellWorld && IsFull == Block.WaterMoving.BlockID)
                        {
                            par2World.PlaySoundEffect(d + 0.5D, d1 + 0.5D, d2 + 0.5D, "random.fizz", 0.5F, 2.6F + (par2World.Rand.NextFloat() - par2World.Rand.NextFloat()) * 0.8F);

                            for (int l = 0; l < 8; l++)
                            {
                                par2World.SpawnParticle("largesmoke", (double)i + (new Random(1)).NextDouble(), (double)j + new Random(2).NextDouble(), (double)k + new Random(3).NextDouble(), 0.0F, 0.0F, 0.0F);
                            }
                        }
                        else
                        {
                            par2World.SetBlockAndMetadataWithNotify(i, j, k, IsFull, 0);
                        }

                        if (par3EntityPlayer.Capabilities.IsCreativeMode)
                        {
                            return(par1ItemStack);
                        }
                        else
                        {
                            return(new ItemStack(Item.BucketEmpty));
                        }
                    }
                }
            }
            else if (IsFull == 0 && (movingobjectposition.EntityHit is EntityCow))
            {
                return(new ItemStack(Item.BucketMilk));
            }

            return(par1ItemStack);
        }
Esempio n. 10
0
        /// <summary>
        /// Called to update the entity's position/logic.
        /// </summary>
        public override void OnUpdate()
        {
            base.OnUpdate();

            if (PrevRotationPitch == 0.0F && PrevRotationYaw == 0.0F)
            {
                float f = MathHelper2.Sqrt_double(MotionX * MotionX + MotionZ * MotionZ);
                PrevRotationYaw   = RotationYaw = (float)((Math.Atan2(MotionX, MotionZ) * 180D) / Math.PI);
                PrevRotationPitch = RotationPitch = (float)((Math.Atan2(MotionY, f) * 180D) / Math.PI);
            }

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

            if (i > 0)
            {
                Block.BlocksList[i].SetBlockBoundsBasedOnState(WorldObj, XTile, YTile, ZTile);
                AxisAlignedBB axisalignedbb = Block.BlocksList[i].GetCollisionBoundingBoxFromPool(WorldObj, XTile, YTile, ZTile);

                if (axisalignedbb != null && axisalignedbb.IsVecInside(Vec3D.CreateVector(PosX, PosY, PosZ)))
                {
                    InGround = true;
                }
            }

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

            if (InGround)
            {
                int j = WorldObj.GetBlockId(XTile, YTile, ZTile);
                int k = WorldObj.GetBlockMetadata(XTile, YTile, ZTile);

                if (j != InTile || k != InData)
                {
                    InGround      = false;
                    MotionX      *= Rand.NextFloat() * 0.2F;
                    MotionY      *= Rand.NextFloat() * 0.2F;
                    MotionZ      *= Rand.NextFloat() * 0.2F;
                    TicksInGround = 0;
                    TicksInAir    = 0;
                    return;
                }

                TicksInGround++;

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

                return;
            }

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

            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        d      = 0.0F;

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

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

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

                if (movingobjectposition1 == null)
                {
                    continue;
                }

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

                if (d1 < d || d == 0.0F)
                {
                    entity = entity1;
                    d      = d1;
                }
            }

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

            if (movingobjectposition != null)
            {
                if (movingobjectposition.EntityHit != null)
                {
                    float f1 = MathHelper2.Sqrt_double(MotionX * MotionX + MotionY * MotionY + MotionZ * MotionZ);
                    int   j1 = (int)Math.Ceiling((double)f1 * Damage);

                    if (ArrowCritical)
                    {
                        j1 += Rand.Next(j1 / 2 + 2);
                    }

                    DamageSource damagesource = null;

                    if (ShootingEntity == null)
                    {
                        damagesource = DamageSource.CauseArrowDamage(this, this);
                    }
                    else
                    {
                        damagesource = DamageSource.CauseArrowDamage(this, ShootingEntity);
                    }

                    if (IsBurning())
                    {
                        movingobjectposition.EntityHit.SetFire(5);
                    }

                    if (movingobjectposition.EntityHit.AttackEntityFrom(damagesource, j1))
                    {
                        if (movingobjectposition.EntityHit is EntityLiving)
                        {
                            ((EntityLiving)movingobjectposition.EntityHit).ArrowHitTempCounter++;

                            if (Field_46027_au > 0)
                            {
                                float f7 = MathHelper2.Sqrt_double(MotionX * MotionX + MotionZ * MotionZ);

                                if (f7 > 0.0F)
                                {
                                    movingobjectposition.EntityHit.AddVelocity((MotionX * Field_46027_au * 0.60000002384185791F) / f7, 0.10000000000000001F, (MotionZ * Field_46027_au * 0.60000002384185791F) / f7);
                                }
                            }
                        }

                        WorldObj.PlaySoundAtEntity(this, "random.bowhit", 1.0F, 1.2F / (Rand.NextFloat() * 0.2F + 0.9F));
                        SetDead();
                    }
                    else
                    {
                        MotionX         *= -0.10000000149011612F;
                        MotionY         *= -0.10000000149011612F;
                        MotionZ         *= -0.10000000149011612F;
                        RotationYaw     += 180F;
                        PrevRotationYaw += 180F;
                        TicksInAir       = 0;
                    }
                }
                else
                {
                    XTile   = movingobjectposition.BlockX;
                    YTile   = movingobjectposition.BlockY;
                    ZTile   = movingobjectposition.BlockZ;
                    InTile  = WorldObj.GetBlockId(XTile, YTile, ZTile);
                    InData  = WorldObj.GetBlockMetadata(XTile, YTile, ZTile);
                    MotionX = (float)(movingobjectposition.HitVec.XCoord - PosX);
                    MotionY = (float)(movingobjectposition.HitVec.YCoord - PosY);
                    MotionZ = (float)(movingobjectposition.HitVec.ZCoord - PosZ);
                    float f2 = MathHelper2.Sqrt_double(MotionX * MotionX + MotionY * MotionY + MotionZ * MotionZ);
                    PosX -= (MotionX / f2) * 0.05000000074505806F;
                    PosY -= (MotionY / f2) * 0.05000000074505806F;
                    PosZ -= (MotionZ / f2) * 0.05000000074505806F;
                    WorldObj.PlaySoundAtEntity(this, "random.bowhit", 1.0F, 1.2F / (Rand.NextFloat() * 0.2F + 0.9F));
                    InGround      = true;
                    ArrowShake    = 7;
                    ArrowCritical = false;
                }
            }

            if (ArrowCritical)
            {
                for (int i1 = 0; i1 < 4; i1++)
                {
                    WorldObj.SpawnParticle("crit", PosX + (MotionX * (double)i1) / 4D, PosY + (MotionY * (double)i1) / 4D, PosZ + (MotionZ * (double)i1) / 4D, -MotionX, -MotionY + 0.20000000000000001D, -MotionZ);
                }
            }

            PosX += MotionX;
            PosY += MotionY;
            PosZ += MotionZ;
            float f3 = MathHelper2.Sqrt_double(MotionX * MotionX + MotionZ * MotionZ);

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

            for (RotationPitch = (float)((Math.Atan2(MotionY, f3) * 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 f4 = 0.99F;
            float f6 = 0.05F;

            if (IsInWater())
            {
                for (int k1 = 0; k1 < 4; k1++)
                {
                    float f8 = 0.25F;
                    WorldObj.SpawnParticle("bubble", PosX - MotionX * (double)f8, PosY - MotionY * (double)f8, PosZ - MotionZ * (double)f8, MotionX, MotionY, MotionZ);
                }

                f4 = 0.8F;
            }

            MotionX *= f4;
            MotionY *= f4;
            MotionZ *= f4;
            MotionY -= f6;
            SetPosition(PosX, PosY, PosZ);
        }
Esempio n. 11
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);
        }