From af28b0e57aeeca8790e3014f3e568c60ae892e39 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 26 Dec 2021 14:15:06 -0600 Subject: reading nbt in the protocol works --- azalea-core/src/game_type.rs | 15 +++++++++++---- azalea-core/src/registries.rs | 8 -------- azalea-core/src/resource_location.rs | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) delete mode 100644 azalea-core/src/registries.rs (limited to 'azalea-core/src') diff --git a/azalea-core/src/game_type.rs b/azalea-core/src/game_type.rs index 61abf898..b6ff479d 100644 --- a/azalea-core/src/game_type.rs +++ b/azalea-core/src/game_type.rs @@ -26,14 +26,21 @@ impl GameType { } } - pub fn from_id(id: u8) -> GameType { - match id { + pub fn from_id(id: u8) -> Result { + Ok(match id { 0 => GameType::SURVIVAL, 1 => GameType::CREATIVE, 2 => GameType::ADVENTURE, 3 => GameType::SPECTATOR, - _ => panic!("Unknown game type id: {}", id), - } + _ => return Err(format!("Unknown game type id: {}", id)), + }) + } + + pub fn from_optional_id(id: i8) -> Result, String> { + Ok(match id { + -1 => None, + id => Some(GameType::from_id(id as u8)?), + }) } pub fn short_name(&self) -> &'static str { diff --git a/azalea-core/src/registries.rs b/azalea-core/src/registries.rs deleted file mode 100644 index 605d7770..00000000 --- a/azalea-core/src/registries.rs +++ /dev/null @@ -1,8 +0,0 @@ -struct RegistryHolder {} - -fn make_network_codec() -> NetworkCodec { - // Codec codec = ResourceLocation.CODEC.xmap(ResourceKey::createRegistryKey, ResourceKey::location); - // Codec codec2 = codec.partialDispatch("type", mappedRegistry -> DataResult.success(mappedRegistry.key()), resourceKey -> RegistryHolder.getNetworkCodec(resourceKey).map(codec -> MappedRegistry.networkCodec(resourceKey, Lifecycle.experimental(), codec))); - // UnboundedMapCodec unboundedMapCodec = Codec.unboundedMap((Codec)codec, (Codec)codec2); - // return RegistryHolder.captureMap(unboundedMapCodec); -} diff --git a/azalea-core/src/resource_location.rs b/azalea-core/src/resource_location.rs index c1fed451..7e28a2a2 100644 --- a/azalea-core/src/resource_location.rs +++ b/azalea-core/src/resource_location.rs @@ -1,6 +1,6 @@ //! A resource, like minecraft:stone -#[derive(Hash, Clone, Debug)] +#[derive(Hash, Clone, Debug, PartialEq, Eq)] pub struct ResourceLocation { pub namespace: String, pub path: String, -- cgit v1.2.3