Exemplo n.º 1
0
        /// <summary>
        /// Determines whether or not the target rail can connect to this rail
        /// </summary>
        private bool CanConnectFrom(int par1, int par2, int par3)
        {
            RailLogic raillogic = GetMinecartTrackLogic(new ChunkPosition(par1, par2, par3));

            if (raillogic == null)
            {
                return(false);
            }
            else
            {
                raillogic.RefreshConnectedTracks();
                return(raillogic.CanConnectTo(this));
            }
        }
Exemplo n.º 2
0
        private bool IsConnectedTo(RailLogic par1RailLogic)
        {
            for (int i = 0; i < ConnectedTracks.Count; i++)
            {
                ChunkPosition chunkposition = (ChunkPosition)ConnectedTracks[i];

                if (chunkposition.x == par1RailLogic.TrackX && chunkposition.z == par1RailLogic.TrackZ)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Neighboring tracks have potentially been broken, so prune the connected track list
        /// </summary>
        private void RefreshConnectedTracks()
        {
            for (int i = 0; i < ConnectedTracks.Count; i++)
            {
                RailLogic raillogic = GetMinecartTrackLogic((ChunkPosition)ConnectedTracks[i]);

                if (raillogic == null || !raillogic.IsConnectedTo(this))
                {
                    ConnectedTracks.RemoveAt(i--);
                }
                else
                {
                    ConnectedTracks[i] = new ChunkPosition(raillogic.TrackX, raillogic.TrackY, raillogic.TrackZ);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Determines whether or not the track can bend to meet the specified rail
        /// </summary>
        private bool CanConnectTo(RailLogic par1RailLogic)
        {
            if (IsConnectedTo(par1RailLogic))
            {
                return(true);
            }

            if (ConnectedTracks.Count == 2)
            {
                return(false);
            }

            if (ConnectedTracks.Count == 0)
            {
                return(true);
            }

            ChunkPosition chunkposition = ConnectedTracks[0];

            return(par1RailLogic.TrackY != TrackY || chunkposition.y != TrackY ? true : true);
        }
Exemplo n.º 5
0
 /// <summary>
 /// get number of adjacent tracks
 /// </summary>
 public static int GetNAdjacentTracks(RailLogic par0RailLogic)
 {
     return(par0RailLogic.GetAdjacentTracks());
 }
Exemplo n.º 6
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);
                    }
                }
            }
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
        /// their own) Args: x, y, z, neighbor BlockID
        /// </summary>
        public override void OnNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
        {
            if (par1World.IsRemote)
            {
                return;
            }

            int i = par1World.GetBlockMetadata(par2, par3, par4);
            int j = i;

            if (isPowered)
            {
                j &= 7;
            }

            bool flag = false;

            if (!par1World.IsBlockNormalCube(par2, par3 - 1, par4))
            {
                flag = true;
            }

            if (j == 2 && !par1World.IsBlockNormalCube(par2 + 1, par3, par4))
            {
                flag = true;
            }

            if (j == 3 && !par1World.IsBlockNormalCube(par2 - 1, par3, par4))
            {
                flag = true;
            }

            if (j == 4 && !par1World.IsBlockNormalCube(par2, par3, par4 - 1))
            {
                flag = true;
            }

            if (j == 5 && !par1World.IsBlockNormalCube(par2, par3, par4 + 1))
            {
                flag = true;
            }

            if (flag)
            {
                DropBlockAsItem(par1World, par2, par3, par4, par1World.GetBlockMetadata(par2, par3, par4), 0);
                par1World.SetBlockWithNotify(par2, par3, par4, 0);
            }
            else if (BlockID == Block.RailPowered.BlockID)
            {
                bool flag1 = par1World.IsBlockIndirectlyGettingPowered(par2, par3, par4);
                flag1 = flag1 || IsNeighborRailPowered(par1World, par2, par3, par4, i, true, 0) || IsNeighborRailPowered(par1World, par2, par3, par4, i, false, 0);
                bool flag2 = false;

                if (flag1 && (i & 8) == 0)
                {
                    par1World.SetBlockMetadataWithNotify(par2, par3, par4, j | 8);
                    flag2 = true;
                }
                else if (!flag1 && (i & 8) != 0)
                {
                    par1World.SetBlockMetadataWithNotify(par2, par3, par4, j);
                    flag2 = true;
                }

                if (flag2)
                {
                    par1World.NotifyBlocksOfNeighborChange(par2, par3 - 1, par4, BlockID);

                    if (j == 2 || j == 3 || j == 4 || j == 5)
                    {
                        par1World.NotifyBlocksOfNeighborChange(par2, par3 + 1, par4, BlockID);
                    }
                }
            }
            else if (par5 > 0 && Block.BlocksList[par5].CanProvidePower() && !isPowered && RailLogic.GetNAdjacentTracks(new RailLogic(this, par1World, par2, par3, par4)) == 3)
            {
                RefreshTrackShape(par1World, par2, par3, par4, false);
            }
        }