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


C# World.GenerateChunk方法代码示例

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


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

示例1: Load

 public static Chunk Load(int x, int z, World w, bool thread = true)
 {
     string file = String.Format("{0}/chunks/{1}/{2}/{3}.{4}.chunk", w.name, Convert.ToString(x & 0x3f, 16), Convert.ToString(z & 0x3f, 16), x.ToString(), z.ToString());
     if (File.Exists(file))
     {
         if (thread)
         {
             World.chunker.QueueChunkLoad(x, z, false, w);
             return null;
         }
         try
         {
             Chunk ch = new Chunk(x, z);
             using (MemoryStream ms = new MemoryStream())
             {
                 using (FileStream fs = new FileStream(file, FileMode.Open))
                 {
                     byte[] comp;
                     ms.SetLength(fs.Length);
                     fs.Read(ms.GetBuffer(), 0, (int)fs.Length);
                     comp = ms.GetBuffer().Decompress();
                     ms.Write(comp, 0, comp.Length);
                 }
                 byte[] bytes = ms.ToArray();
                 Array.Copy(bytes, ch.blocks, 32768);
                 Array.Copy(bytes, 32768, ch.meta, 0, 16384);
                 Array.Copy(bytes, 49152, ch.SkyL, 0, 16384);
                 Array.Copy(bytes, 65536, ch.Light, 0, 16384);
                 int index = 81922;
                 short extraCount = BitConverter.ToInt16(bytes, index - 2);
                 if (extraCount > 0)
                     for (int i = 0; i < extraCount; i++)
                     {
                         ch.extra.Add(BitConverter.ToInt32(bytes, index), BitConverter.ToUInt16(bytes, index + 4));
                         index += 6;
                     }
                 short physCount = BitConverter.ToInt16(bytes, index); index += 2;
                 if (physCount > 0)
                 {
                     ch.physChecks = new Physics.Check[physCount];
                     for (int i = 0; i < physCount; i++)
                     {
                         ch.physChecks[i] = new Physics.Check(BitConverter.ToInt32(bytes, index), BitConverter.ToInt32(bytes, index + 4), BitConverter.ToInt32(bytes, index + 8), bytes[index + 14], BitConverter.ToInt16(bytes, index + 12));
                         index += 15;
                     }
                 }
             }
             //Console.WriteLine("LOADED " + x + " " + z);
             return ch;
         }
         catch (Exception ex)
         {
             Server.ServerLogger.Log("Error loading chunk at " + x + "," + z + "! A new chunk will be generated in it's place.");
             Server.ServerLogger.LogError(ex);
         }
     }
     //Console.WriteLine("GENERATED " + x + " " + z);
     if (thread)
         World.chunker.QueueChunk(x, z, w);
     else
         return w.GenerateChunk(x, z);
     return null;
 }
开发者ID:eszanto8,项目名称:ForgeCraft,代码行数:63,代码来源:Chunk.cs

示例2: Load


