diff --git a/azalea-protocol/src/packets/game/clientbound_sound_packet.rs b/azalea-protocol/src/packets/game/clientbound_sound_packet.rs index 39dd39c8..2b071f2e 100755 --- a/azalea-protocol/src/packets/game/clientbound_sound_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_sound_packet.rs @@ -1,10 +1,10 @@ use azalea_buf::McBuf; +use azalea_core::ResourceLocation; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_registry::OptionalRegistry; #[derive(Clone, Debug, McBuf, ClientboundGamePacket)] pub struct ClientboundSoundPacket { - pub sound: OptionalRegistry, + pub sound: azalea_registry::CustomRegistry, pub source: SoundSource, pub x: i32, pub y: i32, @@ -14,6 +14,12 @@ pub struct ClientboundSoundPacket { pub seed: u64, } +#[derive(McBuf, Clone, Debug)] +pub struct CustomSoundEvent { + pub location: ResourceLocation, + pub range: Option, +} + #[derive(McBuf, Clone, Copy, Debug)] pub enum SoundSource { Master = 0, diff --git a/azalea-registry/src/lib.rs b/azalea-registry/src/lib.rs index e1188216..081b3c3e 100755 --- a/azalea-registry/src/lib.rs +++ b/azalea-registry/src/lib.rs @@ -43,6 +43,38 @@ impl McBufWritable for OptionalRegistry { } } +/// A registry that will either take an ID or a resource location. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum CustomRegistry { + Direct(D), + Custom(C), +} + +impl McBufReadable for CustomRegistry { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result { + let direct_registry = OptionalRegistry::::read_from(buf)?; + if let Some(direct_registry) = direct_registry.0 { + return Ok(CustomRegistry::Direct(direct_registry)); + } + Ok(CustomRegistry::Custom(C::read_from(buf)?)) + } +} +impl McBufWritable for CustomRegistry { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + match self { + CustomRegistry::Direct(direct_registry) => { + // write the id + 1 + (direct_registry.to_u32() + 1).var_write_into(buf) + } + CustomRegistry::Custom(custom_registry) => { + // write 0, then the custom registry + 0u32.var_write_into(buf)?; + custom_registry.write_into(buf) + } + } + } +} + registry! { /// The AI code that's currently being executed for the entity. enum Activity {