예제 #1
0
        /// <summary>
        /// Loads the ClassicWorld map.
        /// </summary>
        public void Load()
        {
            BlockData = null;
            FormatVersion = Basetag["FormatVersion"].ByteValue;

              if (FormatVersion != 1)
               throw new FormatException("Unsupported format version: " + FormatVersion.ToString());

            Foreignmeta = new ForeignMeta();

            MapName = Basetag["Name"].StringValue;

            UUID = Basetag["UUID"].ByteArrayValue;

            Size.x = Basetag["X"].ShortValue;
            Size.y = Basetag["Y"].ShortValue;
            Size.z = Basetag["Z"].ShortValue;

            var CreatedBy = Basetag.Get<NbtCompound>("CreatedBy");

            if (CreatedBy != null)
            {
                CreatingService = CreatedBy["Service"].StringValue;
                CreatingUsername = CreatedBy["Username"].StringValue;
            }

            var Mapgen = Basetag.Get<NbtCompound>("MapGenerator");

            if (Mapgen != null)
            {
                GeneratingSoftware = Mapgen["Software"].StringValue;
                GeneratorName = Mapgen["MapGeneratorName"].StringValue;
            }

            if (Basetag["TimeCreated"] != null)
                TimeCreated = Basetag["TimeCreated"].LongValue;

            if (Basetag["LastAccessed"] != null)
                LastAccessed = Basetag["LastAccessed"].LongValue;

            if (Basetag["LastModified"] != null)
                LastModified = Basetag["LastModified"].LongValue;

            var Spawnpoint = Basetag.Get<NbtCompound>("Spawn");

            if (Spawnpoint == null)
                throw new FormatException("Spawn not found.");
            else
            {
                SpawnPos.x = Spawnpoint["X"].ShortValue;
                SpawnPos.y = Spawnpoint["Y"].ShortValue;
                SpawnPos.z = Spawnpoint["Z"].ShortValue;
                SpawnRotation.x = Spawnpoint["H"].ByteValue;
                SpawnRotation.z = Spawnpoint["P"].ByteValue;
            }

            BlockData = Basetag["BlockArray"].ByteArrayValue;

            var Metadata = Basetag.Get<NbtCompound>("Metadata");

            if (Metadata != null)
            {
                // -- Let user-defined metadata parsers parse metadata...
                foreach (IMetadataStructure Meta in MetadataParsers.Values)
                    Metadata = Meta.Read(Metadata);

                // -- Store all foreign metadata
                Metadata = Foreignmeta.Read(Metadata);
            }

            // -- Now that the map is loaded, we have to ensure all of the required values were included.

            if (BlockData == null)
                throw new FormatException("BlockArray not found.");

            if (Size.x == 0 || Size.y == 0 || Size.z == 0)
                throw new FormatException("Map size not found.");

            if (FormatVersion == 0 || MapName == null || UUID == null)
                throw new FormatException("Map header information not found.");

            if (LastAccessed != 0)
                LastAccessed = GetCurrentUnixTime();

            Basetag = null;
        }
예제 #2
0
        /// <summary>
        /// Loads the ClassicWorld map.
        /// </summary>
        public void Load()
        {
            BlockData     = null;
            FormatVersion = Basetag["FormatVersion"].ByteValue;

            if (FormatVersion != 1)
            {
                throw new FormatException("Unsupported format version: " + FormatVersion.ToString());
            }

            Foreignmeta = new ForeignMeta();

            MapName = Basetag["Name"].StringValue;

            UUID = Basetag["UUID"].ByteArrayValue;

            Size.x = Basetag["X"].ShortValue;
            Size.y = Basetag["Y"].ShortValue;
            Size.z = Basetag["Z"].ShortValue;

            var CreatedBy = Basetag.Get <NbtCompound>("CreatedBy");

            if (CreatedBy != null)
            {
                CreatingService  = CreatedBy["Service"].StringValue;
                CreatingUsername = CreatedBy["Username"].StringValue;
            }

            var Mapgen = Basetag.Get <NbtCompound>("MapGenerator");

            if (Mapgen != null)
            {
                GeneratingSoftware = Mapgen["Software"].StringValue;
                GeneratorName      = Mapgen["MapGeneratorName"].StringValue;
            }

            if (Basetag["TimeCreated"] != null)
            {
                TimeCreated = Basetag["TimeCreated"].LongValue;
            }

            if (Basetag["LastAccessed"] != null)
            {
                LastAccessed = Basetag["LastAccessed"].LongValue;
            }

            if (Basetag["LastModified"] != null)
            {
                LastModified = Basetag["LastModified"].LongValue;
            }

            var Spawnpoint = Basetag.Get <NbtCompound>("Spawn");

            if (Spawnpoint == null)
            {
                throw new FormatException("Spawn not found.");
            }
            else
            {
                SpawnPos.x      = Spawnpoint["X"].ShortValue;
                SpawnPos.y      = Spawnpoint["Y"].ShortValue;
                SpawnPos.z      = Spawnpoint["Z"].ShortValue;
                SpawnRotation.x = Spawnpoint["H"].ByteValue;
                SpawnRotation.z = Spawnpoint["P"].ByteValue;
            }

            BlockData = Basetag["BlockArray"].ByteArrayValue;

            var Metadata = Basetag.Get <NbtCompound>("Metadata");

            if (Metadata != null)
            {
                // -- Let user-defined metadata parsers parse metadata...
                foreach (IMetadataStructure Meta in MetadataParsers.Values)
                {
                    Metadata = Meta.Read(Metadata);
                }

                // -- Store all foreign metadata
                Metadata = Foreignmeta.Read(Metadata);
            }

            // -- Now that the map is loaded, we have to ensure all of the required values were included.

            if (BlockData == null)
            {
                throw new FormatException("BlockArray not found.");
            }

            if (Size.x == 0 || Size.y == 0 || Size.z == 0)
            {
                throw new FormatException("Map size not found.");
            }

            if (FormatVersion == 0 || MapName == null || UUID == null)
            {
                throw new FormatException("Map header information not found.");
            }

            if (LastAccessed != 0)
            {
                LastAccessed = GetCurrentUnixTime();
            }

            Basetag = null;
        }