예제 #1
0
        public void Save(ChunkData chunk)
        {
            var nbt = new NbtFile {
                RootTag = new NbtCompound("", new NbtTag[] {
                    new NbtCompound("Level", new NbtTag[] {
                        new NbtByteArray("Blocks", chunk.Blocks),
                        new NbtByteArray("BlockLight", chunk.BlockLight.Data),
                        new NbtByteArray("SkyLight", chunk.SkyLight.Data),
                        new NbtByteArray("Data", chunk.MetaData.Data),
                        new NbtByteArray("HeightMap", chunk.Heightmap),

                        new NbtInt("xPos", chunk.X),
                        new NbtInt("yPos", chunk.Y),
                    })
                })
            };

            var path = GetChunkPath(chunk.X, chunk.Y);
            Directory.CreateDirectory(Path.GetDirectoryName(path));
            nbt.SaveFile(path, true);
        }
예제 #2
0
 protected void SaveChunk(int x, int y, NbtFile file)
 {
     var realPath = GetChunkPath(x, y);
     file.SaveFile(realPath, true);
 }
예제 #3
0
 public byte[] GetChunk(int x, int y)
 {
     NbtFile file = new NbtFile();
     NbtCompound c = new NbtCompound("__ROOT__");
     c.Tags.Add(new NbtInt("x", x));
     c.Tags.Add(new NbtInt("y", y));
     c.Tags.Add(new NbtInt("z", 0));
     c.Tags.Add(new NbtByteArray("c", GetChunkData(x,y)));
     file.RootTag = c;
     byte[] endresult;
     using (MemoryStream ms = new MemoryStream())
     {
         file.SaveFile(ms,true);
         endresult= ms.ToArray();
     }
     return endresult;
 }
예제 #4
0
		public void SaveToFile(string file)
		{
			using(NbtFile rdr = new NbtFile())
			{
				rdr.RootTag=new NbtCompound("Region");
				NbtCompound cMats = new NbtCompound("VoxMaterials");
				rdr.RootTag.Tags.Add(mMaterials.ToNBT());
				rdr.RootTag.Tags.Add(new NbtByteArray("Voxels",ToBytes()));
				rdr.SaveFile(file);
			}
		}
예제 #5
0
		public void SaveChunk(Chunk cnk)
		{
			NbtFile c = new NbtFile(cnk.Filename);

            // TODO: PosY -> PosZ
            c.RootTag = NewNBTChunk(cnk.Position.X, cnk.Position.Y);
            NbtCompound Level = (NbtCompound)c.RootTag["Level"];

			// BLOCKS /////////////////////////////////////////////////////
			byte[] blocks = new byte[ChunkX * ChunkY * ChunkZ];
			for (int X = 0; X < ChunkX; X++)
			{
				for (int Y = 0; Y < ChunkY; Y++)
				{
					for (int Z = 0; Z < ChunkZ; Z++)
					{
						blocks[GetBlockIndex(X, Y, Z)] = cnk.Blocks[X, Y, Z];
					}
				}
			}
			Level.Tags.Add(new NbtByteArray("Blocks", blocks));
			blocks = null;

			// LIGHTING ///////////////////////////////////////////////////
			// TODO:  Whatever is going on in here is crashing Minecraft now.
			byte[] lighting = CompressLightmap(cnk.SkyLight);
			Level.Tags.Add(new NbtByteArray("SkyLight", lighting));

			lighting = CompressLightmap(cnk.BlockLight);
            Level.Tags.Add(new NbtByteArray("BlockLight", lighting));
			
			lighting = CompressDatamap(cnk.Data);
            Level.Tags.Add(new NbtByteArray("Data", lighting));

			// HEIGHTMAP (Needed for lighting).
			byte[] hm = new byte[256];
			for (int x = 0; x < 16; x++)
			{
				for (int y = 0; y < 16; y++)
				{
					hm[y + (x * 16)] = (byte)cnk.HeightMap[x, y];
				}
			}

			NbtList ents = new NbtList("Entities");
			// ENTITIES ///////////////////////////////////////////////////
			foreach (KeyValuePair<Guid, Entity> ent in cnk.Entities)
			{
				ents.Tags.Add(ent.Value.ToNBT());
			}
			Level.Tags.Add(ents);

			NbtList tents = new NbtList("TileEntities");
			// TILE ENTITIES //////////////////////////////////////////////
			foreach (KeyValuePair<Guid, TileEntity> tent in cnk.TileEntities)
			{
				ents.Tags.Add(tent.Value.ToNBT());
			}
			Level.Tags.Add(tents);

			c.RootTag.Set("Level",Level);
			
            c.SaveFile(cnk.Filename);
			
            // For debuggan
            File.WriteAllText(cnk.Filename + ".txt", c.RootTag.ToString());
		}
