diff options
Diffstat (limited to 'azalea-protocol/src/common')
| -rw-r--r-- | azalea-protocol/src/common/mod.rs | 1 | ||||
| -rw-r--r-- | azalea-protocol/src/common/movements.rs | 4 | ||||
| -rw-r--r-- | azalea-protocol/src/common/recipe.rs | 12 | ||||
| -rw-r--r-- | azalea-protocol/src/common/server_links.rs | 6 | ||||
| -rw-r--r-- | azalea-protocol/src/common/tags.rs | 69 |
5 files changed, 81 insertions, 11 deletions
diff --git a/azalea-protocol/src/common/mod.rs b/azalea-protocol/src/common/mod.rs index 9258e538..f666fc8b 100644 --- a/azalea-protocol/src/common/mod.rs +++ b/azalea-protocol/src/common/mod.rs @@ -4,3 +4,4 @@ pub mod client_information; pub mod movements; pub mod recipe; pub mod server_links; +pub mod tags; diff --git a/azalea-protocol/src/common/movements.rs b/azalea-protocol/src/common/movements.rs index f6611fc6..e7b71a2e 100644 --- a/azalea-protocol/src/common/movements.rs +++ b/azalea-protocol/src/common/movements.rs @@ -11,7 +11,7 @@ use azalea_entity::{LookDirection, Physics, Position}; /// /// Often, this field comes alongside a [`RelativeMovements`] field, which /// specifies which parts of this struct should be treated as relative. -#[derive(AzBuf, Clone, Debug)] +#[derive(AzBuf, Clone, Debug, PartialEq)] pub struct PositionMoveRotation { pub pos: Vec3, /// The updated delta movement (velocity). @@ -19,7 +19,7 @@ pub struct PositionMoveRotation { pub look_direction: LookDirection, } -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, PartialEq)] pub struct RelativeMovements { pub x: bool, pub y: bool, diff --git a/azalea-protocol/src/common/recipe.rs b/azalea-protocol/src/common/recipe.rs index 15d40cca..8ab2d5ba 100644 --- a/azalea-protocol/src/common/recipe.rs +++ b/azalea-protocol/src/common/recipe.rs @@ -4,7 +4,7 @@ use azalea_inventory::ItemStack; use azalea_registry::HolderSet; /// [`azalea_registry::RecipeDisplay`] -#[derive(Clone, Debug, AzBuf)] +#[derive(Clone, Debug, AzBuf, PartialEq)] pub enum RecipeDisplayData { Shapeless(ShapelessCraftingRecipeDisplay), Shaped(ShapedCraftingRecipeDisplay), @@ -13,13 +13,13 @@ pub enum RecipeDisplayData { Smithing(SmithingRecipeDisplay), } -#[derive(Clone, Debug, AzBuf)] +#[derive(Clone, Debug, AzBuf, PartialEq)] pub struct ShapelessCraftingRecipeDisplay { pub ingredients: Vec<SlotDisplayData>, pub result: SlotDisplayData, pub crafting_station: SlotDisplayData, } -#[derive(Clone, Debug, AzBuf)] +#[derive(Clone, Debug, AzBuf, PartialEq)] pub struct ShapedCraftingRecipeDisplay { #[var] pub width: u32, @@ -29,7 +29,7 @@ pub struct ShapedCraftingRecipeDisplay { pub result: SlotDisplayData, pub crafting_station: SlotDisplayData, } -#[derive(Clone, Debug, AzBuf)] +#[derive(Clone, Debug, AzBuf, PartialEq)] pub struct FurnaceRecipeDisplay { pub ingredient: SlotDisplayData, pub fuel: SlotDisplayData, @@ -39,13 +39,13 @@ pub struct FurnaceRecipeDisplay { pub duration: u32, pub experience: f32, } -#[derive(Clone, Debug, AzBuf)] +#[derive(Clone, Debug, AzBuf, PartialEq)] pub struct StonecutterRecipeDisplay { pub input: SlotDisplayData, pub result: SlotDisplayData, pub crafting_station: SlotDisplayData, } -#[derive(Clone, Debug, AzBuf)] +#[derive(Clone, Debug, AzBuf, PartialEq)] pub struct SmithingRecipeDisplay { pub template: SlotDisplayData, pub base: SlotDisplayData, diff --git a/azalea-protocol/src/common/server_links.rs b/azalea-protocol/src/common/server_links.rs index 7c6bbec4..34ae43e6 100644 --- a/azalea-protocol/src/common/server_links.rs +++ b/azalea-protocol/src/common/server_links.rs @@ -1,19 +1,19 @@ use azalea_buf::AzBuf; use azalea_chat::FormattedText; -#[derive(Clone, Debug, AzBuf)] +#[derive(Clone, Debug, AzBuf, PartialEq)] pub struct ServerLinkEntry { pub kind: ServerLinkKind, pub link: String, } -#[derive(Clone, Debug, AzBuf)] +#[derive(Clone, Debug, AzBuf, PartialEq)] pub enum ServerLinkKind { Component(FormattedText), Known(KnownLinkKind), } -#[derive(Clone, Copy, Debug, AzBuf)] +#[derive(Clone, Copy, Debug, AzBuf, PartialEq)] pub enum KnownLinkKind { BugReport, CommunityGuidelines, diff --git a/azalea-protocol/src/common/tags.rs b/azalea-protocol/src/common/tags.rs new file mode 100644 index 00000000..0b798519 --- /dev/null +++ b/azalea-protocol/src/common/tags.rs @@ -0,0 +1,69 @@ +use std::{ + io::{self, Cursor, Write}, + ops::Deref, +}; + +use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; +use azalea_core::resource_location::ResourceLocation; +use indexmap::IndexMap; + +#[derive(Clone, Debug, PartialEq)] +pub struct TagMap(pub IndexMap<ResourceLocation, Vec<Tags>>); + +#[derive(Clone, Debug, PartialEq)] +pub struct Tags { + pub name: ResourceLocation, + pub elements: Vec<i32>, +} + +impl AzaleaRead for TagMap { + fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + let length = u32::azalea_read_var(buf)? as usize; + let mut data = IndexMap::with_capacity(length); + for _ in 0..length { + let tag_type = ResourceLocation::azalea_read(buf)?; + let tags_count = i32::azalea_read_var(buf)? as usize; + let mut tags_vec = Vec::with_capacity(tags_count); + for _ in 0..tags_count { + let tags = Tags::azalea_read(buf)?; + tags_vec.push(tags); + } + data.insert(tag_type, tags_vec); + } + Ok(TagMap(data)) + } +} + +impl AzaleaWrite for TagMap { + fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { + (self.len() as u32).azalea_write_var(buf)?; + for (k, v) in &self.0 { + k.azalea_write(buf)?; + v.azalea_write(buf)?; + } + Ok(()) + } +} +impl AzaleaRead for Tags { + fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + let name = ResourceLocation::azalea_read(buf)?; + let elements = Vec::<i32>::azalea_read_var(buf)?; + Ok(Tags { name, elements }) + } +} + +impl AzaleaWrite for Tags { + fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { + self.name.azalea_write(buf)?; + self.elements.azalea_write_var(buf)?; + Ok(()) + } +} + +impl Deref for TagMap { + type Target = IndexMap<ResourceLocation, Vec<Tags>>; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} |
