当前位置: 首页>>代码示例>>C#>>正文


C# Level.CopyBlocks方法代码示例

本文整理汇总了C#中MCForge.Level.CopyBlocks方法的典型用法代码示例。如果您正苦于以下问题:C# Level.CopyBlocks方法的具体用法?C# Level.CopyBlocks怎么用?C# Level.CopyBlocks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MCForge.Level的用法示例。


在下文中一共展示了Level.CopyBlocks方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

        public static Level Load(Stream lvlStream, string fileName)
        {
            byte[] temp = new byte[8];
            using (Level lvl = new Level(fileName, 0, 0, 0, "empty"))
            {
                byte[] data;
                int length;
                try
                {
                    lvlStream.Seek(-4, SeekOrigin.End);
                    lvlStream.Read(temp, 0, sizeof(int));
                    lvlStream.Seek(0, SeekOrigin.Begin);
                    length = BitConverter.ToInt32(temp, 0);
                    data = new byte[length];
                    using (GZipStream reader = new GZipStream(lvlStream, CompressionMode.Decompress, true))
                    {
                        reader.Read(data, 0, length);
                    }

                    for (int i = 0; i < length - 1; i++)
                    {
                        if (data[i] == 0xAC && data[i + 1] == 0xED)
                        {

                            // bypassing the header crap
                            int pointer = i + 6;
                            Array.Copy(data, pointer, temp, 0, sizeof(short));
                            pointer += IPAddress.HostToNetworkOrder(BitConverter.ToInt16(temp, 0));
                            pointer += 13;

                            int headerEnd = 0;
                            // find the end of serialization listing
                            for (headerEnd = pointer; headerEnd < data.Length - 1; headerEnd++)
                            {
                                if (data[headerEnd] == 0x78 && data[headerEnd + 1] == 0x70)
                                {
                                    headerEnd += 2;
                                    break;
                                }
                            }

                            // start parsing serialization listing
                            int offset = 0;
                            while (pointer < headerEnd)
                            {
                                if (data[pointer] == 'Z') offset++;
                                else if (data[pointer] == 'I' || data[pointer] == 'F') offset += 4;
                                else if (data[pointer] == 'J') offset += 8;

                                pointer += 1;
                                Array.Copy(data, pointer, temp, 0, sizeof(short));
                                short skip = IPAddress.HostToNetworkOrder(BitConverter.ToInt16(temp, 0));
                                pointer += 2;

                                // look for relevant variables
                                Array.Copy(data, headerEnd + offset - 4, temp, 0, sizeof(int));
                                if (MemCmp(data, pointer, "width"))
                                {
                                    lvl.width = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(temp, 0));
                                }
                                else if (MemCmp(data, pointer, "depth"))
                                {
                                    lvl.depth = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(temp, 0));
                                }
                                else if (MemCmp(data, pointer, "height"))
                                {
                                    lvl.height = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(temp, 0));
                                }

                                pointer += skip;
                            }

                            lvl.spawnx = (ushort)(lvl.width / 1.3);
                            lvl.spawny = (ushort)(lvl.depth / 1.3);
                            lvl.spawnz = (ushort)(lvl.height / 1.3);

                            // find the start of the block array
                            bool foundBlockArray = false;
                            offset = Array.IndexOf<byte>(data, 0x00, headerEnd);
                            while (offset != -1 && offset < data.Length - 2)
                            {
                                if (data[offset] == 0x00 && data[offset + 1] == 0x78 && data[offset + 2] == 0x70)
                                {
                                    foundBlockArray = true;
                                    pointer = offset + 7;
                                }
                                offset = Array.IndexOf<byte>(data, 0x00, offset + 1);
                            }

                            // copy the block array... or fail
                            if (foundBlockArray)
                            {
                                lvl.CopyBlocks(data, pointer);
                                lvl.Save(true);
                            }
                            else
                            {
                                throw new Exception("Could not locate block array.");
                            }
                            break;
//.........这里部分代码省略.........
开发者ID:Goodlyay,项目名称:MCForge-Vanilla-Redux,代码行数:101,代码来源:ConvertDAT.cs


注:本文中的MCForge.Level.CopyBlocks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。