예제 #6
0
		public void RemoveTileEntity(TileEntity e)
		{
			long CX = e.Pos.X / 16;
			long CY = e.Pos.Y / 16;
			string f = GetChunkFilename((int)CX, (int)CY);

			try
			{
				mChunk = new NbtFile(f);
				mChunk.LoadFile();
				NbtCompound level = (NbtCompound)mChunk.RootTag["Level"];

				NbtList TileEntities = (NbtList)level["TileEntities"];
				int found = -1;
				for (int i = 0; i < TileEntities.Tags.Count; i++)
				{
					TileEntity te = new TileEntity((NbtCompound)TileEntities[i]);
					if (te.Pos == e.Pos)
					{
						found = i;
					}
				}
				if (found > -1)
					TileEntities.Tags.RemoveAt(found);

				level["TileEntities"] = TileEntities;
				mChunk.RootTag["Level"] = level;
				mChunk.SaveFile(f);
			}
			catch (Exception) { }
		}
예제 #7
0
        public void Save()
        {
            NbtFile file = new NbtFile();

            var serializer = new NbtSerializer(typeof(SavedLevel));
            var data = serializer.Serialize(new SavedLevel
            {
                IsRaining = Raining,
                GeneratorVersion = 0,
                Time = Time,
                GameMode = (int)GameMode,
                MapFeatures = MapFeatures,
                GeneratorName =WorldGenerator.GeneratorName,
                Initialized = true,
                Seed = Seed,
                SpawnPoint = SpawnPoint,
                SizeOnDisk = 0,
                ThunderTime = ThunderTime,
                RainTime = RainTime,
                Version = 19133,
                Thundering = Thundering,
                LevelName = Name,
                LastPlayed = DateTime.UtcNow.Ticks
            });
            file.RootTag = new NbtCompound();
            file.RootTag.Tags.Add(data);
            using (var stream = File.Open(Path.Combine(LevelDirectory, "level.dat"), FileMode.Create))
                file.SaveFile(stream, true);

            World.Save();
        }
예제 #8
0
파일: Settings.cs 프로젝트: N3X15/MineEdit
        public static void Save()
        {
            File.WriteAllLines(".luf", LastUsedFiles.ToArray());

            NbtFile f = new NbtFile();
            f.RootTag.Add("GridLines",new NbtByte("GridLines", (byte) (ShowGridLines ? 0x01 : 0x00)));
            f.RootTag.Add("ShowChunks",new NbtByte("ShowChunks", (byte) (ShowChunks ? 0x01 : 0x00)));
            f.RootTag.Add("ShowMapIcons",new NbtByte("ShowMapIcons", (byte) (ShowMapIcons ? 0x01 : 0x00)));
            f.RootTag.Add("ShowWaterDepth",new NbtByte("ShowWaterDepth", (byte) (ShowWaterDepth ? 0x01 : 0x00)));
            f.SaveFile(".settings");
            f.Dispose();
        }
