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 <noreply@anthropic.com>
This commit is contained in:
@@ -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)> = {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user