Merge pull request #2878 from leifiyoo/riptide-spin-server-countdown
Count down Riptide's spin on a server's copy of a player
This commit is contained in:
@@ -2607,6 +2607,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();
|
||||
|
||||
@@ -3514,6 +3514,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")
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user