Exemplo n.º 1
0
        public Map Load(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            using (FileStream mapStream = File.OpenRead(fileName)) {
                GZipStream gs  = new GZipStream(mapStream, CompressionMode.Decompress, true);
                NBTag      tag = NBTag.ReadStream(gs);

                NBTag mapTag = tag["Map"];
                // ReSharper disable UseObjectOrCollectionInitializer
                Map map = new Map(null,
                                  mapTag["Width"].GetShort(),
                                  mapTag["Length"].GetShort(),
                                  mapTag["Height"].GetShort(),
                                  false);
                // ReSharper restore UseObjectOrCollectionInitializer
                map.Spawn = new Position(mapTag["Spawn"][0].GetShort(),
                                         mapTag["Spawn"][2].GetShort(),
                                         mapTag["Spawn"][1].GetShort());

                map.Blocks = mapTag["Blocks"].GetBytes();
                map.RemoveUnknownBlocktypes();

                return(map);
            }
        }
Exemplo n.º 2
0
        public Map Load(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            using (FileStream mapStream = File.OpenRead(fileName)) {
                GZipStream gs   = new GZipStream(mapStream, CompressionMode.Decompress, true);
                NBTag      root = NBTag.ReadStream(gs);

                // ReSharper disable UseObjectOrCollectionInitializer
                Map map = new Map(null,
                                  root["X"].GetShort(),
                                  root["Z"].GetShort(),
                                  root["Y"].GetShort(),
                                  false);
                // ReSharper restore UseObjectOrCollectionInitializer

                NBTag spawnTag = root["Spawn"];
                map.Spawn = new Position {
                    X = (spawnTag["X"].GetShort() * 32),
                    Y = (spawnTag["Z"].GetShort() * 32),
                    Z = (spawnTag["Y"].GetShort() * 32),
                    R = spawnTag["H"].GetByte(),
                    L = spawnTag["P"].GetByte(),
                };

                // read UUID
                map.Guid = new Guid(root["UUID"].GetBytes());

                // read creation/modification dates of the file (for fallback)
                DateTime fileCreationDate = File.GetCreationTime(fileName);
                DateTime fileModTime      = File.GetCreationTime(fileName);

                // try to read embedded creation date
                if (root.Contains("TimeCreated"))
                {
                    map.DateCreated = DateTimeUtil.ToDateTime(root["TimeCreated"].GetLong());
                }
                else
                {
                    // for fallback, pick the older of two filesystem dates
                    map.DateCreated = (fileModTime > fileCreationDate) ? fileCreationDate : fileModTime;
                }

                // try to read embedded modification date
                if (root.Contains("LastModified"))
                {
                    map.DateModified = DateTimeUtil.ToDateTime(root["LastModified"].GetLong());
                }
                else
                {
                    // for fallback, use file modification date
                    map.DateModified = fileModTime;
                }

                map.Blocks = root["BlockArray"].GetBytes();
                return(map);
            }
        }
Exemplo n.º 3
0
        public Map Load(string fileName)
        {
            using (FileStream mapStream = File.OpenRead(fileName)) {
                GZipStream gs  = new GZipStream(mapStream, CompressionMode.Decompress, true);
                NBTag      tag = NBTag.ReadStream(gs);


                NBTag mapTag = tag["Map"];
                Map   map    = new Map(null,
                                       mapTag["Width"].GetShort(),
                                       mapTag["Length"].GetShort(),
                                       mapTag["Height"].GetShort(),
                                       false);
                map.Spawn = new Position {
                    X = mapTag["Spawn"][0].GetShort(),
                    H = mapTag["Spawn"][1].GetShort(),
                    Y = mapTag["Spawn"][2].GetShort(),
                    R = 0,
                    L = 0
                };

                if (!map.ValidateHeader())
                {
                    throw new MapFormatException("One or more of the map dimensions are invalid.");
                }

                map.Blocks = mapTag["Blocks"].GetBytes();
                map.RemoveUnknownBlocktypes(false);

                return(map);
            }
        }