예제 #1
0
        public virtual Vec3D Func_515_a(double par1, double par3, double par5, double par7)
        {
            int i = MathHelper2.Floor_double(par1);
            int j = MathHelper2.Floor_double(par3);
            int k = MathHelper2.Floor_double(par5);

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

            int l = WorldObj.GetBlockId(i, j, k);

            if (BlockRail.IsRailBlock(l))
            {
                int i1 = WorldObj.GetBlockMetadata(i, j, k);

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

                par3 = j;

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

                int[][] ai = Field_855_j[i1];
                float   d  = ai[1][0] - ai[0][0];
                float   d1 = ai[1][2] - ai[0][2];
                float   d2 = (float)Math.Sqrt(d * d + d1 * d1);
                d    /= d2;
                d1   /= d2;
                par1 += d * par7;
                par5 += d1 * par7;

                if (ai[0][1] != 0 && MathHelper2.Floor_double(par1) - i == ai[0][0] && MathHelper2.Floor_double(par5) - k == ai[0][2])
                {
                    par3 += ai[0][1];
                }
                else if (ai[1][1] != 0 && MathHelper2.Floor_double(par1) - i == ai[1][0] && MathHelper2.Floor_double(par5) - k == ai[1][2])
                {
                    par3 += ai[1][1];
                }

                return(Func_514_g(par1, par3, par5));
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        private bool IsMinecartTrack(int par1, int par2, int par3)
        {
            if (BlockRail.IsRailBlockAt(WorldObj, par1, par2, par3))
            {
                return(true);
            }

            if (BlockRail.IsRailBlockAt(WorldObj, par1, par2 + 1, par3))
            {
                return(true);
            }

            return(BlockRail.IsRailBlockAt(WorldObj, par1, par2 - 1, par3));
        }
예제 #3
0
        private RailLogic GetMinecartTrackLogic(ChunkPosition par1ChunkPosition)
        {
            if (BlockRail.IsRailBlockAt(WorldObj, par1ChunkPosition.x, par1ChunkPosition.y, par1ChunkPosition.z))
            {
                return(new RailLogic(Rail, WorldObj, par1ChunkPosition.x, par1ChunkPosition.y, par1ChunkPosition.z));
            }

            if (BlockRail.IsRailBlockAt(WorldObj, par1ChunkPosition.x, par1ChunkPosition.y + 1, par1ChunkPosition.z))
            {
                return(new RailLogic(Rail, WorldObj, par1ChunkPosition.x, par1ChunkPosition.y + 1, par1ChunkPosition.z));
            }

            if (BlockRail.IsRailBlockAt(WorldObj, par1ChunkPosition.x, par1ChunkPosition.y - 1, par1ChunkPosition.z))
            {
                return(new RailLogic(Rail, WorldObj, par1ChunkPosition.x, par1ChunkPosition.y - 1, par1ChunkPosition.z));
            }
            else
            {
                return(null);
            }
        }
예제 #4
0
        public RailLogic(BlockRail par1BlockRail, World par2World, int par3, int par4, int par5)
        {
            Rail            = par1BlockRail;
            ConnectedTracks = new List <ChunkPosition>();
            WorldObj        = par2World;
            TrackX          = par3;
            TrackY          = par4;
            TrackZ          = par5;
            int i = par2World.GetBlockId(par3, par4, par5);
            int j = par2World.GetBlockMetadata(par3, par4, par5);

            if (BlockRail.IsPoweredBlockRail((BlockRail)Block.BlocksList[i]))
            {
                IsPoweredRail = true;
                j            &= -9;
            }
            else
            {
                IsPoweredRail = false;
            }

            SetConnections(j);
        }
예제 #5
0
        public virtual Vec3D Func_514_g(double par1, double par3, double par5)
        {
            int i = MathHelper2.Floor_double(par1);
            int j = MathHelper2.Floor_double(par3);
            int k = MathHelper2.Floor_double(par5);

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

            int l = WorldObj.GetBlockId(i, j, k);

            if (BlockRail.IsRailBlock(l))
            {
                int i1 = WorldObj.GetBlockMetadata(i, j, k);
                par3 = j;

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

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

                int[][] ai = Field_855_j[i1];
                double  d  = 0.0F;
                double  d1 = (double)i + 0.5D + (double)ai[0][0] * 0.5D;
                double  d2 = (double)j + 0.5D + (double)ai[0][1] * 0.5D;
                double  d3 = (double)k + 0.5D + (double)ai[0][2] * 0.5D;
                double  d4 = (double)i + 0.5D + (double)ai[1][0] * 0.5D;
                double  d5 = (double)j + 0.5D + (double)ai[1][1] * 0.5D;
                double  d6 = (double)k + 0.5D + (double)ai[1][2] * 0.5D;
                double  d7 = d4 - d1;
                double  d8 = (d5 - d2) * 2D;
                double  d9 = d6 - d3;

                if (d7 == 0.0F)
                {
                    par1 = (double)i + 0.5D;
                    d    = par5 - (double)k;
                }
                else if (d9 == 0.0F)
                {
                    par5 = (double)k + 0.5D;
                    d    = par1 - (double)i;
                }
                else
                {
                    double d10 = par1 - d1;
                    double d11 = par5 - d3;
                    double d12 = (d10 * d7 + d11 * d9) * 2D;
                    d = d12;
                }

                par1 = d1 + d7 * d;
                par3 = d2 + d8 * d;
                par5 = d3 + d9 * d;

                if (d8 < 0.0F)
                {
                    par3++;
                }

                if (d8 > 0.0F)
                {
                    par3 += 0.5D;
                }

                return(Vec3D.CreateVector(par1, par3, par5));
            }
            else
            {
                return(null);
            }
        }
예제 #6
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);
        }
