diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 225948e31..5f8df671e 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -587,6 +587,9 @@ impl Game<'_> { ..base.clone() }; let m = &mut mobs[i]; + // getCurrentDifficultyAt(blockPosition()): the mob's own chunk, + // not the local player's (a server thread has no player). + w.difficulty = self.local_difficulty([m.position.x, m.position.y, m.position.z]); w.nearest_player = super::natural_spawning::nearest_player( &players, m.position.x, diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rs index 731dccb09..93b70695f 100644 --- a/crates/horizon-client/src/mobs.rs +++ b/crates/horizon-client/src/mobs.rs @@ -1676,7 +1676,8 @@ pub struct MobWorld<'a> { pub mob_griefing: bool, /// The `mob_drops` game rule (`shouldDropLoot`). pub mob_drops: bool, - /// `getCurrentDifficultyAt` near the player. + /// `getCurrentDifficultyAt` at the mob being ticked (near the player + /// outside the mob tick). pub difficulty: spawning::LocalDifficulty, /// The End (its dimension type's monster spawn light rules). pub end: bool, diff --git a/crates/horizon-client/src/mobs/ai.rs b/crates/horizon-client/src/mobs/ai.rs index ad130ea68..f13992f43 100644 --- a/crates/horizon-client/src/mobs/ai.rs +++ b/crates/horizon-client/src/mobs/ai.rs @@ -1556,17 +1556,26 @@ pub fn do_hurt_target(m: &mut Mob, who: Who, cx: &mut Cx) { let from = [m.position.x, m.position.y, m.position.z]; let source = Damage::mob(m.id, from); match m.species() { - // Difficulty NORMAL: cave spiders poison for 7 seconds. - Species::CaveSpider if who == Who::Player => cx.events.push(MobEvent::EffectPlayer { - effect: "minecraft:poison", - ticks: 7 * 20, - amplifier: 0, - }), - Species::Husk if who == Who::Player => cx.events.push(MobEvent::EffectPlayer { - effect: "minecraft:hunger", - ticks: 140, - amplifier: 0, - }), + // CaveSpider.doHurtTarget: poison for 7 s on normal, 15 s on hard. + Species::CaveSpider if who == Who::Player && cx.w.difficulty.base >= 2 => { + cx.events.push(MobEvent::EffectPlayer { + effect: "minecraft:poison", + ticks: if cx.w.difficulty.base == 2 { 7 } else { 15 } * 20, + amplifier: 0, + }) + } + // Husk.doHurtTarget: hunger for 140 ticks per whole point of the + // local difficulty, only with an empty main hand. + Species::Husk if who == Who::Player && m.extra.main_hand.is_none() => { + let ticks = 140 * cx.w.difficulty.effective as i32; + if ticks > 0 { + cx.events.push(MobEvent::EffectPlayer { + effect: "minecraft:hunger", + ticks, + amplifier: 0, + }) + } + } Species::WitherSkeleton if who == Who::Player => cx.events.push(MobEvent::EffectPlayer { effect: "minecraft:wither", ticks: 200, diff --git a/crates/horizon-client/src/mobs/spawning.rs b/crates/horizon-client/src/mobs/spawning.rs index 3cce491ef..9f9fbe705 100644 --- a/crates/horizon-client/src/mobs/spawning.rs +++ b/crates/horizon-client/src/mobs/spawning.rs @@ -34,6 +34,8 @@ pub fn placement_ok(species: Species, w: &MobWorld, x: i32, y: i32, z: i32) -> b /// `DifficultyInstance`: the local difficulty at a position. #[derive(Clone, Copy, Debug)] pub struct LocalDifficulty { + /// The world difficulty id, 0 peaceful to 3 hard. + pub base: u8, pub effective: f32, /// The world difficulty is normal. pub normal: bool, @@ -52,6 +54,7 @@ impl LocalDifficulty { let normal = base == 2; if base == 0 { return Self { + base, effective: 0.0, normal, hard, @@ -66,6 +69,7 @@ impl LocalDifficulty { local *= 0.5; } Self { + base, effective: f32::from(base) * (0.75 + global + local), normal, hard,