void LoadMap(string path) { IMapFormatImporter importer = null; if (path.EndsWith(".dat")) { importer = new MapDatImporter(); } else if (path.EndsWith(".fcm")) { importer = new MapFcm3Importer(); } else if (path.EndsWith(".cw")) { importer = new MapCwImporter(); } else if (path.EndsWith(".lvl")) { importer = new MapLvlImporter(); } try { using (FileStream fs = File.OpenRead(path)) { int width, height, length; game.World.Reset(); game.WorldEvents.RaiseOnNewMap(); if (game.World.TextureUrl != null) { TexturePack.ExtractDefault(game); game.World.TextureUrl = null; } BlockInfo.Reset(game); game.Inventory.SetDefaultMapping(); byte[] blocks = importer.Load(fs, game, out width, out height, out length); #if USE16_BIT game.World.SetNewMap(Utils.UInt8sToUInt16s(blocks), width, height, length); #else game.World.SetNewMap(blocks, width, height, length); #endif game.WorldEvents.RaiseOnNewMapLoaded(); if (game.UseServerTextures && game.World.TextureUrl != null) { game.Server.RetrieveTexturePack(game.World.TextureUrl); } LocalPlayer p = game.LocalPlayer; LocationUpdate update = LocationUpdate.MakePosAndOri(p.Spawn, p.SpawnRotY, p.SpawnHeadX, false); p.SetLocation(update, false); } } catch (Exception ex) { ErrorHandler.LogError("loading map", ex); string file = Path.GetFileName(path); game.Chat.Add("&eFailed to load map \"" + file + "\""); } }
internal static void LoadMap(Game game, string path) { game.World.Reset(); Events.RaiseOnNewMap(); if (game.World.TextureUrl != null) { TexturePack.ExtractDefault(game); game.World.TextureUrl = null; } BlockInfo.Reset(); game.Inventory.SetDefaultMapping(); int width, height, length; byte[] blocks; try { using (Stream fs = Platform.FileOpen(path)) { IMapFormatImporter importer = null; if (path.EndsWith(".dat")) { importer = new MapDatImporter(); } else if (path.EndsWith(".fcm")) { importer = new MapFcm3Importer(); } else if (path.EndsWith(".cw")) { importer = new MapCwImporter(); } else if (path.EndsWith(".lvl")) { importer = new MapLvlImporter(); } blocks = importer.Load(fs, game, out width, out height, out length); } } catch (Exception ex) { ErrorHandler.LogError("loading map", ex); game.Chat.Add("&eFailed to load map \"" + path + "\""); return; } game.World.SetNewMap(blocks, width, height, length); Events.RaiseOnNewMapLoaded(); LocalPlayer p = game.LocalPlayer; LocationUpdate update = LocationUpdate.MakePosAndOri(p.Spawn, p.SpawnRotY, p.SpawnHeadX, false); p.SetLocation(update, false); }
void LoadMap(string path) { IMapFormatImporter importer = null; if (path.EndsWith(".dat")) { importer = new MapDatImporter(); } else if (path.EndsWith(".fcm")) { importer = new MapFcm3Importer(); } else if (path.EndsWith(".cw")) { importer = new MapCwImporter(); } else if (path.EndsWith(".lvl")) { importer = new MapLvlImporter(); } try { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { int width, height, length; game.World.Reset(); game.World.TextureUrl = null; for (int block = BlockInfo.CpeCount; block < BlockInfo.BlocksCount; block++) { game.BlockInfo.ResetBlockInfo((byte)block, false); } game.BlockInfo.SetupCullingCache(); game.BlockInfo.InitLightOffsets(); byte[] blocks = importer.Load(fs, game, out width, out height, out length); game.World.SetNewMap(blocks, width, height, length); game.WorldEvents.RaiseOnNewMapLoaded(); if (game.AllowServerTextures && game.World.TextureUrl != null) { game.Network.RetrieveTexturePack(game.World.TextureUrl); } LocalPlayer p = game.LocalPlayer; LocationUpdate update = LocationUpdate.MakePosAndOri(p.Spawn, p.SpawnYaw, p.SpawnPitch, false); p.SetLocation(update, false); } } catch (Exception ex) { ErrorHandler.LogError("loading map", ex); string file = Path.GetFileName(path); game.Chat.Add("&e/client loadmap: Failed to load map \"" + file + "\""); } }