diff options
| author | mat <git@matdoes.dev> | 2025-01-13 04:52:40 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-01-13 04:52:40 +0000 |
| commit | 5721eaf193977ce0d7c2fee9504b8ad057d1c1a2 (patch) | |
| tree | f789d0707e46885e1da454b81740f2f4c20a2d6f /azalea-protocol/src | |
| parent | 862dec529bf7619401fd0ae021fc55cbbe27c697 (diff) | |
| download | azalea-drasl-5721eaf193977ce0d7c2fee9504b8ad057d1c1a2.tar.xz | |
fix ClientboundSound and implement az_registry::Holder
Diffstat (limited to 'azalea-protocol/src')
| -rwxr-xr-x | azalea-protocol/src/packets/game/c_sound.rs | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/azalea-protocol/src/packets/game/c_sound.rs b/azalea-protocol/src/packets/game/c_sound.rs index 77161769..8ec028a7 100755 --- a/azalea-protocol/src/packets/game/c_sound.rs +++ b/azalea-protocol/src/packets/game/c_sound.rs @@ -1,11 +1,13 @@ use azalea_buf::AzBuf; +use azalea_core::resource_location::ResourceLocation; use azalea_protocol_macros::ClientboundGamePacket; use azalea_registry::SoundEvent; #[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] pub struct ClientboundSound { - pub sound: SoundEvent, + pub sound: azalea_registry::Holder<SoundEvent, CustomSound>, pub source: SoundSource, + // this can't be a BlockPos because it serializes differently :( pub x: i32, pub y: i32, pub z: i32, @@ -14,6 +16,12 @@ pub struct ClientboundSound { pub seed: u64, } +#[derive(Clone, Debug, AzBuf)] +pub struct CustomSound { + pub location: ResourceLocation, + pub fixed_range: Option<f32>, +} + #[derive(AzBuf, Clone, Copy, Debug)] pub enum SoundSource { Master = 0, @@ -27,3 +35,30 @@ pub enum SoundSource { Ambient = 8, Voice = 9, } + +#[cfg(test)] +mod tests { + use std::io::Cursor; + + use azalea_buf::AzaleaRead; + + use crate::packets::game::ClientboundSound; + + #[test] + fn test_read_write_custom_sound() { + let contents = [ + 0, 21, 109, 105, 110, 101, 99, 114, 97, 102, 116, 58, 97, 115, 102, 97, 115, 100, 102, + 115, 100, 102, 103, 0, 8, 0, 0, 0, 63, 255, 255, 254, 32, 0, 0, 0, 82, 66, 200, 0, 0, + 63, 128, 0, 0, 71, 94, 219, 133, 200, 13, 150, 31, + ]; + let mut buf = Cursor::new(contents.as_slice()); + let packet = ClientboundSound::azalea_read(&mut buf).unwrap(); + println!("{:?}", packet); + + assert_eq!(buf.position(), contents.len() as u64); + + let mut buf = Vec::new(); + packet.write(&mut buf).unwrap(); + assert_eq!(buf, contents); + } +} |
