diff options
| author | mat <github@matdoes.dev> | 2022-09-04 23:01:15 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-09-04 23:01:15 -0500 |
| commit | 4f00ddace08bd5ad17500a405f55554dff343be7 (patch) | |
| tree | 8a8503fe4b9d0055b73952d2fb7f38941000f9d0 /azalea-protocol | |
| parent | 99fcad7bc4133c32627fe2e4751faad05b9b4ef1 (diff) | |
| download | azalea-drasl-4f00ddace08bd5ad17500a405f55554dff343be7.tar.xz | |
remove some debug stuff and fix recipe packet
Diffstat (limited to 'azalea-protocol')
| -rw-r--r-- | azalea-protocol/src/packets/game/clientbound_recipe_packet.rs | 57 |
1 files changed, 50 insertions, 7 deletions
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<ResourceLocation>, - pub to_highlight: Vec<ResourceLocation>, +} + +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<Self, azalea_buf::BufReadError> { + let action_id = u32::var_read_from(buf)?; + let settings = RecipeBookSettings::read_from(buf)?; + let recipes = Vec::<ResourceLocation>::read_from(buf)?; + let action = match action_id { + 0 => State::Init { + to_highlight: Vec::<ResourceLocation>::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<ResourceLocation> }, + Add, + Remove, } |
