diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-12-12 00:56:02 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-12 00:56:02 -0600 |
| commit | f9c25665c203d6377ace62f1e95381d037d8fd9e (patch) | |
| tree | 8b4131d20fe661d3cc1175ec27f801fe61df41ea /azalea-protocol/src | |
| parent | 82ad975242292d5875780b4398b62637674bf50a (diff) | |
| download | azalea-drasl-f9c25665c203d6377ace62f1e95381d037d8fd9e.tar.xz | |
Refactor azalea-registry (#294)
* move registries in azalea-registry into separate modules
* rename Item and Block to ItemKind and BlockKind
* remove 'extra' registries from azalea-registry
* hide deprecated items from docs
* use DamageKindKey instead of Identifier when parsing registries
* store tag entries as a Vec instead of a HashSet
* sort tag values by protocol id
* update changelog
Diffstat (limited to 'azalea-protocol/src')
55 files changed, 168 insertions, 87 deletions
diff --git a/azalea-protocol/src/common/debug_subscription.rs b/azalea-protocol/src/common/debug_subscription.rs index 221cd98c..0be792e1 100644 --- a/azalea-protocol/src/common/debug_subscription.rs +++ b/azalea-protocol/src/common/debug_subscription.rs @@ -2,7 +2,7 @@ use std::fmt::Debug; use azalea_buf::AzBuf; use azalea_core::position::{BlockPos, Vec3}; -use azalea_registry::{Block, DebugSubscription, GameEvent, PointOfInterestKind}; +use azalea_registry::builtin::{BlockKind, DebugSubscription, GameEvent, PointOfInterestKind}; // see DebugSubscriptions.java @@ -119,7 +119,7 @@ pub enum DebugEntityBlockIntersection { #[derive(Clone, Debug, AzBuf, PartialEq)] pub struct DebugHiveInfo { - pub kind: Block, + pub kind: BlockKind, #[var] pub occupant_count: i32, #[var] diff --git a/azalea-protocol/src/common/recipe.rs b/azalea-protocol/src/common/recipe.rs index 709679f1..43a64469 100644 --- a/azalea-protocol/src/common/recipe.rs +++ b/azalea-protocol/src/common/recipe.rs @@ -1,7 +1,6 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; use azalea_inventory::ItemStack; -use azalea_registry::HolderSet; +use azalea_registry::{HolderSet, builtin::ItemKind, identifier::Identifier}; /// [`azalea_registry::RecipeDisplay`] #[derive(Clone, Debug, AzBuf, PartialEq)] @@ -56,7 +55,7 @@ pub struct SmithingRecipeDisplay { #[derive(Clone, Debug, PartialEq, AzBuf)] pub struct Ingredient { - pub allowed: HolderSet<azalea_registry::Item, Identifier>, + pub allowed: HolderSet<ItemKind, Identifier>, } /// [`azalea_registry::SlotDisplay`] @@ -64,7 +63,7 @@ pub struct Ingredient { pub enum SlotDisplayData { Empty, AnyFuel, - Item(ItemStackDisplay), + ItemKind(ItemStackDisplay), ItemStack(ItemStackSlotDisplay), Tag(Identifier), SmithingTrim(Box<SmithingTrimDemoSlotDisplay>), @@ -74,7 +73,7 @@ pub enum SlotDisplayData { #[derive(Clone, Debug, PartialEq, AzBuf)] pub struct ItemStackDisplay { - pub item: azalea_registry::Item, + pub item: ItemKind, } #[derive(Clone, Debug, PartialEq, AzBuf)] pub struct ItemStackSlotDisplay { @@ -82,7 +81,7 @@ pub struct ItemStackSlotDisplay { } #[derive(Clone, Debug, PartialEq, AzBuf)] pub struct TagSlotDisplay { - pub tag: azalea_registry::Item, + pub tag: ItemKind, } #[derive(Clone, Debug, PartialEq, AzBuf)] pub struct SmithingTrimDemoSlotDisplay { diff --git a/azalea-protocol/src/common/tags.rs b/azalea-protocol/src/common/tags.rs index f8ddfc81..f22175ee 100644 --- a/azalea-protocol/src/common/tags.rs +++ b/azalea-protocol/src/common/tags.rs @@ -4,7 +4,7 @@ use std::{ }; use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use indexmap::IndexMap; #[derive(Clone, Debug, PartialEq)] diff --git a/azalea-protocol/src/lib.rs b/azalea-protocol/src/lib.rs index 45abf240..b5c0fd1e 100644 --- a/azalea-protocol/src/lib.rs +++ b/azalea-protocol/src/lib.rs @@ -27,6 +27,7 @@ pub mod read; pub mod resolve; pub mod write; +#[doc(hidden)] #[deprecated(note = "Renamed to resolve")] pub mod resolver { pub use super::resolve::*; diff --git a/azalea-protocol/src/packets/common.rs b/azalea-protocol/src/packets/common.rs index eb377683..a6cfc03f 100644 --- a/azalea-protocol/src/packets/common.rs +++ b/azalea-protocol/src/packets/common.rs @@ -2,15 +2,15 @@ use azalea_buf::AzBuf; use azalea_core::{ data_registry::ResolvableDataRegistry, game_type::{GameMode, OptionalGameType}, - identifier::Identifier, position::GlobalPos, - registry_holder::{RegistryHolder, dimension_type::DimensionTypeElement}, + registry_holder::{RegistryHolder, dimension_type::DimensionKindElement}, }; +use azalea_registry::{data::DimensionKind, identifier::Identifier}; use tracing::error; #[derive(Clone, Debug, AzBuf, PartialEq)] pub struct CommonPlayerSpawnInfo { - pub dimension_type: azalea_registry::DimensionType, + pub dimension_type: DimensionKind, pub dimension: Identifier, pub seed: i64, pub game_type: GameMode, @@ -27,7 +27,7 @@ impl CommonPlayerSpawnInfo { pub fn dimension_type<'a>( &self, registry_holder: &'a RegistryHolder, - ) -> Option<(&'a Identifier, &'a DimensionTypeElement)> { + ) -> Option<(&'a Identifier, &'a DimensionKindElement)> { let dimension_res = self.dimension_type.resolve(registry_holder); let Some((dimension_type, dimension_data)) = dimension_res else { error!("Couldn't resolve dimension_type {:?}", self.dimension_type); diff --git a/azalea-protocol/src/packets/config/c_cookie_request.rs b/azalea-protocol/src/packets/config/c_cookie_request.rs index ff368b63..0edbf21e 100644 --- a/azalea-protocol/src/packets/config/c_cookie_request.rs +++ b/azalea-protocol/src/packets/config/c_cookie_request.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ClientboundConfigPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundConfigPacket)] diff --git a/azalea-protocol/src/packets/config/c_custom_payload.rs b/azalea-protocol/src/packets/config/c_custom_payload.rs index 03776bf9..c9417dcd 100644 --- a/azalea-protocol/src/packets/config/c_custom_payload.rs +++ b/azalea-protocol/src/packets/config/c_custom_payload.rs @@ -1,5 +1,5 @@ use azalea_buf::{AzBuf, UnsizedByteArray}; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ClientboundConfigPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundConfigPacket)] diff --git a/azalea-protocol/src/packets/config/c_registry_data.rs b/azalea-protocol/src/packets/config/c_registry_data.rs index 16a86a9f..cb46958c 100644 --- a/azalea-protocol/src/packets/config/c_registry_data.rs +++ b/azalea-protocol/src/packets/config/c_registry_data.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ClientboundConfigPacket; use simdnbt::owned::NbtCompound; diff --git a/azalea-protocol/src/packets/config/c_store_cookie.rs b/azalea-protocol/src/packets/config/c_store_cookie.rs index 3d797d18..1b695b22 100644 --- a/azalea-protocol/src/packets/config/c_store_cookie.rs +++ b/azalea-protocol/src/packets/config/c_store_cookie.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ClientboundConfigPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundConfigPacket)] diff --git a/azalea-protocol/src/packets/config/c_update_enabled_features.rs b/azalea-protocol/src/packets/config/c_update_enabled_features.rs index b4e0e9c1..0080b65a 100644 --- a/azalea-protocol/src/packets/config/c_update_enabled_features.rs +++ b/azalea-protocol/src/packets/config/c_update_enabled_features.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ClientboundConfigPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundConfigPacket)] diff --git a/azalea-protocol/src/packets/config/s_cookie_response.rs b/azalea-protocol/src/packets/config/s_cookie_response.rs index ae44953e..44f74150 100644 --- a/azalea-protocol/src/packets/config/s_cookie_response.rs +++ b/azalea-protocol/src/packets/config/s_cookie_response.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ServerboundConfigPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundConfigPacket)] diff --git a/azalea-protocol/src/packets/config/s_custom_click_action.rs b/azalea-protocol/src/packets/config/s_custom_click_action.rs index 21b5cfbb..c36c2080 100644 --- a/azalea-protocol/src/packets/config/s_custom_click_action.rs +++ b/azalea-protocol/src/packets/config/s_custom_click_action.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ServerboundConfigPacket; use simdnbt::owned::Nbt; diff --git a/azalea-protocol/src/packets/config/s_custom_payload.rs b/azalea-protocol/src/packets/config/s_custom_payload.rs index 1bdc85af..e602bdca 100644 --- a/azalea-protocol/src/packets/config/s_custom_payload.rs +++ b/azalea-protocol/src/packets/config/s_custom_payload.rs @@ -1,5 +1,5 @@ use azalea_buf::{AzBuf, UnsizedByteArray}; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ServerboundConfigPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundConfigPacket)] diff --git a/azalea-protocol/src/packets/game/c_add_entity.rs b/azalea-protocol/src/packets/game/c_add_entity.rs index fbd2cb8a..e7b46750 100644 --- a/azalea-protocol/src/packets/game/c_add_entity.rs +++ b/azalea-protocol/src/packets/game/c_add_entity.rs @@ -1,7 +1,8 @@ use azalea_buf::AzBuf; -use azalea_core::{delta::LpVec3, identifier::Identifier, position::Vec3}; +use azalea_core::{delta::LpVec3, position::Vec3}; use azalea_entity::{EntityBundle, metadata::apply_default_metadata}; use azalea_protocol_macros::ClientboundGamePacket; +use azalea_registry::{builtin::EntityKind, identifier::Identifier}; use azalea_world::MinecraftEntityId; use uuid::Uuid; @@ -11,7 +12,7 @@ pub struct ClientboundAddEntity { #[var] pub id: MinecraftEntityId, pub uuid: Uuid, - pub entity_type: azalea_registry::EntityKind, + pub entity_type: EntityKind, pub position: Vec3, pub movement: LpVec3, pub x_rot: i8, diff --git a/azalea-protocol/src/packets/game/c_award_stats.rs b/azalea-protocol/src/packets/game/c_award_stats.rs index bb58a066..79a00f7b 100644 --- a/azalea-protocol/src/packets/game/c_award_stats.rs +++ b/azalea-protocol/src/packets/game/c_award_stats.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; +use azalea_registry::builtin::{BlockKind, CustomStat, EntityKind, ItemKind}; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundAwardStats { @@ -11,13 +12,13 @@ pub struct ClientboundAwardStats { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, AzBuf)] pub enum Stat { - Mined(azalea_registry::Block), - Crafted(azalea_registry::Item), - Used(azalea_registry::Item), - Broken(azalea_registry::Item), - PickedUp(azalea_registry::Item), - Dropped(azalea_registry::Item), - Killed(azalea_registry::EntityKind), - KilledBy(azalea_registry::EntityKind), - Custom(azalea_registry::CustomStat), + Mined(BlockKind), + Crafted(ItemKind), + Used(ItemKind), + Broken(ItemKind), + PickedUp(ItemKind), + Dropped(ItemKind), + Killed(EntityKind), + KilledBy(EntityKind), + Custom(CustomStat), } diff --git a/azalea-protocol/src/packets/game/c_block_entity_data.rs b/azalea-protocol/src/packets/game/c_block_entity_data.rs index e0c7bb1b..0798e2bd 100644 --- a/azalea-protocol/src/packets/game/c_block_entity_data.rs +++ b/azalea-protocol/src/packets/game/c_block_entity_data.rs @@ -1,11 +1,12 @@ use azalea_buf::AzBuf; use azalea_core::position::BlockPos; use azalea_protocol_macros::ClientboundGamePacket; +use azalea_registry::builtin::BlockEntityKind; use simdnbt::owned::Nbt; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundBlockEntityData { pub pos: BlockPos, - pub block_entity_type: azalea_registry::BlockEntityKind, + pub block_entity_type: BlockEntityKind, pub tag: Nbt, } diff --git a/azalea-protocol/src/packets/game/c_block_event.rs b/azalea-protocol/src/packets/game/c_block_event.rs index 38b5099b..30bb8e6c 100644 --- a/azalea-protocol/src/packets/game/c_block_event.rs +++ b/azalea-protocol/src/packets/game/c_block_event.rs @@ -1,12 +1,12 @@ use azalea_buf::AzBuf; use azalea_core::position::BlockPos; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_registry::Block; +use azalea_registry::builtin::BlockKind; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundBlockEvent { pub pos: BlockPos, pub action_id: u8, pub action_parameter: u8, - pub block: Block, + pub block: BlockKind, } diff --git a/azalea-protocol/src/packets/game/c_commands.rs b/azalea-protocol/src/packets/game/c_commands.rs index 46be5613..f96e7ef0 100644 --- a/azalea-protocol/src/packets/game/c_commands.rs +++ b/azalea-protocol/src/packets/game/c_commands.rs @@ -1,8 +1,9 @@ use std::io::{self, Cursor, Write}; use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; -use azalea_core::{bitset::FixedBitSet, identifier::Identifier}; +use azalea_core::bitset::FixedBitSet; use azalea_protocol_macros::ClientboundGamePacket; +use azalea_registry::identifier::Identifier; use tracing::warn; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] diff --git a/azalea-protocol/src/packets/game/c_cookie_request.rs b/azalea-protocol/src/packets/game/c_cookie_request.rs index 7b1e8e30..283b686d 100644 --- a/azalea-protocol/src/packets/game/c_cookie_request.rs +++ b/azalea-protocol/src/packets/game/c_cookie_request.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ClientboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] diff --git a/azalea-protocol/src/packets/game/c_cooldown.rs b/azalea-protocol/src/packets/game/c_cooldown.rs index c25bdad6..398690f4 100644 --- a/azalea-protocol/src/packets/game/c_cooldown.rs +++ b/azalea-protocol/src/packets/game/c_cooldown.rs @@ -1,9 +1,10 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; +use azalea_registry::builtin::ItemKind; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundCooldown { - pub item: azalea_registry::Item, + pub item: ItemKind, #[var] pub duration: u32, } diff --git a/azalea-protocol/src/packets/game/c_custom_payload.rs b/azalea-protocol/src/packets/game/c_custom_payload.rs index e76967a6..a198c547 100644 --- a/azalea-protocol/src/packets/game/c_custom_payload.rs +++ b/azalea-protocol/src/packets/game/c_custom_payload.rs @@ -1,5 +1,5 @@ use azalea_buf::{AzBuf, UnsizedByteArray}; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ClientboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] diff --git a/azalea-protocol/src/packets/game/c_disguised_chat.rs b/azalea-protocol/src/packets/game/c_disguised_chat.rs index e0225096..1b7505c6 100644 --- a/azalea-protocol/src/packets/game/c_disguised_chat.rs +++ b/azalea-protocol/src/packets/game/c_disguised_chat.rs @@ -3,14 +3,16 @@ use azalea_chat::{ FormattedText, translatable_component::{PrimitiveOrComponent, TranslatableComponent}, }; +use azalea_core::registry_holder::RegistryHolder; use azalea_protocol_macros::ClientboundGamePacket; use super::c_player_chat::ChatTypeBound; +use crate::packets::game::c_player_chat::GUESSED_DEFAULT_REGISTRIES_FOR_CHAT; -// A disguised chat packet is basically the same as a normal -// [`ClientboundPlayerChat`], except that it doesn't have any of the chat -// signing things. Vanilla servers use this when messages are sent from the -// console. +/// Similar to a [`ClientboundPlayerChat`](super::ClientboundPlayerChat), but +/// without chat signing. +/// +/// Vanilla servers use this packet when messages are sent from the console. #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundDisguisedChat { pub message: FormattedText, @@ -19,8 +21,22 @@ pub struct ClientboundDisguisedChat { impl ClientboundDisguisedChat { /// Get the full message, including the sender part. + /// + /// Note that the returned message may be incorrect on servers that + /// customize the chat type registry. Consider using + /// [`Self::message_using_registries`] if you'd like to avoid that + /// problem. #[must_use] pub fn message(&self) -> FormattedText { + self.message_using_registries(&GUESSED_DEFAULT_REGISTRIES_FOR_CHAT) + } + + /// Get the full message, including the sender part, while ensuring that the + /// message chat type is correct based on the server's registries. + /// + /// Also see [`Self::message`]. + #[must_use] + pub fn message_using_registries(&self, registries: &RegistryHolder) -> FormattedText { let sender = self.chat_type.name.clone(); let content = self.message.clone(); let target = self.chat_type.target_name.clone(); @@ -33,7 +49,7 @@ impl ClientboundDisguisedChat { args.push(PrimitiveOrComponent::FormattedText(target)); } - let translation_key = self.chat_type.translation_key(); + let translation_key = self.chat_type.translation_key(registries); let component = TranslatableComponent::new(translation_key.to_string(), args); FormattedText::Translatable(component) diff --git a/azalea-protocol/src/packets/game/c_explode.rs b/azalea-protocol/src/packets/game/c_explode.rs index 15e036ea..e8744b79 100644 --- a/azalea-protocol/src/packets/game/c_explode.rs +++ b/azalea-protocol/src/packets/game/c_explode.rs @@ -2,7 +2,7 @@ use azalea_buf::AzBuf; use azalea_core::position::Vec3; use azalea_entity::particle::Particle; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_registry::SoundEvent; +use azalea_registry::builtin::SoundEvent; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundExplode { diff --git a/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs b/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs index af2228eb..d9d1097f 100644 --- a/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs +++ b/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs @@ -2,6 +2,7 @@ use std::sync::Arc; use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; +use azalea_registry::builtin::BlockEntityKind; use azalea_world::heightmap::HeightmapKind; use simdnbt::owned::Nbt; @@ -34,6 +35,6 @@ pub struct ClientboundLevelChunkPacketData { pub struct BlockEntity { pub packed_xz: u8, pub y: u16, - pub kind: azalea_registry::BlockEntityKind, + pub kind: BlockEntityKind, pub data: Nbt, } diff --git a/azalea-protocol/src/packets/game/c_login.rs b/azalea-protocol/src/packets/game/c_login.rs index 1c89dbac..9439eec9 100644 --- a/azalea-protocol/src/packets/game/c_login.rs +++ b/azalea-protocol/src/packets/game/c_login.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ClientboundGamePacket; use azalea_world::MinecraftEntityId; diff --git a/azalea-protocol/src/packets/game/c_merchant_offers.rs b/azalea-protocol/src/packets/game/c_merchant_offers.rs index c8baff78..079041f6 100644 --- a/azalea-protocol/src/packets/game/c_merchant_offers.rs +++ b/azalea-protocol/src/packets/game/c_merchant_offers.rs @@ -10,7 +10,7 @@ use azalea_inventory::{ components::{self, DataComponentUnion}, }; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_registry::{DataComponentKind, Item}; +use azalea_registry::builtin::{DataComponentKind, ItemKind}; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundMerchantOffers { @@ -45,7 +45,7 @@ pub struct MerchantOffer { /// [`Self::into_item_stack`]. #[derive(Clone, Debug, AzBuf, PartialEq)] pub struct ItemCost { - pub item: Item, + pub item: ItemKind, #[var] pub count: i32, pub components: DataComponentExactPredicate, diff --git a/azalea-protocol/src/packets/game/c_open_screen.rs b/azalea-protocol/src/packets/game/c_open_screen.rs index b4a38387..cac3495f 100644 --- a/azalea-protocol/src/packets/game/c_open_screen.rs +++ b/azalea-protocol/src/packets/game/c_open_screen.rs @@ -1,11 +1,12 @@ use azalea_buf::AzBuf; use azalea_chat::FormattedText; use azalea_protocol_macros::ClientboundGamePacket; +use azalea_registry::builtin::MenuKind; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundOpenScreen { #[var] pub container_id: i32, - pub menu_type: azalea_registry::MenuKind, + pub menu_type: MenuKind, pub title: FormattedText, } diff --git a/azalea-protocol/src/packets/game/c_player_chat.rs b/azalea-protocol/src/packets/game/c_player_chat.rs index f3201e3f..3904d0d9 100644 --- a/azalea-protocol/src/packets/game/c_player_chat.rs +++ b/azalea-protocol/src/packets/game/c_player_chat.rs @@ -1,14 +1,25 @@ -use std::io::{self, Cursor, Write}; +use std::{ + io::{self, Cursor, Write}, + sync::LazyLock, +}; use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; use azalea_chat::{ FormattedText, translatable_component::{PrimitiveOrComponent, TranslatableComponent}, }; -use azalea_core::bitset::BitSet; +use azalea_core::{ + bitset::BitSet, + data_registry::DataRegistryWithKey, + registry_holder::{RegistryHolder, RegistryType}, +}; use azalea_crypto::signing::MessageSignature; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_registry::Holder; +use azalea_registry::{ + DataRegistryKey, Holder, + data::{ChatKind, ChatKindKey}, + identifier::Identifier, +}; use simdnbt::owned::NbtCompound; use uuid::Uuid; @@ -57,7 +68,7 @@ pub enum FilterMask { #[derive(Clone, Debug, PartialEq, AzBuf)] pub struct ChatTypeBound { - pub chat_type: Holder<azalea_registry::ChatType, DirectChatType>, + pub chat_type: Holder<ChatKind, DirectChatType>, pub name: FormattedText, pub target_name: Option<FormattedText>, } @@ -87,6 +98,27 @@ pub struct MessageSignatureCache { pub entries: Vec<Option<MessageSignature>>, } +/// A `RegistryHolder` that only has the `chat_type` registry (without values), +/// with the keys being in the default order for vanilla servers. +/// +/// This is used when we call [`ClientboundPlayerChat::message`] without also +/// passing registries. +pub static GUESSED_DEFAULT_REGISTRIES_FOR_CHAT: LazyLock<RegistryHolder> = + LazyLock::new(|| RegistryHolder { + extra: [( + Identifier::new("chat_type"), + RegistryType { + map: ChatKindKey::ALL + .iter() + .map(|k| (k.clone().into_ident(), NbtCompound::new())) + .collect(), + }, + )] + .into_iter() + .collect(), + ..Default::default() + }); + impl ClientboundPlayerChat { /// Returns the content of the message. /// @@ -100,8 +132,22 @@ impl ClientboundPlayerChat { } /// Get the full message, including the sender part. + /// + /// Note that the returned message may be incorrect on servers that + /// customize the chat type registry. Consider using + /// [`Self::message_using_registries`] if you'd like to avoid that + /// problem. #[must_use] pub fn message(&self) -> FormattedText { + self.message_using_registries(&GUESSED_DEFAULT_REGISTRIES_FOR_CHAT) + } + + /// Get the full message, including the sender part, while ensuring that the + /// message chat type is correct based on the server's registries. + /// + /// Also see [`Self::message`]. + #[must_use] + pub fn message_using_registries(&self, registries: &RegistryHolder) -> FormattedText { let sender = self.chat_type.name.clone(); let content = self.content(); let target = self.chat_type.target_name.clone(); @@ -114,7 +160,8 @@ impl ClientboundPlayerChat { args.push(PrimitiveOrComponent::FormattedText(target)); } - let translation_key = self.chat_type.translation_key(); + // TODO: implement chat type registry and apply the styles from it here + let translation_key = self.chat_type.translation_key(registries); let component = TranslatableComponent::new(translation_key.to_string(), args); FormattedText::Translatable(component) @@ -122,9 +169,12 @@ impl ClientboundPlayerChat { } impl ChatTypeBound { - pub fn translation_key(&self) -> &str { + pub fn translation_key(&self, registries: &RegistryHolder) -> &str { match &self.chat_type { - Holder::Reference(r) => r.chat_translation_key(), + Holder::Reference(r) => r + .key(registries) + .map(|r| r.chat_translation_key()) + .unwrap_or("chat.type.text"), Holder::Direct(d) => d.chat.translation_key.as_str(), } } diff --git a/azalea-protocol/src/packets/game/c_recipe_book_add.rs b/azalea-protocol/src/packets/game/c_recipe_book_add.rs index 699843fa..0fcd8b04 100644 --- a/azalea-protocol/src/packets/game/c_recipe_book_add.rs +++ b/azalea-protocol/src/packets/game/c_recipe_book_add.rs @@ -1,5 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; +use azalea_registry::builtin::RecipeBookCategory; use crate::common::recipe::{Ingredient, RecipeDisplayData}; @@ -23,6 +24,6 @@ pub struct RecipeDisplayEntry { // optional varint #[var] pub group: u32, - pub category: azalea_registry::RecipeBookCategory, + pub category: RecipeBookCategory, pub crafting_requirements: Option<Vec<Ingredient>>, } diff --git a/azalea-protocol/src/packets/game/c_remove_mob_effect.rs b/azalea-protocol/src/packets/game/c_remove_mob_effect.rs index 950c07ec..f17cfd37 100644 --- a/azalea-protocol/src/packets/game/c_remove_mob_effect.rs +++ b/azalea-protocol/src/packets/game/c_remove_mob_effect.rs @@ -1,10 +1,11 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; +use azalea_registry::builtin::MobEffect; use azalea_world::MinecraftEntityId; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundRemoveMobEffect { #[var] pub entity_id: MinecraftEntityId, - pub effect: azalea_registry::MobEffect, + pub effect: MobEffect, } diff --git a/azalea-protocol/src/packets/game/c_select_advancements_tab.rs b/azalea-protocol/src/packets/game/c_select_advancements_tab.rs index 0eee09de..0ff46365 100644 --- a/azalea-protocol/src/packets/game/c_select_advancements_tab.rs +++ b/azalea-protocol/src/packets/game/c_select_advancements_tab.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ClientboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] diff --git a/azalea-protocol/src/packets/game/c_show_dialog.rs b/azalea-protocol/src/packets/game/c_show_dialog.rs index 1bcce17f..52d9be78 100644 --- a/azalea-protocol/src/packets/game/c_show_dialog.rs +++ b/azalea-protocol/src/packets/game/c_show_dialog.rs @@ -1,9 +1,9 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_registry::Holder; +use azalea_registry::{Holder, data::Dialog}; use simdnbt::owned::Nbt; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundShowDialog { - pub dialog: Holder<azalea_registry::Dialog, Nbt>, + pub dialog: Holder<Dialog, Nbt>, } diff --git a/azalea-protocol/src/packets/game/c_sound.rs b/azalea-protocol/src/packets/game/c_sound.rs index a125546a..31d30942 100644 --- a/azalea-protocol/src/packets/game/c_sound.rs +++ b/azalea-protocol/src/packets/game/c_sound.rs @@ -1,7 +1,7 @@ use azalea_buf::AzBuf; use azalea_core::sound::CustomSound; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_registry::SoundEvent; +use azalea_registry::builtin::SoundEvent; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundSound { diff --git a/azalea-protocol/src/packets/game/c_sound_entity.rs b/azalea-protocol/src/packets/game/c_sound_entity.rs index e728e6eb..72325c04 100644 --- a/azalea-protocol/src/packets/game/c_sound_entity.rs +++ b/azalea-protocol/src/packets/game/c_sound_entity.rs @@ -1,7 +1,7 @@ use azalea_buf::AzBuf; use azalea_core::sound::CustomSound; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_registry::SoundEvent; +use azalea_registry::builtin::SoundEvent; use azalea_world::MinecraftEntityId; use super::c_sound::SoundSource; diff --git a/azalea-protocol/src/packets/game/c_stop_sound.rs b/azalea-protocol/src/packets/game/c_stop_sound.rs index f6b42325..419216eb 100644 --- a/azalea-protocol/src/packets/game/c_stop_sound.rs +++ b/azalea-protocol/src/packets/game/c_stop_sound.rs @@ -1,8 +1,9 @@ use std::io::{self, Cursor, Write}; use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError}; -use azalea_core::{bitset::FixedBitSet, identifier::Identifier}; +use azalea_core::bitset::FixedBitSet; use azalea_protocol_macros::ClientboundGamePacket; +use azalea_registry::identifier::Identifier; use super::c_sound::SoundSource; diff --git a/azalea-protocol/src/packets/game/c_store_cookie.rs b/azalea-protocol/src/packets/game/c_store_cookie.rs index 9646c3b9..fff6fb71 100644 --- a/azalea-protocol/src/packets/game/c_store_cookie.rs +++ b/azalea-protocol/src/packets/game/c_store_cookie.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ClientboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] diff --git a/azalea-protocol/src/packets/game/c_update_advancements.rs b/azalea-protocol/src/packets/game/c_update_advancements.rs index 7296d916..bba53998 100644 --- a/azalea-protocol/src/packets/game/c_update_advancements.rs +++ b/azalea-protocol/src/packets/game/c_update_advancements.rs @@ -5,7 +5,7 @@ use std::{ use azalea_buf::AzBuf; use azalea_chat::FormattedText; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_inventory::ItemStack; use azalea_protocol_macros::ClientboundGamePacket; use indexmap::IndexMap; diff --git a/azalea-protocol/src/packets/game/c_update_attributes.rs b/azalea-protocol/src/packets/game/c_update_attributes.rs index d11b08cb..80e4729f 100644 --- a/azalea-protocol/src/packets/game/c_update_attributes.rs +++ b/azalea-protocol/src/packets/game/c_update_attributes.rs @@ -1,7 +1,7 @@ use azalea_buf::AzBuf; use azalea_inventory::components::AttributeModifier; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_registry::Attribute; +use azalea_registry::builtin::Attribute; use azalea_world::MinecraftEntityId; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] diff --git a/azalea-protocol/src/packets/game/c_update_mob_effect.rs b/azalea-protocol/src/packets/game/c_update_mob_effect.rs index e9892950..adc33f62 100644 --- a/azalea-protocol/src/packets/game/c_update_mob_effect.rs +++ b/azalea-protocol/src/packets/game/c_update_mob_effect.rs @@ -1,7 +1,7 @@ use azalea_buf::AzBuf; use azalea_entity::MobEffectData; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_registry::MobEffect; +use azalea_registry::builtin::MobEffect; use azalea_world::MinecraftEntityId; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] diff --git a/azalea-protocol/src/packets/game/c_update_recipes.rs b/azalea-protocol/src/packets/game/c_update_recipes.rs index e05708a3..de9f6e3b 100644 --- a/azalea-protocol/src/packets/game/c_update_recipes.rs +++ b/azalea-protocol/src/packets/game/c_update_recipes.rs @@ -1,8 +1,9 @@ use std::collections::HashMap; use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ClientboundGamePacket; +use azalea_registry::builtin::ItemKind; use crate::common::recipe::{Ingredient, SlotDisplayData}; @@ -24,5 +25,5 @@ pub struct SelectableRecipe { #[derive(Clone, Debug, PartialEq, AzBuf)] pub struct RecipePropertySet { - pub items: Vec<azalea_registry::Item>, + pub items: Vec<ItemKind>, } diff --git a/azalea-protocol/src/packets/game/c_waypoint.rs b/azalea-protocol/src/packets/game/c_waypoint.rs index 0debb0d0..a701622f 100644 --- a/azalea-protocol/src/packets/game/c_waypoint.rs +++ b/azalea-protocol/src/packets/game/c_waypoint.rs @@ -1,8 +1,9 @@ use std::io::{self, Cursor, Write}; use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; -use azalea_core::{color::RgbColor, identifier::Identifier, position::Vec3i}; +use azalea_core::{color::RgbColor, position::Vec3i}; use azalea_protocol_macros::ClientboundGamePacket; +use azalea_registry::identifier::Identifier; use uuid::Uuid; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] diff --git a/azalea-protocol/src/packets/game/s_container_click.rs b/azalea-protocol/src/packets/game/s_container_click.rs index ef2e832d..bfce320e 100644 --- a/azalea-protocol/src/packets/game/s_container_click.rs +++ b/azalea-protocol/src/packets/game/s_container_click.rs @@ -2,6 +2,7 @@ use azalea_buf::AzBuf; use azalea_core::{checksum::Checksum, registry_holder::RegistryHolder}; use azalea_inventory::{ItemStack, operations::ClickType}; use azalea_protocol_macros::ServerboundGamePacket; +use azalea_registry::builtin::{DataComponentKind, ItemKind}; use indexmap::IndexMap; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundGamePacket)] @@ -24,7 +25,7 @@ pub struct HashedStack(pub Option<HashedActualItem>); #[derive(Clone, Debug, AzBuf, PartialEq)] pub struct HashedActualItem { - pub kind: azalea_registry::Item, + pub kind: ItemKind, #[var] pub count: i32, pub components: HashedPatchMap, @@ -33,9 +34,9 @@ pub struct HashedActualItem { #[derive(Clone, Debug, AzBuf, PartialEq)] pub struct HashedPatchMap { #[limit(256)] - pub added_components: Vec<(azalea_registry::DataComponentKind, Checksum)>, + pub added_components: Vec<(DataComponentKind, Checksum)>, #[limit(256)] - pub removed_components: Vec<azalea_registry::DataComponentKind>, + pub removed_components: Vec<DataComponentKind>, } impl HashedStack { diff --git a/azalea-protocol/src/packets/game/s_cookie_response.rs b/azalea-protocol/src/packets/game/s_cookie_response.rs index a6a99cf7..72b95f4d 100644 --- a/azalea-protocol/src/packets/game/s_cookie_response.rs +++ b/azalea-protocol/src/packets/game/s_cookie_response.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ServerboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundGamePacket)] diff --git a/azalea-protocol/src/packets/game/s_custom_click_action.rs b/azalea-protocol/src/packets/game/s_custom_click_action.rs index 193405df..e10e8749 100644 --- a/azalea-protocol/src/packets/game/s_custom_click_action.rs +++ b/azalea-protocol/src/packets/game/s_custom_click_action.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ServerboundGamePacket; use simdnbt::owned::Nbt; diff --git a/azalea-protocol/src/packets/game/s_custom_payload.rs b/azalea-protocol/src/packets/game/s_custom_payload.rs index 8753c7f7..7e5468d9 100644 --- a/azalea-protocol/src/packets/game/s_custom_payload.rs +++ b/azalea-protocol/src/packets/game/s_custom_payload.rs @@ -1,5 +1,5 @@ use azalea_buf::{AzBuf, UnsizedByteArray}; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ServerboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundGamePacket)] diff --git a/azalea-protocol/src/packets/game/s_debug_subscription_request.rs b/azalea-protocol/src/packets/game/s_debug_subscription_request.rs index ea31b113..23bd49a5 100644 --- a/azalea-protocol/src/packets/game/s_debug_subscription_request.rs +++ b/azalea-protocol/src/packets/game/s_debug_subscription_request.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ServerboundGamePacket; -use azalea_registry::DebugSubscription; +use azalea_registry::builtin::DebugSubscription; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundGamePacket)] pub struct ServerboundDebugSubscriptionRequest { diff --git a/azalea-protocol/src/packets/game/s_place_recipe.rs b/azalea-protocol/src/packets/game/s_place_recipe.rs index a1f007a0..90821d08 100644 --- a/azalea-protocol/src/packets/game/s_place_recipe.rs +++ b/azalea-protocol/src/packets/game/s_place_recipe.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ServerboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundGamePacket)] diff --git a/azalea-protocol/src/packets/game/s_recipe_book_seen_recipe.rs b/azalea-protocol/src/packets/game/s_recipe_book_seen_recipe.rs index 350c7290..e9766a64 100644 --- a/azalea-protocol/src/packets/game/s_recipe_book_seen_recipe.rs +++ b/azalea-protocol/src/packets/game/s_recipe_book_seen_recipe.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ServerboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundGamePacket)] diff --git a/azalea-protocol/src/packets/game/s_seen_advancements.rs b/azalea-protocol/src/packets/game/s_seen_advancements.rs index 7d9e552b..7e001b7f 100644 --- a/azalea-protocol/src/packets/game/s_seen_advancements.rs +++ b/azalea-protocol/src/packets/game/s_seen_advancements.rs @@ -1,7 +1,7 @@ use std::io::{self, Cursor, Write}; use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite}; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ServerboundGamePacket; use crate::packets::BufReadError; diff --git a/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs b/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs index ac942d88..2203d3e9 100644 --- a/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs +++ b/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs @@ -4,8 +4,9 @@ use std::{ }; use azalea_buf::{AzBuf, AzaleaRead}; -use azalea_core::{identifier::Identifier, position::BlockPos}; +use azalea_core::position::BlockPos; use azalea_protocol_macros::ServerboundGamePacket; +use azalea_registry::identifier::Identifier; use crate::packets::{AzaleaWrite, BufReadError}; diff --git a/azalea-protocol/src/packets/game/s_test_instance_block_action.rs b/azalea-protocol/src/packets/game/s_test_instance_block_action.rs index eacf18a6..c4baf78d 100644 --- a/azalea-protocol/src/packets/game/s_test_instance_block_action.rs +++ b/azalea-protocol/src/packets/game/s_test_instance_block_action.rs @@ -2,7 +2,7 @@ use azalea_buf::AzBuf; use azalea_chat::FormattedText; use azalea_core::position::{BlockPos, Vec3i}; use azalea_protocol_macros::ServerboundGamePacket; -use azalea_registry::TestInstanceKind; +use azalea_registry::builtin::TestInstanceKind; use super::s_set_structure_block::Rotation; diff --git a/azalea-protocol/src/packets/login/c_cookie_request.rs b/azalea-protocol/src/packets/login/c_cookie_request.rs index fbe72c6a..2df3aaa0 100644 --- a/azalea-protocol/src/packets/login/c_cookie_request.rs +++ b/azalea-protocol/src/packets/login/c_cookie_request.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ClientboundLoginPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundLoginPacket)] diff --git a/azalea-protocol/src/packets/login/c_custom_query.rs b/azalea-protocol/src/packets/login/c_custom_query.rs index 9c7ee50a..6f975cf4 100644 --- a/azalea-protocol/src/packets/login/c_custom_query.rs +++ b/azalea-protocol/src/packets/login/c_custom_query.rs @@ -1,7 +1,7 @@ use std::hash::Hash; use azalea_buf::{AzBuf, UnsizedByteArray}; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ClientboundLoginPacket; #[derive(Hash, Clone, Debug, AzBuf, PartialEq, ClientboundLoginPacket)] diff --git a/azalea-protocol/src/packets/login/s_cookie_response.rs b/azalea-protocol/src/packets/login/s_cookie_response.rs index c9e7ced9..73efc2a8 100644 --- a/azalea-protocol/src/packets/login/s_cookie_response.rs +++ b/azalea-protocol/src/packets/login/s_cookie_response.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ServerboundLoginPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundLoginPacket)] diff --git a/azalea-protocol/src/resolve.rs b/azalea-protocol/src/resolve.rs index f18a04a8..468371aa 100644 --- a/azalea-protocol/src/resolve.rs +++ b/azalea-protocol/src/resolve.rs @@ -10,6 +10,7 @@ use hickory_resolver::{Name, TokioResolver, name_server::TokioConnectionProvider use crate::ServerAddress; +#[doc(hidden)] #[deprecated(note = "Renamed to ResolveError")] pub type ResolverError = ResolveError; |
