From 4f00ddace08bd5ad17500a405f55554dff343be7 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 4 Sep 2022 23:01:15 -0500 Subject: remove some debug stuff and fix recipe packet --- .../src/packets/game/clientbound_recipe_packet.rs | 57 +++++++++++++++++++--- 1 file changed, 50 insertions(+), 7 deletions(-) (limited to 'azalea-protocol') diff --git a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs index 29ad5800..dd7a162c 100644 --- a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs @@ -1,13 +1,56 @@ -use azalea_buf::McBuf; +use azalea_buf::{ + BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable, +}; use azalea_core::ResourceLocation; use packet_macros::ClientboundGamePacket; -#[derive(Clone, Debug, McBuf, ClientboundGamePacket)] +#[derive(Clone, Debug, ClientboundGamePacket)] pub struct ClientboundRecipePacket { pub action: State, pub settings: RecipeBookSettings, pub recipes: Vec, - pub to_highlight: Vec, +} + +impl McBufWritable for ClientboundRecipePacket { + fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { + match self.action { + State::Init { .. } => 0, + State::Add => 1, + State::Remove => 2, + } + .var_write_into(buf)?; + self.settings.write_into(buf)?; + self.recipes.write_into(buf)?; + if let State::Init { to_highlight } = &self.action { + to_highlight.write_into(buf)?; + } + Ok(()) + } +} +impl McBufReadable for ClientboundRecipePacket { + fn read_from(buf: &mut impl std::io::Read) -> Result { + let action_id = u32::var_read_from(buf)?; + let settings = RecipeBookSettings::read_from(buf)?; + let recipes = Vec::::read_from(buf)?; + let action = match action_id { + 0 => State::Init { + to_highlight: Vec::::read_from(buf)?, + }, + 1 => State::Add, + 2 => State::Remove, + _ => { + return Err(BufReadError::UnexpectedEnumVariant { + id: action_id as i32, + }) + } + }; + + Ok(ClientboundRecipePacket { + action: action, + settings: settings, + recipes: recipes, + }) + } } #[derive(Clone, Debug, McBuf)] @@ -25,9 +68,9 @@ pub struct RecipeBookSettings { pub smoker_filtering_craftable: bool, } -#[derive(Clone, Debug, Copy, McBuf)] +#[derive(Clone, Debug)] pub enum State { - Init = 0, - Add = 1, - Remove = 2, + Init { to_highlight: Vec }, + Add, + Remove, } -- cgit v1.2.3