aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-protocol')
-rw-r--r--azalea-protocol/src/packets/game/clientbound_recipe_packet.rs57
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,
}