//.........这里部分代码省略.........
                        {
                            byte[] comp;
                            ms.SetLength(fs.Length);
                            fs.Read(ms.GetBuffer(), 0, (int)fs.Length);
                            comp = ms.GetBuffer().Decompress(CompressionType.GZip);
                            ms.Write(comp, 0, comp.Length);
                        }

                        ms.Position = 0;
                        NbtTree nbt = new NbtTree(ms);
                        ch.generated = (nbt.Root["Generated"].ToTagByte().Data > 0);
                        ch.populated = (nbt.Root["Populated"].ToTagByte().Data > 0);
                        Array.Copy(nbt.Root["Blocks"].ToTagByteArray(), ch.blocks, ch.blocks.Length);
                        Array.Copy(nbt.Root["Meta"].ToTagByteArray(), ch.meta, ch.meta.Length);
                        Array.Copy(nbt.Root["BlockLight"].ToTagByteArray(), ch.Light, ch.Light.Length);
                        Array.Copy(nbt.Root["SkyLight"].ToTagByteArray(), ch.SkyL, ch.SkyL.Length);
                        Array.Copy(nbt.Root["HeightMap"].ToTagByteArray(), ch.heightMap, ch.heightMap.Length);
                        Array.Copy(nbt.Root["HeightMapPrec"].ToTagByteArray().Data.ToIntArray(), ch.precipitationHeightMap, ch.precipitationHeightMap.Length);
                        TagNodeCompound nbtCompound;
                        foreach (TagNode tag in nbt.Root["Extra"].ToTagList())
                        {
                            nbtCompound = tag.ToTagCompound();
                            ch.extra.Add(nbtCompound["Pos"].ToTagInt(), (ushort)nbtCompound["Value"].ToTagShort());
                        }
                        TagNodeList nbtList = nbt.Root["Physics"].ToTagList();
                        int count = nbtList.Count;
                        if (count > 0)
                        {
                            ch.physChecks = new Physics.Check[count]; TagNodeList nbtList2;
                            for (int i = 0; i < count; i++)
                            {
                                nbtCompound = nbtList[i].ToTagCompound();
                                nbtList2 = nbtCompound["Pos"].ToTagList();
                                ch.physChecks[i] = new Physics.Check(nbtList2[0].ToTagInt(), nbtList2[1].ToTagInt(), nbtList2[2].ToTagInt(), nbtCompound["Meta"].ToTagByte(), nbtCompound["Time"].ToTagShort());
                            }
                        }
                        AI ai; McObject obj; Item item; Entity e; TagNodeCompound nbtCompound2;
                        foreach (TagNode tag in nbt.Root["Entities"].ToTagList())
                        {
                            e = null;
                            nbtCompound = tag.ToTagCompound();
                            switch ((EntityType)(byte)nbtCompound["Type"].ToTagByte())
                            {
                                case EntityType.AI:
                                    // TODO
                                    break;
                                case EntityType.Object:
                                    // TODO
                                    break;
                                case EntityType.Item:
                                    nbtCompound2 = nbtCompound["Data"].ToTagCompound();
                                    item = new Item(true) { id = nbtCompound2["ID"].ToTagShort(), count = nbtCompound2["Count"].ToTagByte(), meta = nbtCompound2["Meta"].ToTagShort() };
                                    item.e = new Entity(w) { isItem = true, I = item };
                                    e = item.e;
                                    break;
                            }
                            if (e != null)
                            {
                                nbtList = nbtCompound["Motion"].ToTagList();
                                e.velocity = new double[] { nbtList[0].ToTagDouble(), nbtList[1].ToTagDouble(), nbtList[2].ToTagDouble() };
                                nbtList = nbtCompound["Pos"].ToTagList();
                                e.pos = new Point3(nbtList[0].ToTagDouble(), nbtList[1].ToTagDouble(), nbtList[2].ToTagDouble());
                                nbtList = nbtCompound["Rotation"].ToTagList();
                                e.rot = new float[] { nbtList[0].ToTagFloat(), nbtList[1].ToTagFloat() };
                                e.age = nbtCompound["Age"].ToTagInt();
                                e.OnGround = (nbtCompound["OnGround"].ToTagByte() > 0);
                                e.health = nbtCompound["Health"].ToTagShort();
                                ch.entityLoad.Add(e);
                            }
                        }
                        Container c; Point3 point3;
                        foreach (TagNode tag in nbt.Root["Containers"].ToTagList())
                        {
                            nbtCompound = tag.ToTagCompound();
                            nbtList = nbtCompound["Pos"].ToTagList();
                            point3 = new Point3(nbtList[0].ToTagInt(), nbtList[1].ToTagInt(), nbtList[2].ToTagInt());
                            c = Container.CreateInstance((ContainerType)(byte)nbtCompound["Type"].ToTagByte(), w, point3);
                            c.LoadNBTData(nbtCompound["Items"].ToTagList());
                            if (!w.containers.ContainsKey(point3)) w.containers.Add(point3, c);
                        }
                    }
                    //Console.WriteLine("LOADED " + x + " " + z);
                    return ch;
                }
                catch (Exception ex)
                {
                    Logger.LogToFile("Error loading chunk at " + x + "," + z + "! A new chunk will be generated in it's place.");
                    Logger.LogErrorToFile(ex);
                }
            }
            //Console.WriteLine("GENERATED " + x + " " + z);
            if (generate)
            {
                if (thread) World.chunker.QueueChunk(x, z, w);
                else return w.GenerateChunk(x, z);
                return null;
            }
            if (dummy) return new Chunk(x, z);
            return null;
        }
开发者ID:Cazzar,项目名称:ForgeCraft,代码行数:101,代码来源:Chunk.cs

示例3: Load

 public static Chunk Load(int x, int z, World w)
 {
     string file = w.name + "/chunks/" + Convert.ToString(x & 0x3f, 16) + "/" + Convert.ToString(z & 0x3f, 16) + "/" + x.ToString() + "." + z.ToString() + ".chunk";
     if (File.Exists(file))
     {
         Chunk ch = new Chunk(x, z);
         using (MemoryStream ms = new MemoryStream())
         {
             using (FileStream fs = new FileStream(file, FileMode.Open))
             {
                 byte[] comp;
                 ms.SetLength(fs.Length);
                 fs.Read(ms.GetBuffer(), 0, (int)fs.Length);
                 comp = ms.GetBuffer().Decompress();
                 ms.Write(comp, 0, comp.Length);
             }
             byte[] bytes = ms.ToArray();
             Array.Copy(bytes, ch.blocks, 32768);
             Array.Copy(bytes, 32768, ch.meta, 0, 16384);
             Array.Copy(bytes, 49152, ch.SkyL, 0, 16384);
             Array.Copy(bytes, 65536, ch.Light, 0, 16384);
             int index = 81922;
             short extraCount = BitConverter.ToInt16(bytes, index - 2);
             lock (ch.extra)
                 for (int i = 0; i < extraCount; i++)
                 {
                     ch.extra.Add(BitConverter.ToInt32(bytes, index), BitConverter.ToUInt16(bytes, index + 4));
                     index += 6;
                 }
         }
         //Console.WriteLine("LOADED " + x + " " + z);
         return ch;
     }
     //Console.WriteLine("GENERATED " + x + " " + z);
     return w.GenerateChunk(x, z);
 }
开发者ID:ProLoks,项目名称:ForgeCraft,代码行数:36,代码来源:Chunk.cs


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