Scale mob damage to players with the difficulty

Damage types marked when_caused_by_living_non_player now scale when a mob
(or the owner of its projectile, or an exploding mob) caused the hit.
This commit is contained in:
Kacpherek
2026-10-26 13:43:51 +01:00
parent aea0df9770
commit aec3b7e262
4 changed files with 33 additions and 4 deletions
+5 -1
View File
@@ -1509,15 +1509,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,