aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-26 22:53:47 -0500
committermat <github@matdoes.dev>2022-04-26 22:53:47 -0500
commit4f9f2468f0fc80b19baac6904c05c9cc9a9cb61a (patch)
treea93051bfba443269622e51650ca8fa3b80d89f2e
parentf859dbbba06278f52517b0096b92ff3a6932ee28 (diff)
downloadazalea-drasl-4f9f2468f0fc80b19baac6904c05c9cc9a9cb61a.tar.xz
add recipe packet
-rwxr-xr-xazalea-client/src/connect.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_recipe_packet.rs59
-rwxr-xr-xazalea-protocol/src/packets/game/mod.rs2
3 files changed, 64 insertions, 0 deletions
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<ResourceLocation>,
+ pub to_highlight: Vec<ResourceLocation>,
+}
+
+#[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<u8>) -> Result<(), std::io::Error> {
+ buf.write_varint(*self as i32)?;
+ Ok(())
+ }
+}
+#[async_trait]
+impl McBufReadable for State {
+ async fn read_into<R>(buf: &mut R) -> Result<Self, String>
+ 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,