예제 #9
0
파일: Level.cs 프로젝트: pdelvo/Craft.Net
        public void SavePlayer(PlayerEntity entity)
        {
            // TODO: Generalize to all mobs
            NbtFile file = new NbtFile();
            var data = new NbtCompound();
            data.Tags.Add(new NbtByte("OnGround", (byte)(entity.OnGround ? 1 : 0)));
            data.Tags.Add(new NbtShort("Air", entity.Air));
            data.Tags.Add(new NbtShort("Health", entity.Health));
            data.Tags.Add(new NbtInt("Dimension", 0)); // TODO
            data.Tags.Add(new NbtInt("foodLevel", entity.Food));
            data.Tags.Add(new NbtInt("XpLevel", entity.XpLevel));
            data.Tags.Add(new NbtInt("XpTotal", entity.XpTotal));
            data.Tags.Add(new NbtFloat("foodExhaustionLevel", entity.FoodExhaustion));
            data.Tags.Add(new NbtFloat("foodSaturationLevel", entity.FoodSaturation));
            data.Tags.Add(new NbtFloat("XpP", entity.XpProgress));
            data.Tags.Add(new NbtList("Equipment"));
            var inventory = new NbtList("Inventory");
            for (int index = 0; index < entity.Inventory.Length; index++)
            {
                var slot = entity.Inventory[index];
                if (slot.Empty)
                    continue;
                slot.Index = NetworkSlotToDataSlot(index);
                inventory.Tags.Add(slot.ToNbt());
            }
            data.Tags.Add(inventory);
            var motion = new NbtList("Motion");
            motion.Tags.Add(new NbtDouble(entity.Velocity.X));
            motion.Tags.Add(new NbtDouble(entity.Velocity.Y));
            motion.Tags.Add(new NbtDouble(entity.Velocity.Z));
            data.Tags.Add(motion);

            var pos = new NbtList("Pos");
            pos.Tags.Add(new NbtDouble(entity.Position.X));
            pos.Tags.Add(new NbtDouble(entity.Position.Y));
            pos.Tags.Add(new NbtDouble(entity.Position.Z));
            data.Tags.Add(pos);

            var rotation = new NbtList("Rotation");
            rotation.Tags.Add(new NbtFloat(entity.Yaw));
            rotation.Tags.Add(new NbtFloat(entity.Pitch));
            data.Tags.Add(rotation);

            data.Tags.Add(new NbtCompound("abilities"));

            file.RootTag = data;
            if (!Directory.Exists(Path.Combine(LevelDirectory, "players")))
                Directory.CreateDirectory(Path.Combine(LevelDirectory, "players"));
            using (Stream stream = File.Open(Path.Combine(LevelDirectory, "players", entity.Username + ".dat"), FileMode.OpenOrCreate))
                file.SaveFile(stream, true);
        }
예제 #10
0
파일: Level.cs 프로젝트: pdelvo/Craft.Net
        public void Save()
        {
            NbtFile file = new NbtFile();
            NbtCompound data = new NbtCompound("Data");
            data.Tags.Add(new NbtByte("raining", (byte)(Raining ? 1 : 0)));
            data.Tags.Add(new NbtInt("generatorVersion", 0)); // TODO
            data.Tags.Add(new NbtLong("Time", Time));
            data.Tags.Add(new NbtInt("GameType", (int)GameMode));
            data.Tags.Add(new NbtByte("MapFeatures", (byte)(MapFeatures ? 1 : 0))); // TODO: Move to world generator
            data.Tags.Add(new NbtString("generatorName", WorldGenerator.GeneratorName));
            data.Tags.Add(new NbtByte("initialized", 1));
            data.Tags.Add(new NbtByte("hardcore", 0)); // TODO
            data.Tags.Add(new NbtLong("RandomSeed", Seed));
            data.Tags.Add(new NbtInt("SpawnX", (int)SpawnPoint.X));
            data.Tags.Add(new NbtInt("SpawnY", (int)SpawnPoint.Y));
            data.Tags.Add(new NbtInt("SpawnZ", (int)SpawnPoint.Z));
            data.Tags.Add(new NbtLong("SizeOnDisk", 0));
            data.Tags.Add(new NbtInt("thunderTime", ThunderTime));
            data.Tags.Add(new NbtInt("rainTime", RainTime));
            data.Tags.Add(new NbtInt("version", 19133));
            data.Tags.Add(new NbtByte("thundering", (byte)(Thundering ? 1 : 0)));
            data.Tags.Add(new NbtString("LevelName", Name));
            data.Tags.Add(new NbtLong("LastPlayed", DateTime.UtcNow.Ticks));
            file.RootTag = new NbtCompound();
            file.RootTag.Tags.Add(data);
            using (var stream = File.Open(Path.Combine(LevelDirectory, "level.dat"), FileMode.Create))
                file.SaveFile(stream, true);

            World.Save();
        }
