Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }