void ResetPlayerPosition() { float x = (game.World.Width / 2) + 0.5f; float z = (game.World.Length / 2) + 0.5f; Vector3 spawn = Respawn.FindSpawnPosition(game, x, z, game.LocalPlayer.Size); LocationUpdate update = LocationUpdate.MakePosAndOri(spawn, 0, 0, false); game.LocalPlayer.SetLocation(update, false); game.LocalPlayer.Spawn = spawn; game.CurrentCameraPos = game.Camera.GetCameraPos(0); }
void HandleRelPosAndOrientationUpdate() { byte playerId = reader.ReadUInt8(); float x = reader.ReadInt8() / 32f; float y = reader.ReadInt8() / 32f; float z = reader.ReadInt8() / 32f; float yaw = (float)Utils.PackedToDegrees(reader.ReadUInt8()); float pitch = (float)Utils.PackedToDegrees(reader.ReadUInt8()); LocationUpdate update = LocationUpdate.MakePosAndOri(x, y, z, yaw, pitch, true); UpdateLocation(playerId, update, 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 + "\""); } }
void ReadAbsoluteLocation(byte playerId, bool interpolate) { float x = reader.ReadInt16() / 32f; float y = (reader.ReadInt16() - 51) / 32f; // We have to do this. if (playerId == 255) { y += 22 / 32f; } float z = reader.ReadInt16() / 32f; float yaw = (float)Utils.PackedToDegrees(reader.ReadUInt8()); float pitch = (float)Utils.PackedToDegrees(reader.ReadUInt8()); if (playerId == 0xFF) { receivedFirstPosition = true; } LocationUpdate update = LocationUpdate.MakePosAndOri(x, y, z, yaw, pitch, false); UpdateLocation(playerId, update, interpolate); }
internal bool HandleKeyDown(Key key) { KeyMap keys = game.InputHandler.Keys; if (key == keys[KeyBinding.Respawn] && Hacks.CanRespawn) { Vector3I p = Vector3I.Floor(SpawnPoint); if (game.Map.IsValidPos(p)) { // Spawn player at highest valid position. for (int y = p.Y; y <= game.Map.Height; y++) { byte block1 = physics.GetPhysicsBlockId(p.X, y, p.Z); byte block2 = physics.GetPhysicsBlockId(p.X, y + 1, p.Z); if (info.CollideType[block1] != BlockCollideType.Solid && info.CollideType[block2] != BlockCollideType.Solid) { p.Y = y; break; } } } Vector3 spawn = (Vector3)p + new Vector3(0.5f, 0.01f, 0.5f); LocationUpdate update = LocationUpdate.MakePosAndOri(spawn, SpawnYaw, SpawnPitch, false); SetLocation(update, false); } else if (key == keys[KeyBinding.SetSpawn] && Hacks.CanRespawn) { SpawnPoint = Position; SpawnYaw = HeadYawDegrees; SpawnPitch = PitchDegrees; } else if (key == keys[KeyBinding.Fly] && Hacks.CanFly && Hacks.Enabled) { flying = !flying; } else if (key == keys[KeyBinding.NoClip] && Hacks.CanNoclip && Hacks.Enabled) { if (noClip) { Velocity.Y = 0; } noClip = !noClip; } else if (key == keys[KeyBinding.Jump] && !onGround && !(flying || noClip)) { if (!firstJump && Hacks.CanDoubleJump && Hacks.DoubleJump) { DoNormalJump(); firstJump = true; } else if (!secondJump && Hacks.CanDoubleJump && Hacks.DoubleJump) { DoNormalJump(); secondJump = true; } } else { return(false); } return(true); }