Merge pull request #2164 from kacpherek/fix/witch-drinking
🤖 Agent: Gate check by Ludovic's AI agent (Claude). Checked against 26.3: `Witch.aiStep` stands still while drinking (the -0.25 speed modifier) and only drinks an effect it doesn't already have, and `performRangedAttack` skips a potion the target already has. It merges after #2138, since both add fields to `Seen`. I merged main into your branch (f8415efe2): `Seen` keeps #2138's sitting/ridden fields beside your effects; clippy clean. Gate: this wave's 55 PRs merged on main in one tree: clippy `-D warnings` clean, 1186 horizon-client and 163 horizon-world tests pass, and of the 101 harnesses `parity.py --changed-files` picked, 100 pass (`block_removal` failed on one spawner case from #2199's orb merging, fixed there). `lan_e2e.py` passes 24 checks with the host on its server thread and in-frame (chest, xp, pvp, doors, villagers, beds, frames, projectiles, arrows, fishing, damage, mobs, blast, drops, elytra, breath, predict, cracks, barter, kills, hurt, contacts, underwater, plates), plus forced-levels on the server thread. Thanks @kacpherek!
This commit is contained in:
@@ -1057,6 +1057,7 @@ pub fn main() -> horizon_client::Result<()> {
|
||||
velocity: Vec3::ZERO,
|
||||
yaw: 0.0,
|
||||
hero: false,
|
||||
effects: Vec::new(),
|
||||
uuid: PLAYER_UUID,
|
||||
allies: Default::default(),
|
||||
remote: false,
|
||||
|
||||
@@ -193,6 +193,7 @@ impl Game<'_> {
|
||||
velocity: p.velocity,
|
||||
yaw: self.yaw,
|
||||
hero: self.potions.effects.get("hero_of_the_village").is_some(),
|
||||
effects: self.potions.effects.list.iter().map(|e| e.id).collect(),
|
||||
uuid: self.level.player_uuid.unwrap_or_default(),
|
||||
allies: std::sync::Arc::new(self.player_allies()),
|
||||
remote: false,
|
||||
|
||||
@@ -370,6 +370,7 @@ mod tests {
|
||||
velocity: Vec3::ZERO,
|
||||
yaw: 0.0,
|
||||
hero: false,
|
||||
effects: Vec::new(),
|
||||
uuid: [0; 4],
|
||||
allies: Default::default(),
|
||||
remote: false,
|
||||
|
||||
@@ -1278,6 +1278,14 @@ pub struct Seen {
|
||||
pub sitting: bool,
|
||||
/// `Entity.isVehicle` or `isPassenger`.
|
||||
pub ridden: bool,
|
||||
/// The active effects, without namespace (`slowness`, `poison`...).
|
||||
pub effects: Vec<&'static str>,
|
||||
}
|
||||
impl Seen {
|
||||
/// `LivingEntity.hasEffect`, by id without namespace.
|
||||
pub fn has_effect(&self, effect: &str) -> bool {
|
||||
self.effects.contains(&effect)
|
||||
}
|
||||
}
|
||||
impl Mob {
|
||||
pub fn burning_time(&self) -> f64 {
|
||||
@@ -1352,6 +1360,12 @@ impl Mob {
|
||||
],
|
||||
sitting: m.extra.sitting,
|
||||
ridden: m.rider.is_some() || m.extra.rider.is_some() || m.extra.mount.is_some(),
|
||||
effects: m
|
||||
.extra
|
||||
.effects
|
||||
.iter()
|
||||
.map(|e| e.0.trim_start_matches("minecraft:"))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
/// `EntityType.getCategory`'s name.
|
||||
@@ -1496,6 +1510,8 @@ pub struct PlayerView {
|
||||
pub yaw: f32,
|
||||
/// The Hero of the Village effect.
|
||||
pub hero: bool,
|
||||
/// The active effects, without namespace (`slowness`, `poison`...).
|
||||
pub effects: Vec<&'static str>,
|
||||
/// The player's UUID (villagers' gossip is keyed by it).
|
||||
pub uuid: [i32; 4],
|
||||
/// The mobs on the player's team (`isAlliedTo`): combat targeting
|
||||
@@ -1505,6 +1521,12 @@ pub struct PlayerView {
|
||||
/// (`EntitySelector.pushableBy` on the client).
|
||||
pub remote: bool,
|
||||
}
|
||||
impl PlayerView {
|
||||
/// `LivingEntity.hasEffect`, by id without namespace.
|
||||
pub fn has_effect(&self, effect: &str) -> bool {
|
||||
self.effects.contains(&effect)
|
||||
}
|
||||
}
|
||||
#[derive(Clone)]
|
||||
pub struct MobWorld<'a> {
|
||||
pub world: &'a World,
|
||||
@@ -1880,7 +1902,8 @@ impl Mob {
|
||||
/// Movement speed attribute bonus (baby zombies, sprinting modifiers).
|
||||
/// MOVEMENT_SPEED including effects (speed +20%/level, slowness -15%/level).
|
||||
pub fn movement_speed(&self) -> f64 {
|
||||
let mut v = strider::movement_speed(self, self.attrs.speed) * self.speed_bonus();
|
||||
let mut v = strider::movement_speed(self, witch::speed(self, self.attrs.speed))
|
||||
* self.speed_bonus();
|
||||
for (e, _, amp) in &self.extra.effects {
|
||||
match *e {
|
||||
"minecraft:speed" => v *= 1.0 + 0.2 * f64::from(amp + 1),
|
||||
|
||||
@@ -193,6 +193,11 @@ fn witch_attack(m: &mut Mob, who: Who, _power: f32, cx: &mut Cx) {
|
||||
}
|
||||
Who::Player => false,
|
||||
};
|
||||
// `target.hasEffect`: a target that already has the effect gets the next one.
|
||||
let has = |effect: &str| match who {
|
||||
Who::Player => cx.w.player.as_ref().is_some_and(|p| p.has_effect(effect)),
|
||||
Who::Mob(id) => cx.w.seen(id).is_some_and(|s| s.has_effect(effect)),
|
||||
};
|
||||
let (effect, ticks, amplifier) = if heals {
|
||||
m.ai.target = None;
|
||||
if health <= 4.0 {
|
||||
@@ -200,11 +205,11 @@ fn witch_attack(m: &mut Mob, who: Who, _power: f32, cx: &mut Cx) {
|
||||
} else {
|
||||
("minecraft:regeneration", 900, 0)
|
||||
}
|
||||
} else if dist >= 8.0 {
|
||||
} else if dist >= 8.0 && !has("slowness") {
|
||||
("minecraft:slowness", 1800, 0)
|
||||
} else if health >= 8.0 {
|
||||
} else if health >= 8.0 && !has("poison") {
|
||||
("minecraft:poison", 900, 0)
|
||||
} else if dist <= 3.0 && m.random.next_float() < 0.25 {
|
||||
} else if dist <= 3.0 && !has("weakness") && m.random.next_float() < 0.25 {
|
||||
("minecraft:weakness", 1800, 0)
|
||||
} else {
|
||||
("minecraft:instant_damage", 1, 0)
|
||||
@@ -236,6 +241,15 @@ fn witch_attack(m: &mut Mob, who: Who, _power: f32, cx: &mut Cx) {
|
||||
pitch,
|
||||
));
|
||||
}
|
||||
/// The movement speed of a witch with `SPEED_MODIFIER_DRINKING` (-0.25,
|
||||
/// `ADD_VALUE`) while it drinks: it stands still for the 32 ticks.
|
||||
pub fn speed(m: &Mob, base: f64) -> f64 {
|
||||
if m.species() == Species::Witch && m.extra.flag {
|
||||
(base - 0.25).max(0.0)
|
||||
} else {
|
||||
base
|
||||
}
|
||||
}
|
||||
/// Witch.aiStep before `super.aiStep()`: the healing cooldown, then drink
|
||||
/// water breathing, fire resistance, healing or swiftness.
|
||||
pub fn ai_step(m: &mut Mob, cx_events: &mut Vec<MobEvent>, target_far: bool) {
|
||||
|
||||
Reference in New Issue
Block a user