From 4f9f2468f0fc80b19baac6904c05c9cc9a9cb61a Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 26 Apr 2022 22:53:47 -0500 Subject: [PATCH] add recipe packet --- azalea-client/src/connect.rs | 3 + .../packets/game/clientbound_recipe_packet.rs | 59 +++++++++++++++++++ azalea-protocol/src/packets/game/mod.rs | 2 + 3 files changed, 64 insertions(+) create mode 100644 azalea-protocol/src/packets/game/clientbound_recipe_packet.rs diff --git a/azalea-client/src/connect.rs b/azalea-client/src/connect.rs index 77303930..d8b47321 100755 --- a/azalea-client/src/connect.rs +++ b/azalea-client/src/connect.rs @@ -120,6 +120,9 @@ pub async fn join_server(address: &ServerAddress) -> Result<(), String> { GamePacket::ClientboundEntityEventPacket(p) => { println!("Got entity event packet {:?}", p); } + GamePacket::ClientboundRecipePacket(p) => { + println!("Got recipe packet {:?}", p); + } }, Err(e) => { panic!("Error: {:?}", e); diff --git a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs new file mode 100644 index 00000000..69f26ddc --- /dev/null +++ b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs @@ -0,0 +1,59 @@ +use async_trait::async_trait; +use azalea_chat::component::Component; +use azalea_core::{resource_location::ResourceLocation, Slot}; +use packet_macros::{GamePacket, McBufReadable, McBufWritable}; +use tokio::io::AsyncRead; + +use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; + +#[derive(Clone, Debug, GamePacket)] +pub struct ClientboundRecipePacket { + pub action: State, + pub settings: RecipeBookSettings, + pub recipes: Vec, + pub to_highlight: Vec, +} + +#[derive(Clone, Debug, McBufReadable, McBufWritable)] +pub struct RecipeBookSettings { + pub gui_open: bool, + pub filtering_craftable: bool, + + pub furnace_gui_open: bool, + pub furnace_filtering_craftable: bool, + + pub blast_furnace_gui_open: bool, + pub blast_furnace_filtering_craftable: bool, + + pub smoker_gui_open: bool, + pub smoker_filtering_craftable: bool, +} + +#[derive(Clone, Debug, Copy)] +pub enum State { + Init = 0, + Add = 1, + Remove = 2, +} + +impl McBufWritable for State { + fn write_into(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + buf.write_varint(*self as i32)?; + Ok(()) + } +} +#[async_trait] +impl McBufReadable for State { + async fn read_into(buf: &mut R) -> Result + where + R: AsyncRead + std::marker::Unpin + std::marker::Send, + { + let state = buf.read_varint().await?.try_into().unwrap(); + Ok(match state { + 0 => State::Init, + 1 => State::Add, + 2 => State::Remove, + _ => panic!("Invalid state: {}", state), + }) + } +} diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs index fefeb08b..d197015a 100755 --- a/azalea-protocol/src/packets/game/mod.rs +++ b/azalea-protocol/src/packets/game/mod.rs @@ -5,6 +5,7 @@ pub mod clientbound_disconnect_packet; pub mod clientbound_entity_event_packet; pub mod clientbound_login_packet; pub mod clientbound_player_abilities_packet; +pub mod clientbound_recipe_packet; pub mod clientbound_set_carried_item_packet; pub mod clientbound_update_recipes_packet; pub mod clientbound_update_tags_packet; @@ -23,6 +24,7 @@ declare_state_packets!( 0x18: clientbound_custom_payload_packet::ClientboundCustomPayloadPacket, 0x26: clientbound_login_packet::ClientboundLoginPacket, 0x32: clientbound_player_abilities_packet::ClientboundPlayerAbilitiesPacket, + 0x39: clientbound_recipe_packet::ClientboundRecipePacket, 0x48: clientbound_set_carried_item_packet::ClientboundSetCarriedItemPacket, 0x4a: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket, 0x66: clientbound_update_recipes_packet::ClientboundUpdateRecipesPacket,