Skip to main content

steel_protocol/packets/game/
c_stop_sound.rs

1use steel_macros::{ClientPacket, WriteTo};
2use steel_registry::packets::play::C_STOP_SOUND;
3use steel_utils::Identifier;
4
5use super::SoundSource;
6
7const SOURCE_FLAG: u8 = 1;
8const SOUND_FLAG: u8 = 2;
9
10#[derive(ClientPacket, WriteTo, Clone, Debug)]
11#[packet_id(Play = C_STOP_SOUND)]
12pub struct CStopSound {
13    pub flags: u8,
14
15    #[write(as = Unprefixed)]
16    pub source: Option<SoundSource>,
17
18    #[write(as = Unprefixed)]
19    pub sound: Option<Identifier>,
20}
21
22impl CStopSound {
23    #[must_use]
24    pub const fn new(source: Option<SoundSource>, sound: Option<Identifier>) -> Self {
25        let mut flags = 0;
26
27        if source.is_some() {
28            flags |= SOURCE_FLAG;
29        }
30
31        if sound.is_some() {
32            flags |= SOUND_FLAG;
33        }
34
35        Self {
36            flags,
37            source,
38            sound,
39        }
40    }
41}