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


C# Chunk.UpdateOverview方法代码示例

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


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

示例1: _LoadChunk

        private Chunk _LoadChunk(int x, int z)
        {
            byte[] CurrentBlocks;
            /*
            if (CurrentBlock.X == x && CurrentBlock.Z == z)
            {
                Console.WriteLine("Already loaded...!");
                return null;
            }
            */
            //x = (x < 0) ? x - 2 : x;
            //z = (z < 0) ? z - 2 : z;
            CurrentBlock.X = x;
            CurrentBlock.Z = z;
            string derp;
            Chunk c = new Chunk(this);
            c.Loading = true;
            c.Filename = GetChunkFilename(x, z);
            c.CreationDate = File.GetCreationTime(c.Filename);
            c.Creator = "?";
            c.Size = ChunkScale;
            if (!File.Exists(c.Filename))
            {
                Console.WriteLine("! {0}", c.Filename);
                return null;
            }
            //try
            {
                chunk = new NbtFile(c.Filename);
                chunk.LoadFile();

                NbtCompound level = (NbtCompound)chunk.RootTag["Level"];

                c.Position = new Vector3i(
                    level.Get<NbtInt>("xPos").Value,
                    level.Get<NbtInt>("zPos").Value, 0);

                if ((int)c.Position.X != x || (int)c.Position.Y != z)
                {
                    throw new Exception(string.Format("Chunk pos is wrong.  {0}!={1}", c.Filename, c.Position));
                }
                NbtList TileEntities = (NbtList)level["TileEntities"];
                if (TileEntities.Tags.Count > 0)
                {
                    //Console.WriteLine("*** Found TileEntities.");
                    LoadTileEnts(ref c, (int)x, (int)z, TileEntities);
                }

                NbtList Entities = (NbtList)level["Entities"];
                if (Entities.Tags.Count > 0)
                {
                    //Console.WriteLine("*** Found Entities.");
                    LoadEnts(ref c, (int)x, (int)z, Entities);
                }

                // Blocks
                c.Blocks = DecompressBlocks(level.Get<NbtByteArray>("Blocks").Value);
                c.BlockLight = DecompressLightmap(level.Get<NbtByteArray>("BlockLight").Value);
                c.SkyLight = DecompressLightmap(level.Get<NbtByteArray>("SkyLight").Value);
                c.Data = DecompressDatamap(level.Get<NbtByteArray>("Data").Value);

                c.Loading = false;
                c.UpdateOverview();

                string ci = string.Format("{0},{1}", x, z);
                if (Chunks.ContainsKey(ci))
                    return Chunks[ci];
                Chunks.Add(ci, c);
                /*
                @TODO: Make Pig spawner converter.
                for (int Z = 0; Z < ChunkScale.X; Z++)
                {
                    for (int Y = 0; Y < ChunkScale.Y; Y++)
                    {
                        for (int X = 0; X < ChunkScale.X; X++)
                        {
                            long index = X + (Z * ChunkY + Y) * ChunkZ;
                            byte b = CurrentChunks[index];
                            if (b == Blocks.Find("Mob spawner").ID)
                            {
                                MobSpawner ms = new MobSpawner(X + (int)(x * ChunkScale.X), Y + (int)(z * ChunkScale.Y), Z, "Pig", 20);
                                ms.id = "MobSpawner";
                                ms.UUID = Guid.NewGuid();
                                _TileEntities.Add(ms.UUID, ms);
                                c++;
                            }
                        }
                    }
                }
                    */
                //if (c>0)  Console.WriteLine("*** {0} spawners found.", c);
                //Console.WriteLine("Loaded {0} bytes from chunk {1}.", CurrentChunks.Length, c.Filename);
                return c;
            }
            /*catch (Exception e)
            {
                string err = string.Format(" *** ERROR: Chunk {0},{1} ({2}) failed to load:\n\n{3}", x, z, c.Filename, e);
                Console.WriteLine(err);
                if (CorruptChunk != null)
                    CorruptChunk(err, c.Filename);
//.........这里部分代码省略.........
开发者ID:herpit,项目名称:MineEdit,代码行数:101,代码来源:InfdevHandler.cs

示例2: _LoadChunk

		private Chunk _LoadChunk(int x, int z)
		{
			//CurrentBlock.X = x;
			//CurrentBlock.Z = z;

			Chunk c = new Chunk(this);
			c.Loading = true;
			c.Filename = GetChunkFilename(x, z);
			c.CreationDate = File.GetCreationTime(c.Filename);
			c.Creator = "?";
			c.Size = ChunkScale;

			if (!File.Exists(c.Filename))
			{
				Console.WriteLine("! {0}", c.Filename);
				return null;
			}
#if !DEBUG || CATCH_CHUNK_ERRORS
			try
			{
#endif
				mChunk = new NbtFile(c.Filename);
				mChunk.LoadFile();

				NbtCompound level = (NbtCompound)mChunk.RootTag["Level"];

				c.Position = new Vector3i(
					level.Get<NbtInt>("xPos").Value,
					level.Get<NbtInt>("zPos").Value, 0);

				if ((int)c.Position.X != x || (int)c.Position.Y != z)
				{
					throw new Exception(string.Format("Chunk pos is wrong.  {0}!={1}", c.Filename, c.Position));
				}
				NbtList TileEntities = (NbtList)level["TileEntities"];
				if (TileEntities.Tags.Count > 0)
				{
					//Console.WriteLine("*** Found TileEntities.");
					LoadTileEnts(ref c, (int)x, (int)z, TileEntities);
				}

                NbtList Entities = (NbtList)level["Entities"];
                Console.WriteLine("*** Found {0} Entities.",Entities.Tags.Count);
				if (Entities.Tags.Count > 0)
				{
					LoadEnts(ref c, (int)x, (int)z, Entities);
				}

				// Blocks
				c.Blocks = DecompressBlocks(level.Get<NbtByteArray>("Blocks").Value);
				c.BlockLight = DecompressLightmap(level.Get<NbtByteArray>("BlockLight").Value);
				c.SkyLight = DecompressLightmap(level.Get<NbtByteArray>("SkyLight").Value);
				c.Data = DecompressDatamap(level.Get<NbtByteArray>("Data").Value);

				c.Loading = false;
				c.UpdateOverview();

				string ci = string.Format("{0},{1}", x, z);
				if (mChunks.ContainsKey(ci))
					return mChunks[ci];
				mChunks.Add(ci, c);
				//TODO: Make Pig spawner converter.
				for (int Z = 0; Z < ChunkScale.X; Z++)
				{
					for (int Y = 0; Y < ChunkScale.Y; Y++)
					{
						for (int X = 0; X < ChunkScale.X; X++)
						{
                            byte b = c.Blocks[X, Y, Z];
							if (b == 52)
							{
								MobSpawner ms = new MobSpawner();
                                ms.Pos=new Vector3i(X, Y, Z);
                                ms.EntityId = "Pig";
								ms.UUID = Guid.NewGuid();
								mTileEntities.Add(ms.UUID, ms);
								//c++;
							}
						}
					}
				}
				//if (c>0)  Console.WriteLine("*** {0} spawners found.", c);
				//Console.WriteLine("Loaded {0} bytes from chunk {1}.", CurrentChunks.Length, c.Filename);
				return c;

#if !DEBUG || CATCH_CHUNK_ERRORS
            }
			catch (Exception e)
			{
				string err = string.Format(" *** ERROR: Chunk {0},{1} ({2}) failed to load:\n\n{3}", x, z, c.Filename, e);
				Console.WriteLine(err);
				if (CorruptChunk != null)
					CorruptChunk(x,z,err, c.Filename);
				return null;
			}
#endif
        }
开发者ID:aphistic,项目名称:MineEdit,代码行数:97,代码来源:InfdevHandler.cs

示例3: SaveChunkMetadata

        internal void SaveChunkMetadata(Chunk c)
        {
            if (!mEnabled) return;
            c.UpdateOverview();
            try
            {
                rwLock.AcquireWriterLock(1000);
                using (SQLiteCommand cmd = database.CreateCommand())
                {
                    cmd.CommandText = "REPLACE INTO Chunks (cnkX, cnkZ, dimID, cnkMD5, cnkFile, cnkTemperatures, cnkHumidity, cnkOverview, cnkFlags) VALUES (@cnkX,@cnkZ,@dimID,@cnkMD5,@cnkFile,@cnkTemperatures,@cnkHumidity,@cnkOverview,@cnkFlags);";
                    cmd.Parameters.Add(new SQLiteParameter("@cnkX", c.Position.X));
                    cmd.Parameters.Add(new SQLiteParameter("@cnkZ", c.Position.Z));
                    cmd.Parameters.Add(new SQLiteParameter("@dimID", c.Dimension));
                    cmd.Parameters.Add(new SQLiteParameter("@cnkMD5", GetMD5HashFromFile(c.Filename)));

                    byte[] tmap, hmap, omap;
                    int idx = 0;
                    tmap = new byte[c.Size.X * c.Size.Z];
                    hmap = new byte[c.Size.X * c.Size.Z];
                    omap = new byte[c.Size.X * c.Size.Z];
                    if (c.Temperatures != null && c.Humidity != null)
                    {
                        for (int x = 0; x < c.Size.X; x++)
                        {
                            for (int z = 0; z < c.Size.Z; z++)
                            {
                                tmap[idx] = (byte)(c.Temperatures[x, z] * 255);
                                hmap[idx] = (byte)(c.Humidity[x, z] * 255);
                                omap[idx] = c.Overview[x, z];
                                idx++;
                            }
                        }
                    }
                    idx = 0;
                    for (int x = 0; x < c.Size.X; x++)
                    {
                        for (int z = 0; z < c.Size.Z; z++)
                        {
                            omap[idx] = c.Overview[x, z];
                            idx++;
                        }
                    }

                    cmd.Parameters.Add(new SQLiteParameter("@cnkTemperatures", DbType.Binary, tmap.Length,
            ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, tmap));
                    cmd.Parameters.Add(new SQLiteParameter("@cnkHumidity", DbType.Binary, hmap.Length,
            ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, hmap));
                    cmd.Parameters.Add(new SQLiteParameter("@cnkOverview", DbType.Binary, omap.Length,
            ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, omap));

                    cmd.Parameters.Add(new SQLiteParameter("@cnkFile", c.Filename));

                    int flags = 0;
                    if (c.TerrainPopulated)
                        flags |= 1;
                    if (c.GeneratedByMineEdit)
                        flags |= 2;
                    cmd.Parameters.Add(new SQLiteParameter("@cnkFlags", flags));
                    cmd.ExecuteNonQuery();
                }
            }
            finally
            {
                if (rwLock.IsWriterLockHeld)
                    rwLock.ReleaseWriterLock();
            }

            ExecuteNonquerySQL(
                string.Format(
            @"DELETE FROM Entities
            WHERE
            entX < {0}+15 AND
            entY < {1}+127 AND
            entZ < {2}+15 AND
            entX > {0} AND
            entY > {1} AND
            entZ > {2} AND
            dimID = {3};",
                 c.Position.X,
                 c.Position.Y,
                 c.Position.Z,
                 c.Dimension));

            ExecuteNonquerySQL(
                string.Format(
            @"DELETE FROM TileEntities
            WHERE
            tentX < {0}+15 AND
            tentY < {1}+127 AND
            tentZ < {2}+15 AND
            tentX > {0} AND
            tentY > {1} AND
            tentZ > {2} AND
            dimID = {3};",
                 c.Position.X,
                 c.Position.Y,
                 c.Position.Z,
                 c.Dimension));

            try
//.........这里部分代码省略.........
开发者ID:N3X15,项目名称:MineEdit,代码行数:101,代码来源:MapMetadata.cs


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