aboutsummaryrefslogtreecommitdiff
path: root/azalea-registry/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-06-15 14:37:20 -0500
committermat <git@matdoes.dev>2023-06-15 14:37:20 -0500
commitfe687f9bdbdf3e0214ac4ac6da47a181e4dc23dd (patch)
tree9217e8041abd048689fcd897ce3ff0925bd929cd /azalea-registry/src
parent804a9fd80084ead45c5b1b72fdb7c16e2f7ab712 (diff)
downloadazalea-drasl-fe687f9bdbdf3e0214ac4ac6da47a181e4dc23dd.tar.xz
fix clientboundsoundpacket
closes #89
Diffstat (limited to 'azalea-registry/src')
-rwxr-xr-xazalea-registry/src/lib.rs32
1 files changed, 32 insertions, 0 deletions
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<T: Registry> McBufWritable for OptionalRegistry<T> {
}
}
+/// A registry that will either take an ID or a resource location.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+pub enum CustomRegistry<D: Registry, C: McBufReadable + McBufWritable> {
+ Direct(D),
+ Custom(C),
+}
+
+impl<D: Registry, C: McBufReadable + McBufWritable> McBufReadable for CustomRegistry<D, C> {
+ fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
+ let direct_registry = OptionalRegistry::<D>::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<D: Registry, C: McBufReadable + McBufWritable> McBufWritable for CustomRegistry<D, C> {
+ 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 {