From 4218a496b2756bb9f9261bb4025b6f1a9711c582 Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 14:40:28 -0400 Subject: [PATCH 01/11] Preserve ominous banner components through placement and drops --- crates/horizon-client/src/containers.rs | 2 + crates/horizon-client/src/game/spill.rs | 74 +++++++++++++++++++++++-- crates/horizon-client/src/save.rs | 12 +++- 3 files changed, 81 insertions(+), 7 deletions(-) diff --git a/crates/horizon-client/src/containers.rs b/crates/horizon-client/src/containers.rs index 46e73f067..9cdac1463 100644 --- a/crates/horizon-client/src/containers.rs +++ b/crates/horizon-client/src/containers.rs @@ -132,6 +132,8 @@ impl Crafter { pub struct Banner { pub layers: Vec, pub name: Option, + /// Components not consumed by BannerBlockEntity's implicit fields. + pub components: horizon_world::nbt::Compound, } /// `CreakingHeartBlockEntity` (the logic is in `game/creaking.rs`). #[derive(Clone, Debug, Default)] diff --git a/crates/horizon-client/src/game/spill.rs b/crates/horizon-client/src/game/spill.rs index ac508dfb8..5f10622f5 100644 --- a/crates/horizon-client/src/game/spill.rs +++ b/crates/horizon-client/src/game/spill.rs @@ -6,6 +6,7 @@ use super::{Game, GameLevel, Screen, dispenser::new_item_motion, storage::is_shulker_box}; use horizon_client::{ containers::{Banner, BlockEntity}, + item_data, items::ItemStack, }; use horizon_core::position::BlockPos; @@ -15,6 +16,7 @@ use horizon_world::{ LevelEvent, removal::{self, PreRemove}, }, + nbt::{JavaString, Tag}, registry::BlockStateId, }; use std::collections::HashMap; @@ -80,14 +82,37 @@ impl Pending { stack.data_mut().pot_decorations = Some(Box::new(sides)); } if stack.item.ends_with("_banner") - && let Some(Banner { layers, name }) = self.banner.remove(&pos) + && let Some(Banner { + layers, + name, + components, + }) = self.banner.remove(&pos) { - let data = stack.data_mut(); - data.banner_patterns = layers; - if name.is_some() { - data.custom_name = name; + let mut patch = match item_data::encode_components(stack) { + Some(Tag::Compound(c)) => c, + _ => Default::default(), + }; + // The remaining components in the banner loot table's copy_components. + for key in [ + "minecraft:item_name", + "minecraft:rarity", + "minecraft:tooltip_display", + ] { + if let Some(value) = components.get(&JavaString::from(key)) { + patch.insert(key.into(), value.clone()); + } } - stack.tidy(); + patch.insert( + "minecraft:banner_patterns".into(), + horizon_client::banner::layers_to_nbt(&layers), + ); + if let Some(name) = name { + patch.insert( + "minecraft:custom_name".into(), + Tag::String(name.as_str().into()), + ); + } + (stack.damage, stack.extra) = item_data::decode_components(Some(&Tag::Compound(patch))); } } /// Remember a decorated pot's sherds from its saved block entity. @@ -553,3 +578,40 @@ impl Game<'_> { } } } + +#[cfg(test)] +mod tests { + use super::*; + use horizon_client::{block_entity_item, item_data, mobs::raider, save}; + use horizon_world::nbt::Tag; + + #[test] + fn ominous_banner_survives_placement_save_and_drop() { + let original = raider::ominous_banner(); + let Tag::Compound(components) = item_data::encode_components(&original).unwrap() else { + panic!("banner components"); + }; + for block in ["minecraft:white_banner", "minecraft:white_wall_banner"] { + let pos = (1, 64, 2); + let fresh = BlockEntity::for_block(block).unwrap(); + let fresh = save::encode_block_entity(pos, &fresh, block); + let placed = block_entity_item::place(&fresh, &components, false); + let (_, placed) = save::decode_block_entity(&placed).unwrap(); + let saved = save::encode_block_entity(pos, &placed, block); + let (_, loaded) = save::decode_block_entity(&saved).unwrap(); + let BlockEntity::Banner(banner) = &loaded else { + panic!("placed banner"); + }; + assert_eq!(banner.layers.len(), item_data::OMINOUS_LAYERS.len()); + let mut pending = Pending::default(); + pending.record([pos.0, pos.1, pos.2], &loaded, block, None); + let mut dropped = ItemStack::new("minecraft:white_banner", 1); + pending.attach([pos.0, pos.1, pos.2], &mut dropped); + assert!(dropped.data().unwrap().ominous_banner); + assert_eq!( + item_data::encode_components(&dropped), + Some(Tag::Compound(components.clone())) + ); + } + } +} diff --git a/crates/horizon-client/src/save.rs b/crates/horizon-client/src/save.rs index a3ee81912..61317c8aa 100644 --- a/crates/horizon-client/src/save.rs +++ b/crates/horizon-client/src/save.rs @@ -449,13 +449,17 @@ pub fn encode_block_entity( block: &str, ) -> Tag { use crate::containers::BlockEntity; + let components = match e { + BlockEntity::Banner(b) => b.components.clone(), + _ => Compound::new(), + }; let mut entries = vec![ ("id", string(&block_entity_id(e, block))), ("x", Tag::Int(p.0)), ("y", Tag::Int(p.1)), ("z", Tag::Int(p.2)), ("keepPacked", Tag::Byte(0)), - ("components", Tag::Compound(Compound::new())), + ("components", Tag::Compound(components)), ]; match e { BlockEntity::Chest(items) => entries.push(("Items", encode_items(items))), @@ -583,6 +587,10 @@ pub fn decode_block_entity(tag: &Tag) -> Option<((i32, i32, i32), crate::contain BlockEntity::Banner(crate::containers::Banner { layers: crate::banner::layers_from_nbt(tag.get("patterns")), name: text(tag.get("CustomName")), + components: match tag.get("components") { + Some(Tag::Compound(c)) => c.clone(), + _ => Compound::new(), + }, }), )); } @@ -2984,6 +2992,7 @@ mod tests { let banner = crate::containers::Banner { layers: vec![crate::banner::BannerLayer::new("minecraft:creeper", "lime")], name: Some("Flag".into()), + components: [("minecraft:rarity".into(), string("uncommon"))].into(), }; let tag = encode_block_entity( (1, 2, 3), @@ -2997,6 +3006,7 @@ mod tests { }; assert_eq!(back.layers, banner.layers); assert_eq!(back.name, banner.name); + assert_eq!(back.components, banner.components); } use super::*; From 8f86098a02ffb3101fa35bcf1cff6a14b8bb3582 Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 15:07:19 -0400 Subject: [PATCH 02/11] Show ominous banner names and rarity in HUD and Creative tooltips --- crates/horizon-client/src/game.rs | 10 +++--- crates/horizon-client/src/game/spill.rs | 8 +++++ crates/horizon-client/src/game/stations.rs | 16 +++------ crates/horizon-client/src/game/titles.rs | 21 ++++------- crates/horizon-client/src/item_tooltip.rs | 42 ++++++++++++++++++++++ 5 files changed, 66 insertions(+), 31 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 7072abeb5..c65c00d25 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -7999,7 +7999,7 @@ impl Game<'_> { self.creative_screen.search_focused.elapsed().as_millis(), ); } - let mut hovered: Option = None; + let mut hovered: Option = None; if tab.inventory { self.draw_player_preview( batch, @@ -8049,7 +8049,7 @@ impl Game<'_> { && self.cursor.1 < y + 16.0 { batch.fill(&self.res.atlas, x, y, 16.0, 16.0, rgba(255, 255, 255, 128)); - hovered = Some(stack.item.to_string()); + hovered = Some(stack.clone()); } } } @@ -8064,7 +8064,7 @@ impl Game<'_> { && self.cursor.1 >= y && self.cursor.1 < y + 16.0 { - hovered = Some(stack.item.to_string()); + hovered = Some(stack); } } let scrollable = self.creative_screen.rows(&self.res.names) > 5; @@ -8100,8 +8100,8 @@ impl Game<'_> { } else if self.carried.is_none() && let Some(item) = hovered { - let name = self.res.names.item(&item); - self.tooltip(batch, &name, self.cursor.0, self.cursor.1); + let lines = self.stack_tooltip(&item); + self.draw_tooltip_lines(batch, &lines, self.cursor.0, self.cursor.1); } self.draw_inventory_effects(batch, (ox, oy), Creative::WIDTH as i32); } diff --git a/crates/horizon-client/src/game/spill.rs b/crates/horizon-client/src/game/spill.rs index 5f10622f5..b64bcb9d7 100644 --- a/crates/horizon-client/src/game/spill.rs +++ b/crates/horizon-client/src/game/spill.rs @@ -608,6 +608,14 @@ mod tests { let mut dropped = ItemStack::new("minecraft:white_banner", 1); pending.attach([pos.0, pos.1, pos.2], &mut dropped); assert!(dropped.data().unwrap().ominous_banner); + assert_eq!( + horizon_client::item_tooltip::name_line(&dropped, &|_| None), + "Ominous Banner" + ); + assert_eq!( + horizon_client::item_tooltip::rarity(&dropped, "common"), + "uncommon" + ); assert_eq!( item_data::encode_components(&dropped), Some(Tag::Compound(components.clone())) diff --git a/crates/horizon-client/src/game/stations.rs b/crates/horizon-client/src/game/stations.rs index d8a5d1416..1c253757d 100644 --- a/crates/horizon-client/src/game/stations.rs +++ b/crates/horizon-client/src/game/stations.rs @@ -1860,18 +1860,10 @@ impl Game<'_> { pub(super) fn stack_tooltip(&self, stack: &ItemStack) -> Vec<(String, u32)> { let e: &Enchantments = &self.res.stations.enchantments; let props = e.props(&stack.item); - let mut rarity = props.map_or("common", |p| p.rarity.as_str()); - // The ominous banner's rarity component. - if stack.data().is_some_and(|d| d.ominous_banner) { - rarity = "uncommon"; - } - if !stack.enchantments().is_empty() { - rarity = match rarity { - "common" | "uncommon" => "rare", - "rare" => "epic", - r => r, - }; - } + let rarity = horizon_client::item_tooltip::rarity( + stack, + props.map_or("common", |p| p.rarity.as_str()), + ); let color = match rarity { "uncommon" => rgba(255, 255, 85, 255), "rare" => rgba(85, 255, 255, 255), diff --git a/crates/horizon-client/src/game/titles.rs b/crates/horizon-client/src/game/titles.rs index 89e50c0d0..f0de6ad9e 100644 --- a/crates/horizon-client/src/game/titles.rs +++ b/crates/horizon-client/src/game/titles.rs @@ -6,6 +6,7 @@ use horizon_client::{ hud::HudBatch, hud_layout, hud_overlays::HeldName, + item_tooltip, text::{self, Text}, }; @@ -24,22 +25,14 @@ impl Game<'_> { fn held_name(&self) -> Option { let stack = self.inventory.get(self.selected)?.as_ref()?; let custom = stack.custom_name(); - // ItemStack.getRarity: enchanting raises common and uncommon to rare - // and rare to epic. - let mut rarity = self.item_rarity(&stack.item); - if !stack.enchantments().is_empty() { - rarity = match rarity.as_str() { - "common" | "uncommon" => "rare".into(), - "rare" => "epic".into(), - _ => rarity, - }; - } + let default_rarity = self.item_rarity(&stack.item); + let rarity = item_tooltip::rarity(stack, &default_rarity); Some(HeldName { item: stack.item.to_string(), - hover_name: Text::literal( - custom.map_or_else(|| self.res.names.item(&stack.item), str::to_owned), - ), - rarity_color: match rarity.as_str() { + hover_name: Text::literal(item_tooltip::name_line(stack, &|key| { + self.res.names.get(key).map(str::to_owned) + })), + rarity_color: match rarity { "uncommon" => text::YELLOW, "rare" => text::AQUA, "epic" => text::LIGHT_PURPLE, diff --git a/crates/horizon-client/src/item_tooltip.rs b/crates/horizon-client/src/item_tooltip.rs index cd827d411..a039edfc5 100644 --- a/crates/horizon-client/src/item_tooltip.rs +++ b/crates/horizon-client/src/item_tooltip.rs @@ -102,6 +102,10 @@ pub fn name_line(stack: &ItemStack, translate: &dyn Fn(&str) -> Option) if let Some(name) = stack.custom_name() { return name.to_owned(); } + if stack.data().is_some_and(|d| d.ominous_banner) { + return translate("block.minecraft.ominous_banner") + .unwrap_or_else(|| "Ominous Banner".to_owned()); + } let key = if is_potion_item(&stack.item) { Some(crate::brewing::potion_name_key(&stack.item, stack.potion())) } else if let Some(pattern) = path.strip_suffix("_armor_trim_smithing_template") { @@ -120,6 +124,24 @@ pub fn name_line(stack: &ItemStack, translate: &dyn Fn(&str) -> Option) .unwrap_or_else(|| path.replace('_', " ")) } +/// ItemStack.getRarity: the ominous banner override, then the enchantment upgrade. +pub fn rarity<'a>(stack: &ItemStack, default: &'a str) -> &'a str { + let rarity = if stack.data().is_some_and(|d| d.ominous_banner) { + "uncommon" + } else { + default + }; + if stack.enchantments().is_empty() { + rarity + } else { + match rarity { + "common" | "uncommon" => "rare", + "rare" => "epic", + r => r, + } + } +} + /// The lines of `stack` below its name that its components give, in /// `ItemStack.addDetailsToTooltip` order. pub fn detail_lines( @@ -292,6 +314,26 @@ pub fn lines( mod tests { use super::*; + #[test] + fn ominous_banner_name_and_rarity_use_the_stack() { + let translate = |key: &str| match key { + "block.minecraft.ominous_banner" => Some("Ominous Banner".to_owned()), + "block.minecraft.white_banner" => Some("White Banner".to_owned()), + _ => None, + }; + let mut banner = crate::mobs::raider::ominous_banner(); + assert_eq!(name_line(&banner, &translate), "Ominous Banner"); + assert_eq!(name_line(&banner, &|_| None), "Ominous Banner"); + assert_eq!(rarity(&banner, "common"), "uncommon"); + banner.data_mut().custom_name = Some("Captain's Standard".into()); + assert_eq!(name_line(&banner, &translate), "Captain's Standard"); + banner.enchant("minecraft:unbreaking", 1); + assert_eq!(rarity(&banner, "common"), "rare"); + let plain = ItemStack::new("minecraft:white_banner", 1); + assert_eq!(name_line(&plain, &translate), "White Banner"); + assert_eq!(rarity(&plain, "common"), "common"); + } + #[test] fn container_lines_list_five_stacks_then_how_many_more() { let mut chest = ItemStack::new("minecraft:chest", 1); From 86ccd5d299b2752aca6c29cafd3d88601af9bf66 Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 16:40:29 -0400 Subject: [PATCH 03/11] Render banner breaking cracks and oak-plank particles --- .../horizon-client/src/block_entity_render.rs | 155 +++++++++++++++++- crates/horizon-client/src/breaking.rs | 48 ++++++ crates/horizon-client/src/game.rs | 24 ++- crates/horizon-client/src/models/catalog.rs | 7 + 4 files changed, 227 insertions(+), 7 deletions(-) diff --git a/crates/horizon-client/src/block_entity_render.rs b/crates/horizon-client/src/block_entity_render.rs index 9ffd888a1..85107c1cb 100644 --- a/crates/horizon-client/src/block_entity_render.rs +++ b/crates/horizon-client/src/block_entity_render.rs @@ -876,7 +876,7 @@ impl BlockEntityRenderer { .as_vec3(); let base = Mat4::from_translation(origin); let packed = scene.world.light(pos[0], pos[1], pos[2]); - self.render_one(scene, *pos, kind, base, packed, lights, out); + self.render_one(scene, *pos, kind, base, packed, lights, false, out); } } /// One block entity at `pos` drawn under `base` with the given packed light @@ -892,12 +892,39 @@ impl BlockEntityRenderer { ) { let kind = self.kind(state); let lights = diffuse_lights(scene.nether); - self.render_one(scene, pos, kind, base, packed, lights, out); + self.render_one(scene, pos, kind, base, packed, lights, false, out); } /// Whether this block state has a block-entity renderer here. pub fn renders(&self, state: u32) -> bool { !matches!(self.kind(state), Kind::None) } + /// BannerRenderer submits the support and animated flag once for crumbling. + pub fn render_banner_breaking( + &self, + scene: &Scene, + pos: [i32; 3], + state: u32, + out: &mut Vec, + ) { + if !matches!(self.kind(state), Kind::Banner { .. }) { + return; + } + let origin = (DVec3::new(f64::from(pos[0]), f64::from(pos[1]), f64::from(pos[2])) + - scene.camera) + .as_vec3(); + let start = out.len(); + self.render_one( + scene, + pos, + self.kind(state), + Mat4::from_translation(origin), + 0xff, + diffuse_lights(scene.nether), + true, + out, + ); + crate::breaking::entity_geometry(&mut out[start..], origin); + } /// `ChestRenderer.extractRenderState`'s openness for the chest of `state` /// at `pos`: `ChestBlock.combine` (`DoubleBlockCombiner.combineWithNeigbour`) /// pairs a double half with its neighbour only when that is the same @@ -970,7 +997,7 @@ impl BlockEntityRenderer { let kind = self.kind(state); if !matches!(kind, Kind::None) { let lights = diffuse_lights(scene.nether); - self.render_one(scene, [i32::MAX; 3], kind, base, packed, lights, out); + self.render_one(scene, [i32::MAX; 3], kind, base, packed, lights, false, out); } } #[allow(clippy::too_many_arguments)] @@ -982,11 +1009,24 @@ impl BlockEntityRenderer { base: Mat4, packed: u8, lights: (Vec3, Vec3), + crumbling: bool, out: &mut Vec, ) { let sprite = |name: &str| scene.sprites.get(name).copied(); let paint = |name: &str, tint: u32, packed: u8| { - sprite(name).map(|s| Paint { + let rect = if crumbling { + Some(Rect { + u0: 0.0, + v0: 0.0, + u1: 1.0, + v1: 1.0, + w: 16, + h: 16, + }) + } else { + sprite(name) + }; + rect.map(|s| Paint { sprite: s, tint, light: vertex_light(packed), @@ -1145,6 +1185,10 @@ impl BlockEntityRenderer { draw_part(main, "root", m, &none, paint, out); draw_part(flag, "root", m, &wave, paint, out); } + // Pattern passes must not multiply the crumbling decal. + if crumbling { + return; + } // BannerRenderer.submitPatterns: the base pattern layer in the dye colour, // then up to 16 pattern layers in order. if let Some(paint) = paint("entity/banner/base", *color, packed) { @@ -1673,6 +1717,109 @@ fn portal_cube(m: Mat4, faces: &[Direction], layer: u32, out: &mut Vec) #[cfg(test)] mod tests { use super::*; + #[test] + #[ignore = "requires prepared models/textures in HORIZON_TEST_RESOURCES"] + fn banner_particle_and_breaking_use_exported_models() -> crate::Result<()> { + use crate::{models::catalog::StateModels, sprites::Sprites}; + use horizon_world::{DATA_VERSION, chunk::BlockState, nbt::Tag}; + let root = std::path::PathBuf::from( + std::env::var_os("HORIZON_TEST_RESOURCES").expect("HORIZON_TEST_RESOURCES"), + ); + let names = ["white_banner", "white_wall_banner"]; + let mut facts: std::collections::BTreeMap = + serde_json::from_slice(&std::fs::read(root.join("model-states.json"))?)?; + let states = names.map(|name| { + let name = format!("minecraft:{name}"); + let first = facts[&name]["states"][0].clone(); + facts.get_mut(&name).unwrap()["states"] = serde_json::json!([first.clone()]); + BlockState { + name, + properties: serde_json::from_value(first).unwrap(), + } + .to_nbt() + }); + let registry = BlockRegistry::from_nbt(&Tag::compound([ + ("DataVersion", Tag::Int(DATA_VERSION)), + ("states", Tag::List(states.into())), + ( + "defaults", + Tag::compound([ + ("minecraft:white_banner", Tag::Int(0)), + ("minecraft:white_wall_banner", Tag::Int(1)), + ]), + ), + ]))?; + let mut sprites = Sprites::default(); + let catalog = StateModels::from_facts(&root, ®istry, &names, &mut sprites, &facts)?; + for id in 0..2 { + let models = catalog.collect( + BlockStateId(id), + horizon_core::position::BlockPos::default(), + )?; + assert!(models.iter().all(|(_, model)| model.faces.is_empty())); + assert_eq!( + models[0].1.particle, + Some(sprites.layers["minecraft:block/oak_planks"]) + ); + } + let all: Value = serde_json::from_slice(&std::fs::read(root.join("entity-models.json"))?)?; + let renderer = BlockEntityRenderer::new( + MODELS + .iter() + .filter_map(|(key, layer)| all.get(*layer).map(|v| (*key, ModelPart::parse(v)))) + .collect(), + ®istry, + ); + let world = World::new(BlockStateId(0), 1); + let base_sprites = HashMap::from([( + "entity/banner/banner_base".to_owned(), + Rect { + u0: 0.0, + v0: 0.0, + u1: 1.0, + v1: 1.0, + w: 16, + h: 16, + }, + )]); + let mut scene = Scene { + camera: DVec3::ZERO, + orientation: Quat::IDENTITY, + anim: &|_| BlockAnim::default(), + texts: None, + partial: 0.5, + game_time: 0, + max_y: 320, + world: &world, + sprites: &base_sprites, + nether: false, + lid: &|_| 0.0, + sign: &|_| None, + banner: &|_| Vec::new(), + glyph: &|_| (None, 0.0), + }; + for state in 0..2 { + let mut base = Vec::new(); + renderer.render_block(&scene, [0; 3], state, Mat4::IDENTITY, 0xff, &mut base); + let mut cracks = Vec::new(); + renderer.render_banner_breaking(&scene, [0; 3], state, &mut cracks); + assert!(!cracks.is_empty()); + assert_eq!( + base.iter().map(|v| v.pos).collect::>(), + cracks.iter().map(|v| v.pos).collect::>() + ); + assert!(cracks.iter().all(|v| v.layer == 11 + && v.color == u32::MAX + && v.uv.iter().all(|u| u.is_finite()))); + scene.game_time = 20; + let mut animated = Vec::new(); + renderer.render_banner_breaking(&scene, [0; 3], state, &mut animated); + assert!(cracks.iter().zip(&animated).any(|(a, b)| a.pos != b.pos)); + scene.game_time = 0; + } + Ok(()) + } + #[test] fn classifies_vanilla_block_names() { let props = |pairs: &'static [(&'static str, &'static str)]| { diff --git a/crates/horizon-client/src/breaking.rs b/crates/horizon-client/src/breaking.rs index 9dc948ae3..c7ee19206 100644 --- a/crates/horizon-client/src/breaking.rs +++ b/crates/horizon-client/src/breaking.rs @@ -41,6 +41,35 @@ pub fn geometry(model: &BakedModel, origin: glam::Vec3, translucent: bool, out: } } +/// Project a block entity's transformed quads onto the same destroy-stage pass. +pub fn entity_geometry(vertices: &mut [Vertex], origin: glam::Vec3) { + for quad in vertices.as_chunks_mut::<4>().0 { + let positions = [0, 1, 2].map(|i| glam::Vec3::from(quad[i].pos)); + let normal = (positions[1] - positions[0]).cross(positions[2] - positions[0]); + let mut facing = Direction::North; + let mut best = f32::from_bits(1); + for (direction, dot) in [ + (Direction::Down, -normal.y), + (Direction::Up, normal.y), + (Direction::North, -normal.z), + (Direction::South, normal.z), + (Direction::West, -normal.x), + (Direction::East, normal.x), + ] { + if dot > best { + facing = direction; + best = dot; + } + } + for vertex in quad { + vertex.uv = decal_uv((glam::Vec3::from(vertex.pos) - origin).to_array(), facing); + vertex.layer = 11; + vertex.color = 0xffff_ffff; + vertex.light = 240 | (240 << 8); + } + } +} + #[cfg(test)] mod tests { use super::*; @@ -49,6 +78,7 @@ mod tests { fn slab_top() -> BakedModel { BakedModel { ambient_occlusion: true, + particle: None, cube: None, faces: vec![BakedFace { layer: 0, @@ -86,6 +116,24 @@ mod tests { assert_eq!(v.color, 0xffff_ffff); } } + #[test] + fn entity_overlay_uses_block_local_projected_uvs() { + let origin = glam::Vec3::new(12.0, -3.0, 8.0); + let mut expected = Vec::new(); + geometry(&slab_top(), origin, false, &mut expected); + let mut actual = expected.clone(); + for vertex in &mut actual { + vertex.uv = [0.0; 2]; + vertex.layer = 0; + vertex.color = 0; + } + entity_geometry(&mut actual, origin); + assert_eq!( + bytemuck::cast_slice::<_, u8>(&actual), + bytemuck::cast_slice::<_, u8>(&expected) + ); + } + #[test] fn small_faces_use_projected_not_stretched_uvs() { let a = decal_uv([0.0, 0.0, 0.0], Direction::North); diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index c65c00d25..21f59af94 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1377,9 +1377,13 @@ impl Game<'_> { .iter() .flat_map(|(_, m)| m.faces.iter()) .find(|f| f.quad.facing == horizon_assets::model::Direction::Up) - .or_else(|| models.iter().flat_map(|(_, m)| m.faces.iter()).next())?; - let name = self.res.layer_names.get(&face.layer)?.clone(); - let tint = if face.quad.tint_index >= 0 { + .or_else(|| models.iter().flat_map(|(_, m)| m.faces.iter()).next()); + // Entity-rendered blocks may have a particle texture without any faces. + let layer = face + .map(|face| face.layer) + .or_else(|| models.iter().find_map(|(_, model)| model.particle))?; + let name = self.res.layer_names.get(&layer)?.clone(); + let tint = if face.is_some_and(|face| face.quad.tint_index >= 0) { let n = &self.res.facts.get(state).name; if n.contains("leaves") || n.contains("vine") { 0x48B518 @@ -5515,6 +5519,20 @@ impl Game<'_> { .block_entity_render .render(&scene, visible, &mut out); } + if let Some(mining) = &self.mining + && mining.progress > 0.0 + && self.res.atlas.sprites.contains_key(&format!( + "block/destroy_stage_{}", + ((mining.progress * 10.0) as u32).min(9) + )) + { + let state = self + .world + .block(mining.pos[0], mining.pos[1], mining.pos[2]); + self.res + .block_entity_render + .render_banner_breaking(&scene, mining.pos, state.0, &mut out); + } } // Experience orbs (ExperienceOrbRenderer): pulsing billboards from a 4x4 icon sheet. if let Some(r) = self diff --git a/crates/horizon-client/src/models/catalog.rs b/crates/horizon-client/src/models/catalog.rs index 59a885821..abb9e6c50 100644 --- a/crates/horizon-client/src/models/catalog.rs +++ b/crates/horizon-client/src/models/catalog.rs @@ -34,6 +34,8 @@ pub struct BakedFace { } pub struct BakedModel { pub ambient_occlusion: bool, + /// The model's particle slot also exists for models without block faces. + pub particle: Option, pub faces: Vec, pub cube: Option<[super::cube::CubeStyle; 6]>, } @@ -188,6 +190,10 @@ impl StateModels { let mut baked = BTreeMap::new(); for (name, turns, lock) in variants { let model = library.resolve(&name)?; + let particle = model + .material("particle")? + .map(|material| sprites.insert(root, &material.sprite)) + .transpose()?; let faces: Vec = bake_block_model(&model, BlockModelTransform::new(turns, lock))? .into_iter() @@ -207,6 +213,7 @@ impl StateModels { (name, turns, lock), BakedModel { ambient_occlusion: model.ambient_occlusion, + particle, faces, cube, }, From 53955abf99941128c2c263cd046deb0a92958957 Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 16:56:14 -0400 Subject: [PATCH 04/11] Hide ominous banner pattern descriptions in tooltips --- crates/horizon-client/src/banner.rs | 26 ++++++++++++++++++++++ crates/horizon-client/src/game/spill.rs | 1 + crates/horizon-client/src/game/stations.rs | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/horizon-client/src/banner.rs b/crates/horizon-client/src/banner.rs index d2bc33fba..861294722 100644 --- a/crates/horizon-client/src/banner.rs +++ b/crates/horizon-client/src/banner.rs @@ -199,6 +199,14 @@ pub fn dye_rgb(name: &str) -> u32 { pub fn layers(stack: &ItemStack) -> &[BannerLayer] { stack.data().map_or(&[], |d| &d.banner_patterns) } +/// The ominous banner's component patch hides its pattern tooltip. +pub fn tooltip_layers(stack: &ItemStack) -> &[BannerLayer] { + if stack.data().is_some_and(|d| d.ominous_banner) { + &[] + } else { + layers(stack) + } +} /// `LoomMenu.setupResultSlot`: one banner with the pattern added in the dye colour. pub fn loom_result(banner: &ItemStack, dye: &str, pattern: &str) -> ItemStack { let mut result = ItemStack { @@ -302,6 +310,24 @@ mod tests { } assert!(has_max_layers(&banner)); } + #[test] + fn ominous_banner_hides_tooltip_layers_but_keeps_its_patterns() { + let mut banner = crate::mobs::raider::ominous_banner(); + (banner.damage, banner.extra) = crate::item_data::decode_components( + crate::item_data::encode_components(&banner).as_ref(), + ); + assert_eq!( + layers(&banner).len(), + crate::item_data::OMINOUS_LAYERS.len() + ); + assert!(tooltip_layers(&banner).is_empty()); + banner.data_mut().custom_name = Some("Captain's Standard".into()); + assert!(tooltip_layers(&banner).is_empty()); + banner.data_mut().ominous_banner = false; + assert_eq!(tooltip_layers(&banner), layers(&banner)); + assert!(!tooltip_layers(&banner).is_empty()); + } + #[test] fn layers_round_trip_through_nbt() { let l = vec![ diff --git a/crates/horizon-client/src/game/spill.rs b/crates/horizon-client/src/game/spill.rs index b64bcb9d7..20dcdf0de 100644 --- a/crates/horizon-client/src/game/spill.rs +++ b/crates/horizon-client/src/game/spill.rs @@ -608,6 +608,7 @@ mod tests { let mut dropped = ItemStack::new("minecraft:white_banner", 1); pending.attach([pos.0, pos.1, pos.2], &mut dropped); assert!(dropped.data().unwrap().ominous_banner); + assert!(horizon_client::banner::tooltip_layers(&dropped).is_empty()); assert_eq!( horizon_client::item_tooltip::name_line(&dropped, &|_| None), "Ominous Banner" diff --git a/crates/horizon-client/src/game/stations.rs b/crates/horizon-client/src/game/stations.rs index 1c253757d..5e8952901 100644 --- a/crates/horizon-client/src/game/stations.rs +++ b/crates/horizon-client/src/game/stations.rs @@ -1944,7 +1944,7 @@ impl Game<'_> { )); } // BannerPatternLayers.addToTooltip: up to six layer names. - for layer in horizon_client::banner::layers(stack).iter().take(6) { + for layer in horizon_client::banner::tooltip_layers(stack).iter().take(6) { let key = self.res.stations.banners.layer_key(layer); lines.push((self.translate(&key, &key), rgba(170, 170, 170, 255))); } From ac2cc43aa663a66417739333bab5fcbf848c58e5 Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 19:35:47 -0400 Subject: [PATCH 05/11] Add mod management to Classic Options --- crates/horizon-client/src/game/control.rs | 3 +- crates/horizon-client/src/options_ui.rs | 136 +++++++++++++++++++++- 2 files changed, 137 insertions(+), 2 deletions(-) diff --git a/crates/horizon-client/src/game/control.rs b/crates/horizon-client/src/game/control.rs index e1169b2c8..495e6422b 100644 --- a/crates/horizon-client/src/game/control.rs +++ b/crates/horizon-client/src/game/control.rs @@ -29,7 +29,7 @@ const HELP: &[&str] = &[ "chat TEXT send a chat line or /command as if typed", "type TEXT type into the open chat box (key enter tap sends)", "chat-log [N] the newest N chat messages (default 10)", - "options [PAGE] open the options (video sound controls keybinds mouse chat accessibility language font packs graphics graphics-advanced)", + "options [PAGE] open the options (video sound controls keybinds mouse chat accessibility language font packs mods graphics graphics-advanced)", "stats [reset] frame-time summary since the last reset", "bench SECONDS reset stats, wait, then reply with the summary", "fly X1 Y1 Z1 X2 Y2 Z2 SECONDS [PITCH [raw]] fly the camera along a line at constant speed, then reply with the frame summary (raw: every frame time too)", @@ -462,6 +462,7 @@ impl Game<'_> { "language" => Page::Language, "font" => Page::Font, "packs" => Page::Packs, + "mods" => Page::Mods, "graphics" => Page::Graphics, "graphics-advanced" => Page::GraphicsAdvanced, other => return Err(format!("unknown options page {other}").into()), diff --git a/crates/horizon-client/src/options_ui.rs b/crates/horizon-client/src/options_ui.rs index 38be29576..71ca2d2cc 100644 --- a/crates/horizon-client/src/options_ui.rs +++ b/crates/horizon-client/src/options_ui.rs @@ -708,6 +708,7 @@ pub enum Page { Language, Font, Packs, + Mods, /// Horizon's graphics settings (`graphics_ui`). Graphics, GraphicsAdvanced, @@ -730,6 +731,7 @@ enum Act { ResetPadKeys, /// Back to Horizon's own menus (Horizon only, see `list_rows`). HorizonMenus, + ToggleMod(usize), } enum WKind { Button { @@ -971,6 +973,7 @@ impl OptionsUi { Page::Language => "options.language.title", Page::Font => "options.font.title", Page::Packs => "resourcePack.title", + Page::Mods => "Mods", Page::Graphics | Page::GraphicsAdvanced => "options.videoTitle", Page::Controller => "Controller Settings", Page::PadBinds => "Controller Binds", @@ -1161,6 +1164,36 @@ impl OptionsUi { Opt::AutoJump, ]), Page::Font => pairs(&[Opt::ForceUnicode, Opt::JapaneseGlyphs]), + Page::Mods => { + if s.mods.installed.is_empty() { + return vec![Row::Header( + "No mods: put .hmod files in the horizon-mods folder", + )]; + } + s.mods + .installed + .iter() + .enumerate() + .map(|(i, installed)| { + let mut label = Text::literal(format!("{}: ", installed.title)) + .append(on_off(s.mods.is_on(i))); + if installed.problem.is_some() { + label = label.append(" (Stopped)"); + } else if installed.dev { + label = label.append(" (Dev)"); + } + let widget = button(0.0, 0.0, 310.0, label, Act::ToggleMod(i)); + Row::Buttons( + if installed.dev || installed.id.is_empty() { + inactive(widget) + } else { + widget + }, + None, + ) + }) + .collect() + } _ => { let _ = s; Vec::new() @@ -1206,7 +1239,7 @@ impl OptionsUi { ("options.chat", Some(Page::Chat)), ("options.resourcepack", Some(Page::Packs)), ("options.accessibility", Some(Page::Accessibility)), - ("options.telemetry", None), + ("Mods...", Some(Page::Mods)), ("options.credits_and_attribution", None), ]; let gy = (61.0 + 30.0f32).min(h - 33.0 - 120.0); @@ -1650,6 +1683,21 @@ impl OptionsUi { if let Some(key) = key.filter(|key| lang::has(key)) { tooltip = Some(atlas.font.split(&tr(&key), 170.0)); } + if let WKind::Button { + act: Act::ToggleMod(i), + .. + } = &wd.kind + && let Some(installed) = s.mods.installed.get(*i) + { + let description = installed + .problem + .as_deref() + .unwrap_or(&installed.description); + tooltip = Some(atlas.font.split( + &Text::literal(format!("{}\n{description}", installed.title)), + 170.0, + )); + } } match &wd.kind { WKind::Button { label, active, act } => { @@ -1944,6 +1992,10 @@ impl OptionsUi { crate::ui_theme::save_preferences(&dir); } } + Act::ToggleMod(i) => { + s.mods.toggle(i); + events.push(Event::Changed); + } Act::None => {} } } @@ -2201,6 +2253,88 @@ mod tests { HudAtlas::build(std::path::Path::new("/nonexistent/horizon-test-assets")).unwrap() } + #[test] + fn classic_mods_page_toggles_mods_and_keeps_dev_and_invalid_entries_inactive() { + let atlas = atlas(); + let mut s = Settings::default(); + let mut ui = OptionsUi::default(); + let size = (480.0, 240.0); + assert!(ui.layout(&s, size.0, size.1).0.iter().any(|w| { + matches!( + w.kind, + WKind::Button { + active: true, + act: Act::Push(Page::Mods), + .. + } + ) + })); + ui.show(Page::Mods); + let empty = ui.layout(&s, size.0, size.1).0; + assert!(empty.iter().any(|w| { + matches!(&w.kind, WKind::Text { text, .. } if text.plain().contains(".hmod")) + })); + for (id, dev) in [("normal", false), ("dev", true), ("", false)] { + s.mods.installed.push(crate::mod_list::Installed { + id: id.into(), + title: id.into(), + description: "May show HUD panels.".into(), + problem: id.is_empty().then(|| "Invalid package".into()), + dev, + }); + } + let (widgets, ..) = ui.layout(&s, size.0, size.1); + let rows: Vec<_> = widgets + .iter() + .filter(|w| { + matches!( + w.kind, + WKind::Button { + act: Act::ToggleMod(_), + .. + } + ) + }) + .collect(); + assert_eq!(rows.len(), 3); + for (i, row) in rows.iter().enumerate() { + let events = ui.click( + &mut s, + &atlas, + row.x + 1.0, + row.y + 1.0, + size, + [480, 240], + false, + false, + ); + if i == 0 { + assert!(events.contains(&Event::Changed)); + assert!(events.contains(&Event::ButtonClick)); + } else { + assert!(events.is_empty()); + } + } + assert!(s.mods.is_on(0)); + assert!(s.mods.is_on(1)); + assert!(!s.mods.is_on(2)); + assert_eq!(s.mods.serialize(), "mod.normal:true\n"); + let row = rows[0]; + ui.click( + &mut s, + &atlas, + row.x + 1.0, + row.y + 1.0, + size, + [480, 240], + false, + false, + ); + assert!(!s.mods.is_on(0)); + assert!(!ui.back(&mut s).contains(&Event::Close)); + assert_eq!(ui.page(), Page::Main); + } + #[test] fn option_tooltip_keys_follow_value_dependent_descriptions() { let mut s = Settings::default(); From b2f0af559b3244dc07caedd1cfcbd33b0cc92bb1 Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 21:34:18 -0400 Subject: [PATCH 06/11] Accept and handle mouse bindings for Extras --- crates/horizon-client/src/game.rs | 3 + crates/horizon-client/src/game/extras.rs | 6 +- crates/horizon-client/src/game/options.rs | 11 +-- crates/horizon-client/src/game/tweaks.rs | 10 ++- crates/horizon-client/src/options_horizon.rs | 11 ++- crates/horizon-client/src/options_ui.rs | 83 +++++++++++++++++--- 6 files changed, 100 insertions(+), 24 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index e552eb118..4496e6e73 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -9360,6 +9360,9 @@ impl ApplicationHandler for Game<'_> { } WindowEvent::MouseInput { state, button, .. } => { let pressed = state == ElementState::Pressed; + if pressed && self.sort_mouse_press(button) { + return Ok(()); + } match self.screen { Screen::Playing => { if pressed && !self.captured { diff --git a/crates/horizon-client/src/game/extras.rs b/crates/horizon-client/src/game/extras.rs index c6ac6d25e..712796a81 100644 --- a/crates/horizon-client/src/game/extras.rs +++ b/crates/horizon-client/src/game/extras.rs @@ -58,8 +58,12 @@ impl Game<'_> { pub(super) fn extras_scroll(&mut self, steps: f32) -> bool { self.settings.extras.zoom && self.extras.zoom.scroll(steps) } - /// Mouse buttons while playing, for the keystroke overlay. + /// Mouse buttons while playing, for zoom and the keystroke overlay. pub(super) fn extras_mouse(&mut self, button: MouseButton, pressed: bool) { + let e = &self.settings.extras; + if e.zoom && e.zoom_key == keybinds::mouse_name(button) { + self.extras.zoom.key(pressed, false, true, e.zoom_level); + } let i = match button { MouseButton::Left => 0, MouseButton::Right => 1, diff --git a/crates/horizon-client/src/game/options.rs b/crates/horizon-client/src/game/options.rs index dcc7bb23b..e8057cf31 100644 --- a/crates/horizon-client/src/game/options.rs +++ b/crates/horizon-client/src/game/options.rs @@ -186,16 +186,11 @@ impl Game<'_> { } /// Mouse buttons pressed while a key is being bound. pub(super) fn options_waiting_for_key(&self) -> bool { - self.ui.options.selected_key.is_some() && self.ui.options.page() == Page::KeyBinds + self.ui.options.selected_key.is_some() } pub(super) fn options_bind_mouse(&mut self, button: MouseButton) -> Result<()> { - if let Some(name) = self.ui.options.selected_key.take() { - self.settings - .keys - .set(name, &horizon_client::keybinds::mouse_name(button)); - self.handle_option_events(vec![Event::Changed])?; - } - Ok(()) + let events = self.ui.options.bind_mouse(&mut self.settings, button); + self.handle_option_events(events) } pub(super) fn handle_option_events(&mut self, events: Vec) -> Result<()> { for e in events { diff --git a/crates/horizon-client/src/game/tweaks.rs b/crates/horizon-client/src/game/tweaks.rs index dc87a13bf..018b6640b 100644 --- a/crates/horizon-client/src/game/tweaks.rs +++ b/crates/horizon-client/src/game/tweaks.rs @@ -28,7 +28,7 @@ use horizon_client::{ menu::Input, stations::hover_name, }; -use winit::keyboard::KeyCode; +use winit::{event::MouseButton, keyboard::KeyCode}; /// A sort button's side in GUI pixels. const SORT_BUTTON: f32 = 9.0; @@ -377,8 +377,14 @@ impl Game<'_> { /// The sort key: sorts the part under the cursor (the container when /// the cursor is over no slot). pub(super) fn sort_key_press(&mut self, key: KeyCode) -> bool { + keybinds::key_name(key).is_some_and(|name| self.sort_input(name)) + } + pub(super) fn sort_mouse_press(&mut self, button: MouseButton) -> bool { + self.sort_input(&keybinds::mouse_name(button)) + } + fn sort_input(&mut self, name: &str) -> bool { let e = &self.settings.extras; - if !e.sort || keybinds::key_code(&e.sort_key) != Some(key) || self.recipe_search_focused() { + if !e.sort || e.sort_key != name || self.recipe_search_focused() { return false; } let buttons = self.sort_buttons(); diff --git a/crates/horizon-client/src/options_horizon.rs b/crates/horizon-client/src/options_horizon.rs index bfaf05c9b..634bb8d75 100644 --- a/crates/horizon-client/src/options_horizon.rs +++ b/crates/horizon-client/src/options_horizon.rs @@ -587,9 +587,16 @@ impl OptionsUi { } return events; } - // A click anywhere stops waiting for an extra's key. + // Rebinding consumes the click before sidebar or widget actions. if matches!(self.selected_key, Some(extras::ZOOM_KEY | extras::SORT_KEY)) { - self.selected_key = None; + return self.bind_mouse( + s, + if right { + winit::event::MouseButton::Right + } else { + winit::event::MouseButton::Left + }, + ); } match self.horizon_target(s, atlas, x, y) { Some(Target::Nav(i)) => { diff --git a/crates/horizon-client/src/options_ui.rs b/crates/horizon-client/src/options_ui.rs index 38be29576..6606d31fd 100644 --- a/crates/horizon-client/src/options_ui.rs +++ b/crates/horizon-client/src/options_ui.rs @@ -1876,15 +1876,13 @@ impl OptionsUi { return events; } // Key Binds: a mouse button pressed while waiting binds it. - if let Some(name) = self.selected_key.take() { + if self.selected_key.is_some() { let button = if right { - "key.mouse.right" + winit::event::MouseButton::Right } else { - "key.mouse.left" + winit::event::MouseButton::Left }; - s.keys.set(name, button); - events.push(Event::Changed); - return events; + return self.bind_mouse(s, button); } // AbstractWidget accepts only the primary button. Rebinding above // accepts other mouse buttons, but is not a widget activation. @@ -2126,6 +2124,23 @@ impl OptionsUi { } false } + fn bind_key(&mut self, s: &mut Settings, value: String) -> Vec { + let Some(name) = self.selected_key.take() else { + return Vec::new(); + }; + if !s.extras.set_key(name, value.clone()) { + s.keys.set(name, &value); + } + vec![Event::Changed] + } + /// Mouse bindings use the same settings and persistence as keyboard bindings. + pub fn bind_mouse( + &mut self, + s: &mut Settings, + button: winit::event::MouseButton, + ) -> Vec { + self.bind_key(s, keybinds::mouse_name(button)) + } /// Keys while the options are open. Returns events; `handled` false lets /// Escape fall through. pub fn key( @@ -2160,7 +2175,7 @@ impl OptionsUi { } return vec![Event::Changed]; } - if let Some(name) = self.selected_key.take() { + if self.selected_key.is_some() { // KeyBindsScreen.keyPressed: Escape unbinds. let value = if key == K::Escape { "key.keyboard.unknown".to_owned() @@ -2169,10 +2184,7 @@ impl OptionsUi { .unwrap_or("key.keyboard.unknown") .to_owned() }; - if !s.extras.set_key(name, value.clone()) { - s.keys.set(name, &value); - } - return vec![Event::Changed]; + return self.bind_key(s, value); } if key == K::Escape { return self.back(s); @@ -2831,6 +2843,55 @@ mod tests { } } + #[test] + fn extras_and_vanilla_bindings_accept_mouse_buttons() { + use crate::extras::{Extras, SORT_KEY, ZOOM_KEY}; + use winit::event::MouseButton; + for button in [ + MouseButton::Left, + MouseButton::Right, + MouseButton::Middle, + MouseButton::Back, + MouseButton::Forward, + ] { + for name in [SORT_KEY, ZOOM_KEY, "key.jump"] { + let mut ui = OptionsUi::default(); + let mut s = Settings::default(); + ui.selected_key = Some(name); + assert_eq!(ui.bind_mouse(&mut s, button), vec![Event::Changed]); + assert_eq!(ui.selected_key, None); + let value = keybinds::mouse_name(button); + match name { + SORT_KEY => assert_eq!(s.extras.sort_key, value), + ZOOM_KEY => assert_eq!(s.extras.zoom_key, value), + _ => assert_eq!(s.keys.get(name), value), + } + assert_eq!(Extras::parse(&s.extras.serialize()), s.extras); + if name != "key.jump" { + assert_eq!(s.keys, Settings::default().keys); + } + assert!(ui.bind_mouse(&mut s, button).is_empty()); + } + } + } + + #[test] + fn horizon_extra_mouse_binding_consumes_the_click() { + let atlas = atlas(); + let mut s = Settings::default(); + let mut ui = OptionsUi::default(); + for (right, expected) in [(false, "key.mouse.left"), (true, "key.mouse.right")] { + ui.selected_key = Some(crate::extras::SORT_KEY); + assert_eq!( + ui.click_horizon(&mut s, &atlas, 2.0, 2.0, [960, 480], false, right), + vec![Event::Changed] + ); + assert_eq!(s.extras.sort_key, expected); + assert_eq!(ui.selected_key, None); + assert_eq!(ui.section, 0); + } + } + #[test] fn key_rebinding_takes_precedence_over_scrollbar_dragging() { let atlas = atlas(); From b174299f2527fd55cd5d988c2a16ad9040131c8d Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 21:37:36 -0400 Subject: [PATCH 07/11] Match vanilla player render scale and inventory title height --- crates/horizon-client/src/game.rs | 9 +-------- crates/horizon-client/src/game/perspective.rs | 17 +++++++++++++++++ crates/horizon-client/src/mobs/render.rs | 4 ++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 5ffcd9124..e4fd53062 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -4336,14 +4336,7 @@ impl Game<'_> { } else { ("Crafting", 97.0) }; - batch.text( - atlas, - title, - ox + tx, - oy + if self.craft_size == 3 { 6.0 } else { 8.0 }, - grey, - false, - ); + batch.text(atlas, title, ox + tx, oy + 6.0, grey, false); if self.craft_size == 3 { batch.text(atlas, "Inventory", ox + 8.0, oy + 72.0, grey, false); } diff --git a/crates/horizon-client/src/game/perspective.rs b/crates/horizon-client/src/game/perspective.rs index a66ca487d..e09d06244 100644 --- a/crates/horizon-client/src/game/perspective.rs +++ b/crates/horizon-client/src/game/perspective.rs @@ -619,6 +619,23 @@ fn player_preview_quads( #[cfg(test)] mod preview_tests { use super::*; + #[test] + #[ignore = "requires prepared model data in HORIZON_TEST_RESOURCES"] + fn player_render_transform_uses_vanilla_avatar_scale() { + let root = std::path::PathBuf::from( + std::env::var_os("HORIZON_TEST_RESOURCES").expect("HORIZON_TEST_RESOURCES"), + ); + let mut m = Mob::new(1, player_type(&root).unwrap(), Vec3::ZERO, 0.0); + for (id, expected) in [("minecraft:player", 0.9375), ("minecraft:zombie", 1.0)] { + Arc::make_mut(&mut m.kind).id = id.into(); + let transform = + horizon_client::mobs::render::base_transform_at(&m, 1.0, glam::Mat4::IDENTITY); + for axis in [glam::Vec3::X, glam::Vec3::Y, glam::Vec3::Z] { + assert!((transform.transform_vector3(axis).length() - expected).abs() < 1e-6); + } + } + } + #[test] fn burning_inventory_preview_keeps_visible_fullbright_flames() { let rect = |u0| horizon_client::hud::Rect { diff --git a/crates/horizon-client/src/mobs/render.rs b/crates/horizon-client/src/mobs/render.rs index 4c312e5fd..e8120e92e 100644 --- a/crates/horizon-client/src/mobs/render.rs +++ b/crates/horizon-client/src/mobs/render.rs @@ -847,6 +847,10 @@ fn red_overlay(m: &Mob) -> bool { m.hurt_time > 0 || (m.death_time > 0 && !super::creaking::tearing_down(m)) } fn species_scale(m: &Mob, alpha: f32) -> glam::Mat4 { + if m.kind.id == "minecraft:player" { + // AvatarRenderer.scale, shared by the inventory and world renderer. + return glam::Mat4::from_scale(glam::Vec3::splat(0.9375)); + } match m.species() { Species::Wither => { glam::Mat4::from_scale(glam::Vec3::splat(super::wither::scale(m, alpha))) From fab2a7cb0607e84f7d7b339e2407f7a17d97595c Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 21:40:07 -0400 Subject: [PATCH 08/11] Expose Horizon Extras in Classic Options --- crates/horizon-client/src/game/control.rs | 1 + crates/horizon-client/src/options_ui.rs | 113 +++++++++++++++++++++- 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/crates/horizon-client/src/game/control.rs b/crates/horizon-client/src/game/control.rs index e1169b2c8..87b6de5de 100644 --- a/crates/horizon-client/src/game/control.rs +++ b/crates/horizon-client/src/game/control.rs @@ -464,6 +464,7 @@ impl Game<'_> { "packs" => Page::Packs, "graphics" => Page::Graphics, "graphics-advanced" => Page::GraphicsAdvanced, + "extras" => Page::Extras, other => return Err(format!("unknown options page {other}").into()), }; if self.screen == Screen::Playing && self.title.is_none() { diff --git a/crates/horizon-client/src/options_ui.rs b/crates/horizon-client/src/options_ui.rs index 38be29576..11a398cc6 100644 --- a/crates/horizon-client/src/options_ui.rs +++ b/crates/horizon-client/src/options_ui.rs @@ -714,6 +714,7 @@ pub enum Page { /// Horizon's controller settings and button binds. Controller, PadBinds, + Extras, } #[derive(Clone, Debug, PartialEq)] enum Act { @@ -721,6 +722,7 @@ enum Act { Push(Page), Done, Cycle(Opt), + Extra(crate::extras::Item), Key(&'static str), ResetKey(&'static str), ResetKeys, @@ -974,6 +976,7 @@ impl OptionsUi { Page::Graphics | Page::GraphicsAdvanced => "options.videoTitle", Page::Controller => "Controller Settings", Page::PadBinds => "Controller Binds", + Page::Extras => "Horizon Extras", } } fn scrollbar_x(&self, width: f32) -> f32 { @@ -986,6 +989,22 @@ impl OptionsUi { } fn list_rows(&self, s: &Settings) -> Vec { match self.page() { + Page::Extras => crate::extras::rows() + .into_iter() + .map(|row| match row { + Err(header) => Row::Header(header), + Ok(item) => { + let value = format!("{}: {}", item.caption(), item.value(&s.extras)); + let label = + if item.key_name().is_some() && self.selected_key == item.key_name() { + Text::literal(format!("> {value} <")).with_color(text::YELLOW) + } else { + Text::literal(value) + }; + Row::Buttons(button(0.0, 0.0, 310.0, label, Act::Extra(item)), None) + } + }) + .collect(), Page::Video => { // Horizon's graphics screens, Simple and Advanced. let mut rows = vec![Row::Buttons( @@ -1207,7 +1226,7 @@ impl OptionsUi { ("options.resourcepack", Some(Page::Packs)), ("options.accessibility", Some(Page::Accessibility)), ("options.telemetry", None), - ("options.credits_and_attribution", None), + ("Horizon Extras...", Some(Page::Extras)), ]; let gy = (61.0 + 30.0f32).min(h - 33.0 - 120.0); for (i, (key, page)) in entries.iter().enumerate() { @@ -1631,6 +1650,13 @@ impl OptionsUi { let hover = ui::hovered(cursor, wd.x, wd.y, wd.w, wd.h) && (!wd.list || cursor.1 >= top && cursor.1 < bottom); if hover { + if let WKind::Button { + act: Act::Extra(item), + .. + } = &wd.kind + { + tooltip = Some(atlas.font.split(&Text::literal(item.description()), 170.0)); + } let key = match &wd.kind { WKind::Button { act: Act::Cycle(opt), @@ -1919,6 +1945,14 @@ impl OptionsUi { } events.push(Event::Changed); } + Act::Extra(item) => { + if let Some(name) = item.key_name() { + self.selected_key = Some(name); + } else { + item.cycle(&mut s.extras, right); + events.push(Event::Changed); + } + } Act::Key(name) => self.selected_key = Some(name), Act::ResetKey(name) => { s.keys.set(name, KeyBinds::default_of(name)); @@ -2316,6 +2350,83 @@ mod tests { } } + #[test] + fn classic_extras_entry_edits_shared_settings_and_returns_without_changing_style() { + let previous_style = style(); + set_style(MenuStyle::Classic); + let atlas = atlas(); + let mut s = Settings::default(); + let mut ui = OptionsUi::default(); + let size = (480.0, 480.0); + let click = |ui: &mut OptionsUi, s: &mut Settings, act: Act| { + let (widgets, _, _, _) = ui.layout(s, size.0, size.1); + let widget = widgets + .iter() + .find( + |w| matches!(&w.kind, WKind::Button { act: a, active: true, .. } if *a == act), + ) + .unwrap(); + ui.click( + s, + &atlas, + widget.x + 1.0, + widget.y + 1.0, + size, + [960, 960], + false, + false, + ) + }; + assert_eq!( + click(&mut ui, &mut s, Act::Push(Page::Extras)), + vec![Event::ButtonClick] + ); + assert_eq!(ui.page(), Page::Extras); + let (widgets, _, _, _) = ui.layout(&s, size.0, size.1); + assert_eq!( + widgets + .iter() + .filter(|w| matches!( + w.kind, + WKind::Button { + act: Act::Extra(_), + .. + } + )) + .count(), + crate::extras::rows().iter().filter(|r| r.is_ok()).count() + ); + assert_eq!( + click(&mut ui, &mut s, Act::Extra(crate::extras::Item::Zoom)), + vec![Event::ButtonClick, Event::Changed] + ); + assert!(s.extras.zoom); + assert_eq!( + click(&mut ui, &mut s, Act::Extra(crate::extras::Item::ZoomKey)), + vec![Event::ButtonClick] + ); + assert_eq!(ui.selected_key, Some(crate::extras::ZOOM_KEY)); + assert_eq!( + ui.key(&mut s, &atlas, winit::keyboard::KeyCode::KeyC, None), + vec![Event::Changed] + ); + assert_eq!(s.extras.zoom_key, "key.keyboard.c"); + assert_eq!( + crate::extras::Extras::parse(&s.extras.serialize()), + s.extras + ); + ui.scroll(&s, size, -1000.0); + let (_, top, bottom, content) = ui.layout(&s, size.0, size.1); + assert_eq!(ui.scroll, content - (bottom - top)); + assert_eq!( + ui.key(&mut s, &atlas, winit::keyboard::KeyCode::Escape, None), + vec![Event::Changed] + ); + assert_eq!(ui.page(), Page::Main); + assert_eq!(style(), MenuStyle::Classic); + set_style(previous_style); + } + #[test] fn classic_graphics_presets_set_the_distances() { let atlas = atlas(); From 8fa5c3866328ea6ae2879a0b750f3726a9a4eeba Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 21:42:01 -0400 Subject: [PATCH 09/11] Add an optional Fullbright extra --- crates/horizon-client/src/extras.rs | 18 ++++++++++++++++-- crates/horizon-client/src/game/options.rs | 1 + crates/horizon-client/src/gfx.rs | 6 ++++++ docs/extras.md | 7 ++++++- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/crates/horizon-client/src/extras.rs b/crates/horizon-client/src/extras.rs index 264456c1a..ee142486c 100644 --- a/crates/horizon-client/src/extras.rs +++ b/crates/horizon-client/src/extras.rs @@ -68,6 +68,7 @@ impl Corner { #[derive(Clone, Debug, PartialEq)] pub struct Extras { + pub fullbright: bool, pub zoom: bool, /// A vanilla key name (`key.keyboard.z`). pub zoom_key: String, @@ -108,6 +109,7 @@ pub struct Extras { impl Default for Extras { fn default() -> Self { Self { + fullbright: false, zoom: false, zoom_key: "key.keyboard.z".into(), zoom_level: 4, @@ -155,6 +157,7 @@ impl Extras { _ => d, }; match key.trim() { + "fullbright" => e.fullbright = flag(e.fullbright), "zoom" => e.zoom = flag(e.zoom), "zoomKey" if value.starts_with("key.") => e.zoom_key = value.to_owned(), "zoomLevel" => { @@ -198,7 +201,8 @@ impl Extras { } pub fn serialize(&self) -> String { format!( - "zoom:{}\nzoomKey:{}\nzoomLevel:{}\nzoomSmooth:{}\nzoomSensitivity:{}\nfps:{}\nfpsCorner:{}\nfpsLows:{}\nkeystrokes:{}\nkeystrokesCorner:{}\nkeystrokesCps:{}\nminimap:{}\nminimapCorner:{}\nminimapSize:{}\nminimapShape:{}\nminimapZoom:{}\nminimapRotate:{}\nautoReconnect:{}\nmouseTweaks:{}\nmouseTweaksWheel:{}\nsort:{}\nsortKey:{}\n", + "fullbright:{}\nzoom:{}\nzoomKey:{}\nzoomLevel:{}\nzoomSmooth:{}\nzoomSensitivity:{}\nfps:{}\nfpsCorner:{}\nfpsLows:{}\nkeystrokes:{}\nkeystrokesCorner:{}\nkeystrokesCps:{}\nminimap:{}\nminimapCorner:{}\nminimapSize:{}\nminimapShape:{}\nminimapZoom:{}\nminimapRotate:{}\nautoReconnect:{}\nmouseTweaks:{}\nmouseTweaksWheel:{}\nsort:{}\nsortKey:{}\n", + bool_text(self.fullbright), bool_text(self.zoom), self.zoom_key, self.zoom_level, @@ -418,6 +422,7 @@ impl Cps { /// The settings the Extras page shows, one per row. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Item { + Fullbright, Zoom, ZoomKey, ZoomLevel, @@ -445,6 +450,8 @@ pub enum Item { pub fn rows() -> Vec> { use Item::*; vec![ + Err("Lighting"), + Ok(Fullbright), Err("Zoom"), Ok(Zoom), Ok(ZoomKey), @@ -493,6 +500,7 @@ fn next(all: &[T], current: T, back: bool) -> T { impl Item { pub fn caption(self) -> &'static str { match self { + Item::Fullbright => "Fullbright", Item::Zoom => "Zoom", Item::ZoomKey => "Zoom key", Item::ZoomLevel => "Starting zoom", @@ -518,6 +526,7 @@ impl Item { /// What the row says under its caption. pub fn description(self) -> &'static str { match self { + Item::Fullbright => "Show blocks and entities at full light, even in dark areas.", Item::Zoom => "Hold the zoom key to zoom; the wheel changes it while held.", Item::ZoomKey => "Click, then press a key. Escape unbinds it.", Item::ZoomLevel => "The zoom the key starts at.", @@ -556,7 +565,7 @@ impl Item { pub fn cost(self) -> Option { use crate::graphics_style::Cost; match self { - Item::Zoom | Item::Fps | Item::Keystrokes => Some(Cost::None), + Item::Fullbright | Item::Zoom | Item::Fps | Item::Keystrokes => Some(Cost::None), Item::Minimap => Some(Cost::Low), Item::AutoReconnect | Item::MouseTweaks | Item::Sort => Some(Cost::None), _ => None, @@ -565,6 +574,7 @@ impl Item { /// On/off items and their value. pub fn switch(self, e: &Extras) -> Option { Some(match self { + Item::Fullbright => e.fullbright, Item::Zoom => e.zoom, Item::ZoomSmooth => e.zoom_smooth, Item::ZoomSensitivity => e.zoom_sensitivity, @@ -606,6 +616,7 @@ impl Item { /// A click (`back` for the right button). The zoom key binds instead. pub fn cycle(self, e: &mut Extras, back: bool) { match self { + Item::Fullbright => e.fullbright = !e.fullbright, Item::Zoom => e.zoom = !e.zoom, Item::ZoomSmooth => e.zoom_smooth = !e.zoom_smooth, Item::ZoomSensitivity => e.zoom_sensitivity = !e.zoom_sensitivity, @@ -651,11 +662,14 @@ mod tests { #[test] fn everything_is_off_by_default_and_round_trips() { let d = Extras::default(); + assert!(!d.fullbright); assert!(!d.zoom && !d.fps && !d.keystrokes && !d.minimap && !d.auto_reconnect); assert!(!d.mouse_tweaks && !d.sort); assert_eq!(Extras::parse(""), d); assert_eq!(Extras::parse(&d.serialize()), d); let mut e = d.clone(); + Item::Fullbright.cycle(&mut e, false); + assert_eq!(Item::Fullbright.switch(&e), Some(true)); e.zoom = true; e.zoom_key = "key.keyboard.c".into(); e.zoom_level = 6; diff --git a/crates/horizon-client/src/game/options.rs b/crates/horizon-client/src/game/options.rs index dcc7bb23b..86a2f789e 100644 --- a/crates/horizon-client/src/game/options.rs +++ b/crates/horizon-client/src/game/options.rs @@ -244,6 +244,7 @@ impl Game<'_> { let s = &self.settings; if let Some(r) = self.renderer.as_mut() { r.gamma = s.gamma; + r.fullbright = s.extras.fullbright; r.set_present_mode(s.vsync, s.horizon.present_mode); r.animated_textures = s.horizon.animated_textures; r.set_mipmap_levels(s.mipmap_levels.max(0) as u32); diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index 4401ea22d..26f596185 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -348,6 +348,8 @@ pub struct Renderer { pub screenshot_result: Option>, /// Brightness option (lightmap gamma), 0..1. pub gamma: f32, + /// Optional full-light lightmap (Horizon Extras). + pub fullbright: bool, /// Advance animated block textures (Horizon setting; vanilla always does). pub animated_textures: bool, present_modes: Vec, @@ -1616,6 +1618,7 @@ impl Renderer { screenshot: None, screenshot_result: None, gamma: 0.5, + fullbright: false, animated_textures: true, present_modes, }) @@ -1972,6 +1975,9 @@ impl Renderer { pixels[i + 3] = 255; } } + if self.fullbright { + pixels.fill(255); + } // The lightmap changes with the time of day, flicker and effects, // not every frame: upload only what differs from the texture. if pixels == self.lightmap_pixels && self.lightmap_uploaded { diff --git a/docs/extras.md b/docs/extras.md index 4129a88eb..3c952d5ac 100644 --- a/docs/extras.md +++ b/docs/extras.md @@ -1,6 +1,6 @@ # Horizon extras -Optional conveniences built into the client: zoom, a minimap, an FPS counter, a +Optional conveniences built into the client: fullbright, zoom, a minimap, an FPS counter, a keystroke overlay, auto-reconnect, Mouse Tweaks-style inventory controls and inventory sorting. **Every one is off by default**: a fresh install looks and behaves exactly like vanilla 26.3, and turning an extra off @@ -36,6 +36,11 @@ Horizon category in Controls, and adding one would put a non-vanilla mapping int ## The extras +### Fullbright (`fullbright`, default off) +- Displays blocks and entities with a fully bright lightmap, including in dark caves. +- Turning it off restores the normal lightmap using the current brightness, + time of day and effects. The brightness slider keeps its normal range. + ### Zoom (`zoom`, default off) - Hold the zoom key (default **Z**, unused by every vanilla 26.3 key mapping; C is `key.saveToolbarActivator`) to zoom. The key does nothing while zoom is off. From cf7ed868b90cdd64c7434708ca8a9d9fa5585644 Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 21:46:47 -0400 Subject: [PATCH 10/11] Light redstone ore when mining begins --- crates/horizon-client/src/game.rs | 7 +++++++ crates/horizon-client/src/game/hand.rs | 5 ++++- crates/horizon-world/src/level/interact.rs | 16 ++++++++++++++++ crates/horizon-world/src/level/tests.rs | 21 +++++++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 5ffcd9124..cc17dc64a 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1777,6 +1777,12 @@ impl Game<'_> { }); self.process_level_events() } + fn attack_block(&mut self, pos: [i32; 3]) -> Result<()> { + self.with_level(|b, level, ticks| { + b.attack_block(level, ticks, BlockPos::new(pos[0], pos[1], pos[2])); + }); + self.process_level_events() + } /// Track which chunks are ticking (Ticks needs chunk load/unload). fn sync_tick_chunks(&mut self) { if !self.tick_chunks.synchronize(&self.world.chunks) { @@ -2885,6 +2891,7 @@ impl Game<'_> { return Ok(()); } if self.mining.as_ref().is_none_or(|m| m.pos != hit.pos) { + self.attack_block(hit.pos)?; self.mining = Some(Mining { pos: hit.pos, progress: 0.0, diff --git a/crates/horizon-client/src/game/hand.rs b/crates/horizon-client/src/game/hand.rs index 431e6661a..a932913af 100644 --- a/crates/horizon-client/src/game/hand.rs +++ b/crates/horizon-client/src/game/hand.rs @@ -409,7 +409,10 @@ impl HandWorld for GameHands<'_, '_> { fn within_border(&mut self, _: [i32; 3]) -> bool { true } - fn attack_block(&mut self, _: [i32; 3]) {} + fn attack_block(&mut self, pos: [i32; 3]) { + let result = self.game.attack_block(pos); + self.keep(result); + } fn destroy_progress(&mut self, pos: [i32; 3]) -> f32 { self.game.destroy_progress(pos) } diff --git a/crates/horizon-world/src/level/interact.rs b/crates/horizon-world/src/level/interact.rs index 791daf7c2..c38d81f26 100644 --- a/crates/horizon-world/src/level/interact.rs +++ b/crates/horizon-world/src/level/interact.rs @@ -513,6 +513,22 @@ impl Behaviours { sim.game_event_state(pos, "minecraft:block_change", next); } + /// The state change of `RedStoneOreBlock.attack` when mining begins. + pub fn attack_block( + &self, + level: &mut L, + ticks: &mut Ticks, + pos: BlockPos, + ) { + let mut sim = self.sim(level, ticks); + let state = sim.state(pos); + if self.data(state).chain.contains(&Class::RedStoneOre) + && !self.table.bool(state, self.props.lit) + { + sim.set_block_and_update(pos, self.table.set_bool(state, self.props.lit, true)); + } + } + /// `BlockState.useWithoutItem` for a right-click on `pos` (hit face and /// absolute hit location as in `BlockHitResult`). pub fn use_without_item( diff --git a/crates/horizon-world/src/level/tests.rs b/crates/horizon-world/src/level/tests.rs index 270ee48fa..c0ceddc6f 100644 --- a/crates/horizon-world/src/level/tests.rs +++ b/crates/horizon-world/src/level/tests.rs @@ -634,6 +634,27 @@ impl World<'_> { } } +#[test] +fn mining_lights_redstone_ore_until_its_random_tick() { + let mut w = world!(); + let pos = BlockPos::new(0, 1, 0); + for ore in ["redstone_ore", "deepslate_redstone_ore"] { + let unlit = w.id(ore, &[("lit", "false")]); + let lit = w.id(ore, &[("lit", "true")]); + w.put(pos, unlit); + w.b().attack_block(&mut w.level, &mut w.ticks, pos); + assert_eq!(w.get(pos), lit); + w.b().attack_block(&mut w.level, &mut w.ticks, pos); + assert_eq!(w.get(pos), lit); + w.b().random_tick(&mut w.level, &mut w.ticks, pos); + assert_eq!(w.get(pos), unlit); + } + let stone = w.id("stone", &[]); + w.put(pos, stone); + w.b().attack_block(&mut w.level, &mut w.ticks, pos); + assert_eq!(w.get(pos), stone); +} + #[test] fn placement_orients_blocks() { let mut w = world!(); From 6d8b1742167d79e619aa3abe34367c377072f4e6 Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 22:03:57 -0400 Subject: [PATCH 11/11] Depth-test inventory preview equipment and clip it with a scissor --- crates/horizon-client/src/game/perspective.rs | 51 +++++- crates/horizon-client/src/gfx.rs | 1 + crates/horizon-client/src/hud.rs | 166 +++++++++++++++--- crates/horizon-client/src/hud.wgsl | 4 +- crates/horizon-client/src/ui_theme.rs | 1 + 5 files changed, 194 insertions(+), 29 deletions(-) diff --git a/crates/horizon-client/src/game/perspective.rs b/crates/horizon-client/src/game/perspective.rs index e09d06244..bb463547f 100644 --- a/crates/horizon-client/src/game/perspective.rs +++ b/crates/horizon-client/src/game/perspective.rs @@ -427,7 +427,7 @@ impl Game<'_> { } /// `extractEntityInInventoryFollowsMouse`: the player in the box /// `[x0, x1) x [y0, y1)`, `size` pixels per block, turned toward the - /// cursor; drawn as depth-sorted, back-face-culled quads. + /// cursor; drawn with a depth buffer and back-face culling. #[allow(clippy::too_many_arguments)] pub(super) fn draw_player_preview( &self, @@ -495,9 +495,9 @@ impl Game<'_> { let quads = player_preview_quads(verts, gui, fire, &atlas.sprites); let start = batch.vertices.len(); for (_, p, uv, color) in quads { - batch.quad(p, uv, color); + batch.quad_3d(p, uv, color); } - batch.clip_since(start, x0, y0, x1, y1); + batch.depth_since(start, [x0, y0, x1, y1]); } /// The survival inventory's player box (`InventoryScreen`). pub(super) fn draw_inventory_player(&self, batch: &mut HudBatch, ox: f32, oy: f32) { @@ -570,7 +570,7 @@ fn player_preview_quads( gui: glam::Mat4, fire: Option<(f32, f32)>, sprites: &std::collections::HashMap, -) -> Vec<(f32, [[f32; 2]; 4], [[f32; 2]; 4], u32)> { +) -> Vec<(f32, [[f32; 3]; 4], [[f32; 2]; 4], u32)> { let flame_start = verts.len(); if let Some((width, height)) = fire { horizon_client::fire_render::flames( @@ -584,7 +584,7 @@ fn player_preview_quads( &mut verts, ); } - let mut quads: Vec<(f32, [[f32; 2]; 4], [[f32; 2]; 4], u32)> = Vec::new(); + let mut quads: Vec<(f32, [[f32; 3]; 4], [[f32; 2]; 4], u32)> = Vec::new(); for (index, q) in verts.as_chunks::<4>().0.iter().enumerate() { let p: [glam::Vec3; 4] = std::array::from_fn(|i| gui.transform_point3(glam::Vec3::from_array(q[i].pos))); @@ -606,12 +606,12 @@ fn player_preview_quads( let depth = p.iter().map(|v| v.z).sum::() / 4.0; quads.push(( depth, - p.map(|v| [v.x, v.y]), + p.map(|v| v.to_array()), std::array::from_fn(|i| q[i].uv), color, )); } - // Far (low z) first: the viewer is on the +z side. + // Keep far-to-near order for translucent faces; opaque overlap uses depth. quads.sort_by(|a, b| a.0.total_cmp(&b.0)); quads } @@ -619,6 +619,43 @@ fn player_preview_quads( #[cfg(test)] mod preview_tests { use super::*; + #[test] + fn preview_keeps_crossing_faces_depth_and_clips_without_dropping_faces() { + use horizon_client::{ + hud::{Blend, HudBatch}, + mesher::Vertex, + }; + let face = |z: [f32; 4]| { + [[-2.0, -1.0], [-2.0, 1.0], [2.0, 1.0], [2.0, -1.0]] + .into_iter() + .zip(z) + .map(|([x, y], z)| Vertex { + pos: [x, y, z], + uv: [0.0; 2], + layer: 0, + color: u32::MAX, + light: 0, + normal: [0; 4], + }) + }; + // A shield and arm can intersect: neither average depth orders both ends. + let verts = face([1.0, 1.0, -1.0, -1.0]).chain(face([0.0; 4])).collect(); + let quads = player_preview_quads(verts, glam::Mat4::IDENTITY, None, &Default::default()); + assert_eq!(quads.len(), 2); + let mut batch = HudBatch::new([320, 240]); + for (_, p, uv, color) in quads { + batch.quad_3d(p, uv, color); + } + // Its centre is outside this scissor; the visible part must still be drawn. + batch.depth_since(0, [1.0, 0.0, 2.0, 1.0]); + assert_eq!(batch.vertices.len(), 12); + let shield = &batch.vertices[..6]; + let arm = &batch.vertices[6..]; + assert!(shield[0].depth < arm[0].depth); + assert!(shield[2].depth > arm[2].depth); + assert_eq!(batch.runs(), vec![(0..12, Blend::Depth([1, 0, 1, 1]))]); + } + #[test] #[ignore = "requires prepared model data in HORIZON_TEST_RESOURCES"] fn player_render_transform_uses_vanilla_avatar_scale() { diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index 4401ea22d..0e1ccb920 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -2776,6 +2776,7 @@ impl Renderer { &mut self.uploads, &mut encoder, &view_target, + &self.depth, frame.hud, [self.config.width, self.config.height], ); diff --git a/crates/horizon-client/src/hud.rs b/crates/horizon-client/src/hud.rs index 77ba0e342..c5462eaee 100644 --- a/crates/horizon-client/src/hud.rs +++ b/crates/horizon-client/src/hud.rs @@ -319,6 +319,7 @@ pub struct HudVertex { pub pos: [f32; 2], pub uv: [f32; 2], pub color: u32, + pub depth: f32, } /// The GUI Scale option (0 = auto). pub static GUI_SCALE: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0); @@ -330,10 +331,10 @@ pub struct HudBatch { pub height: f32, /// Glyph pixels to upload into the atlas before drawing. pub patches: Vec, - /// Vertex ranges drawn with another blend than alpha blending, in order. + /// Vertex ranges with another blend or depth/scissor state, in order. pub blends: Vec<(std::ops::Range, Blend)>, } -/// How a run of HUD vertices blends with what is under it. +/// How a run of HUD vertices blends and tests depth. #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum Blend { /// `BlendFunction.TRANSLUCENT`. @@ -342,6 +343,8 @@ pub enum Blend { Invert, /// `BlendFunction.ADDITIVE` (`RenderPipelines.GUI_TEXT_HIGHLIGHT`). Additive, + /// Alpha blending with an isolated depth buffer and a pixel scissor. + Depth([u32; 4]), } pub fn rgba(r: u8, g: u8, b: u8, a: u8) -> u32 { u32::from(a) << 24 | u32::from(b) << 16 | u32::from(g) << 8 | u32::from(r) @@ -430,9 +433,44 @@ impl HudBatch { pos: p[i], uv: uv[i], color, + depth: 0.0, }); } } + pub fn quad_3d(&mut self, p: [[f32; 3]; 4], uv: [[f32; 2]; 4], color: u32) { + for i in [0, 1, 2, 0, 2, 3] { + self.vertices.push(HudVertex { + pos: [p[i][0], p[i][1]], + uv: uv[i], + color, + depth: p[i][2], + }); + } + } + /// Keep per-vertex depth for an orthographic GUI model, with +z toward the viewer. + pub fn depth_since(&mut self, start: usize, clip: [f32; 4]) { + let vertices = &mut self.vertices[start..]; + if vertices.is_empty() { + return; + } + let min = vertices + .iter() + .map(|v| v.depth) + .fold(f32::INFINITY, f32::min); + let max = vertices + .iter() + .map(|v| v.depth) + .fold(f32::NEG_INFINITY, f32::max); + for v in vertices { + v.depth = (max - v.depth) / (max - min).max(f32::EPSILON); + } + let [x0, y0, x1, y1] = clip.map(|v| (v * self.scale).max(0.0) as u32); + // Separate previews clear depth independently, even if their scissors match. + self.blends.push(( + start as u32..self.vertices.len() as u32, + Blend::Depth([x0, y0, x1.saturating_sub(x0), y1.saturating_sub(y0)]), + )); + } pub fn rect_uv(&mut self, x: f32, y: f32, w: f32, h: f32, r: Rect, color: u32) { self.quad( [[x, y], [x + w, y], [x + w, y + h], [x, y + h]], @@ -569,6 +607,7 @@ impl HudBatch { pos: p[i], uv, color: c[i], + depth: 0.0, }); } } @@ -729,6 +768,7 @@ pub struct HudRenderer { /// `RenderPipelines.CROSSHAIR`. invert_pipeline: wgpu::RenderPipeline, additive_pipeline: wgpu::RenderPipeline, + depth_pipeline: wgpu::RenderPipeline, group: wgpu::BindGroup, uniform: wgpu::Buffer, buffer: wgpu::Buffer, @@ -808,8 +848,8 @@ impl HudRenderer { bind_group_layouts: &[Some(&layout)], ..Default::default() }); - let attributes = wgpu::vertex_attr_array![0=>Float32x2,1=>Float32x2,2=>Unorm8x4]; - let create = |label, blend, fragment_entry| { + let attributes = wgpu::vertex_attr_array![0=>Float32x2,1=>Float32x2,2=>Unorm8x4,3=>Float32]; + let create = |label, blend, fragment_entry, depth: bool| { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some(label), layout: Some(&pipeline_layout), @@ -824,7 +864,13 @@ impl HudRenderer { })], }, primitive: Default::default(), - depth_stencil: None, + depth_stencil: depth.then_some(wgpu::DepthStencilState { + format: wgpu::TextureFormat::Depth32Float, + depth_write_enabled: Some(true), + depth_compare: Some(wgpu::CompareFunction::LessEqual), + stencil: Default::default(), + bias: Default::default(), + }), multisample: Default::default(), fragment: Some(wgpu::FragmentState { module: &shader, @@ -840,7 +886,13 @@ impl HudRenderer { cache: None, }) }; - let pipeline = create("HUD", wgpu::BlendState::ALPHA_BLENDING, "fs_main"); + let pipeline = create("HUD", wgpu::BlendState::ALPHA_BLENDING, "fs_main", false); + let depth_pipeline = create( + "HUD model", + wgpu::BlendState::ALPHA_BLENDING, + "fs_main", + true, + ); // BlendFunction.INVERT: ONE_MINUS_DST_COLOR, ONE_MINUS_SRC_COLOR, // ONE, ZERO. let invert_pipeline = create( @@ -858,6 +910,7 @@ impl HudRenderer { }, }, "fs_crosshair", + false, ); // BlendFunction.ADDITIVE: ONE, ONE. let add = wgpu::BlendComponent { @@ -872,6 +925,7 @@ impl HudRenderer { alpha: add, }, "fs_main", + false, ); let capacity = 1 << 16; let buffer = device.create_buffer(&wgpu::BufferDescriptor { @@ -886,6 +940,7 @@ impl HudRenderer { pipeline, invert_pipeline, additive_pipeline, + depth_pipeline, group, uniform, buffer, @@ -935,6 +990,7 @@ impl HudRenderer { uploads: &mut crate::gfx::upload::Uploads, encoder: &mut wgpu::CommandEncoder, target: &wgpu::TextureView, + depth: &wgpu::TextureView, batch: &HudBatch, size: [u32; 2], ) { @@ -965,7 +1021,7 @@ impl HudRenderer { ); } } - if batch.vertices.is_empty() { + if batch.vertices.is_empty() || size.contains(&0) { return; } let count = batch.vertices.len() as u64; @@ -1001,20 +1057,55 @@ impl HudRenderer { store: wgpu::StoreOp::Store, }, })]; - let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: Some("HUD"), - color_attachments: &attachments, - ..Default::default() - }); - pass.set_bind_group(0, &self.group, &[]); - pass.set_vertex_buffer(0, self.buffer.slice(..)); - for (range, blend) in batch.runs() { - pass.set_pipeline(match blend { - Blend::Alpha => &self.pipeline, - Blend::Invert => &self.invert_pipeline, - Blend::Additive => &self.additive_pipeline, + let runs = batch.runs(); + let mut at = 0; + while at < runs.len() { + let clip = match runs[at].1 { + Blend::Depth(clip) => Some(clip), + _ => None, + }; + let end = if clip.is_some() { + at + 1 + } else { + runs[at..] + .iter() + .position(|(_, b)| matches!(b, Blend::Depth(_))) + .map_or(runs.len(), |n| at + n) + }; + let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("HUD"), + color_attachments: &attachments, + depth_stencil_attachment: clip.map(|_| wgpu::RenderPassDepthStencilAttachment { + view: depth, + depth_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Clear(1.0), + store: wgpu::StoreOp::Discard, + }), + stencil_ops: None, + }), + ..Default::default() }); - pass.draw(range, 0..1); + pass.set_bind_group(0, &self.group, &[]); + pass.set_vertex_buffer(0, self.buffer.slice(..)); + if let Some([x, y, w, h]) = clip { + let (x, y) = (x.min(size[0]), y.min(size[1])); + let (w, h) = (w.min(size[0] - x), h.min(size[1] - y)); + if w == 0 || h == 0 { + at = end; + continue; + } + pass.set_scissor_rect(x, y, w, h); + } + for (range, blend) in &runs[at..end] { + pass.set_pipeline(match blend { + Blend::Alpha => &self.pipeline, + Blend::Invert => &self.invert_pipeline, + Blend::Additive => &self.additive_pipeline, + Blend::Depth(_) => &self.depth_pipeline, + }); + pass.draw(range.clone(), 0..1); + } + at = end; } } } @@ -1092,6 +1183,41 @@ mod tests { fs::remove_dir_all(root).unwrap(); } + #[test] + fn gui_models_keep_separate_depth_runs_between_overlay_draws() { + let mut batch = HudBatch::new([640, 480]); + batch.scale = 2.0; + let p = [ + [0.0, 0.0, 2.0], + [0.0, 1.0, 2.0], + [1.0, 1.0, 2.0], + [1.0, 0.0, 2.0], + ]; + let uv = [[0.0; 2]; 4]; + batch.quad([[0.0; 2]; 4], uv, u32::MAX); + for _ in 0..2 { + let start = batch.vertices.len(); + batch.quad_3d(p, uv, u32::MAX); + batch.depth_since(start, [1.0, 2.0, 4.0, 6.0]); + } + batch.quad([[0.0; 2]; 4], uv, u32::MAX); + assert_eq!( + batch.runs(), + vec![ + (0..6, Blend::Alpha), + (6..12, Blend::Depth([2, 4, 6, 8])), + (12..18, Blend::Depth([2, 4, 6, 8])), + (18..24, Blend::Alpha), + ] + ); + assert!( + batch + .vertices + .iter() + .all(|v| v.depth.is_finite() && (0.0..=1.0).contains(&v.depth)) + ); + } + #[test] fn hud_shader_validates_both_fragment_entries() { let module = naga::front::wgsl::parse_str(include_str!("hud.wgsl")).unwrap(); diff --git a/crates/horizon-client/src/hud.wgsl b/crates/horizon-client/src/hud.wgsl index 055bfc1f1..17d50d51a 100644 --- a/crates/horizon-client/src/hud.wgsl +++ b/crates/horizon-client/src/hud.wgsl @@ -7,10 +7,10 @@ struct Out { @location(0) uv: vec2, @location(1) color: vec4, } -@vertex fn vs_main(@location(0) pos: vec2, @location(1) uv: vec2, @location(2) color: vec4) -> Out { +@vertex fn vs_main(@location(0) pos: vec2, @location(1) uv: vec2, @location(2) color: vec4, @location(3) depth: f32) -> Out { let pixels = pos * hud.size.z; var out: Out; - out.clip = vec4(pixels.x / hud.size.x * 2.0 - 1.0, 1.0 - pixels.y / hud.size.y * 2.0, 0.0, 1.0); + out.clip = vec4(pixels.x / hud.size.x * 2.0 - 1.0, 1.0 - pixels.y / hud.size.y * 2.0, depth, 1.0); out.uv = uv; out.color = color; return out; diff --git a/crates/horizon-client/src/ui_theme.rs b/crates/horizon-client/src/ui_theme.rs index 1c41add9d..d5073bec9 100644 --- a/crates/horizon-client/src/ui_theme.rs +++ b/crates/horizon-client/src/ui_theme.rs @@ -690,6 +690,7 @@ impl<'a> Ui<'a> { pos: p[i], uv: [cu, cv], color: c[i], + depth: 0.0, }); } }