예제 #11
0
		public override void SaveChunk(Chunk cnk)
		{
			NbtFile c = new NbtFile(cnk.Filename);

            c.RootTag = NewNBTChunk(cnk.Position.X, cnk.Position.Z);
            NbtCompound Level = (NbtCompound)c.RootTag["Level"];

			// BLOCKS /////////////////////////////////////////////////////
			byte[] blocks = new byte[ChunkX * ChunkZ * ChunkY];
			for (int x = 0; x < ChunkX; x++)
			{
				for (int y = 0; y < ChunkY; y++)
				{
					for (int z = 0; z < ChunkZ; z++)
					{
						blocks[GetBlockIndex(x, y, z)] = cnk.Blocks[x, y, z];
					}
				}
            }
            Level.Set("xPos", new NbtInt("xPos", (int)cnk.Position.X));
            Level.Set("zPos", new NbtInt("zPos", (int)cnk.Position.Z));
            Level.Set("Blocks", new NbtByteArray("Blocks", blocks));
			blocks = null;

			// LIGHTING ///////////////////////////////////////////////////
			byte[] lighting = CompressLightmap(cnk.SkyLight,true);
			Level.Set("SkyLight",new NbtByteArray("SkyLight", lighting));

			lighting = CompressLightmap(cnk.BlockLight,false);
            Level.Set("BlockLight",new NbtByteArray("BlockLight", lighting));
			
			lighting = CompressDatamap(cnk.Data);
            Level.Set("Data", new NbtByteArray("Data", lighting));

			// HEIGHTMAP (Needed for lighting).
			byte[] hm = new byte[256];
			for (int x = 0; x < ChunkX; x++)
			{
				for (int z = 0; z < ChunkZ; z++)
				{
                    hm[z << 4 | x] = (byte)(cnk.HeightMap[x, z] & 0xff); // idk
				}
			}
            Level.Set("HeightMap", new NbtByteArray("HeightMap", hm));


			NbtList ents = new NbtList("Entities");
			// ENTITIES ///////////////////////////////////////////////////
			foreach (KeyValuePair<Guid, Entity> ent in cnk.Entities)
			{
				ents.Add(ent.Value.ToNBT());
			}
			Level.Set("Entities",ents);

			NbtList tents = new NbtList("TileEntities");
			// TILE ENTITIES //////////////////////////////////////////////
			foreach (KeyValuePair<Guid, TileEntity> tent in cnk.TileEntities)
			{
				tents.Add(tent.Value.ToNBT());
			}
			Level.Set("TileEntities",tents);

            // Tick when last saved.  But ticks are process associated...
            Level.Set("LastUpdate", new NbtLong("LastUpdate", (long)Utils.UnixTimestamp()));

			c.RootTag.Set("Level",Level);
			
            c.SaveFile(GetChunkFilename((int)cnk.Position.X,(int)cnk.Position.Z));
			
            // For debuggan
            File.WriteAllText(cnk.Filename + ".txt", c.RootTag.ToString());

            Cache.SaveChunkMetadata(cnk); // This is probably what lags.
        }
예제 #12
0
        public void RemoveEntity(Entity e)
        {
            Guid ID = e.UUID;
            if (_Entities.ContainsKey(ID))
                _Entities.Remove(ID);

            int CX = (int)e.Pos.X / 16;
            int CY = (int)e.Pos.Y / 16;
            e.Pos.X = (int)e.Pos.X % 16;
            e.Pos.Y = (int)e.Pos.Y % 16;

            string f = GetChunkFilename(CX, CY);
            if (!File.Exists(f))
            {
                Console.WriteLine("! {0}", f);
                return;
            }
            try
            {
                chunk = new NbtFile(f);
                chunk.LoadFile();
                NbtCompound level = (NbtCompound)chunk.RootTag["Level"];

                NbtList ents = (NbtList)level["Entities"];
                if (e.OrigPos != null)
                {
                    NbtCompound dc = null;
                    foreach (NbtCompound c in ents.Tags)
                    {
                        Entity ent = new Entity(c);
                        if (e.Pos == ent.Pos)
                        {
                            dc = c;
                            break;
                        }
                    }
                    if (dc != null)
                        ents.Tags.Remove(dc);
                }
                level["Entities"] = ents;
                chunk.RootTag["Level"] = level;
                chunk.SaveFile(f);
            }
            catch (Exception) { }
        }
