From cf67db1873454886a542be9f8dbecc0a977b0b67 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 15 Oct 2026 07:30:59 +0200 Subject: [PATCH] Render firework rockets as their lit item model like vanilla FireworkEntityRenderer submits the rocket's item in the GROUND context, turned to the camera (and over on its side when shot at an angle), at the packed light of its eye. Horizon drew a flat 0.5-block sprite at full brightness, so rockets glowed at night and had no item shading. Fixes #279 Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game.rs | 30 +++++----- crates/horizon-client/src/game/fireworks.rs | 62 ++++++++++----------- 2 files changed, 45 insertions(+), 47 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 45068c9d6..d28e7073f 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -4955,6 +4955,22 @@ impl Game<'_> { f.input_clicked(&self.res.recipes, before); } } + /// `Camera.setRotation`: the camera's orientation, turned round in + /// third-person front view. + pub(super) fn camera_orientation(&self) -> glam::Quat { + let (view_yaw, view_pitch) = + if self.camera_type == perspective::CameraType::ThirdPersonFront { + (self.yaw + 180.0, -self.pitch) + } else { + (self.yaw, self.pitch) + }; + glam::Quat::from_euler( + glam::EulerRot::YXZ, + std::f32::consts::PI - view_yaw.to_radians(), + -view_pitch.to_radians(), + 0.0, + ) + } /// ItemEntityRenderer: items bob and spin; blocks render as small cubes. fn entity_geometry( &mut self, @@ -5105,21 +5121,9 @@ impl Game<'_> { if let Some(r) = &self.renderer { let lid = |p: [i32; 3]| self.chest_lid(p, alpha as f32); let anim = |p: [i32; 3]| self.block_anim(p, alpha as f32); - let (view_yaw, view_pitch) = - if self.camera_type == perspective::CameraType::ThirdPersonFront { - (self.yaw + 180.0, -self.pitch) - } else { - (self.yaw, self.pitch) - }; let scene = horizon_client::block_entity_render::Scene { camera, - // Camera.setRotation. - orientation: glam::Quat::from_euler( - glam::EulerRot::YXZ, - std::f32::consts::PI - view_yaw.to_radians(), - -view_pitch.to_radians(), - 0.0, - ), + orientation: self.camera_orientation(), anim: &anim, texts: None, partial: alpha as f32, diff --git a/crates/horizon-client/src/game/fireworks.rs b/crates/horizon-client/src/game/fireworks.rs index 79ddd562a..cd4e01a16 100644 --- a/crates/horizon-client/src/game/fireworks.rs +++ b/crates/horizon-client/src/game/fireworks.rs @@ -2,8 +2,10 @@ //! from a block face, boosting a gliding player, the 1.15 horizontal //! acceleration and 0.04 lift, the flight-duration lifetime, explosion //! damage with line of sight, and the client explosion (`createFireworks`). -use super::{Game, Hit, view_vector}; +use super::{Game, Hit, item_draw::owner_at, view_vector}; +use horizon_assets::item_model::DisplayContext; use horizon_client::{ + block_entity_render::vertex_light, collisions::SceneCollisions, items::ItemStack, mesher::Vertex, @@ -27,7 +29,8 @@ pub(super) struct Rocket { /// `DATA_SHOT_AT_ANGLE` (dispensers): constant velocity, exploding on /// the first block it hits. angled: bool, - icon: Option, + /// `DATA_ID_FIREWORKS_ITEM`: the stack it was launched from. + item: ItemStack, } impl Rocket { /// Position and motion (the dispenser parity fixture). @@ -61,7 +64,7 @@ impl Game<'_> { explosions, attached, angled: false, - icon: Some("item/firework_rocket".into()), + item: stack.clone(), } } /// `FireworkRocketItem.useOn`: launch from the clicked point. @@ -244,44 +247,35 @@ impl Game<'_> { self.particles .fireworks(at, v, r.explosions.clone(), camera); } + /// `FireworkEntityRenderer.submit`: the item (GROUND) facing the camera, + /// lit at the rocket's light probe. pub(super) fn rocket_geometry(&self, camera: glam::DVec3, alpha: f64, out: &mut Vec) { - let forward = glam::DVec3::from_array(view_vector(self.yaw, self.pitch)); - let right = forward.cross(glam::DVec3::Y).normalize_or_zero(); - let up = right.cross(forward).normalize_or_zero(); + let orientation = glam::Mat4::from_quat(self.camera_orientation()); for r in self.rockets.iter().filter(|r| !r.attached) { - let Some(s) = r - .icon - .as_ref() - .and_then(|n| self.res.atlas.sprites.get(n)) - .copied() - else { - continue; - }; let p = glam::DVec3::new( r.previous.x + (r.position.x - r.previous.x) * alpha, r.previous.y + (r.position.y - r.previous.y) * alpha, r.previous.z + (r.position.z - r.previous.z) * alpha, - ) - camera; - let h = 0.25; - let c = [ - p - right * h - up * h, - p + right * h - up * h, - p + right * h + up * h, - p - right * h + up * h, - ]; - for (v, uv) in c - .iter() - .zip([[s.u0, s.v1], [s.u1, s.v1], [s.u1, s.v0], [s.u0, s.v0]]) - { - out.push(Vertex { - normal: [0; 4], - pos: v.as_vec3().to_array(), - uv, - layer: 0, - color: 0xFFFF_FFFF, - light: 240 | 240 << 8, - }); + ); + // `updateForNonLiving`: GROUND, owned by the rocket. + let owner = owner_at(p.to_array(), 0.0, "minecraft:firework_rocket"); + let state = self.resolve_item(&r.item, DisplayContext::Ground, Some(&owner), 0); + if state.is_empty() { + continue; } + let mut pose = glam::Mat4::from_translation((p - camera).as_vec3()) * orientation; + if r.angled { + pose *= glam::Mat4::from_rotation_z(std::f32::consts::PI) + * glam::Mat4::from_rotation_y(std::f32::consts::PI) + * glam::Mat4::from_rotation_x(std::f32::consts::FRAC_PI_2); + } + // getLightProbePosition: the eye, 0.85 of its 0.25 height. + let light = self.world.light( + p.x.floor() as i32, + (p.y + 0.2125).floor() as i32, + p.z.floor() as i32, + ); + self.submit_item_world(&state, pose, vertex_light(light), out); } } }