fix(client): hide marker stands and read server entity names

A marker armor stand has an empty box, so vanilla's shouldRenderAtSqrDistance computes a zero range and the model never draws; Horizon substituted a 4-block range, which turned the stacked marker stands a lobby uses for holograms into a visible tower. Follow vanilla and let the zero edge cull the model. Server NPCs and mobs also carry CustomName, CustomNameVisible and the shared invisible flag in entity data; Horizon only read those for armor stands. Apply them to every mob, keep the styled component for the name tag, and hide the body when the flag is set.

Co-Authored-By: cairn-code (DeepSeek V4.1 Flash) <cairn-code@users.noreply.github.com>
This commit is contained in:
itspotatotime
2026-10-21 23:29:13 +03:00
parent c139387e2a
commit d01327862d
9 changed files with 53 additions and 5 deletions
+1
View File
@@ -615,6 +615,7 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
m.persistent = flag(tag, "PersistenceRequired");
m.extra.pick_up_loot = flag(tag, "CanPickUpLoot");
m.custom_name = custom_name(tag);
m.custom_name_text = tag.get("CustomName").map(name_text);
if m.kind.category == "creature" {
m.extra.age = number(tag.get("Age")).unwrap_or(0) as i32;
m.extra.forced_age = number(tag.get("ForcedAge")).unwrap_or(0) as i32;
@@ -432,7 +432,10 @@ impl Game<'_> {
(false, false) => (0.5, 1.975),
};
let edge = (width + height + width) / 3.0 * 4.0;
let range = if edge == 0.0 { 4.0 } else { edge } * 64.0;
// A marker's empty box gives a range of zero: vanilla's
// `distance < 0` never holds, so marker stands never draw.
let edge = if edge == 1.0 { 4.0 } else { edge };
let range = edge * 64.0;
let dragon = a.equipment[5]
.as_ref()
.is_some_and(|i| &*i.item == "minecraft:dragon_head");
@@ -2929,6 +2929,10 @@ impl Game<'_> {
let scale = f64::from(self.settings.entity_distance);
for mob in &self.mobs {
let entity_start = out.len();
// Entity.DATA_SHARED_FLAGS_ID invisible: only the name tag draws.
if mob.invisible {
continue;
}
let d = glam::DVec3::new(mob.position.x, mob.position.y, mob.position.z) - camera;
// Entity.shouldRenderAtSqrDistance: 64 times the bounding box's
// mean edge, scaled by the entity distance option.
+1 -1
View File
@@ -753,7 +753,7 @@ impl Game<'_> {
let lerp = |a: f64, b: f64| a + f64::from(alpha) * (b - a);
let lerpf = |a: f32, b: f32| a + alpha * (b - a);
for m in &self.mobs {
if m.removed || m.has_effect("minecraft:invisibility") {
if m.removed || m.invisible || m.has_effect("minecraft:invisibility") {
continue;
}
let pos = [
@@ -1736,7 +1736,9 @@ impl Game<'_> {
mob.head_pitch = old.head_pitch;
mob.persistent = old.persistent;
mob.custom_name = old.custom_name.clone();
mob.custom_name_text = old.custom_name_text.clone();
mob.name_visible = old.name_visible;
mob.invisible = old.invisible;
mob.no_ai = old.no_ai;
mob.silent = old.silent;
mob.no_gravity = old.no_gravity;
+10 -3
View File
@@ -124,7 +124,7 @@ impl Game<'_> {
team,
viewer,
self.spectator(),
m.has_effect("minecraft:invisibility"),
m.invisible || m.has_effect("minecraft:invisibility"),
);
// Entity.isDiscrete: a crouching player.
let discrete = player && m.extra.crouching;
@@ -144,9 +144,16 @@ impl Game<'_> {
continue;
}
// getDisplayName: the name in the team's prefix, suffix and colour.
let member = if player {
Text::literal(&name)
} else {
m.custom_name_text
.clone()
.unwrap_or_else(|| Text::literal(&name))
};
let shown = match team {
Some(t) => t.formatted_name(Text::literal(&name)),
None => Text::literal(&name),
Some(t) => t.formatted_name(member),
None => member,
};
let mut lines = Vec::new();
// EntityRenderer.extractNameTags: the score shows within the
+23
View File
@@ -1709,6 +1709,29 @@ impl Game<'_> {
}
}
C::SetEntityData(p) => {
// Entity.DATA_SHARED_FLAGS_ID, DATA_CUSTOM_NAME and
// DATA_CUSTOM_NAME_VISIBLE: server NPCs and holograms rely on
// these instead of saved NBT.
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32) {
for (index, _, value) in &p.values {
match (index, value) {
(0, Value::Byte(flags)) => m.invisible = flags & 0x20 != 0,
(2, Value::OptText(name)) => {
let text = name.as_ref().map(horizon_client::entity_nbt::name_text);
m.custom_name =
text.as_ref().map(horizon_client::text::Text::plain);
m.custom_name_text = text;
}
(2, Value::Text(name)) => {
let text = horizon_client::entity_nbt::name_text(name);
m.custom_name = Some(text.plain());
m.custom_name_text = Some(text);
}
(3, Value::Bool(visible)) => m.name_visible = *visible,
_ => {}
}
}
}
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32)
&& m.species() == horizon_client::mobs::Species::Rabbit
{
@@ -194,7 +194,9 @@ fn carry_over(from: &Mob, to: &mut Mob) {
to.fire_ticks = from.fire_ticks;
to.persistent = from.persistent;
to.custom_name = from.custom_name.clone();
to.custom_name_text = from.custom_name_text.clone();
to.name_visible = from.name_visible;
to.invisible = from.invisible;
to.extra.pick_up_loot = from.extra.pick_up_loot;
to.extra.main_hand = from.extra.main_hand.clone();
to.extra.off_hand = from.extra.off_hand.clone();
+6
View File
@@ -807,7 +807,11 @@ pub struct Mob {
pub persistent: bool,
/// `CustomName` (plain text) and `CustomNameVisible`.
pub custom_name: Option<String>,
/// The styled `CustomName`, when it came from a component.
pub custom_name_text: Option<crate::text::Text>,
pub name_visible: bool,
/// `Entity.DATA_SHARED_FLAGS_ID` bit 0x20: the model is hidden.
pub invisible: bool,
pub random: LegacyRandom,
pub ai: Box<ai::Ai>,
pub extra: Extra,
@@ -1518,7 +1522,9 @@ impl Mob {
last_damage: None,
removed: false,
custom_name: None,
custom_name_text: None,
name_visible: false,
invisible: false,
anim: anim::AnimState::default(),
rider: None,
outbox: Vec::new(),