Merge pull request #2186 from kacpherek/fix/soul-speed
🤖 Agent: Gate check by Ludovic's AI agent (Claude). Checked against 26.3 Soul Speed: the speed on soul blocks, no soul sand slowdown, the particles and sound, and boot wear on 4% of ticks, now also for each player on a server (`guest_server_tick`), with the particle sent to the players around. I pushed one fix: the random draws come in vanilla's order (the 0.04 wear roll first, then the particles, then the 0.35 sound roll and its pitch). It then conflicted with main (#2190 added the elytra glide wear in the same tick), so I merged main in: Soul Speed comes first, as `LivingEntity.baseTick` runs before `aiStep`, then the glide wear, so both draw from the level random in vanilla order. On that merge: clippy `-D warnings` clean, horizon-client tests pass, the fast build links, and `lan_e2e.py` elytra, damage and breath pass with the host in-frame and on its server thread. CI parity runs the harnesses this head reaches. Thanks @kacpherek!
This commit is contained in:
@@ -4520,6 +4520,22 @@ impl Game<'_> {
|
||||
};
|
||||
self.eye += (camera_eye.unwrap_or(eye_height) - self.eye) * 0.5;
|
||||
let crouching = player.pose == horizon_client::pose::Pose::Crouching;
|
||||
// `LivingEntity.baseTick` (Soul Speed) comes before `aiStep` (the
|
||||
// glide's wear): both draw from the level random.
|
||||
if let Some((at, velocity)) = self.tick_soul_speed() {
|
||||
self.particles.send_particles(
|
||||
&horizon_client::particles::ParticleOptions::simple(
|
||||
horizon_client::particles::ParticleType::Soul,
|
||||
),
|
||||
at,
|
||||
velocity,
|
||||
1.0,
|
||||
0,
|
||||
);
|
||||
if let Some(host) = self.lan.as_ref() {
|
||||
lan_particles::send_soul_particle(host, at, velocity);
|
||||
}
|
||||
}
|
||||
// `ItemStack.hurtAndBreak` for the glide: Unbreaking can save the wear.
|
||||
if glider_wear > 0
|
||||
&& !self.creative
|
||||
|
||||
@@ -3,10 +3,14 @@
|
||||
//! unbreaking (`minecraft:item_damage`), sharpness/smite/bane and power
|
||||
//! (`minecraft:damage`), knockback, fire aspect, infinity (`minecraft:ammo_use`),
|
||||
//! thorns (`minecraft:post_attack`), mending (`minecraft:repair_with_xp`) and
|
||||
//! the armor attribute effects (respiration, depth strider, ...).
|
||||
//! the armor attribute effects (respiration, depth strider, ...) and Soul
|
||||
//! Speed's `location_changed` and `tick` effects.
|
||||
use super::Game;
|
||||
use horizon_client::{enchant::EffectContext, items::ItemStack};
|
||||
use horizon_core::random::RandomSource;
|
||||
use horizon_client::{
|
||||
enchant::{EffectContext, Enchantments, level_value},
|
||||
items::ItemStack,
|
||||
};
|
||||
use horizon_core::{position::BlockPos, random::RandomSource};
|
||||
|
||||
/// Where Mending found a damaged item (`EnchantedItemInUse.inSlot`).
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -458,6 +462,134 @@ impl Game<'_> {
|
||||
}
|
||||
ignite
|
||||
}
|
||||
/// Soul Speed (`data/minecraft/enchantment/soul_speed.json`), the parts of
|
||||
/// `Enchantment.runLocationChangedEffects` and `tick` that file uses. The
|
||||
/// `location_changed` effects run when the player enters a new block, lands,
|
||||
/// or its boots change:
|
||||
/// - the speed and movement efficiency modifiers turn on over a soul speed
|
||||
/// block (not flying, not riding) and stay on while airborne, then off
|
||||
/// (`enchantment_active_check`);
|
||||
/// - the boots lose 1 durability with a 4% chance when on such a block.
|
||||
///
|
||||
/// Every fifth tick the player walking on one also gets a soul particle
|
||||
/// (returned as its position and velocity, for the caller to show or send
|
||||
/// to the players around) and sometimes a sound. Runs for the window's own
|
||||
/// player and for each guest on the server (`guest_server_tick`); a remote
|
||||
/// client leaves it to its server.
|
||||
pub(super) fn tick_soul_speed(&mut self) -> Option<([f64; 3], [f64; 3])> {
|
||||
const ID: &str = "minecraft:soul_speed";
|
||||
let player = self.player.as_mut()?;
|
||||
if player.client_side {
|
||||
return None;
|
||||
}
|
||||
let level = self.armor[3]
|
||||
.as_ref()
|
||||
.map_or(0, |s| s.enchantment_level(ID));
|
||||
let position = player.position;
|
||||
let (on_ground, flying) = (player.ground.on_ground, player.flying);
|
||||
let moved = position.subtract(player.old_position);
|
||||
let (tick, width) = (player.health.tick_count, player.dimensions.width);
|
||||
let fx = &mut player.location_effects;
|
||||
let on_soul = fx.on_soul_speed_block;
|
||||
let block = BlockPos::containing(position);
|
||||
let changed_block = fx.block.replace(block) != Some(block);
|
||||
let landed = std::mem::take(&mut fx.landed);
|
||||
// Changed boots: `stopLocationBasedEffects`, then the effects run again.
|
||||
let equipped = std::mem::replace(&mut fx.boots_level, level) != level;
|
||||
let was_active = fx.applied_level;
|
||||
let mut active = was_active > 0 && !equipped;
|
||||
let mut wear = false;
|
||||
if level > 0 && (changed_block || landed || equipped) {
|
||||
let riding = self.riding.is_some();
|
||||
let wanted = !riding && !flying && (on_soul || (active && !on_ground));
|
||||
active = wanted;
|
||||
// `random_chance` is the first term of the wear's `all_of`: it
|
||||
// draws from the level random before the block is looked at.
|
||||
let roll = self.world.random.next_float() < 0.04;
|
||||
wear = roll && on_ground && on_soul;
|
||||
}
|
||||
fx.applied_level = if active { level } else { 0 };
|
||||
// `Entity.getKnownMovement` horizontal speed of at least 1.0E-5.
|
||||
let walking = moved.x * moved.x + moved.z * moved.z >= 1.0e-10;
|
||||
let tick_effects = level > 0 && !flying && on_ground && walking && on_soul && tick % 5 == 0;
|
||||
// The attribute effects were applied to the player before: swap them.
|
||||
if was_active > 0 && (!active || equipped) {
|
||||
for (attribute, id, _, op) in
|
||||
soul_speed_modifiers(&self.res.stations().enchantments, was_active)
|
||||
{
|
||||
let _ = player.set_modifier(&attribute, &id, 0.0, &op, false);
|
||||
}
|
||||
}
|
||||
if active && (was_active == 0 || equipped) {
|
||||
for (attribute, id, amount, op) in
|
||||
soul_speed_modifiers(&self.res.stations().enchantments, level)
|
||||
{
|
||||
let _ = player.set_modifier(&attribute, &id, amount, &op, true);
|
||||
}
|
||||
}
|
||||
if wear && !self.creative {
|
||||
self.wear_boots(1);
|
||||
}
|
||||
if level == 0 {
|
||||
return None;
|
||||
}
|
||||
let r = &mut self.world.random;
|
||||
// `spawn_particles`: in the bounding box, 0.1 above the feet, thrown
|
||||
// back against the movement (-0.2) and up (0.1).
|
||||
let particle = tick_effects.then(|| {
|
||||
let x = position.x + (r.next_double() - 0.5) * f64::from(width);
|
||||
let z = position.z + (r.next_double() - 0.5) * f64::from(width);
|
||||
(
|
||||
[x, position.y + 0.1, z],
|
||||
[moved.x * -0.2, 0.1, moved.z * -0.2],
|
||||
)
|
||||
});
|
||||
// `play_sound`: its `random_chance` (35%) comes first in its `all_of`,
|
||||
// so the level random is drawn every tick the boots are worn; volume
|
||||
// 0.6, pitch 0.6 to 1.0.
|
||||
if r.next_float() < 0.35 && tick_effects {
|
||||
let pitch = r.next_float() * 0.4 + 0.6;
|
||||
self.audio.play(
|
||||
"minecraft:particle.soul_escape",
|
||||
Some([position.x, position.y, position.z]),
|
||||
0.6,
|
||||
pitch,
|
||||
);
|
||||
}
|
||||
particle
|
||||
}
|
||||
/// `ItemStack.hurtAndBreak` on the worn boots (`change_item_damage`):
|
||||
/// Unbreaking applies, and they break when worn out.
|
||||
fn wear_boots(&mut self, amount: u32) {
|
||||
let Some(stack) = self.armor[3].clone() else {
|
||||
return;
|
||||
};
|
||||
let loss = self.durability_loss(&stack, amount);
|
||||
let max = self
|
||||
.res
|
||||
.items()
|
||||
.get(&stack.item)
|
||||
.map_or(0, |info| info.max_damage);
|
||||
if max == 0 {
|
||||
return;
|
||||
}
|
||||
let Some(boots) = self.armor[3].as_mut() else {
|
||||
return;
|
||||
};
|
||||
boots.damage += loss;
|
||||
if boots.damage >= max {
|
||||
self.armor[3] = None;
|
||||
if let Some(eye) = self.eye_position() {
|
||||
self.audio.play(
|
||||
"minecraft:entity.item.break",
|
||||
Some(eye),
|
||||
0.8,
|
||||
0.8 + self.world.random.next_float() * 0.4,
|
||||
);
|
||||
}
|
||||
self.apply_equipment();
|
||||
}
|
||||
}
|
||||
/// Enchantment attribute modifiers of worn armor (respiration, depth strider...).
|
||||
/// Each piece's modifier id ends with its slot (`EnchantmentAttributeEffect.idForSlot`),
|
||||
/// so the same enchantment on two pieces stacks instead of replacing itself.
|
||||
@@ -481,3 +613,28 @@ impl Game<'_> {
|
||||
self.potions.enchant_modifiers = wanted;
|
||||
}
|
||||
}
|
||||
|
||||
/// Soul Speed's `attribute` effects at `level` (attribute, id, amount, operation),
|
||||
/// the id taking the boots slot like `EnchantmentAttributeEffect.idForSlot`.
|
||||
fn soul_speed_modifiers(
|
||||
enchantments: &Enchantments,
|
||||
level: u32,
|
||||
) -> Vec<(String, String, f64, String)> {
|
||||
let Some(e) = enchantments.get("minecraft:soul_speed") else {
|
||||
return Vec::new();
|
||||
};
|
||||
e.effects["minecraft:location_changed"][0]["effect"]["effects"]
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter(|a| a["type"] == "minecraft:attribute")
|
||||
.map(|a| {
|
||||
(
|
||||
a["attribute"].as_str().unwrap_or("").to_owned(),
|
||||
format!("{}/feet", a["id"].as_str().unwrap_or("")),
|
||||
f64::from(level_value(&a["amount"], level)),
|
||||
a["operation"].as_str().unwrap_or("add_value").to_owned(),
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -2183,6 +2183,7 @@ impl Game<'_> {
|
||||
let in_wall = !g.sleeping && self.in_wall(g.position, g.eye_height());
|
||||
let at = g.position;
|
||||
let sneaking = g.sneaking;
|
||||
let mut soul = None;
|
||||
let events = self.as_guest(host, conn, |game| {
|
||||
let (rules, motion) = (game.world.health_rules, game.motion);
|
||||
let health = &motion.health;
|
||||
@@ -2252,6 +2253,7 @@ impl Game<'_> {
|
||||
w.player.shift_key_down = sneaking;
|
||||
w.player.freeze_immune = freeze_immune;
|
||||
let _ = w.server_block_damage(start);
|
||||
let _ = w.update_soul_speed_block();
|
||||
let _ = w.tick_environment_damage();
|
||||
let _ = w.apply_fire_contact();
|
||||
let _ = w.server_hazards_tick(in_wall);
|
||||
@@ -2279,6 +2281,9 @@ impl Game<'_> {
|
||||
// LivingEntity.baseTick: outside the world border, then tickEffects.
|
||||
game.border_damage();
|
||||
game.tick_mob_effects();
|
||||
// Soul Speed's effects (LivingEntity.baseTick's location_changed
|
||||
// and tick effects); its particle goes to the players around.
|
||||
soul = game.tick_soul_speed();
|
||||
let Some(player) = game.player.as_mut() else {
|
||||
return (Vec::new(), None);
|
||||
};
|
||||
@@ -2307,6 +2312,9 @@ impl Game<'_> {
|
||||
let Some((events, marked)) = events else {
|
||||
return;
|
||||
};
|
||||
if let Some((at, velocity)) = soul {
|
||||
super::lan_particles::send_soul_particle(host, at, velocity);
|
||||
}
|
||||
self.as_guest(host, conn, |game| game.tick_player_sculk_events());
|
||||
for event in events {
|
||||
match event {
|
||||
|
||||
@@ -24,6 +24,35 @@ fn rgb(c: [f32; 4]) -> [f32; 3] {
|
||||
[c[0], c[1], c[2]]
|
||||
}
|
||||
|
||||
/// `ServerLevel.sendParticles` of one soul particle moving by `velocity`
|
||||
/// (Soul Speed's `spawn_particles`): sent to the players within 32 blocks.
|
||||
pub(super) fn send_soul_particle(host: &super::lan::LanHost, at: [f64; 3], velocity: [f64; 3]) {
|
||||
let Some(id) = host
|
||||
.hub
|
||||
.registry_id("minecraft:particle_type", "minecraft:soul")
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let packet = C::LevelParticles(play::LevelParticles {
|
||||
particle: Particle { id, data: None },
|
||||
override_limiter: false,
|
||||
always_show: false,
|
||||
pos: at,
|
||||
dist: velocity.map(|v| v as f32),
|
||||
max_speed: [1.0; 3],
|
||||
count: 0,
|
||||
randomization: 0,
|
||||
});
|
||||
for g in host.hub.guests.iter().filter(|g| host.hub.here(g)) {
|
||||
let distance: f64 = (0..3)
|
||||
.map(|k| (g.position[k].floor() + 0.5 - at[k]).powi(2))
|
||||
.sum();
|
||||
if distance < 32.0 * 32.0 {
|
||||
g.send(&packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Game<'_> {
|
||||
/// `SonicBoom.tick` uses `ServerLevel.sendParticles` for each ray point.
|
||||
/// Keep the local event's rendering; connected players receive one at rest.
|
||||
|
||||
@@ -52,6 +52,8 @@ pub struct MotionResources {
|
||||
pub climbable: BTreeSet<String>,
|
||||
/// `BlockTags.CAN_GLIDE_THROUGH`: climbable blocks a gliding player passes.
|
||||
pub glide_through: BTreeSet<String>,
|
||||
/// `BlockTags.SOUL_SPEED_BLOCKS`: what Soul Speed's effects look for.
|
||||
pub soul_speed_blocks: BTreeSet<String>,
|
||||
pub fall_reset: BTreeSet<String>,
|
||||
pub landing: BlockLandingRegistry,
|
||||
pub health: crate::health::HealthResources,
|
||||
@@ -111,11 +113,29 @@ impl MotionResources {
|
||||
})?,
|
||||
climbable: tag("minecraft:climbable")?,
|
||||
glide_through: tag("minecraft:can_glide_through")?,
|
||||
soul_speed_blocks: tag("minecraft:soul_speed_blocks")?,
|
||||
fall_reset: tag("minecraft:fall_damage_resetting")?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// What the `location_changed` enchantment effects (Soul Speed) need to know
|
||||
/// between ticks.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct LocationEffects {
|
||||
/// `MovementAffectedByPredicate`: the block under the player
|
||||
/// (`getBlockPosBelowThatAffectsMyMovement`) is in `#minecraft:soul_speed_blocks`.
|
||||
pub on_soul_speed_block: bool,
|
||||
/// `LivingEntity.lastPos`: the block the player was in last tick.
|
||||
pub block: Option<BlockPos>,
|
||||
/// A landing ran `onChangedBlock` (`LivingEntity.checkFallDamage`).
|
||||
pub landed: bool,
|
||||
/// The Soul Speed level of the boots seen last tick (0: none).
|
||||
pub boots_level: u32,
|
||||
/// The Soul Speed level whose attribute modifiers are on the player (0: none).
|
||||
pub applied_level: u32,
|
||||
}
|
||||
|
||||
/// Ordered requests and phase records for world/audio/network consumers. Landing
|
||||
/// hurt dispatch updates stored health synchronously before these are drained.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -258,6 +278,8 @@ pub struct PlayerMotion {
|
||||
pub glide_ending: bool,
|
||||
/// Glider durability to take this tick (updateFallFlying).
|
||||
pub glider_wear: u32,
|
||||
/// Soul Speed's `location_changed` bookkeeping.
|
||||
pub location_effects: LocationEffects,
|
||||
/// `LivingEntity.autoSpinAttackTicks` and `autoSpinAttackDmg`: Riptide's
|
||||
/// spin. The damage stays until the game has dealt the hit.
|
||||
pub auto_spin_attack_ticks: i32,
|
||||
@@ -449,6 +471,7 @@ impl PlayerMotion {
|
||||
fall_fly_ticks: 0,
|
||||
glide_ending: false,
|
||||
glider_wear: 0,
|
||||
location_effects: LocationEffects::default(),
|
||||
auto_spin_attack_ticks: 0,
|
||||
auto_spin_attack_dmg: 0.0,
|
||||
spin_targets: Vec::new(),
|
||||
@@ -1006,6 +1029,7 @@ impl MotionWorld<'_, '_, '_> {
|
||||
)
|
||||
});
|
||||
self.player.try_add_frost(on_air)?;
|
||||
self.update_soul_speed_block()?;
|
||||
if self.player.health.tick_count % 40 == 0
|
||||
&& self.player.is_fully_frozen()
|
||||
&& self.player.can_freeze()
|
||||
@@ -1018,6 +1042,22 @@ impl MotionWorld<'_, '_, '_> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
/// Refresh whether the player stands on a soul speed block, for the
|
||||
/// `location_changed` enchantment effects (a server's player too, whose
|
||||
/// client does the walking).
|
||||
pub fn update_soul_speed_block(&mut self) -> Result<()> {
|
||||
self.player.location_effects.on_soul_speed_block = self.on_soul_speed_block()?;
|
||||
Ok(())
|
||||
}
|
||||
/// `MovementAffectedByPredicate` for `#minecraft:soul_speed_blocks`.
|
||||
fn on_soul_speed_block(&mut self) -> Result<bool> {
|
||||
let on = self.support(movement_support::MOVEMENT_SUPPORT_OFFSET)?;
|
||||
Ok(self
|
||||
.assets
|
||||
.registry
|
||||
.state(self.block(on))
|
||||
.is_some_and(|s| self.resources.soul_speed_blocks.contains(&s.name)))
|
||||
}
|
||||
/// Player.travel: swim steering, then LivingEntity.travel (fluids first,
|
||||
/// then gliding, then air), keeping 0.6 of the vertical speed while flying.
|
||||
fn player_travel(&mut self, input: Vec3) -> Result<()> {
|
||||
@@ -1915,6 +1955,10 @@ impl EntityMoveWorld for MotionWorld<'_, '_, '_> {
|
||||
if self.player.status.slow_falling || self.player.status.levitation.is_some() {
|
||||
self.player.fall_distance = 0.0;
|
||||
}
|
||||
// LivingEntity.checkFallDamage: a landing runs onChangedBlock.
|
||||
if grounded && self.player.fall_distance > 0.0 {
|
||||
self.player.location_effects.landed = true;
|
||||
}
|
||||
if self.player.spawn_extra_particles_on_fall && grounded && self.player.fall_distance > 0.0
|
||||
{
|
||||
self.player.events.push(MotionEvent::SmashLanding {
|
||||
|
||||
Reference in New Issue
Block a user