Keep vanilla's death screen message; resolve with the loaded language

- Leave ServerPlayer.die's message as it was: with showDeathMessages off
  vanilla sends CommonComponents.EMPTY to the death screen, and #1858
  reworks the death message from the combat record.
- The effects panel and recipe book tooltips use Names::display_get, so a
  key missing from the language still falls back instead of showing the key.
- net::load_language reuses the language lang already loaded (packs
  included) instead of reading it from disk again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-25 17:27:41 +01:00
parent b457f6382a
commit df23e1bfed
4 changed files with 37 additions and 33 deletions
+24 -24
View File
@@ -1791,33 +1791,33 @@ impl Game<'_> {
// ServerPlayer.die: dropAllDeathLoot unless a spectator, from the eyes less 0.3.
let drops = (g.game_mode != SPECTATOR)
.then(|| [at[0], at[1] + g.eye_height() - 0.3, at[2]]);
// ServerPlayer.die: the death screen always shows the message;
// chat only when the rule allows and the team does not hide it.
let cause = host.play.get_mut(&conn).and_then(|p| p.death_cause.take());
let key = cause.unwrap_or_else(|| {
if at[1] < f64::from(horizon_client::chunk::MIN_Y - 64) {
"death.attack.outOfWorld".into()
} else {
"death.attack.generic".into()
}
});
let text =
horizon_client::text::Text::translate(&key, &[self.player_text(&name, uuid)]);
let message = horizon_client::lan::data::component_nbt(&text.component());
if self.ui.rules.bool("show_death_messages") {
let team = self.score.board.players_team(&name);
if horizon_client::scoreboard::own_death_message_shown(team) {
host.hub.system_message(message.clone());
if self.options.dedicated.is_some() {
super::dedicated::log(
"INFO",
&format!("System chat: {}", text.plain()),
);
} else if self.player.is_some() {
self.system_message(text);
let message = match cause {
// ServerPlayer.die: the death message, to everyone unless
// the player's team hides it.
Some(key) if self.ui.rules.bool("show_death_messages") => {
let text = horizon_client::text::Text::translate(
&key,
&[self.player_text(&name, uuid)],
);
let message = horizon_client::lan::data::component_nbt(&text.component());
let team = self.score.board.players_team(&name);
if horizon_client::scoreboard::own_death_message_shown(team) {
host.hub.system_message(message.clone());
if self.options.dedicated.is_some() {
super::dedicated::log(
"INFO",
&format!("System chat: {}", text.plain()),
);
} else if self.player.is_some() {
self.system_message(text);
}
}
message
}
}
Some(_) => literal(""),
None => literal(&format!("{name} died")),
};
host.hub.send_to(
conn,
&C::PlayerCombatKill(play::PlayerCombatKill { id, message }),
+1 -1
View File
@@ -755,7 +755,7 @@ impl Game<'_> {
image_width,
&self.potions.effects.list,
self.clock.rate(),
&|key| Some(horizon_client::lang::get(key)),
&|key| self.pack.names.display_get(key),
&|text| self.gui.atlas.font.width(text).ceil() as i32,
);
if let Some(lines) = inventory_effects::paint(
@@ -502,7 +502,7 @@ impl Game<'_> {
horizon_client::item_tooltip::lines(
stack,
self.res.items().get(&stack.item),
&|k| Some(horizon_client::lang::get(k)),
&|k| self.pack.names.display_get(k),
)
})
{
+11 -7
View File
@@ -597,14 +597,18 @@ pub fn json_text(v: &serde_json::Value, lang: &Language) -> String {
}
}
/// The language a session resolves server-sent components with: the client's
/// selected language, layered over `en_us` (`ClientLanguage.loadFrom`), so a
/// menu title the server sends as a key follows the language screen.
/// The language a session resolves server-sent components with: the selected
/// one as `lang` loaded it (`en_us` under it, packs included), so a menu title
/// the server sends as a key follows the language screen. A process with no
/// language set (a dedicated server's log) reads en_us.json.
pub fn load_language(resources: &std::path::Path) -> Language {
let root = resources.to_path_buf();
crate::lang::Language::load(&[&root], &crate::lang::code())
.map()
.clone()
if let Some(lang) = crate::lang::current() {
return lang.map().clone();
}
std::fs::read(resources.join("assets/minecraft/lang/en_us.json"))
.ok()
.and_then(|b| serde_json::from_slice(&b).ok())
.unwrap_or_default()
}
/// Ask a server for its status (ServerStatusPinger): MOTD, players and the