コード例 #1
0
        private void UpdatePushedObjects(float par1, float par2)
        {
            if (!Extending)
            {
                par1--;
            }
            else
            {
                par1 = 1.0F - par1;
            }

            AxisAlignedBB axisalignedbb = Block.PistonMoving.GetAxisAlignedBB(WorldObj, XCoord, YCoord, ZCoord, StoredBlockID, par1, StoredOrientation);

            if (axisalignedbb != null)
            {
                List <Entity> list = WorldObj.GetEntitiesWithinAABBExcludingEntity(null, axisalignedbb);

                if (list.Count > 0)
                {
                    PushedObjects.AddRange(list);
                    Entity entity;

                    for (IEnumerator <Entity> iterator = PushedObjects.GetEnumerator(); iterator.MoveNext(); entity.MoveEntity(par2 * (float)Facing.OffsetsXForSide[StoredOrientation], par2 * (float)Facing.OffsetsYForSide[StoredOrientation], par2 * (float)Facing.OffsetsZForSide[StoredOrientation]))
                    {
                        entity = iterator.Current;
                    }

                    PushedObjects.Clear();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Called to update the entity's position/logic.
        /// </summary>
        public override void OnUpdate()
        {
            base.OnUpdate();

            if (LightningState == 2)
            {
                WorldObj.PlaySoundEffect(PosX, PosY, PosZ, "ambient.weather.thunder", 10000F, 0.8F + Rand.NextFloat() * 0.2F);
                WorldObj.PlaySoundEffect(PosX, PosY, PosZ, "random.explode", 2.0F, 0.5F + Rand.NextFloat() * 0.2F);
            }

            LightningState--;

            if (LightningState < 0)
            {
                if (BoltLivingTime == 0)
                {
                    SetDead();
                }
                else if (LightningState < -Rand.Next(10))
                {
                    BoltLivingTime--;
                    LightningState = 1;
                    BoltVertex     = Rand.Next();

                    if (WorldObj.DoChunksNearChunkExist(MathHelper2.Floor_double(PosX), MathHelper2.Floor_double(PosY), MathHelper2.Floor_double(PosZ), 10))
                    {
                        int i = MathHelper2.Floor_double(PosX);
                        int j = MathHelper2.Floor_double(PosY);
                        int k = MathHelper2.Floor_double(PosZ);

                        if (WorldObj.GetBlockId(i, j, k) == 0 && Block.Fire.CanPlaceBlockAt(WorldObj, i, j, k))
                        {
                            WorldObj.SetBlockWithNotify(i, j, k, Block.Fire.BlockID);
                        }
                    }
                }
            }

            if (LightningState >= 0)
            {
                float         d    = 3;
                List <Entity> list = WorldObj.GetEntitiesWithinAABBExcludingEntity(this, AxisAlignedBB.GetBoundingBoxFromPool(PosX - d, PosY - d, PosZ - d, PosX + d, PosY + 6 + d, PosZ + d));

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

                WorldObj.LightningFlash = 2;
            }
        }
コード例 #3
0
        /// <summary>
        /// Called when the entity is attacked.
        /// </summary>
        public override bool AttackEntityFrom(DamageSource par1DamageSource, int par2)
        {
            Entity entity = par1DamageSource.GetEntity();

            if (entity is EntityPlayer)
            {
                List <Entity> list = WorldObj.GetEntitiesWithinAABBExcludingEntity(this, BoundingBox.Expand(32, 32, 32));

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

                    if (entity1 is EntityPigZombie)
                    {
                        EntityPigZombie entitypigzombie = (EntityPigZombie)entity1;
                        entitypigzombie.BecomeAngryAt(entity);
                    }
                }

                BecomeAngryAt(entity);
            }

            return(base.AttackEntityFrom(par1DamageSource, par2));
        }
コード例 #4
0
        /// <summary>
        /// Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
        /// use this to react to sunlight and start to burn.
        /// </summary>
        public override void OnLivingUpdate()
        {
            Field_40173_aw = Field_40172_ax;

            if (!WorldObj.IsRemote)
            {
                DataWatcher.UpdateObject(16, Convert.ToInt32(Health));
            }

            if (Health <= 0)
            {
                float f  = (Rand.NextFloat() - 0.5F) * 8F;
                float f2 = (Rand.NextFloat() - 0.5F) * 4F;
                float f4 = (Rand.NextFloat() - 0.5F) * 8F;
                WorldObj.SpawnParticle("largeexplode", PosX + (double)f, PosY + 2D + (double)f2, PosZ + (double)f4, 0.0F, 0.0F, 0.0F);
                return;
            }

            UpdateDragonEnderCrystal();
            float f1 = 0.2F / (MathHelper2.Sqrt_double(MotionX * MotionX + MotionZ * MotionZ) * 10F + 1.0F);

            f1 *= (float)Math.Pow(2D, MotionY);

            if (Field_40161_az)
            {
                Field_40172_ax += f1 * 0.5F;
            }
            else
            {
                Field_40172_ax += f1;
            }

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

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

            if (Field_40164_e < 0)
            {
                for (int i = 0; i < Field_40162_d.Length; i++)
                {
                    Field_40162_d[i][0] = RotationYaw;
                    Field_40162_d[i][1] = PosY;
                }
            }

            if (++Field_40164_e == Field_40162_d.Length)
            {
                Field_40164_e = 0;
            }

            Field_40162_d[Field_40164_e][0] = RotationYaw;
            Field_40162_d[Field_40164_e][1] = PosY;

            if (WorldObj.IsRemote)
            {
                if (NewPosRotationIncrements > 0)
                {
                    float  d  = PosX + (NewPosX - PosX) / NewPosRotationIncrements;
                    float  d2 = PosY + (NewPosY - PosY) / NewPosRotationIncrements;
                    float  d4 = PosZ + (NewPosZ - PosZ) / NewPosRotationIncrements;
                    double d6;

                    for (d6 = NewRotationYaw - (double)RotationYaw; d6 < -180D; d6 += 360D)
                    {
                    }

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

                    RotationYaw   += (float)d6 / NewPosRotationIncrements;
                    RotationPitch += (float)(NewRotationPitch - RotationPitch) / NewPosRotationIncrements;
                    NewPosRotationIncrements--;
                    SetPosition(d, d2, d4);
                    SetRotation(RotationYaw, RotationPitch);
                }
            }
            else
            {
                double d1 = TargetX - PosX;
                float  d3 = TargetY - PosY;
                double d5 = TargetZ - PosZ;
                double d7 = d1 * d1 + d3 * d3 + d5 * d5;

                if (Target != null)
                {
                    TargetX = Target.PosX;
                    TargetZ = Target.PosZ;
                    float d8  = TargetX - PosX;
                    float d10 = TargetZ - PosZ;
                    float d12 = (float)Math.Sqrt(d8 * d8 + d10 * d10);
                    float d13 = (0.40000000596046448F + d12 / 80F) - 1.0F;

                    if (d13 > 10F)
                    {
                        d13 = 10F;
                    }

                    TargetY = Target.BoundingBox.MinY + d13;
                }
                else
                {
                    TargetX += Rand.NextGaussian() * 2F;
                    TargetZ += Rand.NextGaussian() * 2F;
                }

                if (Field_40163_ay || d7 < 100D || d7 > 22500D || IsCollidedHorizontally || IsCollidedVertically)
                {
                    Func_41006_aA();
                }

                d3 /= MathHelper2.Sqrt_double(d1 * d1 + d5 * d5);
                float f10 = 0.6F;

                if (d3 < (double)(-f10))
                {
                    d3 = -f10;
                }

                if (d3 > (double)f10)
                {
                    d3 = f10;
                }

                MotionY += d3 * 0.10000000149011612F;

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

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

                double d9 = 180D - (Math.Atan2(d1, d5) * 180D) / Math.PI;
                double d11;

                for (d11 = d9 - (double)RotationYaw; d11 < -180D; d11 += 360D)
                {
                }

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

                if (d11 > 50D)
                {
                    d11 = 50D;
                }

                if (d11 < -50D)
                {
                    d11 = -50D;
                }

                Vec3D vec3d  = Vec3D.CreateVector(TargetX - PosX, TargetY - PosY, TargetZ - PosZ).Normalize();
                Vec3D vec3d1 = Vec3D.CreateVector(MathHelper2.Sin((RotationYaw * (float)Math.PI) / 180F), MotionY, -MathHelper2.Cos((RotationYaw * (float)Math.PI) / 180F)).Normalize();
                float f18    = (float)(vec3d1.DotProduct(vec3d) + 0.5D) / 1.5F;

                if (f18 < 0.0F)
                {
                    f18 = 0.0F;
                }

                RandomYawVelocity *= 0.8F;
                float  f19 = MathHelper2.Sqrt_double(MotionX * MotionX + MotionZ * MotionZ) * 1.0F + 1.0F;
                double d14 = Math.Sqrt(MotionX * MotionX + MotionZ * MotionZ) * 1.0D + 1.0D;

                if (d14 > 40D)
                {
                    d14 = 40D;
                }

                RandomYawVelocity += (float)(d11 * (0.69999998807907104D / d14 / f19));
                RotationYaw       += RandomYawVelocity * 0.1F;
                float f20 = (float)(2D / (d14 + 1.0D));
                float f21 = 0.06F;
                MoveFlying(0.0F, -1F, f21 * (f18 * f20 + (1.0F - f20)));

                if (Field_40161_az)
                {
                    MoveEntity(MotionX * 0.80000001192092896F, MotionY * 0.80000001192092896F, MotionZ * 0.80000001192092896F);
                }
                else
                {
                    MoveEntity(MotionX, MotionY, MotionZ);
                }

                Vec3D vec3d2 = Vec3D.CreateVector(MotionX, MotionY, MotionZ).Normalize();
                float f22    = (float)(vec3d2.DotProduct(vec3d1) + 1.0D) / 2.0F;
                f22      = 0.8F + 0.15F * f22;
                MotionX *= f22;
                MotionZ *= f22;
                MotionY *= 0.9100000262260437F;
            }

            RenderYawOffset        = RotationYaw;
            DragonPartHead.Width   = DragonPartHead.Height = 3F;
            DragonPartTail1.Width  = DragonPartTail1.Height = 2.0F;
            DragonPartTail2.Width  = DragonPartTail2.Height = 2.0F;
            DragonPartTail3.Width  = DragonPartTail3.Height = 2.0F;
            DragonPartBody.Height  = 3F;
            DragonPartBody.Width   = 5F;
            DragonPartWing1.Height = 2.0F;
            DragonPartWing1.Width  = 4F;
            DragonPartWing2.Height = 3F;
            DragonPartWing2.Width  = 4F;
            float f3 = (((float)(Func_40160_a(5, 1.0F)[1] - Func_40160_a(10, 1.0F)[1]) * 10F) / 180F) * (float)Math.PI;
            float f5 = MathHelper2.Cos(f3);
            float f6 = -MathHelper2.Sin(f3);
            float f7 = (RotationYaw * (float)Math.PI) / 180F;
            float f8 = MathHelper2.Sin(f7);
            float f9 = MathHelper2.Cos(f7);

            DragonPartBody.OnUpdate();
            DragonPartBody.SetLocationAndAngles(PosX + (f8 * 0.5F), PosY, PosZ - (f9 * 0.5F), 0.0F, 0.0F);
            DragonPartWing1.OnUpdate();
            DragonPartWing1.SetLocationAndAngles(PosX + (f9 * 4.5F), PosY + 2F, PosZ + (f8 * 4.5F), 0.0F, 0.0F);
            DragonPartWing2.OnUpdate();
            DragonPartWing2.SetLocationAndAngles(PosX - (f9 * 4.5F), PosY + 2F, PosZ - (f8 * 4.5F), 0.0F, 0.0F);

            if (!WorldObj.IsRemote)
            {
                Func_41007_az();
            }

            if (!WorldObj.IsRemote && MaxHurtTime == 0)
            {
                CollideWithEntities(WorldObj.GetEntitiesWithinAABBExcludingEntity(this, DragonPartWing1.BoundingBox.Expand(4, 2, 4).Offset(0.0F, -2F, 0.0F)));
                CollideWithEntities(WorldObj.GetEntitiesWithinAABBExcludingEntity(this, DragonPartWing2.BoundingBox.Expand(4, 2, 4).Offset(0.0F, -2F, 0.0F)));
                AttackEntitiesInList(WorldObj.GetEntitiesWithinAABBExcludingEntity(this, DragonPartHead.BoundingBox.Expand(1.0F, 1.0F, 1.0F)));
            }

            float[] ad  = Func_40160_a(5, 1.0F);
            float[] ad1 = Func_40160_a(0, 1.0F);
            float   f11 = MathHelper2.Sin((RotationYaw * (float)Math.PI) / 180F - RandomYawVelocity * 0.01F);
            float   f12 = MathHelper2.Cos((RotationYaw * (float)Math.PI) / 180F - RandomYawVelocity * 0.01F);

            DragonPartHead.OnUpdate();
            DragonPartHead.SetLocationAndAngles(PosX + (f11 * 5.5F * f5), PosY + (ad1[1] - ad[1]) * 1.0F + (f6 * 5.5F), PosZ - (f12 * 5.5F * f5), 0.0F, 0.0F);

            for (int j = 0; j < 3; j++)
            {
                EntityDragonPart entitydragonpart = null;

                if (j == 0)
                {
                    entitydragonpart = DragonPartTail1;
                }

                if (j == 1)
                {
                    entitydragonpart = DragonPartTail2;
                }

                if (j == 2)
                {
                    entitydragonpart = DragonPartTail3;
                }

                float[] ad2 = Func_40160_a(12 + j * 2, 1.0F);
                float   f13 = (RotationYaw * (float)Math.PI) / 180F + ((SimplifyAngle(ad2[0] - ad[0]) * (float)Math.PI) / 180F) * 1.0F;
                float   f14 = MathHelper2.Sin(f13);
                float   f15 = MathHelper2.Cos(f13);
                float   f16 = 1.5F;
                float   f17 = (float)(j + 1) * 2.0F;
                entitydragonpart.OnUpdate();
                entitydragonpart.SetLocationAndAngles(PosX - ((f8 * f16 + f14 * f17) * f5), ((PosY + (ad2[1] - ad[1]) * 1.0F) - ((f17 + f16) * f6)) + 1.5F, PosZ + ((f9 * f16 + f15 * f17) * f5), 0.0F, 0.0F);
            }

            if (!WorldObj.IsRemote)
            {
                Field_40161_az = DestroyBlocksInAABB(DragonPartHead.BoundingBox) | DestroyBlocksInAABB(DragonPartBody.BoundingBox);
            }
        }
コード例 #5
0
        /// <summary>
        /// checks to make sure painting can be placed there
        /// </summary>
        public virtual bool OnValidSurface()
        {
            if (WorldObj.GetCollidingBoundingBoxes(this, BoundingBox).Count > 0)
            {
                return(false);
            }

            int i  = Art.SizeX / 16;
            int j  = Art.SizeY / 16;
            int k  = XPosition;
            int l  = YPosition;
            int i1 = ZPosition;

            if (Direction == 0)
            {
                k = MathHelper2.Floor_double(PosX - (double)((float)Art.SizeX / 32F));
            }

            if (Direction == 1)
            {
                i1 = MathHelper2.Floor_double(PosZ - (double)((float)Art.SizeX / 32F));
            }

            if (Direction == 2)
            {
                k = MathHelper2.Floor_double(PosX - (double)((float)Art.SizeX / 32F));
            }

            if (Direction == 3)
            {
                i1 = MathHelper2.Floor_double(PosZ - (double)((float)Art.SizeX / 32F));
            }

            l = MathHelper2.Floor_double(PosY - (double)((float)Art.SizeY / 32F));

            for (int j1 = 0; j1 < i; j1++)
            {
                for (int k1 = 0; k1 < j; k1++)
                {
                    Material material;

                    if (Direction == 0 || Direction == 2)
                    {
                        material = WorldObj.GetBlockMaterial(k + j1, l + k1, ZPosition);
                    }
                    else
                    {
                        material = WorldObj.GetBlockMaterial(XPosition, l + k1, i1 + j1);
                    }

                    if (!material.IsSolid())
                    {
                        return(false);
                    }
                }
            }

            List <Entity> list = WorldObj.GetEntitiesWithinAABBExcludingEntity(this, BoundingBox);

            for (int l1 = 0; l1 < list.Count; l1++)
            {
                if (list[l1] is EntityPainting)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
        /// <summary>
        /// Called to update the entity's position/logic.
        /// </summary>
        public override void OnUpdate()
        {
            if (Func_41023_l() > 0)
            {
                Func_41028_c(Func_41023_l() - 1);
            }

            if (Func_41025_i() > 0)
            {
                Func_41024_b(Func_41025_i() - 1);
            }

            if (PosY < -64D)
            {
                Kill();
            }

            if (IsMinecartPowered() && Rand.Next(4) == 0)
            {
                WorldObj.SpawnParticle("largesmoke", PosX, PosY + 0.80000000000000004D, PosZ, 0.0F, 0.0F, 0.0F);
            }

            if (WorldObj.IsRemote)
            {
                if (TurnProgress > 0)
                {
                    float  d  = PosX + (MinecartX - PosX) / TurnProgress;
                    float  d1 = PosY + (MinecartY - PosY) / TurnProgress;
                    float  d3 = PosZ + (MinecartZ - PosZ) / TurnProgress;
                    double d5;

                    for (d5 = MinecartYaw - RotationYaw; d5 < -180D; d5 += 360D)
                    {
                    }

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

                    RotationYaw   += (float)d5 / TurnProgress;
                    RotationPitch += ((float)MinecartPitch - RotationPitch) / TurnProgress;
                    TurnProgress--;
                    SetPosition(d, d1, d3);
                    SetRotation(RotationYaw, RotationPitch);
                }
                else
                {
                    SetPosition(PosX, PosY, PosZ);
                    SetRotation(RotationYaw, RotationPitch);
                }

                return;
            }

            PrevPosX = PosX;
            PrevPosY = PosY;
            PrevPosZ = PosZ;
            MotionY -= 0.039999999105930328F;
            int i = MathHelper2.Floor_double(PosX);
            int j = MathHelper2.Floor_double(PosY);
            int k = MathHelper2.Floor_double(PosZ);

            if (BlockRail.IsRailBlockAt(WorldObj, i, j - 1, k))
            {
                j--;
            }

            float d2 = 0.40000000000000002F;
            float d4 = 0.0078125F;
            int   l  = WorldObj.GetBlockId(i, j, k);

            if (BlockRail.IsRailBlock(l))
            {
                Vec3D vec3d = Func_514_g(PosX, PosY, PosZ);
                int   i1    = WorldObj.GetBlockMetadata(i, j, k);
                PosY = j;
                bool flag  = false;
                bool flag1 = false;

                if (l == Block.RailPowered.BlockID)
                {
                    flag  = (i1 & 8) != 0;
                    flag1 = !flag;
                }

                if (((BlockRail)Block.BlocksList[l]).IsPowered())
                {
                    i1 &= 7;
                }

                if (i1 >= 2 && i1 <= 5)
                {
                    PosY = j + 1;
                }

                if (i1 == 2)
                {
                    MotionX -= d4;
                }

                if (i1 == 3)
                {
                    MotionX += d4;
                }

                if (i1 == 4)
                {
                    MotionZ += d4;
                }

                if (i1 == 5)
                {
                    MotionZ -= d4;
                }

                int[][] ai  = Field_855_j[i1];
                float   d9  = ai[1][0] - ai[0][0];
                float   d10 = ai[1][2] - ai[0][2];
                float   d11 = (float)Math.Sqrt(d9 * d9 + d10 * d10);
                double  d12 = MotionX * d9 + MotionZ * d10;

                if (d12 < 0.0F)
                {
                    d9  = -d9;
                    d10 = -d10;
                }

                float d13 = (float)Math.Sqrt(MotionX * MotionX + MotionZ * MotionZ);
                MotionX = (d13 * d9) / d11;
                MotionZ = (d13 * d10) / d11;

                if (flag1)
                {
                    double d16 = Math.Sqrt(MotionX * MotionX + MotionZ * MotionZ);

                    if (d16 < 0.029999999999999999D)
                    {
                        MotionX *= 0.0F;
                        MotionY *= 0.0F;
                        MotionZ *= 0.0F;
                    }
                    else
                    {
                        MotionX *= 0.5F;
                        MotionY *= 0.0F;
                        MotionZ *= 0.5F;
                    }
                }

                float d17 = 0.0F;
                float d18 = i + 0.5F + ai[0][0] * 0.5F;
                float d19 = k + 0.5F + ai[0][2] * 0.5F;
                float d20 = i + 0.5F + ai[1][0] * 0.5F;
                float d21 = k + 0.5F + ai[1][2] * 0.5F;
                d9  = d20 - d18;
                d10 = d21 - d19;

                if (d9 == 0.0F)
                {
                    PosX = i + 0.5F;
                    d17  = PosZ - k;
                }
                else if (d10 == 0.0F)
                {
                    PosZ = k + 0.5F;
                    d17  = PosX - i;
                }
                else
                {
                    float d22 = PosX - d18;
                    float d24 = PosZ - d19;
                    float d26 = (d22 * d9 + d24 * d10) * 2F;
                    d17 = d26;
                }

                PosX = d18 + d9 * d17;
                PosZ = d19 + d10 * d17;
                SetPosition(PosX, PosY + YOffset, PosZ);
                float d23 = MotionX;
                float d25 = MotionZ;

                if (RiddenByEntity != null)
                {
                    d23 *= 0.75F;
                    d25 *= 0.75F;
                }

                if (d23 < -d2)
                {
                    d23 = -d2;
                }

                if (d23 > d2)
                {
                    d23 = d2;
                }

                if (d25 < -d2)
                {
                    d25 = -d2;
                }

                if (d25 > d2)
                {
                    d25 = d2;
                }

                MoveEntity(d23, 0.0F, d25);

                if (ai[0][1] != 0 && MathHelper2.Floor_double(PosX) - i == ai[0][0] && MathHelper2.Floor_double(PosZ) - k == ai[0][2])
                {
                    SetPosition(PosX, PosY + ai[0][1], PosZ);
                }
                else if (ai[1][1] != 0 && MathHelper2.Floor_double(PosX) - i == ai[1][0] && MathHelper2.Floor_double(PosZ) - k == ai[1][2])
                {
                    SetPosition(PosX, PosY + ai[1][1], PosZ);
                }

                if (RiddenByEntity != null)
                {
                    MotionX *= 0.99699997901916504F;
                    MotionY *= 0.0F;
                    MotionZ *= 0.99699997901916504F;
                }
                else
                {
                    if (MinecartType == 2)
                    {
                        float d27 = MathHelper2.Sqrt_double(PushX * PushX + PushZ * PushZ);

                        if (d27 > 0.01D)
                        {
                            PushX /= d27;
                            PushZ /= d27;
                            float d29 = 0.040000000000000001F;
                            MotionX *= 0.80000001192092896F;
                            MotionY *= 0.0F;
                            MotionZ *= 0.80000001192092896F;
                            MotionX += PushX * d29;
                            MotionZ += PushZ * d29;
                        }
                        else
                        {
                            MotionX *= 0.89999997615814209F;
                            MotionY *= 0.0F;
                            MotionZ *= 0.89999997615814209F;
                        }
                    }

                    MotionX *= 0.95999997854232788F;
                    MotionY *= 0.0F;
                    MotionZ *= 0.95999997854232788F;
                }

                Vec3D vec3d1 = Func_514_g(PosX, PosY, PosZ);

                if (vec3d1 != null && vec3d != null)
                {
                    float d28 = ((float)vec3d.YCoord - (float)vec3d1.YCoord) * 0.050000000000000003F;
                    float d14 = (float)Math.Sqrt(MotionX * MotionX + MotionZ * MotionZ);

                    if (d14 > 0.0F)
                    {
                        MotionX = (MotionX / d14) * (d14 + d28);
                        MotionZ = (MotionZ / d14) * (d14 + d28);
                    }

                    SetPosition(PosX, (float)vec3d1.YCoord, PosZ);
                }

                int k1 = MathHelper2.Floor_double(PosX);
                int l1 = MathHelper2.Floor_double(PosZ);

                if (k1 != i || l1 != k)
                {
                    float d15 = (float)Math.Sqrt(MotionX * MotionX + MotionZ * MotionZ);
                    MotionX = d15 * (k1 - i);
                    MotionZ = d15 * (l1 - k);
                }

                if (MinecartType == 2)
                {
                    float d30 = MathHelper2.Sqrt_double(PushX * PushX + PushZ * PushZ);

                    if (d30 > 0.01F && MotionX * MotionX + MotionZ * MotionZ > 0.001F)
                    {
                        PushX /= d30;
                        PushZ /= d30;

                        if (PushX * MotionX + PushZ * MotionZ < 0.0F)
                        {
                            PushX = 0.0F;
                            PushZ = 0.0F;
                        }
                        else
                        {
                            PushX = MotionX;
                            PushZ = MotionZ;
                        }
                    }
                }

                if (flag)
                {
                    float d31 = (float)Math.Sqrt(MotionX * MotionX + MotionZ * MotionZ);

                    if (d31 > 0.01D)
                    {
                        float d32 = 0.059999999999999998F;
                        MotionX += (MotionX / d31) * d32;
                        MotionZ += (MotionZ / d31) * d32;
                    }
                    else if (i1 == 1)
                    {
                        if (WorldObj.IsBlockNormalCube(i - 1, j, k))
                        {
                            MotionX = 0.02F;
                        }
                        else if (WorldObj.IsBlockNormalCube(i + 1, j, k))
                        {
                            MotionX = -0.02F;
                        }
                    }
                    else if (i1 == 0)
                    {
                        if (WorldObj.IsBlockNormalCube(i, j, k - 1))
                        {
                            MotionZ = 0.02F;
                        }
                        else if (WorldObj.IsBlockNormalCube(i, j, k + 1))
                        {
                            MotionZ = -0.02F;
                        }
                    }
                }
            }
            else
            {
                if (MotionX < -d2)
                {
                    MotionX = -d2;
                }

                if (MotionX > d2)
                {
                    MotionX = d2;
                }

                if (MotionZ < -d2)
                {
                    MotionZ = -d2;
                }

                if (MotionZ > d2)
                {
                    MotionZ = d2;
                }

                if (OnGround)
                {
                    MotionX *= 0.5F;
                    MotionY *= 0.5F;
                    MotionZ *= 0.5F;
                }

                MoveEntity(MotionX, MotionY, MotionZ);

                if (!OnGround)
                {
                    MotionX *= 0.94999998807907104F;
                    MotionY *= 0.94999998807907104F;
                    MotionZ *= 0.94999998807907104F;
                }
            }

            RotationPitch = 0.0F;
            float d6 = PrevPosX - PosX;
            float d7 = PrevPosZ - PosZ;

            if (d6 * d6 + d7 * d7 > 0.001F)
            {
                RotationYaw = (float)((Math.Atan2(d7, d6) * 180F) / Math.PI);

                if (Field_856_i)
                {
                    RotationYaw += 180F;
                }
            }

            float d8;

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

            for (; d8 < -180D; d8 += 360F)
            {
            }

            if (d8 < -170D || d8 >= 170D)
            {
                RotationYaw += 180F;
                Field_856_i  = !Field_856_i;
            }

            SetRotation(RotationYaw, RotationPitch);
            List <Entity> list = WorldObj.GetEntitiesWithinAABBExcludingEntity(this, BoundingBox.Expand(0.20000000298023224F, 0.0F, 0.20000000298023224F));

            if (list != null && list.Count > 0)
            {
                for (int j1 = 0; j1 < list.Count; j1++)
                {
                    Entity entity = list[j1];

                    if (entity != RiddenByEntity && entity.CanBePushed() && (entity is EntityMinecart))
                    {
                        entity.ApplyEntityCollision(this);
                    }
                }
            }

            if (RiddenByEntity != null && RiddenByEntity.IsDead)
            {
                if (RiddenByEntity.RidingEntity == this)
                {
                    RiddenByEntity.RidingEntity = null;
                }

                RiddenByEntity = null;
            }

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

            if (Fuel <= 0)
            {
                PushX = PushZ = 0.0F;
            }

            SetMinecartPowered(Fuel > 0);
        }
コード例 #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);
        }
コード例 #9
0
        /// <summary>
        /// Called to update the entity's position/logic.
        /// </summary>
        public override void OnUpdate()
        {
            base.OnUpdate();

            if (GetTimeSinceHit() > 0)
            {
                SetTimeSinceHit(GetTimeSinceHit() - 1);
            }

            if (GetDamageTaken() > 0)
            {
                SetDamageTaken(GetDamageTaken() - 1);
            }

            PrevPosX = PosX;
            PrevPosY = PosY;
            PrevPosZ = PosZ;
            int   i = 5;
            float d = 0.0F;

            for (int j = 0; j < i; j++)
            {
                float         d2            = (BoundingBox.MinY + ((BoundingBox.MaxY - BoundingBox.MinY) * (j + 0)) / i) - 0.125F;
                float         d8            = (BoundingBox.MinY + ((BoundingBox.MaxY - BoundingBox.MinY) * (j + 1)) / i) - 0.125F;
                AxisAlignedBB axisalignedbb = AxisAlignedBB.GetBoundingBoxFromPool(BoundingBox.MinX, d2, BoundingBox.MinZ, BoundingBox.MaxX, d8, BoundingBox.MaxZ);

                if (WorldObj.IsAABBInMaterial(axisalignedbb, Material.Water))
                {
                    d += 1.0F / i;
                }
            }

            double d1 = Math.Sqrt(MotionX * MotionX + MotionZ * MotionZ);

            if (d1 > 0.14999999999999999D)
            {
                double d3 = Math.Cos(((double)RotationYaw * Math.PI) / 180D);
                double d9 = Math.Sin(((double)RotationYaw * Math.PI) / 180D);

                for (int i1 = 0; (double)i1 < 1.0D + d1 * 60D; i1++)
                {
                    double d16 = Rand.NextFloat() * 2.0F - 1.0F;
                    double d19 = (double)(Rand.Next(2) * 2 - 1) * 0.69999999999999996D;

                    if (Rand.NextBool())
                    {
                        double d21 = (PosX - d3 * d16 * 0.80000000000000004D) + d9 * d19;
                        double d23 = PosZ - d9 * d16 * 0.80000000000000004D - d3 * d19;
                        WorldObj.SpawnParticle("splash", d21, PosY - 0.125D, d23, MotionX, MotionY, MotionZ);
                    }
                    else
                    {
                        double d22 = PosX + d3 + d9 * d16 * 0.69999999999999996D;
                        double d24 = (PosZ + d9) - d3 * d16 * 0.69999999999999996D;
                        WorldObj.SpawnParticle("splash", d22, PosY - 0.125D, d24, MotionX, MotionY, MotionZ);
                    }
                }
            }

            if (WorldObj.IsRemote)
            {
                if (BoatPosRotationIncrements > 0)
                {
                    float  d4  = PosX + (BoatX - PosX) / BoatPosRotationIncrements;
                    float  d10 = PosY + (BoatY - PosY) / BoatPosRotationIncrements;
                    float  d13 = PosZ + (BoatZ - PosZ) / BoatPosRotationIncrements;
                    double d17;

                    for (d17 = BoatYaw - (double)RotationYaw; d17 < -180D; d17 += 360D)
                    {
                    }

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

                    RotationYaw   += (float)d17 / BoatPosRotationIncrements;
                    RotationPitch += ((float)BoatPitch - RotationPitch) / BoatPosRotationIncrements;
                    BoatPosRotationIncrements--;
                    SetPosition(d4, d10, d13);
                    SetRotation(RotationYaw, RotationPitch);
                }
                else
                {
                    float d5  = PosX + MotionX;
                    float d11 = PosY + MotionY;
                    float d14 = PosZ + MotionZ;
                    SetPosition(d5, d11, d14);

                    if (OnGround)
                    {
                        MotionX *= 0.5F;
                        MotionY *= 0.5F;
                        MotionZ *= 0.5F;
                    }

                    MotionX *= 0.99000000953674316F;
                    MotionY *= 0.94999998807907104F;
                    MotionZ *= 0.99000000953674316F;
                }

                return;
            }

            if (d < 1.0F)
            {
                float d6 = d * 2F - 1.0F;
                MotionY += 0.039999999105930328F * d6;
            }
            else
            {
                if (MotionY < 0.0F)
                {
                    MotionY /= 2F;
                }

                MotionY += 0.0070000002160668373F;
            }

            if (RiddenByEntity != null)
            {
                MotionX += RiddenByEntity.MotionX * 0.20000000000000001F;
                MotionZ += RiddenByEntity.MotionZ * 0.20000000000000001F;
            }

            float d7 = 0.40000000000000002F;

            if (MotionX < -d7)
            {
                MotionX = -d7;
            }

            if (MotionX > d7)
            {
                MotionX = d7;
            }

            if (MotionZ < -d7)
            {
                MotionZ = -d7;
            }

            if (MotionZ > d7)
            {
                MotionZ = d7;
            }

            if (OnGround)
            {
                MotionX *= 0.5F;
                MotionY *= 0.5F;
                MotionZ *= 0.5F;
            }

            MoveEntity(MotionX, MotionY, MotionZ);

            if (IsCollidedHorizontally && d1 > 0.20000000000000001F)
            {
                if (!WorldObj.IsRemote)
                {
                    SetDead();

                    for (int k = 0; k < 3; k++)
                    {
                        DropItemWithOffset(Block.Planks.BlockID, 1, 0.0F);
                    }

                    for (int l = 0; l < 2; l++)
                    {
                        DropItemWithOffset(Item.Stick.ShiftedIndex, 1, 0.0F);
                    }
                }
            }
            else
            {
                MotionX *= 0.99000000953674316F;
                MotionY *= 0.94999998807907104F;
                MotionZ *= 0.99000000953674316F;
            }

            RotationPitch = 0.0F;
            double d12 = RotationYaw;
            double d15 = PrevPosX - PosX;
            double d18 = PrevPosZ - PosZ;

            if (d15 * d15 + d18 * d18 > 0.001D)
            {
                d12 = (float)((Math.Atan2(d18, d15) * 180D) / Math.PI);
            }

            double d20;

            for (d20 = d12 - (double)RotationYaw; d20 >= 180D; d20 -= 360D)
            {
            }

            for (; d20 < -180D; d20 += 360D)
            {
            }

            if (d20 > 20D)
            {
                d20 = 20D;
            }

            if (d20 < -20D)
            {
                d20 = -20D;
            }

            RotationYaw += (float)d20;
            SetRotation(RotationYaw, RotationPitch);
            List <Entity> list = WorldObj.GetEntitiesWithinAABBExcludingEntity(this, BoundingBox.Expand(0.20000000298023224F, 0.0F, 0.20000000298023224F));

            if (list != null && list.Count > 0)
            {
                for (int j1 = 0; j1 < list.Count; j1++)
                {
                    Entity entity = (Entity)list[j1];

                    if (entity != RiddenByEntity && entity.CanBePushed() && (entity is EntityBoat))
                    {
                        entity.ApplyEntityCollision(this);
                    }
                }
            }

            for (int k1 = 0; k1 < 4; k1++)
            {
                int l1 = MathHelper2.Floor_double(PosX + ((double)(k1 % 2) - 0.5D) * 0.80000000000000004D);
                int i2 = MathHelper2.Floor_double(PosY);
                int j2 = MathHelper2.Floor_double(PosZ + ((double)(k1 / 2) - 0.5D) * 0.80000000000000004D);

                if (WorldObj.GetBlockId(l1, i2, j2) == Block.Snow.BlockID)
                {
                    WorldObj.SetBlockWithNotify(l1, i2, j2, 0);
                }
            }

            if (RiddenByEntity != null && RiddenByEntity.IsDead)
            {
                RiddenByEntity = null;
            }
        }
コード例 #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);
        }
コード例 #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);
        }