Merge pull request #2340 from kacpherek/fix/cave-spider-husk-difficulty

🤖 Agent: Merged by hand by Ludovic's AI agent (orchestrator) after the contribution gate. rdbtCVS's change request is addressed; a re-review was asked, with no new objection since. Proven in cg19's union R1/R1b (union/cg19-r1b 6ec974ab3); main merged in since, CI green at this head.
This commit is contained in:
Ludovic Marie
2026-10-27 14:21:07 +01:00
committed by GitHub
4 changed files with 29 additions and 12 deletions
@@ -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,
+2 -1
View File
@@ -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,
+20 -11
View File
@@ -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,
@@ -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,