From ee697cadc60e2d0cd854d22386f48fb36f03083a Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Wed, 14 Oct 2026 23:40:18 +0200 Subject: [PATCH] End crystals from EndCrystalModel, lit, with their base and beams The crystals were a hand-built mesh without normals (so unshaded), without the bedrock base and without beams. They now draw the baked minecraft:end_crystal#main layer under EndCrystalRenderer's transform (scale 2, down 0.5, not flipped) with EndCrystalModel.setupAnim's poses (end_crystal::poses: the base shown per showsBottom, the glass raised by half the bob, outer glass, inner glass and cube turned with rotateBy), the entity light at their block, and the beam to their target (submitCrystalBeams from the target's centre up to the crystal) while the spikes are being summoned back. Crystals placed outside the End draw too. The entity model harness no longer skips end_crystal: the oracle runs EndCrystalModel.setupAnim on EndCrystalRenderState and the fixture poses the layer with end_crystal::poses. Co-Authored-By: Claude Opus 5.5 --- .../examples/entity_anim_fixture.rs | 73 +++++---- crates/horizon-client/src/end_crystal.rs | 38 +++++ crates/horizon-client/src/game.rs | 3 + crates/horizon-client/src/game/dragon.rs | 6 +- crates/horizon-client/src/game/end.rs | 147 +++++------------- crates/horizon-client/src/lib.rs | 1 + tools/test_entity_model_parity.py | 6 +- 7 files changed, 135 insertions(+), 139 deletions(-) create mode 100644 crates/horizon-client/src/end_crystal.rs diff --git a/crates/horizon-client/examples/entity_anim_fixture.rs b/crates/horizon-client/examples/entity_anim_fixture.rs index 663bc288a..e5a146ef9 100644 --- a/crates/horizon-client/examples/entity_anim_fixture.rs +++ b/crates/horizon-client/examples/entity_anim_fixture.rs @@ -294,12 +294,26 @@ fn main() -> horizon_client::Result<()> { let types = MobTypes::load(&root)?; let animations = MobData::load_animations(&root); let mut out = String::new(); + let crystal = horizon_client::mobs::load_model(&root, "minecraft:end_crystal#main"); for line in fs::read_to_string(&args[1])?.lines() { let v: Value = serde_json::from_str(line)?; let layer = v["layer"] .as_str() .unwrap_or_default() .trim_start_matches("minecraft:"); + // EndCrystalModel is not a mob's: horizon_client::end_crystal poses it. + if layer == "end_crystal#main" + && let Some(model) = &crystal + { + let case = &v["case"]; + let mut poses = horizon_client::end_crystal::poses( + model, + case["ageInTicks"].as_f64().unwrap_or(0.0) as f32, + case["showsBottom"].as_bool().unwrap_or(false), + ); + out.push_str(&format!("{}\n", emit(model, &mut poses, case, layer))); + continue; + } let baby = layer.contains("_baby#"); let adult = layer.replace("_baby#", "#"); // Variant layers (sizes, hatless villagers, climate cows...) animate @@ -576,35 +590,38 @@ fn main() -> horizon_client::Result<()> { } _ => anim::setup(&mob, s, p, &animations), } - // The harness's part-scale override, set after setupAnim as the oracle does. - if let Some(scale) = case["@partScale"].as_array() { - let pose = poses.get(scale[0].as_str().unwrap_or_default()); - for i in 0..3 { - pose[6 + i] = scale[1 + i].as_f64().unwrap_or(1.0) as f32; - } - } - let mut parts = BTreeMap::new(); - walk(&model, "", &poses, &mut parts); - let mut emitted = Vec::new(); - render::draw( - &model, - root_transform(case), - &poses, - [0.0, 0.0, 1.0, 1.0], - 0xFFFF_FFFF, - 240 | 240 << 8, - 0, - &mut emitted, - ); - let mut vertices = BTreeMap::new(); - let mut cursor = 0; - drawn(&model, "", &poses, &emitted, &mut cursor, &mut vertices); - assert_eq!(cursor, emitted.len(), "{layer}: draw's walk changed"); - out.push_str(&format!( - "{}\n", - json!({"parts": parts, "vertices": vertices}) - )); + out.push_str(&format!("{}\n", emit(&model, &mut poses, case, layer))); } fs::write(&args[2], out)?; Ok(()) } + +/// Every part's pose, and the vertices drawn under the harness's root transform. +fn emit(model: &Part, poses: &mut Poses, case: &Value, layer: &str) -> Value { + // The harness's part-scale override, set after setupAnim as the oracle does. + if let Some(scale) = case["@partScale"].as_array() { + let pose = poses.get(scale[0].as_str().unwrap_or_default()); + for i in 0..3 { + pose[6 + i] = scale[1 + i].as_f64().unwrap_or(1.0) as f32; + } + } + let poses = &*poses; + let mut parts = BTreeMap::new(); + walk(model, "", poses, &mut parts); + let mut emitted = Vec::new(); + render::draw( + model, + root_transform(case), + poses, + [0.0, 0.0, 1.0, 1.0], + 0xFFFF_FFFF, + 240 | 240 << 8, + 0, + &mut emitted, + ); + let mut vertices = BTreeMap::new(); + let mut cursor = 0; + drawn(model, "", poses, &emitted, &mut cursor, &mut vertices); + assert_eq!(cursor, emitted.len(), "{layer}: draw's walk changed"); + json!({"parts": parts, "vertices": vertices}) +} diff --git a/crates/horizon-client/src/end_crystal.rs b/crates/horizon-client/src/end_crystal.rs new file mode 100644 index 000000000..037ccf6b1 --- /dev/null +++ b/crates/horizon-client/src/end_crystal.rs @@ -0,0 +1,38 @@ +//! `EndCrystalRenderer` and `EndCrystalModel.setupAnim`: the crystal's bob +//! and the poses of its base, glass and cube. +use crate::mobs::{Part, anim::Poses}; +use horizon_core::geometry::trig::Mth; + +/// `EndCrystalRenderer.getY`: the crystal's bob below its resting height. +pub fn y(age: f32) -> f32 { + let hh = (age * 0.2).msin() / 2.0 + 0.5; + (hh * hh + hh) * 0.4 - 1.4 +} + +/// `EndCrystalModel.setupAnim`: the base shown or not, the glass raised by +/// half the bob (in model pixels) and the three cubes turned with +/// `ModelPart.rotateBy`, which stores the composed rotation as ZYX angles. +pub fn poses(model: &Part, age: f32, show_bottom: bool) -> Poses { + let mut poses = Poses::new(model); + poses.visible("base", show_bottom); + let speed = age * 3.0; + let sin45 = std::f32::consts::FRAC_PI_4.sin(); + let tilt = glam::Quat::from_axis_angle( + glam::Vec3::new(sin45, 0.0, sin45), + std::f32::consts::FRAC_PI_3, + ); + let spin = glam::Quat::from_rotation_y(speed.to_radians()); + poses.get("outer_glass")[1] += y(age) * 16.0 / 2.0; + for (part, rotation) in [ + ("outer_glass", spin * tilt), + ("inner_glass", tilt * spin), + ("cube", tilt * spin), + ] { + let (z, y, x) = rotation.to_euler(glam::EulerRot::ZYX); + let pose = poses.get(part); + pose[3] = x; + pose[4] = y; + pose[5] = z; + } + poses +} diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index ed70ddc65..1e05d1172 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -835,6 +835,8 @@ struct Game<'a> { armor_stand_assets: armor_stands::ArmorStandAssets, boats: Vec, boat_models: boats::BoatModels, + /// EndCrystalModel's baked layer. + crystal_model: Option, carts: Vec, /// Songs playing from jukeboxes (tracked sound handles). jukebox_sounds: HashMap<(i32, i32, i32), u64>, @@ -9138,6 +9140,7 @@ pub fn run() -> Result<()> { armor_stand_assets: armor_stands::ArmorStandAssets::load(&root), boats: Vec::new(), boat_models: boats::BoatModels::load(&root), + crystal_model: horizon_client::mobs::load_model(&root, "minecraft:end_crystal#main"), carts: Vec::new(), jukebox_sounds: HashMap::new(), bolts: Vec::new(), diff --git a/crates/horizon-client/src/game/dragon.rs b/crates/horizon-client/src/game/dragon.rs index a1cf7bfc2..00fc4b12f 100644 --- a/crates/horizon-client/src/game/dragon.rs +++ b/crates/horizon-client/src/game/dragon.rs @@ -2066,9 +2066,7 @@ impl Game<'_> { } // The healing beam to the nearest crystal. if let Some(c) = d.nearest_crystal.and_then(|i| self.crystals.get(i)) { - let age = c.time as f32 + a; - let hh = (age * 0.2).sin() / 2.0 + 0.5; - let bob = f64::from((hh * hh + hh) * 0.4 - 1.4); + let bob = f64::from(horizon_client::end_crystal::y(c.time as f32 + a)); let to = glam::DVec3::new(c.position.x, c.position.y + bob, c.position.z); self.crystal_beam(pos, to - pos, self.ticks as f32 + a, camera, out); } @@ -2122,7 +2120,7 @@ impl Game<'_> { } /// `submitCrystalBeams`: an eight-sided tube from `from` (+2 up) along /// `delta`, the beam texture scrolling along it. - fn crystal_beam( + pub(super) fn crystal_beam( &self, from: glam::DVec3, delta: glam::DVec3, diff --git a/crates/horizon-client/src/game/end.rs b/crates/horizon-client/src/game/end.rs index 126bd322b..5ac4b5c45 100644 --- a/crates/horizon-client/src/game/end.rs +++ b/crates/horizon-client/src/game/end.rs @@ -881,130 +881,67 @@ impl Game<'_> { Ok(()) } - /// The End crystals on the spikes and thrown eyes of ender, as - /// camera-relative entity geometry (End portals and gateways are block - /// entities). + /// End crystals (on the spikes, or placed in any dimension) and thrown + /// eyes of ender, as camera-relative entity geometry (End portals and + /// gateways are block entities). pub(super) fn end_geometry(&self, camera: glam::DVec3, out: &mut Vec) { - if self.dim == Dim::End { - self.end_crystal_geometry(camera, out); - } + self.end_crystal_geometry(camera, out); self.eye_geometry(camera, out); } - /// EndCrystalRenderer and EndCrystalModel for the end crystals. + /// EndCrystalRenderer and EndCrystalModel for the end crystals, and the + /// beam to a crystal's target (the spikes being summoned back). fn end_crystal_geometry(&self, camera: glam::DVec3, out: &mut Vec) { - let Some(r) = self - .res - .atlas - .sprites - .get("entity/end_crystal/end_crystal") - .copied() - else { + let (Some(model), Some(r)) = ( + self.crystal_model.as_ref(), + self.res + .atlas + .sprites + .get("entity/end_crystal/end_crystal") + .copied(), + ) else { return; }; - let sin45 = std::f32::consts::FRAC_PI_4.sin(); - let axis = glam::Vec3::new(sin45, 0.0, sin45).normalize(); - let tilt = glam::Quat::from_axis_angle(axis, std::f32::consts::FRAC_PI_3); - // A 8×8×8 model box at texture offset (u, v) of the 64×32 texture. - let uv = |u: f32, v: f32, w: f32, h: f32| { - let su = |x: f32| r.u0 + (r.u1 - r.u0) * x / 64.0; - let sv = |y: f32| r.v0 + (r.v1 - r.v0) * y / 32.0; - (su(u), su(u + w), sv(v), sv(v + h)) - }; + let uv = [r.u0, r.v0, r.u1, r.v1]; + let partial = self.clock.fraction() as f32; for crystal in &self.crystals { let feet = glam::DVec3::new(crystal.position.x, crystal.position.y, crystal.position.z); - let age = crystal.time as f32 + self.clock.fraction() as f32; - let spin = glam::Quat::from_rotation_y((age * 3.0).to_radians()); - let hh = (age * 0.2).sin() / 2.0 + 0.5; - let bob = (hh * hh + hh) * 0.4 - 1.4; let rel = feet - camera; if rel.length_squared() > 256.0 * 256.0 { continue; } + let age = crystal.time as f32 + partial; let light = self.world.light( feet.x.floor() as i32, feet.y.floor() as i32, feet.z.floor() as i32, ); let packed = (u32::from(light >> 4) * 16) | ((u32::from(light & 15) * 16) << 8); - // poseStack.scale(2) then translate(0, -0.5, 0); outer_glass at y 24 px + bob. - let center = rel.as_vec3() + glam::Vec3::new(0.0, 2.0 * (24.0 / 16.0 - 0.5) + bob, 0.0); - let outer = spin * tilt; - let inner = tilt * spin; - let parts = [ - (outer, 1.0, 0.0), - (outer * inner, 0.875, 0.0), - (outer * inner * inner, 0.875 * 0.765_625, 32.0), - ]; - for (rotation, scale, u) in parts { - // Half extent: 4 px, times the renderer's scale of 2. - let h = 0.25 * 2.0 * scale; - let corner = |x: f32, y: f32, z: f32| { - center + rotation * glam::Vec3::new(x * h, y * h, z * h) - }; - let faces: [([f32; 3], [f32; 3], [f32; 3], (f32, f32, f32, f32)); 6] = [ - ( - [-1.0, 1.0, -1.0], - [1.0, 0.0, 0.0], - [0.0, 0.0, 1.0], - uv(u + 8.0, 0.0, 8.0, 8.0), - ), - ( - [-1.0, -1.0, -1.0], - [1.0, 0.0, 0.0], - [0.0, 0.0, 1.0], - uv(u + 16.0, 0.0, 8.0, 8.0), - ), - ( - [-1.0, -1.0, -1.0], - [0.0, 0.0, 1.0], - [0.0, 1.0, 0.0], - uv(u, 8.0, 8.0, 8.0), - ), - ( - [-1.0, -1.0, -1.0], - [1.0, 0.0, 0.0], - [0.0, 1.0, 0.0], - uv(u + 8.0, 8.0, 8.0, 8.0), - ), - ( - [1.0, -1.0, -1.0], - [0.0, 0.0, 1.0], - [0.0, 1.0, 0.0], - uv(u + 16.0, 8.0, 8.0, 8.0), - ), - ( - [-1.0, -1.0, 1.0], - [1.0, 0.0, 0.0], - [0.0, 1.0, 0.0], - uv(u + 24.0, 8.0, 8.0, 8.0), - ), - ]; - for (o, a, b, (u0, u1, v0, v1)) in faces { - let p = |s: f32, t: f32| { - corner( - o[0] + 2.0 * (a[0] * s + b[0] * t), - o[1] + 2.0 * (a[1] * s + b[1] * t), - o[2] + 2.0 * (a[2] * s + b[2] * t), - ) - }; - let quad = [ - (p(0.0, 0.0), [u0, v1]), - (p(1.0, 0.0), [u1, v1]), - (p(1.0, 1.0), [u1, v0]), - (p(0.0, 1.0), [u0, v0]), - ]; - for (pos, uv) in quad { - out.push(Vertex { - normal: [0; 4], - pos: pos.to_array(), - uv, - layer: 0, - color: 0xFFFF_FFFF, - light: packed, - }); - } - } + let poses = horizon_client::end_crystal::poses(model, age, crystal.show_bottom); + // poseStack.scale(2) then translate(0, -0.5, 0), not flipped. + let base = glam::Mat4::from_translation(rel.as_vec3()) + * glam::Mat4::from_scale(glam::Vec3::splat(2.0)) + * glam::Mat4::from_translation(glam::Vec3::new(0.0, -0.5, 0.0)); + horizon_client::mobs::render::draw( + model, + base, + &poses, + uv, + 0xFFFF_FFFF, + packed, + 0, + out, + ); + if let Some(target) = crystal.beam { + // The beam from the target's centre up to the bobbing crystal. + let from = glam::DVec3::new( + f64::from(target[0]) + 0.5, + f64::from(target[1]) + 0.5, + f64::from(target[2]) + 0.5, + ); + let delta = feet - from + + glam::DVec3::new(0.0, f64::from(horizon_client::end_crystal::y(age)), 0.0); + self.crystal_beam(from, delta, age, camera, out); } } } diff --git a/crates/horizon-client/src/lib.rs b/crates/horizon-client/src/lib.rs index d8f9b0766..f91af584a 100644 --- a/crates/horizon-client/src/lib.rs +++ b/crates/horizon-client/src/lib.rs @@ -44,6 +44,7 @@ pub mod datapack; pub mod debug_keys; pub mod effects; pub mod enchant; +pub mod end_crystal; pub mod entities; pub mod entity_nbt; pub mod environment; diff --git a/tools/test_entity_model_parity.py b/tools/test_entity_model_parity.py index 66e33aba8..5298e1cd7 100644 --- a/tools/test_entity_model_parity.py +++ b/tools/test_entity_model_parity.py @@ -78,7 +78,7 @@ EXTRAS = [ # Layers a renderer reuses for another entity under a different constant. SKIP_LAYERS = re.compile(r'(banner|bell|book|skull|head|chest|shulker_box|boat|cushion|conduit|leash|arrow|trident|' r'shield|elytra|spin_attack|ears|cape|decorated_pot|minecart|wind_charge|evoker_fangs|' - r'llama_spit|shulker_bullet|bee_stinger|end_crystal|armor_stand|copper_golem_\w+|#(helmet|chestplate|leggings|' + r'llama_spit|shulker_bullet|bee_stinger|armor_stand|copper_golem_\w+|#(helmet|chestplate|leggings|' r'boots|outer|armor|decor|saddle|collar|wool|wool_undercoat|eyes|wind|inner|pattern|tendrils|' r'heart|bioluminescent|pulsating_spots|water_patch|flag|cage|shell)$)') @@ -249,6 +249,8 @@ SPECIES = { 'frog': [{'isSwimming': T}, {'isSwimming': F}, {'jumpAnimationState': 2}, {'croakAnimationState': 1}, {'tongueAnimationState': 3}, {'swimIdleAnimationState': 2, 'isSwimming': T}], 'rabbit': [{'hopAnimationState': 2}, {'idleHeadTiltAnimationState': 1}], + # EndCrystalModel (not a mob): the base hidden for a placed crystal. + 'end_crystal': [{'showsBottom': F}, {'showsBottom': F, 'ageInTicks': 91234.5}], 'fox': FOX, # CopperGolemModel: the idle head spin and the four chest interactions (started N ticks ago). 'copper_golem': [{'idleAnimationState': 4}, {'idleAnimationState': 37}, {'interactionGetItem': 3}, @@ -266,7 +268,7 @@ SPECIES = { DEFAULTS = {'creaking': {'canMove': T}, 'wolf': {'tailAngle': 0.6283185307179586}, 'axolotl': {'inWaterFactor': 1.0}, 'bee': {'hasStinger': T}, 'sheep': {'eatTick': 0}, 'goat': {'hasLeftHorn': T, 'hasRightHorn': T}, 'parrot': {'pose': 'STANDING'}, 'phantom': {'flapOffset': 21.0}, 'guardian': {'tailAnimation': 1.3, 'spikesAnimation': 1.0}, - 'elder_guardian': {'tailAnimation': 1.3, 'spikesAnimation': 1.0}} + 'elder_guardian': {'tailAnimation': 1.3, 'spikesAnimation': 1.0}, 'end_crystal': {'showsBottom': T}} def species_cases(layer, base_cases):