SaveToFile() public méthode

Saves this NBT file to a stream. Nothing is written to stream if RootTag is null.
is null. If AutoDetect was given as the mode. If an unrecognized/unsupported value was given for . If given stream does not support writing. If an I/O error occurred while creating the file. Specified file is read-only, or a permission issue occurred. If one of the NbtCompound tags contained unnamed tags; /// or if an NbtList tag had Unknown list type and no elements.
public SaveToFile ( [ fileName, NbtCompression compression ) : long
fileName [ File to write data to. May not be null.
compression NbtCompression Compression mode to use for saving. May not be AutoDetect.
Résultat long
Exemple #1
0
		public static void SaveLevel(LevelInfo level)
		{
			if (!Directory.Exists(_basePath))
				Directory.CreateDirectory(_basePath);

			NbtFile file = new NbtFile();
			NbtTag dataTag = file.RootTag["Data"] = new NbtCompound("Data");
			level.SaveToNbt(dataTag);
			file.SaveToFile(Path.Combine(_basePath, "level.dat"), NbtCompression.ZLib);
		}
Exemple #2
0
 public void SaveTo(string file)
 {
     var nbt = new NbtFile(file);
     nbt.RootTag = new NbtCompound("");
     var list = new NbtList("servers", NbtTagType.Compound);
     foreach (var server in Servers)
     {
         var compound = new NbtCompound();
         compound.Add(new NbtString("name", server.Name));
         compound.Add(new NbtString("ip", server.Ip));
         compound.Add(new NbtByte("hideAddress", (byte)(server.HideAddress ? 1 : 0)));
         compound.Add(new NbtByte("acceptTextures", (byte)(server.AcceptTextures ? 1 : 0)));
         list.Add(compound);
     }
     nbt.RootTag.Add(list);
     nbt.SaveToFile(file, NbtCompression.None);
 }
Exemple #3
0
        public void Save(Map mapToSave, string path) {
            NbtCompound rootTag = new NbtCompound("Schematic") {
                new NbtShort("Width", (short)mapToSave.Width),
                new NbtShort("Height", (short)mapToSave.Height),
                new NbtShort("Length", (short)mapToSave.Length),
                new NbtString("Materials", "Classic"),
                new NbtByteArray("Blocks", mapToSave.Blocks),

                // set to 0 unless converted in overloaded DoConversion
                new NbtByteArray("Data", new byte[mapToSave.Volume]),

                // these two lists are empty, but required for compatibility
                new NbtList("Entities", NbtTagType.Compound),
                new NbtList("TileEntities", NbtTagType.Compound),
            };
            DoConversion(rootTag);
            NbtFile file = new NbtFile(rootTag);
            file.SaveToFile(path, NbtCompression.GZip);
            File.WriteAllText("debug.txt", file.RootTag.ToString("    "));
        }
Exemple #4
0
        public void Save()
        {
            NbtCompound root = new NbtCompound("base");
            root.Add(new NbtString("fileType", "map"));

            NbtList aList = new NbtList("areas", NbtTagType.Compound);
            foreach(Area alpha in areas) {
                aList.Add(alpha.Save());
            }
            root.Add(aList);

            NbtFile saveFile = new NbtFile(root);
            saveFile.BigEndian = true;
            saveFile.SaveToFile("mapfile.nbt", NbtCompression.None);
        }
Exemple #5
0
 /// <summary>
 /// Saves this level. This will not work with an in-memory world.
 /// </summary>
 public void Save()
 {
     if (DatFile == null)
         throw new InvalidOperationException("This level exists only in memory. Use Save(string).");
     LastPlayed = DateTime.UtcNow.Ticks;
     var serializer = new NbtSerializer(typeof(Level));
     var tag = serializer.Serialize(this, "Data") as NbtCompound;
     var file = new NbtFile();
     file.RootTag.Add(tag);
     file.SaveToFile(DatFile, NbtCompression.GZip);
     // Save worlds
     foreach (var world in Worlds)
     {
         if (world.BaseDirectory == null)
             world.Save(Path.Combine(BaseDirectory, world.Name));
         else
             world.Save();
     }
 }
Exemple #6
0
 public void Save()
 {
     var path = Path.Combine(Directory.GetCurrentDirectory(), "players", Username + ".nbt");
     if (Program.ServerConfiguration.Singleplayer)
         path = Path.Combine(((World)World).BaseDirectory, "player.nbt");
     if (!Directory.Exists(Path.GetDirectoryName(path)))
         Directory.CreateDirectory(Path.GetDirectoryName(path));
     if (Entity == null) // I didn't think this could happen but null reference exceptions have been repoted here
         return;
     var nbt = new NbtFile(new NbtCompound("player", new NbtTag[]
         {
             new NbtString("username", Username),
             new NbtList("position", new[]
             {
                 new NbtDouble(Entity.Position.X),
                 new NbtDouble(Entity.Position.Y),
                 new NbtDouble(Entity.Position.Z)
             }),
             new NbtList("inventory", Inventory.GetSlots().Select(s => s.ToNbt())),
             new NbtShort("health", (Entity as PlayerEntity).Health),
             new NbtFloat("yaw", Entity.Yaw),
             new NbtFloat("pitch", Entity.Pitch),
         }
     ));
     nbt.SaveToFile(path, NbtCompression.ZLib);
 }
Exemple #7
0
 public void Save()
 {
     lock (Regions)
     {
         foreach (var region in Regions)
             region.Value.Save(Path.Combine(BaseDirectory, Region.GetRegionFileName(region.Key)));
     }
     var file = new NbtFile();
     file.RootTag.Add(new NbtCompound("SpawnPoint", new[]
     {
         new NbtInt("X", this.SpawnPoint.X),
         new NbtInt("Y", this.SpawnPoint.Y),
         new NbtInt("Z", this.SpawnPoint.Z)
     }));
     file.RootTag.Add(new NbtInt("Seed", this.Seed));
     file.RootTag.Add(new NbtString("ChunkProvider", this.ChunkProvider.GetType().FullName));
     file.RootTag.Add(new NbtString("Name", Name));
     file.SaveToFile(Path.Combine(this.BaseDirectory, "manifest.nbt"), NbtCompression.ZLib);
 }
        /// <summary>
        /// Saves the ClassicWorld map.
        /// </summary>
        public void Save(string Filename)
        {
            var NbtMetadata = Foreignmeta.Write();

            foreach (IMetadataStructure b in MetadataParsers.Values)
            {
                var Nbt = b.Write();

                if (Nbt != null)
                    NbtMetadata.Add(Nbt);

                Nbt = null;
            }

            var compound = new NbtCompound("ClassicWorld") {
                new NbtByte("FormatVersion", 1),
                new NbtString("Name", MapName),
                new NbtByteArray("UUID", UUID),
                new NbtShort("X", Size.x),
                new NbtShort("Y", Size.y),
                new NbtShort("Z", Size.z),
                new NbtCompound("Spawn") {
                    new NbtShort("X", SpawnPos.x),
                    new NbtShort("Y", SpawnPos.y),
                    new NbtShort("Z", SpawnPos.z),
                    new NbtByte("H", (byte)SpawnRotation.x),
                    new NbtByte("P", (byte)SpawnRotation.z)
                },
                new NbtByteArray("BlockArray", BlockData),
                NbtMetadata
            };

            if (CreatingService != null && CreatingUsername != null)
            {
                var CreatedByTag = new NbtCompound("CreatedBy") {
                    new NbtString("Service", CreatingService),
                    new NbtString("Username", CreatingUsername)
                };

                compound.Add(CreatedByTag);
            }

            if (GeneratingSoftware != null && GeneratorName != null)
            {
                var MapGenerator = new NbtCompound("MapGenerator") {
                    new NbtString("Software", GeneratingSoftware),
                    new NbtString("MapGeneratorName", GeneratorName)
                };

                compound.Add(MapGenerator);
            }

            if (TimeCreated != 0.0)
                compound.Add(new NbtLong("TimeCreated", TimeCreated));

            if (LastAccessed != 0.0)
                compound.Add(new NbtLong("LastAccessed", LastAccessed));

            if (LastModified != 0.0)
                compound.Add(new NbtLong("LastModified", LastModified));

            var myFile = new NbtFile(compound);
            myFile.SaveToFile(Filename, NbtCompression.GZip);

            compound = null;
            myFile = null;
            NbtMetadata = null;
        }
 public static void SavePlayer(this Level level, RemoteClient client)
 {
     if (string.IsNullOrEmpty(level.BaseDirectory))
         return;
     try
     {
         Directory.CreateDirectory(Path.Combine(level.BaseDirectory, "players"));
         var file = new NbtFile();
         file.RootTag.Add(new NbtInt("playerGameType", (int)client.GameMode));
         file.RootTag.Add(new NbtShort("SelectedItemSlot", client.Entity.SelectedSlot));
         file.RootTag.Add(new NbtInt("SpawnX", (int)client.Entity.SpawnPoint.X));
         file.RootTag.Add(new NbtInt("SpawnY", (int)client.Entity.SpawnPoint.Y));
         file.RootTag.Add(new NbtInt("SpawnZ", (int)client.Entity.SpawnPoint.Z));
         file.RootTag.Add(new NbtInt("foodLevel", client.Entity.Food));
         file.RootTag.Add(new NbtFloat("foodExhaustionLevel", client.Entity.FoodExhaustion));
         file.RootTag.Add(new NbtFloat("foodSaturationLevel", client.Entity.FoodSaturation));
         file.RootTag.Add(new NbtShort("Health", client.Entity.Health));
         var inventory = new NbtList("Inventory", NbtTagType.Compound);
         var slots = client.Entity.Inventory.GetSlots();
         for (int i = 0; i < slots.Length; i++)
         {
             var slot = (ItemStack)slots[i].Clone();
             slot.Index = Level.NetworkSlotToDataSlot(i);
             if (!slot.Empty)
                 inventory.Add(slot.ToNbt());
         }
         file.RootTag.Add(inventory);
         var position = new NbtList("Pos", NbtTagType.Double);
         position.Add(new NbtDouble(client.Entity.Position.X));
         position.Add(new NbtDouble(client.Entity.Position.Y));
         position.Add(new NbtDouble(client.Entity.Position.Z));
         file.RootTag.Add(position);
         var rotation = new NbtList("Rotation", NbtTagType.Float);
         rotation.Add(new NbtFloat(client.Entity.Yaw));
         rotation.Add(new NbtFloat(client.Entity.Pitch));
         file.RootTag.Add(rotation);
         var velocity = new NbtList("Motion", NbtTagType.Double);
         velocity.Add(new NbtDouble(client.Entity.Velocity.X));
         velocity.Add(new NbtDouble(client.Entity.Velocity.Y));
         velocity.Add(new NbtDouble(client.Entity.Velocity.Z));
         file.RootTag.Add(velocity);
         file.SaveToFile(Path.Combine(level.BaseDirectory, "players", client.Username + ".dat"), NbtCompression.None);
     }
     catch { } // If exceptions happen here, the entire server dies
 }
        /// <summary>
        /// Saves the Classicworld map.
        /// </summary>
        /// <param name="filename">The file name/path to save the map to.</param>
        public void Save(string filename) {
            var nbtMetadata = Foreignmeta.Write();

            foreach (var b in MetadataParsers.Values) {
                var nbt = b.Write();

                if (nbt != null)
                    nbtMetadata.Add(nbt);
            }

            var compound = new NbtCompound("ClassicWorld") {
                new NbtByte("FormatVersion", 1),
                new NbtString("Name", MapName),
                new NbtByteArray("UUID", Uuid),
                new NbtShort("X", SizeX),
                new NbtShort("Y", SizeY),
                new NbtShort("Z", SizeZ),
                new NbtCompound("Spawn") {
                    new NbtShort("X", SpawnX),
                    new NbtShort("Y", SpawnY),
                    new NbtShort("Z", SpawnZ),
                    new NbtByte("H", SpawnRotation),
                    new NbtByte("P", SpawnLook)
                },
                new NbtByteArray("BlockArray", BlockData),
                nbtMetadata
            };

            if (CreatingService != null && CreatingUsername != null) {
                var createdByTag = new NbtCompound("CreatedBy") {
                    new NbtString("Service", CreatingService),
                    new NbtString("Username", CreatingUsername)
                };

                compound.Add(createdByTag);
            }

            if (GeneratingSoftware != null && GeneratorName != null) {
                var mapGenerator = new NbtCompound("MapGenerator") {
                    new NbtString("Software", GeneratingSoftware),
                    new NbtString("MapGeneratorName", GeneratorName)
                };

                compound.Add(mapGenerator);
            }

            compound.Add(new NbtLong("TimeCreated", TimeCreated));

            compound.Add(new NbtLong("LastAccessed", LastAccessed));

            compound.Add(new NbtLong("LastModified", LastModified));

            var myFile = new NbtFile(compound);
            myFile.SaveToFile(filename, NbtCompression.GZip);
        }