diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2023-12-05 10:59:05 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-05 10:59:05 -0600 |
| commit | 7857a014b92e64361ee237ceae7ef1acc185ac46 (patch) | |
| tree | 5d70ea6b41943493873810e6a03c3483ff90a235 /azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs | |
| parent | ea3e8600126a58f5666d50fbf70dff8209d8979f (diff) | |
| download | azalea-drasl-7857a014b92e64361ee237ceae7ef1acc185ac46.tar.xz | |
1.20.3 (#110)
* 23w40a
* 23w41a
* 23w42a
* 23w43a
* 23w44a
* serialize FormattedText as nbt in network
* use azalea-nbt/serde in azalea-chat
* 23w45a
* fix 23w45a to compile
* handle Object in codegen
* 1.20.3-pre2
* remove unused clientbound_resource_pack_packet.rs
* merge main and make azalea-chat use simdnbt
* 1.20.3-rc1
* fix tests
* use simdnbt 0.3
* fix ServerboundSetJigsawBlockPacket
* 1.20.3
Diffstat (limited to 'azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs')
| -rwxr-xr-x | azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs | 80 |
1 files changed, 37 insertions, 43 deletions
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 0699eb30..291cb580 100755 --- a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs @@ -29,66 +29,58 @@ pub struct ShapelessRecipe { pub ingredients: Vec<Ingredient>, pub result: ItemSlot, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, McBuf)] pub struct ShapedRecipe { - pub width: usize, - pub height: usize, pub group: String, pub category: CraftingBookCategory, - pub ingredients: Vec<Ingredient>, + pub pattern: ShapedRecipePattern, pub result: ItemSlot, pub show_notification: bool, } -#[derive(Clone, Debug, Copy, PartialEq, McBuf)] -pub enum CraftingBookCategory { - Building = 0, - Redstone, - Equipment, - Misc, +#[derive(Clone, Debug, PartialEq)] +pub struct ShapedRecipePattern { + pub width: usize, + pub height: usize, + pub ingredients: Vec<Ingredient>, } -impl McBufWritable for ShapedRecipe { +impl McBufWritable for ShapedRecipePattern { fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { (self.width as u32).var_write_into(buf)?; (self.height as u32).var_write_into(buf)?; - self.group.write_into(buf)?; - self.category.write_into(buf)?; debug_assert_eq!(self.width * self.height, self.ingredients.len()); for ingredient in &self.ingredients { ingredient.write_into(buf)?; } - self.result.write_into(buf)?; - self.show_notification.write_into(buf)?; - Ok(()) } } -impl McBufReadable for ShapedRecipe { + +impl McBufReadable for ShapedRecipePattern { fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let width = u32::var_read_from(buf)? as usize; let height = u32::var_read_from(buf)? as usize; - let group = String::read_from(buf)?; - let category = CraftingBookCategory::read_from(buf)?; let mut ingredients = Vec::with_capacity(width * height); for _ in 0..width * height { ingredients.push(Ingredient::read_from(buf)?); } - let result = ItemSlot::read_from(buf)?; - let show_notification = bool::read_from(buf)?; - - Ok(ShapedRecipe { + Ok(ShapedRecipePattern { width, height, - group, - category, ingredients, - result, - show_notification, }) } } +#[derive(Clone, Debug, Copy, PartialEq, McBuf)] +pub enum CraftingBookCategory { + Building = 0, + Redstone, + Equipment, + Misc, +} + #[derive(Clone, Debug, PartialEq, McBuf)] pub struct CookingRecipe { pub group: String, @@ -315,24 +307,26 @@ mod tests { let recipe = Recipe { identifier: ResourceLocation::new("minecraft:crafting_shaped"), data: RecipeData::CraftingShaped(ShapedRecipe { - width: 2, - height: 2, group: String::new(), category: CraftingBookCategory::Building, - ingredients: vec![ - Ingredient { - allowed: vec![ItemSlot::Empty], - }, - Ingredient { - allowed: vec![ItemSlot::Empty], - }, - Ingredient { - allowed: vec![ItemSlot::Empty], - }, - Ingredient { - allowed: vec![ItemSlot::Empty], - }, - ], + pattern: ShapedRecipePattern { + width: 2, + height: 2, + ingredients: vec![ + Ingredient { + allowed: vec![ItemSlot::Empty], + }, + Ingredient { + allowed: vec![ItemSlot::Empty], + }, + Ingredient { + allowed: vec![ItemSlot::Empty], + }, + Ingredient { + allowed: vec![ItemSlot::Empty], + }, + ], + }, result: ItemSlot::Empty, show_notification: false, }), |
