From 4d9ead721e547a3a4983ebf738c316674be1c55b Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 19:36:35 +0100 Subject: [PATCH] Point the recovery compass at the player's last death The local player's last death location is now recorded, saved as LastDeathLocation, taken from the Login and Respawn packets on the server thread, and given to the item owner. --- crates/horizon-client/src/game.rs | 3 ++ crates/horizon-client/src/game/item_draw.rs | 5 ++++ crates/horizon-client/src/game/lan_actions.rs | 2 +- crates/horizon-client/src/game/remote.rs | 6 ++++ crates/horizon-client/src/lan/guest.rs | 2 +- crates/horizon-client/src/lan/hub.rs | 28 +++++++++---------- crates/horizon-client/src/lan/playerdata.rs | 2 ++ crates/horizon-client/src/save.rs | 21 ++++++++++++++ 8 files changed, 53 insertions(+), 16 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 58b89a140..8788c8f2b 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -4587,6 +4587,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 b6b7e2fb7..ce3757305 100644 --- a/crates/horizon-client/src/game/item_draw.rs +++ b/crates/horizon-client/src/game/item_draw.rs @@ -247,6 +247,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 43bb573dc..20fbdf9af 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -2009,7 +2009,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 3cfbd15e3..03f5cc554 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -995,6 +995,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 7e43cf04e..23e1efbe2 100644 --- a/crates/horizon-client/src/lan/guest.rs +++ b/crates/horizon-client/src/lan/guest.rs @@ -210,7 +210,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 b1a8cbc62..7bcea3e79 100644 --- a/crates/horizon-client/src/lan/hub.rs +++ b/crates/horizon-client/src/lan/hub.rs @@ -557,16 +557,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: false, - 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, } @@ -635,7 +643,7 @@ impl Hub { reduced_debug_info: false, show_death_screen: true, 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(), @@ -2361,14 +2369,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). @@ -2481,8 +2482,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 5926e0a1d..c965d36c1 100644 --- a/crates/horizon-client/src/save.rs +++ b/crates/horizon-client/src/save.rs @@ -2761,6 +2761,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_icon). pub active_effects: Vec<(String, i32, i32, bool, bool)>, /// Player.EnderItems: the ender chest inventory (27 slots). @@ -2961,6 +2963,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; @@ -3061,6 +3072,7 @@ impl Level { "Pos", "respawn", "recipeBook", + "LastDeathLocation", ] { map.remove(&JavaString::from(key)); } @@ -3187,6 +3199,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![