Improve teleport
we now use teleport id's and also set player position when receiving the response packet
This commit is contained in:
1 parent
d69f6c5fc1
commit
d8fd1dd00b
2 files changed
+32
-12
No files matched your search
@@ -41,15 +41,23 @@ impl Player {
|
|||||||
_server: &mut Server,
|
_server: &mut Server,
|
||||||
confirm_teleport: SConfirmTeleport,
|
confirm_teleport: SConfirmTeleport,
|
||||||
) {
|
) {
|
||||||
if let Some(id) = self.awaiting_teleport.as_ref() {
|
if let Some((id, position)) = self.awaiting_teleport.as_ref() {
|
||||||
if id == &confirm_teleport.teleport_id {
|
if id == &confirm_teleport.teleport_id {
|
||||||
|
// we should set the pos now to that we requested in the teleport packet, Is may fixed issues when the client sended position packets while being teleported
|
||||||
|
self.entity.x = position.x;
|
||||||
|
self.entity.y = position.y;
|
||||||
|
self.entity.z = position.z;
|
||||||
|
|
||||||
|
self.awaiting_teleport = None;
|
||||||
} else {
|
} else {
|
||||||
log::warn!("Teleport id does not match, Weird but okay");
|
self.kick(TextComponent::text(
|
||||||
|
"Wrong teleport id",
|
||||||
|
))
|
||||||
}
|
}
|
||||||
self.awaiting_teleport = None;
|
|
||||||
} else {
|
} else {
|
||||||
self.client
|
self.kick(TextComponent::text(
|
||||||
.kick("Send Teleport confirm, but we did not teleport")
|
"Send Teleport confirm, but we did not teleport",
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,8 +43,9 @@ pub struct Player {
|
|||||||
// TODO: prbly should put this into an Living Entitiy or something
|
// TODO: prbly should put this into an Living Entitiy or something
|
||||||
pub velocity: Vector3<f64>,
|
pub velocity: Vector3<f64>,
|
||||||
|
|
||||||
// Current awaiting teleport id, None if did not teleport
|
pub teleport_id_count: i32,
|
||||||
pub awaiting_teleport: Option<VarInt>,
|
// Current awaiting teleport id and location, None if did not teleport
|
||||||
|
pub awaiting_teleport: Option<(VarInt, Vector3<f64>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Player {
|
impl Player {
|
||||||
@@ -63,6 +64,7 @@ impl Player {
|
|||||||
current_block_destroy_stage: 0,
|
current_block_destroy_stage: 0,
|
||||||
velocity: Vector3::new(0.0, 0.0, 0.0),
|
velocity: Vector3::new(0.0, 0.0, 0.0),
|
||||||
inventory: PlayerInventory::new(),
|
inventory: PlayerInventory::new(),
|
||||||
|
teleport_id_count: 0,
|
||||||
gamemode,
|
gamemode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,8 +96,11 @@ impl Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn teleport(&mut self, x: f64, y: f64, z: f64, yaw: f32, pitch: f32) {
|
pub fn teleport(&mut self, x: f64, y: f64, z: f64, yaw: f32, pitch: f32) {
|
||||||
// TODO
|
// this is the ultra special magic code used to create the teleport id
|
||||||
let id = 0;
|
self.teleport_id_count += 1;
|
||||||
|
if self.teleport_id_count == i32::max_value() {
|
||||||
|
self.teleport_id_count = 0;
|
||||||
|
}
|
||||||
let entity = &mut self.entity;
|
let entity = &mut self.entity;
|
||||||
entity.x = x;
|
entity.x = x;
|
||||||
entity.y = y;
|
entity.y = y;
|
||||||
@@ -105,9 +110,16 @@ impl Player {
|
|||||||
entity.lastz = z;
|
entity.lastz = z;
|
||||||
entity.yaw = yaw;
|
entity.yaw = yaw;
|
||||||
entity.pitch = pitch;
|
entity.pitch = pitch;
|
||||||
self.awaiting_teleport = Some(id.into());
|
self.awaiting_teleport = Some((self.teleport_id_count.into(), Vector3::new(x, y, z)));
|
||||||
self.client
|
self.client.send_packet(&CSyncPlayerPosition::new(
|
||||||
.send_packet(&CSyncPlayerPosition::new(x, y, z, yaw, pitch, 0, id.into()));
|
x,
|
||||||
|
y,
|
||||||
|
z,
|
||||||
|
yaw,
|
||||||
|
pitch,
|
||||||
|
0,
|
||||||
|
self.teleport_id_count.into(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Kicks the Client with a reason depending on the connection state
|
/// Kicks the Client with a reason depending on the connection state
|
||||||
|
|||||||
Reference in new issue
Block a user