Show the enchanted hit when a melee weapon's enchantments add damage
Player.attack shows magic crit particles whenever the enchantments added damage. Horizon showed only the critical hit, for the window's player and for a guest's attack.
This commit is contained in:
@@ -1658,7 +1658,7 @@ struct Game<'a> {
|
||||
lan_block_events: Vec<([i32; 3], i32, i32, u32)>,
|
||||
lan_entity_events: Vec<(i32, i8, [f64; 3])>,
|
||||
/// Successful crits (attacking guest, hit entity), queued while the hub is taken.
|
||||
lan_critical_hits: Vec<(Option<u32>, i32)>,
|
||||
lan_critical_hits: Vec<(Option<u32>, i32, bool)>,
|
||||
/// Global level events for every guest (`ServerLevel.globalLevelEvent`).
|
||||
lan_global_events: Vec<(i32, [i32; 3], i32)>,
|
||||
/// `ContainerOpenersCounter`: how many players (the host and the guests)
|
||||
@@ -7602,7 +7602,7 @@ impl Game<'_> {
|
||||
/// strength and whether it is a critical hit): the weapon and effects
|
||||
/// scaled by the attack strength, a mace's smash, the critical hit, then
|
||||
/// enchantments.
|
||||
pub(super) fn melee_damage(&mut self, target_kind: &str) -> (f32, f32, bool) {
|
||||
pub(super) fn melee_damage(&mut self, target_kind: &str) -> (f32, f32, bool, bool) {
|
||||
let hand_damage = 1.0 + self.attack_item_info().map_or(0.0, |i| i.attack_damage);
|
||||
// Riptide's spin replaces the attack damage attribute.
|
||||
let spin = self.player.as_ref().map_or(0.0, |p| p.auto_spin_attack_dmg);
|
||||
@@ -7630,8 +7630,9 @@ impl Game<'_> {
|
||||
amount *= 1.5;
|
||||
}
|
||||
// Enchantment damage (sharpness, smite, bane) scaled by the attack strength.
|
||||
amount += self.enchant_damage_bonus(target_kind) * scale;
|
||||
(amount, scale, crit)
|
||||
let magic_boost = self.enchant_damage_bonus(target_kind) * scale;
|
||||
amount += magic_boost;
|
||||
(amount, scale, crit, magic_boost > 0.0)
|
||||
}
|
||||
/// `Player.getAttackStrengthScale(0.5)`.
|
||||
fn attack_strength_scale(&self) -> f32 {
|
||||
@@ -7818,7 +7819,7 @@ impl Game<'_> {
|
||||
pub(super) fn attack_mob(&mut self, index: usize) {
|
||||
let target_kind = self.mobs[index].kind.id.clone();
|
||||
let target_kind = format!("minecraft:{}", target_kind.trim_start_matches("minecraft:"));
|
||||
let (amount, scale, crit) = self.melee_damage(&target_kind);
|
||||
let (amount, scale, crit, magic) = self.melee_damage(&target_kind);
|
||||
let sweep = self.sweep_attack_position(scale, crit);
|
||||
let (knockback, knockback_attack) = self.extra_knockback(&target_kind, scale);
|
||||
self.attack_ticks = 0;
|
||||
@@ -7881,6 +7882,18 @@ impl Game<'_> {
|
||||
feet,
|
||||
width,
|
||||
height,
|
||||
false,
|
||||
);
|
||||
}
|
||||
// Player.attackVisualEffects: magicCrit when the enchantments added damage.
|
||||
if magic {
|
||||
self.critical_hit(
|
||||
self.lan_acting,
|
||||
self.mobs[index].id as i32,
|
||||
feet,
|
||||
width,
|
||||
height,
|
||||
true,
|
||||
);
|
||||
}
|
||||
if actual > 2.0 {
|
||||
|
||||
@@ -1224,8 +1224,9 @@ impl Game<'_> {
|
||||
self.lan_entity_events.push((id, event, at));
|
||||
}
|
||||
}
|
||||
/// `ServerPlayer.crit`: this window's emitter, and an animation for the
|
||||
/// attacker's client and observers once the hub is back in place.
|
||||
/// `ServerPlayer.crit` (or `magicCrit` when `magic`): this window's
|
||||
/// emitter, and an animation for the attacker's client and observers once
|
||||
/// the hub is back in place.
|
||||
pub(super) fn critical_hit(
|
||||
&mut self,
|
||||
attacker: Option<u32>,
|
||||
@@ -1233,16 +1234,18 @@ impl Game<'_> {
|
||||
feet: [f64; 3],
|
||||
width: f64,
|
||||
height: f64,
|
||||
magic: bool,
|
||||
) {
|
||||
use horizon_client::particles::{ParticleOptions, ParticleType};
|
||||
self.particles.tracking_emitter(
|
||||
ParticleOptions::simple(ParticleType::Crit),
|
||||
feet,
|
||||
width,
|
||||
height,
|
||||
);
|
||||
let particle = if magic {
|
||||
ParticleType::EnchantedHit
|
||||
} else {
|
||||
ParticleType::Crit
|
||||
};
|
||||
self.particles
|
||||
.tracking_emitter(ParticleOptions::simple(particle), feet, width, height);
|
||||
if self.audio.capture.is_some() {
|
||||
self.lan_critical_hits.push((attacker, id));
|
||||
self.lan_critical_hits.push((attacker, id, magic));
|
||||
}
|
||||
}
|
||||
/// Send the tick's level events, sounds and mob animations.
|
||||
@@ -1320,13 +1323,13 @@ impl Game<'_> {
|
||||
seen.insert(m.id, (m.hurt_time, dead, swing));
|
||||
}
|
||||
host.mob_state.insert(self.dim, seen);
|
||||
for (attacker, target) in critical_hits {
|
||||
for (attacker, target, magic) in critical_hits {
|
||||
let Some(attacker) = attacker.map_or(Some(host.host_entity), |conn| {
|
||||
host.hub.guest(conn).map(|g| g.entity_id)
|
||||
}) else {
|
||||
continue;
|
||||
};
|
||||
host.hub.critical_hit(attacker, target);
|
||||
host.hub.critical_hit(attacker, target, magic);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ pub(super) struct Strike {
|
||||
amount: f32,
|
||||
scale: f32,
|
||||
crit: bool,
|
||||
/// `Player.attack`'s `magicBoost > 0`: the enchantments added damage.
|
||||
magic: bool,
|
||||
from: [f64; 3],
|
||||
sweep: Option<[f64; 3]>,
|
||||
/// `causeExtraKnockback`: its strength and direction (the attacker's
|
||||
@@ -109,7 +111,7 @@ impl Game<'_> {
|
||||
pub(super) fn pvp_strike(&mut self) -> Option<Strike> {
|
||||
let p = self.player.as_ref()?;
|
||||
let from = [p.position.x, p.position.y, p.position.z];
|
||||
let (amount, scale, crit) = self.melee_damage("minecraft:player");
|
||||
let (amount, scale, crit, magic) = self.melee_damage("minecraft:player");
|
||||
let sweep = self.sweep_attack_position(scale, crit);
|
||||
let (strength, knockback_attack) = self.extra_knockback("minecraft:player", scale);
|
||||
let (xd, zd) = self.extra_knockback_direction();
|
||||
@@ -125,6 +127,7 @@ impl Game<'_> {
|
||||
amount,
|
||||
scale,
|
||||
crit,
|
||||
magic,
|
||||
from,
|
||||
sweep,
|
||||
knockback: (strength, xd, zd),
|
||||
@@ -257,7 +260,7 @@ impl Game<'_> {
|
||||
} else {
|
||||
Default::default()
|
||||
};
|
||||
if hurt && s.crit {
|
||||
if hurt && (s.crit || s.magic) {
|
||||
let target = match victim {
|
||||
Victim::Host => self.player.as_ref().map(|p| (host.host_entity, p)),
|
||||
Victim::Guest(conn) => host
|
||||
@@ -267,13 +270,17 @@ impl Game<'_> {
|
||||
};
|
||||
if let Some((id, p)) = target {
|
||||
let d = p.dimensions;
|
||||
self.critical_hit(
|
||||
s.attacker,
|
||||
id,
|
||||
let (feet, width, height) = (
|
||||
[p.position.x, p.position.y, p.position.z],
|
||||
f64::from(d.width),
|
||||
f64::from(d.height),
|
||||
);
|
||||
if s.crit {
|
||||
self.critical_hit(s.attacker, id, feet, width, height, false);
|
||||
}
|
||||
if s.magic {
|
||||
self.critical_hit(s.attacker, id, feet, width, height, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
// `Enchantment.doPostAttack`: thorns hurt the attacking player.
|
||||
|
||||
@@ -75,7 +75,7 @@ pub(super) struct Parked {
|
||||
lan_events: Vec<(i32, [i32; 3], i32, Option<u32>)>,
|
||||
lan_block_events: Vec<([i32; 3], i32, i32, u32)>,
|
||||
lan_entity_events: Vec<(i32, i8, [f64; 3])>,
|
||||
lan_critical_hits: Vec<(Option<u32>, i32)>,
|
||||
lan_critical_hits: Vec<(Option<u32>, i32, bool)>,
|
||||
/// Only the per-level parts of these are used (`swap_level`).
|
||||
anims: BlockEntityAnims,
|
||||
raiding: Raiding,
|
||||
|
||||
@@ -120,12 +120,13 @@ impl Hub {
|
||||
);
|
||||
}
|
||||
|
||||
/// `ServerPlayer.crit`: send the victim's animation to the players tracking
|
||||
/// the attacker and the attacker themselves (`sendToTrackingPlayersAndSelf`).
|
||||
pub fn critical_hit(&self, attacker: i32, target: i32) {
|
||||
/// `ServerPlayer.crit` (`magicCrit` when `magic`): send the victim's
|
||||
/// animation to the players tracking the attacker and the attacker
|
||||
/// themselves (`sendToTrackingPlayersAndSelf`).
|
||||
pub fn critical_hit(&self, attacker: i32, target: i32, magic: bool) {
|
||||
let body = C::Animate(play::Animate {
|
||||
id: target,
|
||||
action: 1,
|
||||
action: if magic { 2 } else { 1 },
|
||||
})
|
||||
.encode();
|
||||
for g in self.guests.iter().filter(|g| {
|
||||
|
||||
Reference in New Issue
Block a user