1.7.10: Fix player position too high on login. Closes #87

Adds a new TeleportPlayer_NoGround packet, which is subtly different
from TeleportPlayer_NoConfirm. The flags u8 is replaced with an
on_ground bool, but more importantly the Y position is the eyes
position, so we have to translate to feet position for the client.

1.7.10: https://wiki.vg/index.php?title=Protocol&oldid=6003#Player_Position_And_Look
1.8.9: https://wiki.vg/index.php?title=Protocol&oldid=7368#Player_Position_And_Look
This commit is contained in:
ice_iix 2019-05-11 14:53:42 -07:00
parent a159355751
commit ba4a7a9d85
3 changed files with 15 additions and 1 deletions

View File

@ -1310,6 +1310,14 @@ state_packets!(
field pitch: f32 =,
field flags: u8 =,
}
packet TeleportPlayer_OnGround {
field x: f64 =,
field eyes_y: f64 =,
field z: f64 =,
field yaw: f32 =,
field pitch: f32 =,
field on_ground: bool =,
}
/// EntityUsedBed is sent by the server when a player goes to bed.
packet EntityUsedBed {
field entity_id: VarInt =,

View File

@ -42,7 +42,7 @@ protocol_packet_ids!(
0x05 => SpawnPosition_i32
0x06 => UpdateHealth_u16
0x07 => Respawn
0x08 => TeleportPlayer_NoConfirm
0x08 => TeleportPlayer_OnGround
0x09 => SetCurrentHotbarSlot
0x0a => EntityUsedBed_i32
0x0b => Animation

View File

@ -415,6 +415,7 @@ impl Server {
MultiBlockChange_u16 => on_multi_block_change_u16,
TeleportPlayer_WithConfirm => on_teleport_player_withconfirm,
TeleportPlayer_NoConfirm => on_teleport_player_noconfirm,
TeleportPlayer_OnGround => on_teleport_player_onground,
TimeUpdate => on_time_update,
ChangeGameState => on_game_state_change,
UpdateBlockEntity => on_block_entity_update,
@ -1000,6 +1001,11 @@ impl Server {
self.on_teleport_player(teleport.x, teleport.y, teleport.z, teleport.yaw as f64, teleport.pitch as f64, teleport.flags, None)
}
fn on_teleport_player_onground(&mut self, teleport: packet::play::clientbound::TeleportPlayer_OnGround) {
let flags: u8 = 0; // always absolute
self.on_teleport_player(teleport.x, teleport.eyes_y - 1.62, teleport.z, teleport.yaw as f64, teleport.pitch as f64, flags, None)
}
fn on_teleport_player(&mut self, x: f64, y: f64, z: f64, yaw: f64, pitch: f64, flags: u8, teleport_id: Option<protocol::VarInt>) {
use std::f64::consts::PI;
if let Some(player) = self.player {