예제 #13
0
        public Chunk NewChunk(long X, long Y)
        {
            NbtCompound c = NewNBTChunk(X, Y);
            NbtFile cf = new NbtFile(GetChunkFilename((int)X, (int)Y));
            cf.RootTag = c;
            cf.SaveFile(GetChunkFilename((int)X, (int)Y));

            return GetChunk(X, Y);
        }
예제 #14
0
        public void SaveChunk(Chunk cnk)
        {
            NbtFile c = new NbtFile(cnk.Filename);
            c.LoadFile();
            //Console.WriteLine("Saving "+f);

            NbtCompound Level = (NbtCompound)c.RootTag["Level"];
            //string ci = string.Format("{0},{1}", x, z);
            Level.Tags.Remove(Level["Blocks"]);

            // BLOCKS /////////////////////////////////////////////////////
            byte[] blocks = new byte[ChunkX * ChunkY * ChunkZ];
            for (int X = 0; X < ChunkX; X++)
            {
                for (int Y = 0; Y < ChunkY; Y++)
                {
                    for (int Z = 0; Z < ChunkZ; Z++)
                    {
                        blocks[GetBlockIndex(X, Y, Z)] = cnk.Blocks[X, Y, Z];
                    }
                }
            }
            Level.Tags.Add(new NbtByteArray("Blocks", blocks));
            blocks = null;

            // LIGHTING ///////////////////////////////////////////////////
            // TODO:  Whatever is going on in here is crashing Minecraft now.
            byte[] lighting = CompressLightmap(cnk.SkyLight);
            Level.Tags.Add(new NbtByteArray("SkyLight", lighting));

            lighting = CompressLightmap(cnk.BlockLight);
            Level.Tags.Add(new NbtByteArray("BlockLight", lighting));

            lighting = CompressDatamap(cnk.Data);
            Level.Tags.Add(new NbtByteArray("Data", lighting));

            // HEIGHTMAP (Needed for lighting).
            byte[] hm = new byte[256];
            for (int x = 0; x < 16; x++)
            {
                for (int y = 0; y < 16; y++)
                {
                    hm[y + (x * 16)] = (byte)cnk.HeightMap[x, y];
                }
            }

            NbtList ents = new NbtList("Entities");
            // ENTITIES ///////////////////////////////////////////////////
            foreach (KeyValuePair<Guid, Entity> ent in cnk.Entities)
            {
                ents.Tags.Add(ent.Value.ToNBT());
            }
            Level.Tags.Add(ents);

            NbtList tents = new NbtList("TileEntities");
            // TILE ENTITIES //////////////////////////////////////////////
            foreach (KeyValuePair<Guid, TileEntity> tent in cnk.TileEntities)
            {
                ents.Tags.Add(tent.Value.ToNBT());
            }
            Level.Tags.Add(tents);

            c.RootTag["Level"] = Level;
            //try
            //{
                c.SaveFile(cnk.Filename);
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e);
            //}
        }
예제 #15
0
		public Chunk NewChunk(long X, long Y)
        {
            NbtCompound c = NewNBTChunk(X, Y);
            string f = GetChunkFilename((int)X, (int)Y);

            // Create folder first.
            string d = Path.GetDirectoryName(f);
            
            if(!Directory.Exists(d))
                Directory.CreateDirectory(d);

            // Get around crash where Windows doesn't like creating new files in Write mode for some f*****g stupid reason
            {
                FileInfo fi = new FileInfo(f);
                FileStream fs = fi.Create();
                fs.Close();
            }

            // Create the damn file.
            NbtFile cf = new NbtFile(f);
            cf.RootTag = c;
            cf.SaveFile(f);
            cf.Dispose(); // Pray.

            return GetChunk(X, Y);
        }
