From 372f918e44a14f984e1359001d4285a5ed3958ef Mon Sep 17 00:00:00 2001 From: socksprox Date: Sun, 25 Oct 2026 01:18:53 +0200 Subject: [PATCH 1/5] Multiplayer: keep firework flight duration, boost gliding players Two halves of FireworkRocketEntity on a server were missing: - SetCreativeModeSlot encoded only damage, so a creative-picked rocket lost its minecraft:fireworks component (flight_duration and explosions gone); the wire codec also had no decoder for it or firework_explosion, so a stack carrying them failed to decode at all. The components now follow Fireworks.STREAM_CODEC/FireworkExplosion.STREAM_CODEC both ways (component ids 71/70). - A remote rocket never read DATA_ATTACHED_TO_TARGET, DATA_ID_FIREWORKS_ITEM or DATA_SHOT_AT_ANGLE, so the server-attached boost rocket was an inert marker: attached_to now comes from EntityDataSerializers.OPTIONAL_UNSIGNED_INT (the id plus one), the item feeds the explosion list, and FireworkRocketEntity.tick's isFallFlying boost applies to the local player. Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- crates/horizon-client/src/game/fireworks.rs | 9 +- crates/horizon-client/src/game/remote.rs | 48 +++++++++ .../src/game/remote_projectiles.rs | 54 +++++++++- crates/horizon-protocol/src/item.rs | 99 +++++++++++++++++++ 4 files changed, 207 insertions(+), 3 deletions(-) diff --git a/crates/horizon-client/src/game/fireworks.rs b/crates/horizon-client/src/game/fireworks.rs index 85fccc2de..a0aa276b7 100644 --- a/crates/horizon-client/src/game/fireworks.rs +++ b/crates/horizon-client/src/game/fireworks.rs @@ -25,9 +25,12 @@ pub(super) struct Rocket { pub(super) velocity: Vec3, life: i32, lifetime: i32, - explosions: Vec, + pub(super) explosions: Vec, /// Boosting the player (attachedToEntity). pub(super) attached: bool, + /// `DATA_ATTACHED_TO_TARGET`: the server entity the rocket follows; + /// boosting happens when it is the local player. + pub(super) attached_to: Option, /// `DATA_SHOT_AT_ANGLE` (dispensers): constant velocity, exploding on /// the first block it hits. pub(super) angled: bool, @@ -48,6 +51,7 @@ impl Rocket { lifetime: i32::MAX, explosions, attached: false, + attached_to: None, angled: false, item, } @@ -63,7 +67,7 @@ impl Rocket { (self.position, self.velocity) } } -fn fireworks_of(stack: &ItemStack) -> (u8, Vec) { +pub(super) fn fireworks_of(stack: &ItemStack) -> (u8, Vec) { // The item's default component: flight 1, no explosions. stack .data() @@ -89,6 +93,7 @@ impl Game<'_> { lifetime, explosions, attached, + attached_to: None, angled: false, item: stack.clone(), } diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 45ba4bebe..29a7ab46f 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -596,6 +596,28 @@ impl Game<'_> { out.tidy(); Some(out) } + /// A wire `FireworkExplosion` as vanilla's NBT codec writes it + /// (`FireworkExplosion.Shape`'s BY_ID order). + fn fireworks_tag(e: &horizon_protocol::item::FireworkExplosion) -> Tag { + const SHAPES: [&str; 5] = ["small_ball", "large_ball", "star", "creeper", "burst"]; + let ints = |c: &[i32]| Tag::List(c.iter().map(|c| Tag::Int(*c)).collect()); + Tag::compound([ + ( + "shape", + Tag::String( + SHAPES + .get(e.shape.max(0) as usize) + .copied() + .unwrap_or("small_ball") + .into(), + ), + ), + ("colors", ints(&e.colors)), + ("fade_colors", ints(&e.fade)), + ("has_trail", Tag::Byte(i8::from(e.trail))), + ("has_twinkle", Tag::Byte(i8::from(e.twinkle))), + ]) + } /// The item's patched components as vanilla's `components` compound. fn protocol_components(&self, s: &Stack) -> Option { use horizon_protocol::item::{Component, component}; @@ -633,6 +655,14 @@ impl Game<'_> { ("pages", Tag::List(b.pages.clone())), ("resolved", Tag::Byte(i8::from(b.resolved))), ]), + Component::Fireworks { flight, explosions } => Tag::compound([ + ("flight_duration", Tag::Byte(*flight as i8)), + ( + "explosions", + Tag::List(explosions.iter().map(Self::fireworks_tag).collect()), + ), + ]), + Component::FireworkExplosion(e) => Self::fireworks_tag(e), Component::Enchantments(list) => { // Enchantments are a synced (data-driven) registry: the // ids index the server's RegistryData, not the builtin @@ -719,6 +749,24 @@ impl Game<'_> { horizon_protocol::item::Component::Int(s.damage as i32), )); } + if let Some((flight, explosions)) = s.data().and_then(|d| d.fireworks.clone()) { + stack.added.push(( + horizon_protocol::item::component::FIREWORKS, + horizon_protocol::item::Component::Fireworks { + flight: i32::from(flight), + explosions: explosions + .iter() + .map(|e| horizon_protocol::item::FireworkExplosion { + shape: e.shape as i32, + colors: e.colors.iter().map(|c| *c as i32).collect(), + fade: e.fade.iter().map(|c| *c as i32).collect(), + trail: e.trail, + twinkle: e.twinkle, + }) + .collect(), + }, + )); + } Some(stack) } /// A line in the connection's chat, with its styles, click and hover diff --git a/crates/horizon-client/src/game/remote_projectiles.rs b/crates/horizon-client/src/game/remote_projectiles.rs index 58f82e3a9..dbf7f3ccf 100644 --- a/crates/horizon-client/src/game/remote_projectiles.rs +++ b/crates/horizon-client/src/game/remote_projectiles.rs @@ -2,7 +2,7 @@ //! end crystals on a server's client (`ClientPacketListener.handleAddEntity` //! and `handleSetEntityData`): the server simulates them, the client draws //! them where it says and interpolates their moves. -use super::{FallingBlock, Game}; +use super::{FallingBlock, Game, fireworks::fireworks_of, view_vector}; use horizon_client::projectiles::{Projectile, ProjectileKind}; use horizon_core::{geometry::Vec3, position::BlockPos}; use horizon_protocol::entity_data::Value; @@ -117,6 +117,37 @@ impl Game<'_> { pub(super) fn remote_projectile_data(&mut self, id: i32, values: &[(u8, i32, Value)]) { let id = id as u32; self.remote_hook_data(id, values); + if self.rockets.iter().any(|r| r.id == id) { + for (index, _, value) in values { + match (index, value) { + // FireworkRocketEntity.DATA_ID_FIREWORKS_ITEM: its + // explosions for `createFireworks`. + (8, Value::Item(stack)) => { + if let Some(stack) = self.to_stack(stack) + && let Some(r) = self.rockets.iter_mut().find(|r| r.id == id) + { + let (_, explosions) = fireworks_of(&stack); + r.explosions = explosions; + r.item = stack; + } + } + // DATA_ATTACHED_TO_TARGET (OptionalInt: the id plus 1). + (9, Value::Id(v)) => { + let v = (*v > 0).then(|| (*v - 1) as u32); + if let Some(r) = self.rockets.iter_mut().find(|r| r.id == id) { + r.attached_to = v; + } + } + // DATA_SHOT_AT_ANGLE. + (10, Value::Bool(a)) => { + if let Some(r) = self.rockets.iter_mut().find(|r| r.id == id) { + r.angled = *a; + } + } + _ => {} + } + } + } if self.potions.has_thrown(id) { // ThrowableItemProjectile.DATA_ITEM_STACK: the potion it is. for (index, _, value) in values { @@ -199,9 +230,30 @@ impl Game<'_> { let id = t.id; t.remote_step(|at| step(id, at)); } + // FireworkRocketEntity.tick: a rocket attached to the gliding local + // player boosts it client-side too (attachedToEntity.isFallFlying). + let me = self + .remote + .as_ref() + .and_then(|r| u32::try_from(r.entity_id).ok()); for r in &mut self.rockets { let id = r.id; r.remote_step(|at| step(id, at)); + if me.is_some() && r.attached_to == me { + if let Some(p) = self.player.as_mut() + && p.fall_flying + { + let look = view_vector(self.yaw, self.pitch); + let m = p.velocity; + p.velocity = Vec3::new( + m.x + look[0] * 0.1 + (look[0] * 1.5 - m.x) * 0.5, + m.y + look[1] * 0.1 + (look[1] * 1.5 - m.y) * 0.5, + m.z + look[2] * 0.1 + (look[2] * 1.5 - m.z) * 0.5, + ); + r.position = p.position; + r.velocity = p.velocity; + } + } } for c in &mut self.crystals { c.time += 1; diff --git a/crates/horizon-protocol/src/item.rs b/crates/horizon-protocol/src/item.rs index 650fa4baa..753fc7349 100644 --- a/crates/horizon-protocol/src/item.rs +++ b/crates/horizon-protocol/src/item.rs @@ -35,6 +35,8 @@ pub mod component { pub const CHARGED_PROJECTILES: i32 = 51; pub const WRITABLE_BOOK_CONTENT: i32 = 56; pub const WRITTEN_BOOK_CONTENT: i32 = 57; + pub const FIREWORK_EXPLOSION: i32 = 70; + pub const FIREWORKS: i32 = 71; } /// A written book's content (`WrittenBookContent.STREAM_CODEC`): the @@ -78,6 +80,48 @@ pub enum Component { WrittenBook(WrittenBook), /// `ChargedProjectiles`: a loaded crossbow's ammunition, as templates. Stacks(Vec), + /// `Fireworks`: flight duration and its explosions. + Fireworks { + flight: i32, + explosions: Vec, + }, + /// `FireworkExplosion` (a firework star). + FireworkExplosion(FireworkExplosion), +} + +/// `FireworkExplosion.STREAM_CODEC`: shape id, colors, fade colors, trail +/// and twinkle (FireworkExplosion.Shape's BY_ID order). +#[derive(Clone, Debug, PartialEq)] +pub struct FireworkExplosion { + pub shape: i32, + pub colors: Vec, + pub fade: Vec, + pub trail: bool, + pub twinkle: bool, +} +impl FireworkExplosion { + fn read(r: &mut Reader) -> Result { + let ints = |r: &mut Reader| -> Result> { + let n = r.count(1024)?; + (0..n).map(|_| r.i32()).collect() + }; + Ok(Self { + shape: r.varint()?, + colors: ints(r)?, + fade: ints(r)?, + trail: r.bool()?, + twinkle: r.bool()?, + }) + } + fn write(&self, w: &mut Writer) { + w.varint(self.shape); + w.varint(self.colors.len() as i32); + self.colors.iter().for_each(|c| w.i32(*c)); + w.varint(self.fade.len() as i32); + self.fade.iter().for_each(|c| w.i32(*c)); + w.bool(self.trail); + w.bool(self.twinkle); + } } /// `Filterable.streamCodec`: the raw value, then an optional filtered one @@ -224,6 +268,17 @@ impl Component { hidden: (0..n).map(|_| r.varint()).collect::>()?, } } + FIREWORKS => { + let flight = r.varint()?; + let n = r.count(256)?; + Self::Fireworks { + flight, + explosions: (0..n) + .map(|_| FireworkExplosion::read(r)) + .collect::>()?, + } + } + FIREWORK_EXPLOSION => Self::FireworkExplosion(FireworkExplosion::read(r)?), other => return Err(Error::new(format!("unsupported item component {other}"))), }) } @@ -294,6 +349,12 @@ impl Component { w.varint(stacks.len() as i32); stacks.iter().for_each(|s| Template::write(s, w)); } + Self::Fireworks { flight, explosions } => { + w.varint(*flight); + w.varint(explosions.len() as i32); + explosions.iter().for_each(|e| e.write(w)); + } + Self::FireworkExplosion(e) => e.write(w), Self::WritableBook(pages) => { w.varint(pages.len() as i32); for page in pages { @@ -544,6 +605,44 @@ mod tests { round::, HashedSlot>(None); } + #[test] + fn fireworks_components_round_trip() { + let mut rocket = Stack::new(42, 1); + rocket.added.push(( + component::FIREWORKS, + Component::Fireworks { + flight: 3, + explosions: vec![ + FireworkExplosion { + shape: 4, + colors: vec![0xff0000, 0x00ff00], + fade: vec![0x0000ff], + trail: true, + twinkle: false, + }, + FireworkExplosion { + shape: 0, + colors: vec![], + fade: vec![], + trail: false, + twinkle: true, + }, + ], + }, + )); + rocket.added.push(( + component::FIREWORK_EXPLOSION, + Component::FireworkExplosion(FireworkExplosion { + shape: 2, + colors: vec![7], + fade: vec![], + trail: false, + twinkle: false, + }), + )); + round::, Slot>(Some(rocket)); + } + #[test] fn charged_projectiles_are_item_stack_templates() { // A crossbow (id 7) loaded with one arrow (id 9): ChargedProjectiles From 90ae953747a746cc32b20bc1cf4cf73cd21ce8c0 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 10:21:48 +0100 Subject: [PATCH 2/5] Rockets: collapse the boost's nested if (clippy::collapsible_if) Verify failed on it with warnings denied. Co-Authored-By: Claude Opus 5.5 --- .../src/game/remote_projectiles.rs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/horizon-client/src/game/remote_projectiles.rs b/crates/horizon-client/src/game/remote_projectiles.rs index dbf7f3ccf..056efa7c3 100644 --- a/crates/horizon-client/src/game/remote_projectiles.rs +++ b/crates/horizon-client/src/game/remote_projectiles.rs @@ -239,20 +239,20 @@ impl Game<'_> { for r in &mut self.rockets { let id = r.id; r.remote_step(|at| step(id, at)); - if me.is_some() && r.attached_to == me { - if let Some(p) = self.player.as_mut() - && p.fall_flying - { - let look = view_vector(self.yaw, self.pitch); - let m = p.velocity; - p.velocity = Vec3::new( - m.x + look[0] * 0.1 + (look[0] * 1.5 - m.x) * 0.5, - m.y + look[1] * 0.1 + (look[1] * 1.5 - m.y) * 0.5, - m.z + look[2] * 0.1 + (look[2] * 1.5 - m.z) * 0.5, - ); - r.position = p.position; - r.velocity = p.velocity; - } + if me.is_some() + && r.attached_to == me + && let Some(p) = self.player.as_mut() + && p.fall_flying + { + let look = view_vector(self.yaw, self.pitch); + let m = p.velocity; + p.velocity = Vec3::new( + m.x + look[0] * 0.1 + (look[0] * 1.5 - m.x) * 0.5, + m.y + look[1] * 0.1 + (look[1] * 1.5 - m.y) * 0.5, + m.z + look[2] * 0.1 + (look[2] * 1.5 - m.z) * 0.5, + ); + r.position = p.position; + r.velocity = p.velocity; } } for c in &mut self.crystals { From 11035336a0115e7fbf4444934500c06ae93c66a4 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 11:24:29 +0100 Subject: [PATCH 3/5] Server: a gliding player's rocket boosts them FireworkRocketItem.use attaches a rocket only to a player who is fall flying. The server tracks a guest's glide (START_FALL_FLYING) but the body it swaps in for their item use left fall_flying unset, so on the server thread, LAN and dedicated servers the rocket did nothing. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/lan_actions.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index d0f16a0d6..e140f31eb 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -264,6 +264,8 @@ impl Game<'_> { motion.sprinting = g.sprinting; motion.may_fly = g.creative() || g.game_mode == SPECTATOR; motion.flying = g.flying; + // FireworkRocketItem.use boosts only a gliding player. + motion.fall_flying = g.fall_flying; motion.invulnerable = motion.may_fly; let _ = motion.set_health(g.health, false); motion.health.food.food = g.food; From e7ca664e01471d6c8e3581c411138d336c1ffff1 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 11:32:23 +0100 Subject: [PATCH 4/5] Server: a guest's boost rocket is theirs The server attached every boosting rocket to its own player: it followed the host, and DATA_ATTACHED_TO_TARGET named the host (or nothing on the server thread, which has none), so the guest's client never saw a rocket attached to them and did not boost. The rocket now keeps the guest it was fired by, follows them and names their entity. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/fireworks.rs | 23 ++++++++++++++++--- .../horizon-client/src/game/lan_entities.rs | 12 ++++++++-- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/crates/horizon-client/src/game/fireworks.rs b/crates/horizon-client/src/game/fireworks.rs index a0aa276b7..623e0e147 100644 --- a/crates/horizon-client/src/game/fireworks.rs +++ b/crates/horizon-client/src/game/fireworks.rs @@ -28,6 +28,9 @@ pub(super) struct Rocket { pub(super) explosions: Vec, /// Boosting the player (attachedToEntity). pub(super) attached: bool, + /// On a server, the player it boosts when not this game's own: a guest's + /// connection. + pub(super) guest: Option, /// `DATA_ATTACHED_TO_TARGET`: the server entity the rocket follows; /// boosting happens when it is the local player. pub(super) attached_to: Option, @@ -51,6 +54,7 @@ impl Rocket { lifetime: i32::MAX, explosions, attached: false, + guest: None, attached_to: None, angled: false, item, @@ -93,6 +97,7 @@ impl Game<'_> { lifetime, explosions, attached, + guest: None, attached_to: None, angled: false, item: stack.clone(), @@ -132,7 +137,8 @@ impl Game<'_> { return false; } let at = self.player.as_ref().map_or(Vec3::ZERO, |p| p.position); - let rocket = self.new_rocket(at, stack, true); + let mut rocket = self.new_rocket(at, stack, true); + rocket.guest = self.lan_acting; self.rockets.push(rocket); if !self.creative { self.consume_held(); @@ -145,7 +151,18 @@ impl Game<'_> { while i < self.rockets.len() { let mut r = self.rockets.remove(i); r.previous = r.position; - if r.attached { + if r.attached + && let Some(conn) = r.guest + { + // A guest's rocket follows them; their own client boosts them. + let guest = self + .lan + .as_ref() + .and_then(|host| host.hub.guests.iter().find(|g| g.conn == conn)); + if let Some(g) = guest { + r.position = Vec3::new(g.position[0], g.position[1], g.position[2]); + } + } else if r.attached { if let Some(p) = self.player.as_mut() { if p.fall_flying { let look = view_vector(self.yaw, self.pitch); @@ -234,7 +251,7 @@ impl Game<'_> { let at = [r.position.x, r.position.y, r.position.z]; if !r.explosions.is_empty() { let damage = 5.0 + r.explosions.len() as f32 * 2.0; - if r.attached { + if r.attached && r.guest.is_none() { self.hurt_player_by("minecraft:fireworks", damage); } let from = r.position; diff --git a/crates/horizon-client/src/game/lan_entities.rs b/crates/horizon-client/src/game/lan_entities.rs index db0c3e8b2..c525c902e 100644 --- a/crates/horizon-client/src/game/lan_entities.rs +++ b/crates/horizon-client/src/game/lan_entities.rs @@ -417,11 +417,19 @@ impl Game<'_> { Value::Item(hub.stack(&Some(r.item.clone()))), )); } + let boosted = match r.guest { + Some(conn) => hub + .guests + .iter() + .find(|g| g.conn == conn) + .map(|g| g.entity_id), + None => host_entity, + }; if r.attached - && let Some(host) = host_entity + && let Some(player) = boosted { e.meta - .push((9, serializer::OPTIONAL_UNSIGNED_INT, Value::Id(host + 1))); + .push((9, serializer::OPTIONAL_UNSIGNED_INT, Value::Id(player + 1))); } if r.angled { e.meta.push((10, serializer::BOOLEAN, Value::Bool(true))); From 9ec5f1ddbc31908eaa27735a01ecd8ba9cf44182 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 19:51:09 +0100 Subject: [PATCH 5/5] Rockets: a guest's boost rocket hurts them; fireworks sent to a server's clients FireworkRocketEntity.dealExplosionDamage hurts attachedToEntity with the full 5 + 2 per explosion: a guest's boost rocket now hurts that guest instead of nobody. The host's encoder (network_stack) now sends minecraft:fireworks and minecraft:firework_explosion too, so a rocket's flight duration and a star's explosion reach the server thread's window, LAN guests and a dedicated server's players; the creative slot encoder shares it. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/fireworks.rs | 15 ++++++-- crates/horizon-client/src/game/remote.rs | 21 +++--------- crates/horizon-client/src/lan/guest.rs | 38 +++++++++++++++++++++ 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/crates/horizon-client/src/game/fireworks.rs b/crates/horizon-client/src/game/fireworks.rs index 623e0e147..7838c9590 100644 --- a/crates/horizon-client/src/game/fireworks.rs +++ b/crates/horizon-client/src/game/fireworks.rs @@ -251,8 +251,19 @@ impl Game<'_> { let at = [r.position.x, r.position.y, r.position.z]; if !r.explosions.is_empty() { let damage = 5.0 + r.explosions.len() as f32 * 2.0; - if r.attached && r.guest.is_none() { - self.hurt_player_by("minecraft:fireworks", damage); + // The player it boosts takes the full damage, a guest as well. + if r.attached { + match r.guest { + None => self.hurt_player_by("minecraft:fireworks", damage), + Some(conn) => { + if let Some(mut host) = self.lan.take() { + self.as_guest(&mut host, conn, |g| { + g.hurt_player_by("minecraft:fireworks", damage); + }); + self.lan = Some(host); + } + } + } } let from = r.position; let hits: Vec<(u32, f32)> = { diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 5a8582ac9..d8b370af4 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -769,23 +769,10 @@ impl Game<'_> { horizon_protocol::item::Component::Int(s.damage as i32), )); } - if let Some((flight, explosions)) = s.data().and_then(|d| d.fireworks.clone()) { - stack.added.push(( - horizon_protocol::item::component::FIREWORKS, - horizon_protocol::item::Component::Fireworks { - flight: i32::from(flight), - explosions: explosions - .iter() - .map(|e| horizon_protocol::item::FireworkExplosion { - shape: e.shape as i32, - colors: e.colors.iter().map(|c| *c as i32).collect(), - fade: e.fade.iter().map(|c| *c as i32).collect(), - trail: e.trail, - twinkle: e.twinkle, - }) - .collect(), - }, - )); + if let Some(d) = s.data() { + stack + .added + .extend(horizon_client::lan::guest::firework_components(d)); } Some(stack) } diff --git a/crates/horizon-client/src/lan/guest.rs b/crates/horizon-client/src/lan/guest.rs index 440b58284..4bafe7866 100644 --- a/crates/horizon-client/src/lan/guest.rs +++ b/crates/horizon-client/src/lan/guest.rs @@ -431,6 +431,43 @@ impl Guest { } } +/// `FireworkExplosion.STREAM_CODEC`'s fields (`Shape` by its BY_ID order). +fn network_explosion( + e: &crate::particles::FireworkExplosion, +) -> horizon_protocol::item::FireworkExplosion { + horizon_protocol::item::FireworkExplosion { + shape: e.shape as i32, + colors: e.colors.iter().map(|c| *c as i32).collect(), + fade: e.fade.iter().map(|c| *c as i32).collect(), + trail: e.trail, + twinkle: e.twinkle, + } +} + +/// A rocket's `minecraft:fireworks` and a star's `minecraft:firework_explosion`. +pub fn firework_components( + d: &crate::item_data::StackData, +) -> Vec<(i32, horizon_protocol::item::Component)> { + use horizon_protocol::item::{Component, component}; + let mut out = Vec::new(); + if let Some((flight, explosions)) = &d.fireworks { + out.push(( + component::FIREWORKS, + Component::Fireworks { + flight: i32::from(*flight), + explosions: explosions.iter().map(network_explosion).collect(), + }, + )); + } + if let Some(e) = &d.firework_explosion { + out.push(( + component::FIREWORK_EXPLOSION, + Component::FireworkExplosion(network_explosion(e)), + )); + } + out +} + /// The off hand slot is conventionally 40 in saves and 45 in the menu. /// `synced_id` names an entry of a synced registry (enchantments, trim /// materials and patterns) by its id on this connection. @@ -521,6 +558,7 @@ fn network_stack( horizon_protocol::item::Component::Int(i32::from(mode)), )); } + stack.added.extend(firework_components(d)); // A loaded crossbow's ammunition. if !d.charged.is_empty() { let charged = d