예제 #7
0
        /// <summary>
        /// Completely recalculates the track shape based on neighboring tracks and power state
        /// </summary>
        public virtual void RefreshTrackShape(bool par1, bool par2)
        {
            bool  flag  = CanConnectFrom(TrackX, TrackY, TrackZ - 1);
            bool  flag1 = CanConnectFrom(TrackX, TrackY, TrackZ + 1);
            bool  flag2 = CanConnectFrom(TrackX - 1, TrackY, TrackZ);
            bool  flag3 = CanConnectFrom(TrackX + 1, TrackY, TrackZ);
            sbyte byte0 = -1;

            if ((flag || flag1) && !flag2 && !flag3)
            {
                byte0 = 0;
            }

            if ((flag2 || flag3) && !flag && !flag1)
            {
                byte0 = 1;
            }

            if (!IsPoweredRail)
            {
                if (flag1 && flag3 && !flag && !flag2)
                {
                    byte0 = 6;
                }

                if (flag1 && flag2 && !flag && !flag3)
                {
                    byte0 = 7;
                }

                if (flag && flag2 && !flag1 && !flag3)
                {
                    byte0 = 8;
                }

                if (flag && flag3 && !flag1 && !flag2)
                {
                    byte0 = 9;
                }
            }

            if (byte0 == -1)
            {
                if (flag || flag1)
                {
                    byte0 = 0;
                }

                if (flag2 || flag3)
                {
                    byte0 = 1;
                }

                if (!IsPoweredRail)
                {
                    if (par1)
                    {
                        if (flag1 && flag3)
                        {
                            byte0 = 6;
                        }

                        if (flag2 && flag1)
                        {
                            byte0 = 7;
                        }

                        if (flag3 && flag)
                        {
                            byte0 = 9;
                        }

                        if (flag && flag2)
                        {
                            byte0 = 8;
                        }
                    }
                    else
                    {
                        if (flag && flag2)
                        {
                            byte0 = 8;
                        }

                        if (flag3 && flag)
                        {
                            byte0 = 9;
                        }

                        if (flag2 && flag1)
                        {
                            byte0 = 7;
                        }

                        if (flag1 && flag3)
                        {
                            byte0 = 6;
                        }
                    }
                }
            }

            if (byte0 == 0)
            {
                if (BlockRail.IsRailBlockAt(WorldObj, TrackX, TrackY + 1, TrackZ - 1))
                {
                    byte0 = 4;
                }

                if (BlockRail.IsRailBlockAt(WorldObj, TrackX, TrackY + 1, TrackZ + 1))
                {
                    byte0 = 5;
                }
            }

            if (byte0 == 1)
            {
                if (BlockRail.IsRailBlockAt(WorldObj, TrackX + 1, TrackY + 1, TrackZ))
                {
                    byte0 = 2;
                }

                if (BlockRail.IsRailBlockAt(WorldObj, TrackX - 1, TrackY + 1, TrackZ))
                {
                    byte0 = 3;
                }
            }

            if (byte0 < 0)
            {
                byte0 = 0;
            }

            SetConnections(byte0);
            int i = byte0;

            if (IsPoweredRail)
            {
                i = WorldObj.GetBlockMetadata(TrackX, TrackY, TrackZ) & 8 | byte0;
            }

            if (par2 || WorldObj.GetBlockMetadata(TrackX, TrackY, TrackZ) != i)
            {
                WorldObj.SetBlockMetadataWithNotify(TrackX, TrackY, TrackZ, i);

                for (int j = 0; j < ConnectedTracks.Count; j++)
                {
                    RailLogic raillogic = GetMinecartTrackLogic((ChunkPosition)ConnectedTracks[j]);

                    if (raillogic == null)
                    {
                        continue;
                    }

                    raillogic.RefreshConnectedTracks();

                    if (raillogic.CanConnectTo(this))
                    {
                        raillogic.ConnectToNeighbor(this);
                    }
                }
            }
        }
