diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index fb4c4df0c..85770f547 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -5231,6 +5231,9 @@ impl Game<'_> { let feet = [player.position.x, player.position.y, player.position.z]; let at = [feet[0], feet[1] + 1.32, feet[2]]; let killer = self.combat_killer_kind(); + // Player.die: the dimension and block of the death. + self.level.last_death = + Some((self.dim.id().to_owned(), feet.map(|v| v.floor() as i32))); self.death_message(); // ServerPlayer.die: deaths, and the time-since counters restart. self.stats.custom("deaths", 1); diff --git a/crates/horizon-client/src/game/item_draw.rs b/crates/horizon-client/src/game/item_draw.rs index f21a82276..935e6d40d 100644 --- a/crates/horizon-client/src/game/item_draw.rs +++ b/crates/horizon-client/src/game/item_draw.rs @@ -250,6 +250,11 @@ impl Game<'_> { owner.main_arm_left = self.settings.main_hand_left; owner.is_local_player = true; owner.is_view_entity = true; + owner.last_death_location = self + .level + .last_death + .clone() + .map(|(dimension, pos)| GlobalPos { dimension, pos }); if let (Some((slot, ticks)), Some(stack)) = (self.using, stack) && self.stack_in(slot) == Some(stack) { diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 15079a1c8..922710f12 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -2138,7 +2138,7 @@ impl Game<'_> { let g = &mut host.hub.guests[gi]; if g.health <= 0.0 && !g.dead { g.dead = true; - g.last_death = Some(g.position.map(|v| v.floor() as i32)); + g.last_death = Some((g.dimension.clone(), g.position.map(|v| v.floor() as i32))); let (id, at) = (g.entity_id, g.position); let reward = Experience { level: g.xp_level, diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index b8c8eb745..a3a07cff7 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -1031,6 +1031,12 @@ impl Game<'_> { r.predictions.clear(); self.set_mode_id(spawn.game_type); self.dim = Dim::from_id(&spawn.dimension); + // ClientPacketListener.handleLogin / handleRespawn: the server's + // Player.getLastDeathLocation, for the recovery compass. + self.level.last_death = spawn + .last_death + .as_ref() + .map(|d| (d.dimension.clone(), d.pos)); if !same { let mut streaming = Streaming::new( Arc::new(NoTerrain), diff --git a/crates/horizon-client/src/lan/guest.rs b/crates/horizon-client/src/lan/guest.rs index 083a99dec..cc53eeaed 100644 --- a/crates/horizon-client/src/lan/guest.rs +++ b/crates/horizon-client/src/lan/guest.rs @@ -215,7 +215,7 @@ pub struct Guest { /// last sent about itself. pub sent_shared: i8, /// Where the player last died (Player.lastDeathLocation), sent with the respawn. - pub last_death: Option<[i32; 3]>, + pub last_death: Option<(String, [i32; 3])>, /// The last action sequence to acknowledge at the next tick (-1: none). pub ack_up_to: std::cell::Cell, pub sent_selected: usize, diff --git a/crates/horizon-client/src/lan/hub.rs b/crates/horizon-client/src/lan/hub.rs index 70b9babe0..5404e7012 100644 --- a/crates/horizon-client/src/lan/hub.rs +++ b/crates/horizon-client/src/lan/hub.rs @@ -606,16 +606,24 @@ impl Hub { // ---- joining ------------------------------------------------------- - fn spawn_info(&self, game_mode: i32) -> play::SpawnInfo { + fn spawn_info(&self, i: usize) -> play::SpawnInfo { + let g = &self.guests[i]; play::SpawnInfo { dimension_type: self.dimension_type, dimension: self.config.dimension.clone(), seed: horizon_core::biome::obfuscate_seed(self.config.seed), - game_type: game_mode, + game_type: g.game_mode, previous_game_type: None, debug: false, flat: self.flat_world, - last_death: None, + // Player.getLastDeathLocation. + last_death: g + .last_death + .as_ref() + .map(|(dimension, pos)| play::GlobalPos { + dimension: dimension.clone(), + pos: *pos, + }), portal_cooldown: 0, sea_level: 63, } @@ -684,7 +692,7 @@ impl Hub { reduced_debug_info: false, show_death_screen: !self.immediate_respawn, limited_crafting: false, - spawn: self.spawn_info(mode), + spawn: self.spawn_info(i), // MinecraftServer.usesAuthentication, enforceSecureProfile. online_mode: self.lan.shared.config.online.is_some(), enforces_secure_chat: self.enforces_secure_chat(), @@ -2520,14 +2528,7 @@ impl Hub { /// level loading screen from the Respawn packet until the level info's "level chunks load /// start" event and the chunk under the player, so the packets follow vanilla's order. pub fn respawn(&mut self, i: usize, at: [f64; 3], ctx: &TickCtx) { - let mode = self.guests[i].game_mode; - let mut info = self.spawn_info(mode); - // Player.getLastDeathLocation, set where the player died. - // The level they died in: theirs until now. - info.last_death = self.guests[i].last_death.map(|pos| play::GlobalPos { - dimension: self.guests[i].dimension.clone(), - pos, - }); + let info = self.spawn_info(i); self.close_container_for(i); let g = &mut self.guests[i]; // PlayerList.respawn: into the level in place (the respawn level). @@ -2640,8 +2641,7 @@ impl Hub { portal_sound: bool, ctx: &TickCtx, ) { - let mode = self.guests[i].game_mode; - let info = self.spawn_info(mode); + let info = self.spawn_info(i); self.close_container_for(i); let g = &mut self.guests[i]; g.dimension = self.config.dimension.clone(); diff --git a/crates/horizon-client/src/lan/playerdata.rs b/crates/horizon-client/src/lan/playerdata.rs index f5eb935c9..af8f15bb4 100644 --- a/crates/horizon-client/src/lan/playerdata.rs +++ b/crates/horizon-client/src/lan/playerdata.rs @@ -86,6 +86,7 @@ pub fn apply(guest: &mut Guest, level: &Level) { guest.respawn_elsewhere = level.respawn_elsewhere.clone(); guest.saved = level.player_extra.clone(); guest.seen_credits = level.seen_credits; + guest.last_death = level.last_death.clone(); let extra = level.player_extra.as_ref(); let short = |key: &str, default: i64| { extra @@ -168,6 +169,7 @@ pub fn store(guest: &Guest, level: &mut Level) { level.respawn_elsewhere = guest.respawn_elsewhere.clone(); level.on_ground = guest.on_ground; level.seen_credits = guest.seen_credits; + level.last_death = guest.last_death.clone(); level.player_extra = guest.saved.clone(); // The live body's fire, air and fall distance (Entity.saveWithoutId), // or what the file had while the player has no body yet. diff --git a/crates/horizon-client/src/save.rs b/crates/horizon-client/src/save.rs index 885d10771..d304da145 100644 --- a/crates/horizon-client/src/save.rs +++ b/crates/horizon-client/src/save.rs @@ -2711,6 +2711,8 @@ pub struct Level { pub xp_seed: i32, /// ServerPlayer.seenCredits: the end poem has been shown. pub seen_credits: bool, + /// Player.lastDeathLocation: the dimension and block of the last death. + pub last_death: Option<(String, [i32; 3])>, /// Player.active_effects: (id, duration, amplifier, ambient, show_particles). pub active_effects: Vec<(String, i32, i32, bool, bool)>, /// Player.EnderItems: the ender chest inventory (27 slots). @@ -2911,6 +2913,15 @@ impl Level { self.fall_distance = f("fall_distance").unwrap_or(0.0); self.on_ground = n("OnGround").unwrap_or(0) != 0; self.seen_credits = n("seenCredits").unwrap_or(0) != 0; + self.last_death = p.get("LastDeathLocation").and_then(|d| { + let Some(Tag::IntArray(pos)) = d.get("pos") else { + return None; + }; + Some(( + text(d.get("dimension"))?, + [*pos.first()?, *pos.get(1)?, *pos.get(2)?], + )) + }); if let Some(mode) = n("playerGameType") { self.creative = mode == 1; self.game_mode = mode as i32; @@ -3011,6 +3022,7 @@ impl Level { "Pos", "respawn", "recipeBook", + "LastDeathLocation", ] { map.remove(&JavaString::from(key)); } @@ -3137,6 +3149,15 @@ impl Level { entries.push(("Pos", doubles(&pos))); } entries.push(("seenCredits", Tag::Byte(i8::from(self.seen_credits)))); + if let Some((dimension, pos)) = &self.last_death { + entries.push(( + "LastDeathLocation", + Tag::compound([ + ("dimension", string(dimension)), + ("pos", Tag::IntArray(pos.to_vec())), + ]), + )); + } // A respawn point other than the world spawn: an anchor elsewhere, or a bed. if let Some((dimension, block, yaw, forced)) = &self.respawn_elsewhere { let mut respawn = vec![