예제 #16
0
        public static bool Set(string input, string file, bool starterKit, bool sunRize)
        {
            try
            {
                byte[] XOR_KEY = { 108, 111, 108, 32, 101, 97, 115, 116, 101, 114, 32, 101, 103, 103 };

                input = input.Trim();
                if (!input.StartsWith("[") || !input.EndsWith("]"))
                    return false;
                input = input.Replace("[", "").Replace("]", "");
                byte[] data = Convert.FromBase64String(input);

                for (int i = 0; i < data.Length; i++)
                {
                    int mod = i % XOR_KEY.Length;
                    data[i] = (byte)((int)data[i] ^ (int)XOR_KEY[mod]);
                }

                int end = 0;

                long randomSeed = BitConverter.ToInt64(data, 0);
                end += sizeof(long);

                long time = BitConverter.ToInt64(data, end);
                end += sizeof(long);

                int playerX = BitConverter.ToInt32(data, end);
                end += sizeof(int);

                int playerY = BitConverter.ToInt32(data, end); // height
                end += sizeof(int);

                int playerZ = BitConverter.ToInt32(data, end);
                end += sizeof(int);

                float rotationX = BitConverter.ToSingle(data, end);
                end += sizeof(float);

                float rotationY = BitConverter.ToSingle(data, end);

                NbtFile nbt = new NbtFile();

                NbtCompound compound = new NbtCompound();

                NbtCompound data_compound = new NbtCompound("Data");

                data_compound.Tags.Add(new NbtLong("RandomSeed", randomSeed));
                data_compound.Tags.Add(new NbtLong("Time", sunRize ? 1 : time));
                data_compound.Tags.Add(new NbtInt("SpawnX", playerX));
                data_compound.Tags.Add(new NbtInt("SpawnY", playerY));
                data_compound.Tags.Add(new NbtInt("SpawnZ", playerZ));
                data_compound.Tags.Add(new NbtLong("LastPlayed", 1289561130810));
                data_compound.Tags.Add(new NbtLong("SizeOnDisk", 1000));

                NbtCompound player_compound = new NbtCompound("Player");

                player_compound.Tags.Add(new NbtByte("OnGround", 1));
                player_compound.Tags.Add(new NbtShort("Air", 300));
                player_compound.Tags.Add(new NbtShort("AttackTime", 0));
                player_compound.Tags.Add(new NbtShort("DeathTime", 0));
                player_compound.Tags.Add(new NbtShort("Fire", -20));
                player_compound.Tags.Add(new NbtShort("Health", 20));
                player_compound.Tags.Add(new NbtShort("HurtTime", 0));
                player_compound.Tags.Add(new NbtInt("Dimension", 0));
                player_compound.Tags.Add(new NbtInt("Score", 0));
                player_compound.Tags.Add(new NbtFloat("FallDistance", 0));

                NbtList player_pos = new NbtList("Pos");
                player_pos.Tags.Add(new NbtDouble("", (double)playerX + 0.5));
                player_pos.Tags.Add(new NbtDouble("", (double)playerY + 0.65));
                player_pos.Tags.Add(new NbtDouble("", (double)playerZ + 0.5));
                player_compound.Tags.Add(player_pos);

                NbtList player_rot = new NbtList("Rotation");
                player_rot.Tags.Add(new NbtFloat("", rotationX));
                player_rot.Tags.Add(new NbtFloat("", rotationY));
                player_compound.Tags.Add(player_rot);

                NbtList inv_compound = new NbtList("Inventory");
                if (starterKit)
                {
                    inv_compound.Tags.Add(GetItemCompound(263, 3, 34, 0));
                    inv_compound.Tags.Add(GetItemCompound(17, 10, 35, 0));
                    inv_compound.Tags.Add(GetItemCompound(274, 1, 0, 0));
                    inv_compound.Tags.Add(GetItemCompound(273, 1, 1, 0));
                    inv_compound.Tags.Add(GetItemCompound(319, 1, 6, 0));
                    inv_compound.Tags.Add(GetItemCompound(319, 1, 7, 0));
                    inv_compound.Tags.Add(GetItemCompound(50, 10, 8, 0));
                }
                player_compound.Tags.Add(inv_compound);

                NbtList player_mot = new NbtList("Motion");
                player_mot.Tags.Add(new NbtDouble("", 0.0));
                player_mot.Tags.Add(new NbtDouble("", 0.0));
                player_mot.Tags.Add(new NbtDouble("", 0.0));
                player_compound.Tags.Add(player_mot);

                data_compound.Tags.Add(player_compound);
                nbt.RootTag = compound;
                nbt.RootTag.Tags.Add(data_compound);

                Stream stream = File.OpenWrite(file);
                nbt.SaveFile(stream, true);
                stream.Close();
                stream.Dispose();

                return true;
            }
            catch(Exception ex)
            {
                return false;
            }
        }
