diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 2bc40a7af..bd32153d5 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -961,6 +961,18 @@ impl Game<'_> { MobEvent::AttackPlayer(amount, from) => { self.mob_hits_player(amount, from, "minecraft:mob_attack"); } + // doHurtTarget: the effect only when hurtServer took damage. + MobEvent::AttackPlayerWithEffect { + amount, + from, + effect, + ticks, + amplifier, + } => { + if self.mob_hits_player(amount, from, "minecraft:mob_attack") { + self.give_player_effect(effect, ticks, amplifier); + } + } MobEvent::DamagePlayer { amount, from, kind } => { self.mob_hits_player(amount, from, kind); } diff --git a/crates/horizon-client/src/game/lan_mobs.rs b/crates/horizon-client/src/game/lan_mobs.rs index 6527f1015..f9d997452 100644 --- a/crates/horizon-client/src/game/lan_mobs.rs +++ b/crates/horizon-client/src/game/lan_mobs.rs @@ -65,6 +65,7 @@ pub(super) fn acts_on_player(e: &MobEvent) -> bool { matches!( e, MobEvent::AttackPlayer(..) + | MobEvent::AttackPlayerWithEffect { .. } | MobEvent::DamagePlayer { .. } | MobEvent::Push { target: Who::Player, diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rs index 2325c3f5b..ef93a2ff4 100644 --- a/crates/horizon-client/src/mobs.rs +++ b/crates/horizon-client/src/mobs.rs @@ -968,6 +968,16 @@ pub enum MobEvent { state: horizon_world::registry::BlockStateId, }, AttackPlayer(f32, [f64; 3]), + /// A melee hit whose effect comes only if the hit lands (husk hunger, + /// cave spider poison, wither skeleton wither, bee and pufferfish + /// poison): a shield-blocked hit gives nothing. + AttackPlayerWithEffect { + amount: f32, + from: [f64; 3], + effect: &'static str, + ticks: i32, + amplifier: i32, + }, /// Damage of a given type to the player (guardian lasers, thorns). DamagePlayer { amount: f32, diff --git a/crates/horizon-client/src/mobs/ai.rs b/crates/horizon-client/src/mobs/ai.rs index 26b94eeac..0bd93d151 100644 --- a/crates/horizon-client/src/mobs/ai.rs +++ b/crates/horizon-client/src/mobs/ai.rs @@ -1419,6 +1419,7 @@ pub fn do_hurt_target(m: &mut Mob, who: Who, cx: &mut Cx) { let mut amount = m.attrs.attack_damage; let from = [m.position.x, m.position.y, m.position.z]; let source = Damage::mob(m.id, from); + let first_event = cx.events.len(); match m.species() { // Difficulty NORMAL: cave spiders poison for 7 seconds. Species::CaveSpider if who == Who::Player => cx.events.push(MobEvent::EffectPlayer { @@ -1480,7 +1481,28 @@ pub fn do_hurt_target(m: &mut Mob, who: Who, cx: &mut Cx) { }); } match who { - Who::Player => cx.events.push(MobEvent::AttackPlayer(amount, from)), + // The effect picked above goes with the hit: it applies only when + // the player takes damage (a shield-blocked hit gives none). + Who::Player => { + let effect = cx.events[first_event..] + .iter() + .position(|e| matches!(e, MobEvent::EffectPlayer { .. })) + .map(|k| cx.events.remove(first_event + k)); + cx.events.push(match effect { + Some(MobEvent::EffectPlayer { + effect, + ticks, + amplifier, + }) => MobEvent::AttackPlayerWithEffect { + amount, + from, + effect, + ticks, + amplifier, + }, + _ => MobEvent::AttackPlayer(amount, from), + }); + } Who::Mob(id) => cx.events.push(MobEvent::AttackMob { target: id, amount, diff --git a/crates/horizon-client/src/mobs/aquatic.rs b/crates/horizon-client/src/mobs/aquatic.rs index f63a42239..3f42ddd31 100644 --- a/crates/horizon-client/src/mobs/aquatic.rs +++ b/crates/horizon-client/src/mobs/aquatic.rs @@ -244,11 +244,10 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec) { && m.ai.no_action_time % 10 == 0 { let amount = 1.0 + m.extra.size as f32; - events.push(MobEvent::AttackPlayer( + // Only when the sting hurt the player. + events.push(MobEvent::AttackPlayerWithEffect { amount, - [m.position.x, m.position.y, m.position.z], - )); - events.push(MobEvent::EffectPlayer { + from: [m.position.x, m.position.y, m.position.z], effect: "minecraft:poison", ticks: 60 * m.extra.size, amplifier: 0, diff --git a/crates/horizon-client/src/mobs/bee.rs b/crates/horizon-client/src/mobs/bee.rs index 27d8e7c84..330625fb0 100644 --- a/crates/horizon-client/src/mobs/bee.rs +++ b/crates/horizon-client/src/mobs/bee.rs @@ -322,9 +322,11 @@ pub fn sting(m: &mut Mob, who: Who, cx: &mut Cx) { let amount = (m.attrs.attack_damage as i32) as f32; match who { Who::Player => { - cx.events.push(MobEvent::AttackPlayer(amount, from)); + // Bee.doHurtTarget: the poison only when the sting hurt. let seconds = if cx.w.difficulty.hard { 18 } else { 10 }; - cx.events.push(MobEvent::EffectPlayer { + cx.events.push(MobEvent::AttackPlayerWithEffect { + amount, + from, effect: "minecraft:poison", ticks: seconds * 20, amplifier: 0,