Skip to content

Commit ffd91aa

Browse files
committed
fall damage bug fixes
1 parent c4051af commit ffd91aa

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

src/server/state/play.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,18 +205,6 @@ pub async fn play(socket: EncryptedStream<TcpStream>, player: Player) -> anyhow:
205205
Arc::clone(&player)
206206
);
207207

208-
{
209-
let mut player_guard = player.lock().await;
210-
player_guard.sync_player_position().await?;
211-
player_guard.sync_player_inventory().await?;
212-
player_guard.sync_player_health().await?;
213-
214-
crate::log::log(
215-
LogLevel::Debug,
216-
format!("Synchronized intial data for {}", player_guard.username).as_str()
217-
);
218-
}
219-
220208
{
221209
let player_guard = player.lock().await;
222210
let player_clone = player_guard.clone();
@@ -280,6 +268,21 @@ pub async fn play(socket: EncryptedStream<TcpStream>, player: Player) -> anyhow:
280268
})
281269
};
282270

271+
{
272+
let mut player_guard = player.lock().await;
273+
player_guard.sync_player_position().await?;
274+
player_guard.sync_player_inventory().await?;
275+
player_guard.sync_player_health().await?;
276+
277+
crate::log::log(
278+
LogLevel::Debug,
279+
format!("Synchronized intial data for {}", player_guard.username).as_str()
280+
);
281+
282+
player_guard.send_system_message(format!("This server is running Mist {}", env!("CARGO_PKG_VERSION"))).await?;
283+
player_guard.send_system_message("Please report any bugs at https://github.com/cyteon/mist/issues/new".to_string()).await?;
284+
}
285+
283286
loop {
284287
match timeout(Duration::from_secs(30), read_packet(&mut read, &ProtocolState::Play, true)).await {
285288
Ok(Ok(Some(packet))) => {

src/types/player.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct Player {
5353
pub hunger: i32,
5454
pub saturation: f32,
5555
pub dead: bool,
56-
pub ignore_fall_for_ticks: i32,
56+
pub ignore_fall_for_ticks: u32,
5757

5858
pub shared_secret: Option<Vec<u8>>,
5959
pub textures: Option<String>,
@@ -229,7 +229,9 @@ impl Player {
229229
send_sync_player_position(&mut buffer, self).await?;
230230
let _ = tx.send(buffer);
231231

232-
self.ignore_fall_for_ticks = 2;
232+
self.fall_distance = 0.0;
233+
self.server_vy = 0.0;
234+
self.ignore_fall_for_ticks = 100;
233235

234236
Ok(())
235237
}
@@ -364,13 +366,13 @@ impl Player {
364366
self.vx = 0.0;
365367
self.vy = 0.0;
366368
self.vz = 0.0;
369+
self.server_vy = 0.0;
367370

368371
self.yaw = 0.0;
369372
self.pitch = 0.0;
370373

371374
self.dead = false;
372375
self.chunks_loaded = false;
373-
self.ignore_fall_for_ticks = 5;
374376

375377
self.sync_player_health().await?;
376378
self.sync_player_position().await?;
@@ -379,7 +381,7 @@ impl Player {
379381
}
380382

381383
pub async fn tick(&mut self) -> anyhow::Result<()> {
382-
if self.dead {
384+
if self.dead || !self.initial_sync_done {
383385
return Ok(());
384386
}
385387

@@ -436,6 +438,8 @@ impl Player {
436438
self.y += self.vy;
437439
self.z += self.vz;
438440

441+
println!("Server vy: {}, fall distance: {}, on_ground: {}, flying: {}, ignore_fall_for_ticks: {}", self.server_vy, self.fall_distance, self.on_ground, self.flying, self.ignore_fall_for_ticks);
442+
439443
if !self.on_ground && !self.flying {
440444
if self.movement.jumping && !self.jump_applied {
441445
self.server_vy = 0.42;
@@ -472,6 +476,11 @@ impl Player {
472476

473477
self.ignore_fall_for_ticks = self.ignore_fall_for_ticks.saturating_sub(1);
474478

479+
if self.ignore_fall_for_ticks > 0 {
480+
self.fall_distance = 0.0;
481+
self.server_vy = 0.0;
482+
}
483+
475484
if !self.chunks_loaded {
476485
return Ok(());
477486
}

0 commit comments

Comments
 (0)