From fe687f9bdbdf3e0214ac4ac6da47a181e4dc23dd Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 15 Jun 2023 14:37:20 -0500 Subject: fix clientboundsoundpacket closes #89 --- azalea-registry/src/lib.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'azalea-registry/src') 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 { -- cgit v1.2.3