void LoadMap(string path) { IMapFileFormat mapFile = null; if (path.EndsWith(".dat")) { mapFile = new MapDat(); } else if (path.EndsWith(".fcm")) { mapFile = new MapFcm3(); } else if (path.EndsWith(".cw")) { mapFile = new MapCw(); } try { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { int width, height, length; game.Map.Reset(); byte[] blocks = mapFile.Load(fs, game, out width, out height, out length); game.Map.SetData(blocks, width, height, length); game.MapEvents.RaiseOnNewMapLoaded(); LocalPlayer p = game.LocalPlayer; LocationUpdate update = LocationUpdate.MakePos(p.SpawnPoint, false); p.SetLocation(update, false); } } catch (Exception ex) { ErrorHandler.LogError("loading map", ex); game.Chat.Add("&e/client loadmap: Failed to load map \"" + path + "\""); } }
static bool PushbackPlace(Game game, AABB blockBB) { LocalPlayer p = game.LocalPlayer; Vector3 curPos = p.Position, adjPos = p.Position; // Offset position by the closest face PickedPos selected = game.SelectedPos; if (selected.Face == BlockFace.XMax) { adjPos.X = blockBB.Max.X + 0.5f; } else if (selected.Face == BlockFace.ZMax) { adjPos.Z = blockBB.Max.Z + 0.5f; } else if (selected.Face == BlockFace.XMin) { adjPos.X = blockBB.Min.X - 0.5f; } else if (selected.Face == BlockFace.ZMin) { adjPos.Z = blockBB.Min.Z - 0.5f; } else if (selected.Face == BlockFace.YMax) { adjPos.Y = blockBB.Min.Y + 1 + Entity.Adjustment; } else if (selected.Face == BlockFace.YMin) { adjPos.Y = blockBB.Min.Y - p.Size.Y - Entity.Adjustment; } // exclude exact map boundaries, otherwise player can get stuck outside map bool validPos = adjPos.X > 0 && adjPos.Y >= 0 && adjPos.Z > 0 && adjPos.X < game.World.Width && adjPos.Z < game.World.Length; if (!validPos) { return(false); } p.Position = adjPos; if (!p.Hacks.Noclip && p.TouchesAny(p.Bounds, touchesAnySolid)) { p.Position = curPos; return(false); } p.Position = curPos; LocationUpdate update = LocationUpdate.MakePos(adjPos, false); p.SetLocation(update, false); return(true); }
void LoadMap(string path) { IMapFileFormat mapFile = null; if (path.EndsWith(".dat")) { mapFile = new MapDat(); } else if (path.EndsWith(".fcm")) { mapFile = new MapFcm3(); } else if (path.EndsWith(".cw")) { mapFile = new MapCw(); } try { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { int width, height, length; game.Map.Reset(); game.Map.TextureUrl = null; for (int tile = BlockInfo.CpeBlocksCount; tile < BlockInfo.BlocksCount; tile++) { game.BlockInfo.ResetBlockInfo((byte)tile, false); } game.BlockInfo.SetupCullingCache(); game.BlockInfo.InitLightOffsets(); byte[] blocks = mapFile.Load(fs, game, out width, out height, out length); game.Map.SetData(blocks, width, height, length); game.MapEvents.RaiseOnNewMapLoaded(); if (game.AllowServerTextures && game.Map.TextureUrl != null) { game.Network.RetrieveTexturePack(game.Map.TextureUrl); } LocalPlayer p = game.LocalPlayer; LocationUpdate update = LocationUpdate.MakePosAndOri(p.SpawnPoint, p.SpawnYaw, p.SpawnPitch, false); p.SetLocation(update, false); } } catch (Exception ex) { ErrorHandler.LogError("loading map", ex); game.Chat.Add("&e/client loadmap: Failed to load map \"" + path + "\""); } }