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