aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-26 22:58:18 +0000
committermat <github@matdoes.dev>2022-04-26 22:58:18 +0000
commitdd24110019c0ded21e064b2273acc326173c84f5 (patch)
tree5d958ce932379a8b2548e01ccd09d08accce5450 /azalea-protocol/src
parent5736a790d34cb55202521fcfe807bea6eb5f07c7 (diff)
downloadazalea-drasl-dd24110019c0ded21e064b2273acc326173c84f5.tar.xz
add derive mcbufreadable/writable
Diffstat (limited to 'azalea-protocol/src')
-rwxr-xr-xazalea-protocol/src/mc_buf/write.rs18
-rw-r--r--azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs95
2 files changed, 81 insertions, 32 deletions
diff --git a/azalea-protocol/src/mc_buf/write.rs b/azalea-protocol/src/mc_buf/write.rs
index e8845f25..2c46157b 100755
--- a/azalea-protocol/src/mc_buf/write.rs
+++ b/azalea-protocol/src/mc_buf/write.rs
@@ -2,7 +2,7 @@ use super::{UnsizedByteArray, MAX_STRING_LENGTH};
use async_trait::async_trait;
use azalea_chat::component::Component;
use azalea_core::{
- difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation,
+ difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation, Slot,
};
use byteorder::{BigEndian, WriteBytesExt};
use std::io::Write;
@@ -337,3 +337,19 @@ impl McBufWritable for Component {
todo!()
}
}
+
+// Slot
+impl McBufWritable for Slot {
+ fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ match self {
+ Slot::Empty => buf.write_byte(0)?,
+ Slot::Present(i) => {
+ buf.write_varint(i.id)?;
+ buf.write_byte(i.count)?;
+ buf.write_nbt(&i.nbt)?;
+ }
+ }
+
+ Ok(())
+ }
+}
diff --git a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
index 2e8532df..d9e6b262 100644
--- a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
@@ -1,7 +1,7 @@
use async_trait::async_trait;
use azalea_chat::component::Component;
use azalea_core::{resource_location::ResourceLocation, Slot};
-use packet_macros::GamePacket;
+use packet_macros::{GamePacket, McBufReadable, McBufWritable};
use tokio::io::AsyncRead;
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
@@ -17,19 +17,70 @@ pub struct Recipe {
pub data: RecipeData,
}
+#[derive(Clone, Debug, McBufReadable, McBufWritable)]
+pub struct ShapelessRecipe {
+ /// Used to group similar recipes together in the recipe book.
+ /// Tag is present in recipe JSON
+ group: String,
+ ingredients: Vec<Ingredient>,
+ result: Slot,
+}
+#[derive(Clone, Debug, McBufReadable, McBufWritable)]
+pub struct ShapedRecipe {
+ width: u32,
+ height: u32,
+ group: String,
+ ingredients: Vec<Ingredient>,
+ result: Slot,
+}
+#[derive(Clone, Debug, McBufReadable, McBufWritable)]
+pub struct CookingRecipe {
+ group: String,
+ ingredient: Ingredient,
+ result: Slot,
+ experience: f32,
+ #[varint]
+ cooking_time: u32,
+}
+#[derive(Clone, Debug, McBufReadable, McBufWritable)]
+pub struct StoneCuttingRecipe {
+ group: String,
+ ingredient: Ingredient,
+ result: Slot,
+}
+#[derive(Clone, Debug, McBufReadable, McBufWritable)]
+pub struct SmithingRecipe {
+ base: Ingredient,
+ addition: Ingredient,
+ result: Slot,
+}
+
#[derive(Clone, Debug)]
pub enum RecipeData {
- CraftingShapeless {
- /// Used to group similar recipes together in the recipe book.
- /// Tag is present in recipe JSON
- group: String,
- // ingredients
- ingredients: Vec<Ingredient>,
- result: Slot,
- },
+ CraftingShapeless(ShapelessRecipe),
+ CraftingShaped(ShapedRecipe),
+ CraftingSpecialArmorDye,
+ CraftingSpecialBookCloning,
+ CraftingSpecialMapCloning,
+ CraftingSpecialMapExtending,
+ CraftingSpecialFireworkRocket,
+ CraftingSpecialFireworkStar,
+ CraftingSpecialFireworkStarFade,
+ CraftingSpecialRepairItem,
+ CraftingSpecialTippedArrow,
+ CraftingSpecialBannerDuplicate,
+ CraftingSpecialBannerAddPattern,
+ CraftingSpecialShieldDecoration,
+ CraftingSpecialShulkerBoxColoring,
+ CraftingSpecialSuspiciousStew,
+ Smelting(CookingRecipe),
+ Blasting(CookingRecipe),
+ Smoking(CookingRecipe),
+ CampfireCooking(CookingRecipe),
+ Stonecutting(StoneCuttingRecipe),
}
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, McBufReadable, McBufWritable)]
pub struct Ingredient {
pub allowed: Vec<Slot>,
}
@@ -56,13 +107,13 @@ impl McBufReadable for Recipe {
let ingredients = Vec::<Ingredient>::read_into(buf).await?;
let result = Slot::read_into(buf).await?;
- RecipeData::CraftingShapeless {
+ RecipeData::CraftingShapeless(ShapelessRecipe {
group,
ingredients,
result,
- }
+ })
} else {
- panic!();
+ panic!("Unknown recipe type sent by server: {}", recipe_type);
};
let recipe = Recipe { identifier, data };
@@ -70,21 +121,3 @@ impl McBufReadable for Recipe {
Ok(recipe)
}
}
-
-impl McBufWritable for Ingredient {
- fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
- todo!()
- }
-}
-#[async_trait]
-impl McBufReadable for Ingredient {
- async fn read_into<R>(buf: &mut R) -> Result<Self, String>
- where
- R: AsyncRead + std::marker::Unpin + std::marker::Send,
- {
- let ingredient = Ingredient {
- allowed: Vec::<Slot>::read_into(buf).await?,
- };
- Ok(ingredient)
- }
-}