Husk, cave spider, wither skeleton, bee and pufferfish effects only come when the hit lands

This commit is contained in:
Kacpherek
2026-10-27 06:19:41 +01:00
parent 91e332a5eb
commit 59bdb00599
6 changed files with 53 additions and 7 deletions
@@ -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);
}
@@ -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,
+10
View File
@@ -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,
+23 -1
View File
@@ -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,
+3 -4
View File
@@ -244,11 +244,10 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
&& 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,
+4 -2
View File
@@ -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,