Merge pull request #2142 from kacpherek/fix/mob-damage-difficulty-scaling

🤖 Agent: Gate check by Ludovic's AI agent (Claude). Checked against 26.3: `Player.hurtServer` scales damage that `scalesWithDifficulty` from a living non-player: none on Peaceful, `min(d / 2 + 1, d)` on Easy, `d * 3 / 2` on Hard (so a creeper's blast scales, and TNT a player lit doesn't). 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:
Ludovic Marie
2026-10-26 19:14:06 +01:00
committed by GitHub
4 changed files with 33 additions and 4 deletions
+5 -1
View File
@@ -1520,15 +1520,19 @@ impl Game<'_> {
if let Some(a) = attacker.or(owner) {
self.note_attacker(damage_type, a);
}
// DamageSource.scalesWithDifficulty: a mob (or its projectile's
// owner) caused the hit, not a player.
let living_cause = attacker.or(owner).is_some();
let mut outcome = horizon_client::health::BlockOutcome::default();
if let Some(player) = self.player.as_mut()
&& let Some(id) = self.motion.health.damage.id(damage_type)
&& let Ok(o) = player.hurt_blocking(
&& let Ok(o) = player.hurt_caused_by(
&self.motion.health,
self.world.health_rules,
id,
amount,
blocking,
living_cause,
)
&& {
outcome = o;
+3 -1
View File
@@ -296,12 +296,14 @@ impl Game<'_> {
if !creative
&& !spectator
&& hurtable
&& let Ok(o) = p.hurt_blocking(
&& let Ok(o) = p.hurt_caused_by(
&self.motion.health,
self.world.health_rules,
id,
amount,
blocking,
// The exploding mob is the causing entity.
exploding.is_some(),
)
{
outcome = o;
+24 -2
View File
@@ -295,6 +295,20 @@ impl PlayerMotion {
source: DamageTypeId,
amount: f32,
blocking: Option<Blocking>,
) -> Result<BlockOutcome> {
self.hurt_caused_by(resources, rules, source, amount, blocking, false)
}
/// `hurt_blocking` from a source whose causing entity is a living
/// non-player (`living_cause`), which the `when_caused_by_living_non_player`
/// damage types scale with the difficulty.
pub fn hurt_caused_by(
&mut self,
resources: &HealthResources,
rules: HealthRules,
source: DamageTypeId,
amount: f32,
blocking: Option<Blocking>,
living_cause: bool,
) -> Result<BlockOutcome> {
if self.client_side {
return Ok(BlockOutcome::default());
@@ -315,6 +329,7 @@ impl PlayerMotion {
invulnerable,
rules,
source,
living_cause,
events: &mut self.events,
dead: &mut h.dead,
sync_velocity: &mut h.sync_velocity,
@@ -390,6 +405,8 @@ pub(crate) struct Environment<'a> {
pub(crate) invulnerable: bool,
pub(crate) rules: HealthRules,
pub(crate) source: DamageSource<'a, ()>,
/// The causing entity is a living non-player (a mob, or its projectile's owner).
pub(crate) living_cause: bool,
pub(crate) events: &'a mut Vec<MotionEvent>,
pub(crate) dead: &'a mut bool,
pub(crate) sync_velocity: &'a mut bool,
@@ -773,8 +790,13 @@ impl PlayerHurtWorld for Environment<'_> {
Ok(())
}
fn scales_with_difficulty(&mut self, _: &mut State) -> io::Result<bool> {
Ok(self.source.definition().scaling == Scaling::Always)
} // no causing entity
// DamageSource.scalesWithDifficulty.
Ok(match self.source.definition().scaling {
Scaling::Never => false,
Scaling::Always => true,
Scaling::LivingNonPlayer => self.living_cause,
})
}
fn difficulty(&mut self, _: &mut State) -> io::Result<Difficulty> {
Ok(self.rules.difficulty)
}
+1
View File
@@ -151,6 +151,7 @@ impl FoodWorld for TickWorld<'_> {
.damage
.source::<()>(id, None, None, None)
.expect("validated starvation source"),
living_cause: false,
events: self.events,
dead: self.dead,
sync_velocity: self.sync_velocity,