Skip to main content

steel_protocol/packets/game/
c_set_entity_motion.rs

1//! Clientbound set entity motion packet - sent to update entity velocity.
2
3use std::io::{Result, Write};
4
5use glam::DVec3;
6use steel_macros::ClientPacket;
7use steel_registry::packets::play::C_SET_ENTITY_MOTION;
8use steel_utils::{codec::VarInt, serial::WriteTo};
9
10use super::write_lp_vec3;
11
12/// Sent to update an entity's velocity on the client.
13///
14/// Velocity is sent in `LpVec3` format (same as spawn packet).
15/// This is used for:
16/// - Items landing on ground (velocity zeroed)
17/// - Knockback effects
18/// - Explosions
19/// - Any physics-driven velocity change
20#[derive(ClientPacket, Clone, Debug)]
21#[packet_id(Play = C_SET_ENTITY_MOTION)]
22pub struct CSetEntityMotion {
23    /// The entity ID whose velocity is being updated.
24    pub entity_id: i32,
25    /// The entity velocity (blocks/tick).
26    pub vel: DVec3,
27}
28
29impl CSetEntityMotion {
30    /// Creates a new set entity motion packet.
31    #[must_use]
32    pub const fn new(entity_id: i32, vel: DVec3) -> Self {
33        Self { entity_id, vel }
34    }
35}
36
37impl WriteTo for CSetEntityMotion {
38    fn write(&self, writer: &mut impl Write) -> Result<()> {
39        VarInt(self.entity_id).write(writer)?;
40        write_lp_vec3(writer, self.vel)
41    }
42}