Run the trident player_hurt_entity trigger as the thrower

This commit is contained in:
Kacpherek
2026-10-26 17:25:37 +01:00
parent 5fa423169f
commit b62095dfcb
+26 -1
View File
@@ -30,6 +30,8 @@ pub(super) struct ThrownTrident {
pub(super) no_physics: bool,
returning: u32,
creative_only: bool,
/// The guest that threw it (`Projectile.getOwner`); `None` for the host.
guest: Option<u32>,
}
impl ThrownTrident {
/// A trident a server sent (`handleAddEntity`): placed and moved by it.
@@ -49,6 +51,7 @@ impl ThrownTrident {
no_physics: false,
returning: 0,
creative_only: false,
guest: None,
}
}
/// One tick of a server's client: the previous position, then `step`.
@@ -240,11 +243,33 @@ impl Game<'_> {
no_physics: false,
returning: 0,
creative_only: self.creative,
guest: self.lan_acting,
});
self.player_projectile_shot();
self.audio
.play("minecraft:item.trident.throw", at, 1.0, 1.0);
}
/// The thrower's `PLAYER_HURT_ENTITY` for a trident hit: run as the
/// guest that threw it, and not at all once they have left.
fn thrower_hit(
&mut self,
guest: Option<u32>,
victim: &horizon_client::advancements::EntityView,
direct: horizon_client::advancements::EntityView,
damage: f32,
) {
let Some(conn) = guest.filter(|c| self.lan_acting != Some(*c)) else {
self.player_hit(victim, "minecraft:trident", Some(direct), damage);
return;
};
let Some(mut host) = self.lan.take() else {
return;
};
self.as_guest(&mut host, conn, |g| {
g.player_hit(victim, "minecraft:trident", Some(direct), damage)
});
self.lan = Some(host);
}
pub(super) fn tick_tridents(&mut self) {
let Some(eye) = self.eye_position() else {
return;
@@ -331,7 +356,7 @@ impl Game<'_> {
position: [t.position.x, t.position.y, t.position.z],
..Default::default()
};
self.player_hit(&victim, "minecraft:trident", Some(direct), damage);
self.thrower_hit(t.guest, &victim, direct, damage);
}
self.audio.play(
"minecraft:item.trident.hit",