예제 #8
0
        /// <summary>
        /// The specified neighbor has just formed a new connection, so update accordingly
        /// </summary>
        private void ConnectToNeighbor(RailLogic par1RailLogic)
        {
            ConnectedTracks.Add(new ChunkPosition(par1RailLogic.TrackX, par1RailLogic.TrackY, par1RailLogic.TrackZ));
            bool  flag  = IsInTrack(TrackX, TrackY, TrackZ - 1);
            bool  flag1 = IsInTrack(TrackX, TrackY, TrackZ + 1);
            bool  flag2 = IsInTrack(TrackX - 1, TrackY, TrackZ);
            bool  flag3 = IsInTrack(TrackX + 1, TrackY, TrackZ);
            sbyte byte0 = -1;

            if (flag || flag1)
            {
                byte0 = 0;
            }

            if (flag2 || flag3)
            {
                byte0 = 1;
            }

            if (!IsPoweredRail)
            {
                if (flag1 && flag3 && !flag && !flag2)
                {
                    byte0 = 6;
                }

                if (flag1 && flag2 && !flag && !flag3)
                {
                    byte0 = 7;
                }

                if (flag && flag2 && !flag1 && !flag3)
                {
                    byte0 = 8;
                }

                if (flag && flag3 && !flag1 && !flag2)
                {
                    byte0 = 9;
                }
            }

            if (byte0 == 0)
            {
                if (BlockRail.IsRailBlockAt(WorldObj, TrackX, TrackY + 1, TrackZ - 1))
                {
                    byte0 = 4;
                }

                if (BlockRail.IsRailBlockAt(WorldObj, TrackX, TrackY + 1, TrackZ + 1))
                {
                    byte0 = 5;
                }
            }

            if (byte0 == 1)
            {
                if (BlockRail.IsRailBlockAt(WorldObj, TrackX + 1, TrackY + 1, TrackZ))
                {
                    byte0 = 2;
                }

                if (BlockRail.IsRailBlockAt(WorldObj, TrackX - 1, TrackY + 1, TrackZ))
                {
                    byte0 = 3;
                }
            }

            if (byte0 < 0)
            {
                byte0 = 0;
            }

            int i = byte0;

            if (IsPoweredRail)
            {
                i = WorldObj.GetBlockMetadata(TrackX, TrackY, TrackZ) & 8 | byte0;
            }

            WorldObj.SetBlockMetadataWithNotify(TrackX, TrackY, TrackZ, i);
        }
예제 #9
0
 /// <summary>
 /// Return true if the blocks passed is a power related rail.
 /// </summary>
 public static bool IsPoweredBlockRail(BlockRail par0BlockRail)
 {
     return(par0BlockRail.isPowered);
 }