diff options
| author | mat <github@matdoes.dev> | 2021-12-26 14:15:06 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2021-12-26 14:15:06 -0600 |
| commit | af28b0e57aeeca8790e3014f3e568c60ae892e39 (patch) | |
| tree | 497fa95e62393111f0b87d31926066153679bb52 /azalea-core/src | |
| parent | 1cdd061a999bfa16907ebcc5ab38b1863839b5f1 (diff) | |
| download | azalea-drasl-af28b0e57aeeca8790e3014f3e568c60ae892e39.tar.xz | |
reading nbt in the protocol works
Diffstat (limited to 'azalea-core/src')
| -rw-r--r-- | azalea-core/src/game_type.rs | 15 | ||||
| -rw-r--r-- | azalea-core/src/registries.rs | 8 | ||||
| -rw-r--r-- | azalea-core/src/resource_location.rs | 2 |
3 files changed, 12 insertions, 13 deletions
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<GameType, String> { + 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<Option<GameType>, 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, |
