Count down Riptide's spin on a server's copy of a player

The host runs a guest's trident release on its copy of the guest, which
sets the spin for 20 ticks. The copy never ran the client's movement
tick, so the count never went down: the copy stayed in the spin pose
(eye 0.4), and every arrow or projectile the guest shot was spawned from
the leg until something else reset it.

LivingEntity.aiStep counts autoSpinAttackTicks down on the server too.
Count it down in the guest's server tick, before updatePlayerPose.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
leifiyoo
2026-10-27 15:52:19 +01:00
parent 777e0e2eb5
commit de286f236f
3 changed files with 55 additions and 0 deletions
@@ -2330,6 +2330,9 @@ impl Game<'_> {
let _ = w.tick_environment_damage();
let _ = w.apply_fire_contact();
let _ = w.server_hazards_tick(in_wall);
// LivingEntity.aiStep: a Riptide spin counts down on the server's
// copy too, or it would stay in the spin pose (eye 0.4) for good.
w.player.count_down_server_spin();
// Player.tick ends with updatePlayerPose: a swimmer, or a player
// crawling under a block, takes the short box its moves are checked with.
let _ = w.update_player_pose();
+40
View File
@@ -3446,6 +3446,46 @@ mod tests {
}
}
#[test]
fn a_server_copy_of_a_riptide_spin_counts_down_and_stands_again() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../.local/horizon-client")
.join(horizon_core::VANILLA_VERSION);
if !root.join("movement-properties.nbt").exists() {
return;
}
let assets = Assets::load(&root).unwrap();
let render = assets.reload(&root).unwrap();
let binding = crate::collisions::load(&root, assets.registry).unwrap();
let resources = MotionResources::load(&root, &assets).unwrap();
let mut scene = World::test_scene(&assets, &render, 2).unwrap();
let mut player = PlayerMotion::new(&resources, Vec3::new(20.5, 10.0, 20.5)).unwrap();
player.auto_spin_attack_ticks = 2;
player.auto_spin_attack_dmg = 8.0;
let mut w = MotionWorld {
entities: &[],
player: &mut player,
scene: &mut scene,
assets: &assets,
collision_binding: &binding,
resources: &resources,
};
w.update_player_pose().unwrap();
assert_eq!(w.player.pose, crate::pose::Pose::SpinAttack);
w.player.count_down_server_spin();
w.update_player_pose().unwrap();
assert_eq!(w.player.pose, crate::pose::Pose::SpinAttack);
assert_eq!(w.player.auto_spin_attack_dmg, 8.0);
w.player.count_down_server_spin();
assert_eq!(w.player.auto_spin_attack_ticks, 0);
assert_eq!(w.player.auto_spin_attack_dmg, 0.0);
w.update_player_pose().unwrap();
assert_eq!(w.player.pose, crate::pose::Pose::Standing);
assert_eq!(w.player.dimensions.eye_height, 1.62);
// Nothing to count once the spin is over.
w.player.count_down_server_spin();
assert_eq!(w.player.auto_spin_attack_ticks, 0);
}
#[test]
fn a_riptide_spin_lies_flat_and_ends_on_the_first_entity_it_touches() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../.local/horizon-client")
+12
View File
@@ -78,6 +78,18 @@ impl Dimensions {
}
}
impl PlayerMotion {
/// `LivingEntity.aiStep` counting down `autoSpinAttackTicks` for a
/// server's copy of a player, which runs no client tick: the spin ends
/// after its ticks and its damage goes with it, so the pose (and the eye
/// a bow or a trident is shot from) comes back to standing.
pub fn count_down_server_spin(&mut self) {
if self.auto_spin_attack_ticks > 0 {
self.auto_spin_attack_ticks -= 1;
if self.auto_spin_attack_ticks <= 0 {
self.auto_spin_attack_dmg = 0.0;
}
}
}
pub fn dimensions_for_pose(&mut self, pose: Pose) -> Result<Dimensions> {
Ok(pose.dimensions(self.attribute("minecraft:scale")? as f32))
}