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    /// Swing main hand
12    SwingMainHand = 0,
13    /// Wake up from bed
14    WakeUp = 2,
15    /// Swing off hand
16    SwingOffHand = 3,
17    /// Critical hit effect
18    CriticalHit = 4,
19    /// Magic critical hit effect (enchanted weapon)
20    MagicCriticalHit = 5,
21}
22
23/// Sent to play an animation on an entity.
24#[derive(ClientPacket, WriteTo, Clone, Debug)]
25#[packet_id(Play = C_ANIMATE)]
26pub struct CAnimate {
27    /// The entity ID to animate.
28    #[write(as = VarInt)]
29    pub entity_id: i32,
30    /// The animation action to play.
31    pub action: AnimateAction,
32}
33
34impl CAnimate {
35    /// Creates a new animate packet.
36    #[must_use]
37    pub const fn new(entity_id: i32, action: AnimateAction) -> Self {
38        Self { entity_id, action }
39    }
40
41    /// Creates a swing main hand animation.
42    #[must_use]
43    pub const fn swing_main_hand(entity_id: i32) -> Self {
44        Self::new(entity_id, AnimateAction::SwingMainHand)
45    }
46
47    /// Creates a swing off hand animation.
48    #[must_use]
49    pub const fn swing_off_hand(entity_id: i32) -> Self {
50        Self::new(entity_id, AnimateAction::SwingOffHand)
51    }
52
53    /// Creates a critical hit animation.
54    #[must_use]
55    pub const fn critical_hit(entity_id: i32) -> Self {
56        Self::new(entity_id, AnimateAction::CriticalHit)
57    }
58
59    /// Creates a magic critical hit animation.
60    #[must_use]
61    pub const fn magic_critical_hit(entity_id: i32) -> Self {
62        Self::new(entity_id, AnimateAction::MagicCriticalHit)
63    }
64}