Merge pull request #2646 from kacpherek/fix/2630-husk-hunger-shield
🤖 Agent: Proven in union R1 (branch union/cg19-r1, main + 83 of kacpherek's PRs): the 98 harnesses it can affect, clippy -D warnings, tests, lan_e2e in-frame and on the server thread.
This commit is contained in:
@@ -567,7 +567,9 @@ fn print_heart(
|
||||
/// The damage of a mob's direct hit on the player (others count as none).
|
||||
fn player_damage(e: &MobEvent) -> f32 {
|
||||
match e {
|
||||
MobEvent::AttackPlayer(amount, _) | MobEvent::DamagePlayer { amount, .. } => *amount,
|
||||
MobEvent::AttackPlayer(amount, _)
|
||||
| MobEvent::AttackPlayerWithEffect { amount, .. }
|
||||
| MobEvent::DamagePlayer { amount, .. } => *amount,
|
||||
_ => 0.0,
|
||||
}
|
||||
}
|
||||
@@ -578,7 +580,9 @@ fn player_hurt(player: Option<&PlayerView>, e: &MobEvent) -> bool {
|
||||
return false;
|
||||
};
|
||||
match e {
|
||||
MobEvent::AttackPlayer(amount, _) | MobEvent::DamagePlayer { amount, .. } => *amount > 0.0,
|
||||
MobEvent::AttackPlayer(amount, _)
|
||||
| MobEvent::AttackPlayerWithEffect { amount, .. }
|
||||
| MobEvent::DamagePlayer { amount, .. } => *amount > 0.0,
|
||||
// ServerExplosion.hurtEntities: within twice the radius every hit does damage.
|
||||
MobEvent::Explode(at, radius, _) => {
|
||||
let d = Vec3::new(at[0], at[1], at[2])
|
||||
|
||||
@@ -1044,6 +1044,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);
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ pub(super) fn acts_on_player(e: &MobEvent) -> bool {
|
||||
matches!(
|
||||
e,
|
||||
MobEvent::AttackPlayer(..)
|
||||
| MobEvent::AttackPlayerWithEffect { .. }
|
||||
| MobEvent::DamagePlayer { .. }
|
||||
| MobEvent::Push {
|
||||
target: Who::Player,
|
||||
|
||||
@@ -1011,6 +1011,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,
|
||||
|
||||
@@ -1602,6 +1602,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() {
|
||||
// CaveSpider.doHurtTarget: poison for 7 s on normal, 15 s on hard.
|
||||
Species::CaveSpider if who == Who::Player && cx.w.difficulty.base >= 2 => {
|
||||
@@ -1672,7 +1673,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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -333,19 +333,23 @@ 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));
|
||||
// Poison only on normal (10 s) and hard (18 s).
|
||||
// Bee.doHurtTarget: the poison only when the sting hurt, and
|
||||
// only on normal (10 s) and hard (18 s).
|
||||
let seconds = match cx.w.difficulty.id {
|
||||
2 => 10,
|
||||
3 => 18,
|
||||
_ => 0,
|
||||
};
|
||||
if seconds > 0 {
|
||||
cx.events.push(MobEvent::EffectPlayer {
|
||||
cx.events.push(MobEvent::AttackPlayerWithEffect {
|
||||
amount,
|
||||
from,
|
||||
effect: "minecraft:poison",
|
||||
ticks: seconds * 20,
|
||||
amplifier: 0,
|
||||
});
|
||||
} else {
|
||||
cx.events.push(MobEvent::AttackPlayer(amount, from));
|
||||
}
|
||||
}
|
||||
Who::Mob(id) => cx.events.push(MobEvent::AttackMob {
|
||||
|
||||
Reference in New Issue
Block a user