예제 #17
0
		public void SetTileEntity(TileEntity e)
		{
			long CX=e.Pos.X/16;
			long CY=e.Pos.Y/16;
			string f = GetChunkFilename((int)CX, (int)CY);

			try
			{
				mChunk = new NbtFile(f);
				mChunk.LoadFile();
				NbtCompound level = (NbtCompound)mChunk.RootTag["Level"];

				NbtList tents = (NbtList)level["TileEntities"];
				int found = -1;
				for(int i = 0;i<tents.Tags.Count;i++)
				{
					TileEntity te = new TileEntity((NbtCompound)tents[i]);
					if (te.Pos == e.Pos)
					{
						found = i;
					}
				}
				if (found > -1)
					tents[found] = e.ToNBT();
				else
					tents.Tags.Add(e.ToNBT());

				level["TileEntities"] = tents;
				mChunk.RootTag["Level"] = level;
				mChunk.SaveFile(f);
			}
			catch (Exception) { }
		}
예제 #18
0
 public override void Save(string Folder)
 {
     string f = Path.Combine(Folder, "DefaultMapGenerator.dat");
     NbtFile nf = new NbtFile(f);
     nf.RootTag = new NbtCompound("__ROOT__");
     NbtCompound c = new NbtCompound("DefaultMapGenerator");
     c.Tags.Add(new NbtByte("GenerateCaves", (byte) (GenerateCaves ? 1 : 0)));
     c.Tags.Add(new NbtByte("GenerateDungeons", (byte) (GenerateDungeons ? 1 : 0)));
     c.Tags.Add(new NbtByte("GenerateOres", (byte) (GenerateOres ? 1 : 0)));
     c.Tags.Add(new NbtByte("GenerateWater", (byte) (GenerateWater ? 1 : 0)));
     c.Tags.Add(new NbtByte("HellMode", (byte) (HellMode ? 1 : 0)));
     c.Tags.Add(new NbtByte("GenerateTrees", (byte) (GenerateTrees ? 1 : 0)));
     c.Tags.Add(new NbtDouble("Frequency", Frequency));
     c.Tags.Add(new NbtByte("NoiseQuality", (byte) NoiseQuality));
     c.Tags.Add(new NbtInt("OctaveCount", OctaveCount));
     c.Tags.Add(new NbtDouble("Lacunarity", Lacunarity));
     c.Tags.Add(new NbtDouble("Persistance", Persistance));
     c.Tags.Add(new NbtDouble("ContinentNoiseFrequency", ContinentNoiseFrequency));
     c.Tags.Add(new NbtDouble("CaveThreshold", CaveThreshold));
     nf.RootTag.Tags.Add(c);
     nf.SaveFile(f);
 }
예제 #19
0
 private object NBT2Bytes(NbtCompound nbtCompound)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         NbtFile f = new NbtFile();
         f.RootTag = nbtCompound;
         f.SaveFile(ms,false);
         //ms.Position = 0;
         //byte[] buffer = new byte[ms.Length];
         //ms.Read(buffer, 0, buffer.Length);
         return ms.ToArray();
     }
 }