當前位置: 首頁>>代碼示例>>C#>>正文


C# Map.GetBlockCount方法代碼示例

本文整理匯總了C#中fCraft.Map.GetBlockCount方法的典型用法代碼示例。如果您正苦於以下問題:C# Map.GetBlockCount方法的具體用法?C# Map.GetBlockCount怎麽用?C# Map.GetBlockCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fCraft.Map的用法示例。


在下文中一共展示了Map.GetBlockCount方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Load

        public Map Load( System.IO.Stream MapStream )
        {
            // Reset the seeker to the front of the stream
            // This should probably be done differently.
            MapStream.Seek( 0, SeekOrigin.Begin );

            // Setup a GZipStream to decompress and read the map file
            GZipStream gs = new GZipStream( MapStream, CompressionMode.Decompress, true );
            BinaryReader bs = new BinaryReader( gs );

            Map map = new Map();

            // Read in the magic number
            if ( bs.ReadUInt16() != 0x752 ) {
                throw new FormatException();
            }

            // Read in the map dimesions
            map.widthX = bs.ReadInt16();
            map.widthY = bs.ReadInt16();
            map.height = bs.ReadInt16();

            // Read in the spawn location
            map.spawn.x = (short)(bs.ReadInt16() * 32);
            map.spawn.y = (short)(bs.ReadInt16() * 32);
            map.spawn.h = (short)(bs.ReadInt16() * 32);

            // Read in the spawn orientation
            map.spawn.r = bs.ReadByte();
            map.spawn.l = bs.ReadByte();

            // Skip over the VisitPermission and BuildPermission bytes
            bs.ReadByte();
            bs.ReadByte();

            if( !map.ValidateHeader() ) {
                throw new Exception( "One or more of the map dimensions are invalid." );
            }

            // Read in the map data
            map.blocks = bs.ReadBytes( map.GetBlockCount() );

            for( int i = 0; i < map.blocks.Length; i++ ) {
                if( map.blocks[i] > 49 ) {
                    map.blocks[i] = mapping[map.blocks[i]];
                }
            }

            return map;
        }
開發者ID:asiekierka,項目名稱:afCraft,代碼行數:50,代碼來源:MapMCSharp.cs

示例2: Load

        public Map Load( Stream MapStream )
        {
            // Reset the seeker to the front of the stream
            // This should probably be done differently.
            MapStream.Seek( 0, SeekOrigin.Begin );

            Map m = new Map();

            // Setup a GZipStream to decompress and read the map file
            using ( GZipStream gs = new GZipStream( MapStream, CompressionMode.Decompress, true ) ) {
                BinaryReader bs = new BinaryReader( gs );

                // Read in the magic number
                if ( bs.ReadByte() != 0xbe || bs.ReadByte() != 0xee || bs.ReadByte() != 0xef ) {
                    throw new FormatException( "MinerCPP map header is incorrect." );
                }

                // Read in the map dimesions
                // Saved in big endian for who-know-what reason.
                // XYZ(?)
                m.widthX = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
                m.height = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
                m.widthY = IPAddress.NetworkToHostOrder( bs.ReadInt16() );

                // Read in the spawn location
                // XYZ(?)
                m.spawn.x = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
                m.spawn.h = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
                m.spawn.y = IPAddress.NetworkToHostOrder( bs.ReadInt16() );

                // Read in the spawn orientation
                m.spawn.r = bs.ReadByte();
                m.spawn.l = bs.ReadByte();

                // Skip over the block count, totally useless
                bs.ReadInt32();

                // Read in the map data
                m.blocks = bs.ReadBytes( m.GetBlockCount() );
                if ( !m.ValidateBlockTypes( true ) ) {
                    throw new Exception( "Unrecognized block types in the map." );
                }
            }

            return m;
        }
開發者ID:asiekierka,項目名稱:afCraft,代碼行數:46,代碼來源:MapMinerCPP.cs

示例3: Load

        public Map Load( Stream MapStream )
        {
            // Reset the seeker to the front of the stream
            // This should probably be done differently.
            MapStream.Seek( 0, SeekOrigin.Begin );

            Map map = new Map();

            BinaryReader reader = new BinaryReader( MapStream );

            // Read in the magic number
            if ( reader.ReadUInt32() != Identifier ) {
                throw new FormatException();
            }

            // Read in the map dimesions
            map.widthX = reader.ReadInt16();
            map.widthY = reader.ReadInt16();
            map.height = reader.ReadInt16();

            // Read in the spawn location
            map.spawn.x = reader.ReadInt16();
            map.spawn.y = reader.ReadInt16();
            map.spawn.h = reader.ReadInt16();

            // Read in the spawn orientation
            map.spawn.r = reader.ReadByte();
            map.spawn.l = reader.ReadByte();

            // Read the metadata
            map.ReadMetadata( reader );

            if( !map.ValidateHeader() ) {
                throw new Exception( "One or more of the map dimensions are invalid." );
            }

            // Read in the map data
            map.blocks = new Byte[map.GetBlockCount()];
            using ( GZipStream decompressor = new GZipStream( MapStream, CompressionMode.Decompress, true ) ) {
                decompressor.Read( map.blocks, 0, map.blocks.Length );
            }

            return map;
        }
開發者ID:asiekierka,項目名稱:afCraft,代碼行數:44,代碼來源:MapFCMv2.cs


注:本文中的fCraft.Map.GetBlockCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。