Skip to main content

steel_protocol/packets/game/
c_animate.rs

1//! Clientbound animate packet - sent to play an entity animation.
2
3use steel_macros::{ClientPacket, WriteTo};
4use steel_registry::packets::play::C_ANIMATE;
5
6/// Animation action types.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, WriteTo)]
8#[repr(u8)]
9#[write(as = u8)]
10pub enum AnimateAction {
11    /// Wake up from bed
12    WakeUp = 0,
13    /// Critical hit effect
14    CriticalHit = 1,
15    /// Magic critical hit effect (enchanted weapon)
16    MagicCriticalHit = 2,
17}
18
19/// Sent to play an animation on an entity.
20#[derive(ClientPacket, WriteTo, Clone, Debug)]
21#[packet_id(Play = C_ANIMATE)]
22pub struct CAnimate {
23    /// The entity ID to animate.
24    #[write(as = VarInt)]
25    pub entity_id: i32,
26    /// The animation action to play.
27    pub action: AnimateAction,
28}
29
30impl CAnimate {
31    /// Creates a new animate packet.
32    #[must_use]
33    pub const fn new(entity_id: i32, action: AnimateAction) -> Self {
34        Self { entity_id, action }
35    }
36
37    /// Creates a critical hit animation.
38    #[must_use]
39    pub const fn critical_hit(entity_id: i32) -> Self {
40        Self::new(entity_id, AnimateAction::CriticalHit)
41    }
42
43    /// Creates a magic critical hit animation.
44    #[must_use]
45    pub const fn magic_critical_hit(entity_id: i32) -> Self {
46        Self::new(entity_id, AnimateAction::MagicCriticalHit)
47    }
48}