aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-12-07 21:09:58 -0600
committerGitHub <noreply@github.com>2022-12-07 21:09:58 -0600
commit7d901e39bc10a855b545d7b6c167f45148a1fb0a (patch)
tree88fe0a8f2f04f49f4df90e2f5462aa35a4278c68 /azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
parent9f5e5c092be9167e4d5222fdee4a1d2c419e5052 (diff)
downloadazalea-drasl-7d901e39bc10a855b545d7b6c167f45148a1fb0a.tar.xz
1.19.3 (#34)
* start updating to 22w42a * work a bit more on 22w42a * player chat packet * serverbound hello packet * Update mod.rs * add more stuff to clientbound player chat packet * ClientboundPlayerInfoUpdatePacket * features enabled and container closed * serverbound chat packets * make it compile * 22w43a * ServerboundChatSessionUpdatePacket * profile_public_key isn't Option anymore * Update bitset.rs * joining a server works * fix entitydatavalue * backtraces + fix clientbound chat message * fix some warnings and add more ecomments * 22w44a * generate en_us.json * add updating guide to codegen/readme * fix some markdown * update list of generated things * metadata stuff * Replace PJS generator mod with PixLyzer (#38) * pixlizer extractor * start working on shape extraction * fix generating language * fix pixlyzer shape generation * use empty_shape * generate blocks and shapes * update pixlyzer dir * Revert "update pixlyzer dir" This reverts commit ee9a0e7a49936dd8569c610ba9b6455895eeff71. * fix * fix * Revert "fix" This reverts commit ad12ddcb009ccc4eeb13ddef0871db1d9322ab7d. * fix * detect pixlyzer fail * fix pixlyzer * 22w45a * gen entities * add async-trait dep * update codegen/readme.md * explain when rust_log should be used * remove some unused code * start fixing pixlyzer issues * fix a thing in codegen * almost fixed * more progress towards 1.19.3 * 1.19.3-pre2 * fixes * revert some hardcoded property names * Delete clientbound_player_info_packet.rs * handle 1.19.3 player info packets * handle playerinforemove * start updating to 1.19.3-rc1 * optional registries work * fix some issues with 1.19.3 chat doesn't work yet * aaaaaaaaaaaaaaaaa * oh * ignore unused shapes * uncomment generate_blocks * fix migrate * 1.19.3-rc2 * fix clippy warnings * 1.19.3-rc3 * split the azalea-buf macro into separate modules * improve Recipe in protocol * 1.19.3
Diffstat (limited to 'azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs')
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs398
1 files changed, 154 insertions, 244 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 9c325d29..e95e9316 100755
--- a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
@@ -20,17 +20,27 @@ pub struct Recipe {
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,
+ pub group: String,
+ pub category: CraftingBookCategory,
+ pub ingredients: Vec<Ingredient>,
+ pub result: Slot,
}
#[derive(Clone, Debug)]
pub struct ShapedRecipe {
- width: usize,
- height: usize,
- group: String,
- ingredients: Vec<Ingredient>,
- result: Slot,
+ pub width: usize,
+ pub height: usize,
+ pub group: String,
+ pub category: CraftingBookCategory,
+ pub ingredients: Vec<Ingredient>,
+ pub result: Slot,
+}
+
+#[derive(Clone, Debug, Copy, McBuf)]
+pub enum CraftingBookCategory {
+ Building = 0,
+ Redstone,
+ Equipment,
+ Misc,
}
impl McBufWritable for ShapedRecipe {
@@ -38,6 +48,7 @@ impl McBufWritable for ShapedRecipe {
(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)?;
for ingredient in &self.ingredients {
ingredient.write_into(buf)?;
}
@@ -51,6 +62,7 @@ impl McBufReadable for ShapedRecipe {
let width = u32::var_read_from(buf)?.try_into().unwrap();
let height = u32::var_read_from(buf)?.try_into().unwrap();
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)?);
@@ -61,6 +73,7 @@ impl McBufReadable for ShapedRecipe {
width,
height,
group,
+ category,
ingredients,
result,
})
@@ -69,49 +82,55 @@ impl McBufReadable for ShapedRecipe {
#[derive(Clone, Debug, McBuf)]
pub struct CookingRecipe {
- group: String,
- ingredient: Ingredient,
- result: Slot,
- experience: f32,
+ pub group: String,
+ pub category: CraftingBookCategory,
+ pub ingredient: Ingredient,
+ pub result: Slot,
+ pub experience: f32,
#[var]
- cooking_time: u32,
+ pub cooking_time: u32,
}
#[derive(Clone, Debug, McBuf)]
-pub struct StoneCuttingRecipe {
- group: String,
- ingredient: Ingredient,
- result: Slot,
+pub struct StoneCutterRecipe {
+ pub group: String,
+ pub ingredient: Ingredient,
+ pub result: Slot,
}
#[derive(Clone, Debug, McBuf)]
pub struct SmithingRecipe {
- base: Ingredient,
- addition: Ingredient,
- result: Slot,
+ pub base: Ingredient,
+ pub addition: Ingredient,
+ pub result: Slot,
}
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, McBuf)]
+pub struct SimpleRecipe {
+ pub category: CraftingBookCategory,
+}
+
+#[derive(Clone, Debug, McBuf)]
pub enum RecipeData {
CraftingShapeless(ShapelessRecipe),
CraftingShaped(ShapedRecipe),
- CraftingSpecialArmorDye,
- CraftingSpecialBookCloning,
- CraftingSpecialMapCloning,
- CraftingSpecialMapExtending,
- CraftingSpecialFireworkRocket,
- CraftingSpecialFireworkStar,
- CraftingSpecialFireworkStarFade,
- CraftingSpecialRepairItem,
- CraftingSpecialTippedArrow,
- CraftingSpecialBannerDuplicate,
- CraftingSpecialBannerAddPattern,
- CraftingSpecialShieldDecoration,
- CraftingSpecialShulkerBoxColoring,
- CraftingSpecialSuspiciousStew,
+ CraftingSpecialArmorDye(SimpleRecipe),
+ CraftingSpecialBookCloning(SimpleRecipe),
+ CraftingSpecialMapCloning(SimpleRecipe),
+ CraftingSpecialMapExtending(SimpleRecipe),
+ CraftingSpecialFireworkRocket(SimpleRecipe),
+ CraftingSpecialFireworkStar(SimpleRecipe),
+ CraftingSpecialFireworkStarFade(SimpleRecipe),
+ CraftingSpecialRepairItem(SimpleRecipe),
+ CraftingSpecialTippedArrow(SimpleRecipe),
+ CraftingSpecialBannerDuplicate(SimpleRecipe),
+ CraftingSpecialBannerAddPattern(SimpleRecipe),
+ CraftingSpecialShieldDecoration(SimpleRecipe),
+ CraftingSpecialShulkerBoxColoring(SimpleRecipe),
+ CraftingSpecialSuspiciousStew(SimpleRecipe),
Smelting(CookingRecipe),
Blasting(CookingRecipe),
Smoking(CookingRecipe),
CampfireCooking(CookingRecipe),
- Stonecutting(StoneCuttingRecipe),
+ Stonecutting(StoneCutterRecipe),
Smithing(SmithingRecipe),
}
@@ -122,236 +141,127 @@ pub struct Ingredient {
impl McBufWritable for Recipe {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- match &self.data {
- RecipeData::CraftingShapeless(recipe) => {
- ResourceLocation::new("minecraft:crafting_shapeless")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
- recipe.write_into(buf)?;
+ let resource_location = match &self.data {
+ RecipeData::CraftingShapeless(_) => "minecraft:crafting_shapeless",
+ RecipeData::CraftingShaped(_) => "minecraft:crafting_shaped",
+ RecipeData::CraftingSpecialArmorDye(_) => "minecraft:crafting_special_armordye",
+ RecipeData::CraftingSpecialBookCloning(_) => "minecraft:crafting_special_bookcloning",
+ RecipeData::CraftingSpecialMapCloning(_) => "minecraft:crafting_special_mapcloning",
+ RecipeData::CraftingSpecialMapExtending(_) => "minecraft:crafting_special_mapextending",
+ RecipeData::CraftingSpecialFireworkRocket(_) => {
+ "minecraft:crafting_special_firework_rocket"
}
- RecipeData::CraftingShaped(recipe) => {
- ResourceLocation::new("minecraft:crafting_shaped")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
- recipe.write_into(buf)?;
+ RecipeData::CraftingSpecialFireworkStar(_) => {
+ "minecraft:crafting_special_firework_star"
}
- RecipeData::CraftingSpecialArmorDye => {
- ResourceLocation::new("minecraft:crafting_special_armordye")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
+
+ RecipeData::CraftingSpecialFireworkStarFade(_) => {
+ "minecraft:crafting_special_firework_star_fade"
}
- RecipeData::CraftingSpecialBookCloning => {
- ResourceLocation::new("minecraft:crafting_special_bookcloning")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
+ RecipeData::CraftingSpecialRepairItem(_) => "minecraft:crafting_special_repairitem",
+ RecipeData::CraftingSpecialTippedArrow(_) => "minecraft:crafting_special_tippedarrow",
+ RecipeData::CraftingSpecialBannerDuplicate(_) => {
+ "minecraft:crafting_special_bannerduplicate"
}
- RecipeData::CraftingSpecialMapCloning => {
- ResourceLocation::new("minecraft:crafting_special_mapcloning")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
+ RecipeData::CraftingSpecialBannerAddPattern(_) => {
+ "minecraft:crafting_special_banneraddpattern"
}
- RecipeData::CraftingSpecialMapExtending => {
- ResourceLocation::new("minecraft:crafting_special_mapextending")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
+ RecipeData::CraftingSpecialShieldDecoration(_) => {
+ "minecraft:crafting_special_shielddecoration"
}
- RecipeData::CraftingSpecialFireworkRocket => {
- ResourceLocation::new("minecraft:crafting_special_firework_rocket")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
+ RecipeData::CraftingSpecialShulkerBoxColoring(_) => {
+ "minecraft:crafting_special_shulkerboxcoloring"
}
- RecipeData::CraftingSpecialFireworkStar => {
- ResourceLocation::new("minecraft:crafting_special_firework_star")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
+ RecipeData::CraftingSpecialSuspiciousStew(_) => {
+ "minecraft:crafting_special_suspiciousstew"
}
- RecipeData::CraftingSpecialFireworkStarFade => {
- ResourceLocation::new("minecraft:crafting_special_firework_star_fade")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
+ RecipeData::Smelting(_) => "minecraft:smelting",
+ RecipeData::Blasting(_) => "minecraft:blasting",
+ RecipeData::Smoking(_) => "minecraft:smoking",
+ RecipeData::CampfireCooking(_) => "minecraft:campfire_cooking",
+ RecipeData::Stonecutting(_) => "minecraft:stonecutting",
+ RecipeData::Smithing(_) => "minecraft:smithing",
+ };
+ ResourceLocation::new(resource_location)
+ .unwrap()
+ .write_into(buf)?;
+ self.identifier.write_into(buf)?;
+ self.data.write_without_id(buf)?;
+ Ok(())
+ }
+}
+
+impl McBufReadable for Recipe {
+ fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
+ let recipe_type = ResourceLocation::read_from(buf)?;
+ let identifier = ResourceLocation::read_from(buf)?;
+
+ // rust doesn't let us match ResourceLocation so we have to do a big
+ // if-else chain :(
+ let data = match recipe_type.to_string().as_str() {
+ "minecraft:crafting_shapeless" => {
+ RecipeData::CraftingShapeless(ShapelessRecipe::read_from(buf)?)
}
- RecipeData::CraftingSpecialRepairItem => {
- ResourceLocation::new("minecraft:crafting_special_repairitem")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
+ "minecraft:crafting_shaped" => {
+ RecipeData::CraftingShaped(ShapedRecipe::read_from(buf)?)
}
- RecipeData::CraftingSpecialTippedArrow => {
- ResourceLocation::new("minecraft:crafting_special_tippedarrow")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
+ "minecraft:crafting_special_armordye" => {
+ RecipeData::CraftingSpecialArmorDye(SimpleRecipe::read_from(buf)?)
}
- RecipeData::CraftingSpecialBannerDuplicate => {
- ResourceLocation::new("minecraft:crafting_special_bannerduplicate")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
+ "minecraft:crafting_special_bookcloning" => {
+ RecipeData::CraftingSpecialBookCloning(SimpleRecipe::read_from(buf)?)
}
- RecipeData::CraftingSpecialBannerAddPattern => {
- ResourceLocation::new("minecraft:crafting_special_banneraddpattern")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
+ "minecraft:crafting_special_mapcloning" => {
+ RecipeData::CraftingSpecialMapCloning(SimpleRecipe::read_from(buf)?)
}
- RecipeData::CraftingSpecialShieldDecoration => {
- ResourceLocation::new("minecraft:crafting_special_shielddecoration")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
+ "minecraft:crafting_special_mapextending" => {
+ RecipeData::CraftingSpecialMapExtending(SimpleRecipe::read_from(buf)?)
}
- RecipeData::CraftingSpecialShulkerBoxColoring => {
- ResourceLocation::new("minecraft:crafting_special_shulkerboxcoloring")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
+ "minecraft:crafting_special_firework_rocket" => {
+ RecipeData::CraftingSpecialFireworkRocket(SimpleRecipe::read_from(buf)?)
}
- RecipeData::CraftingSpecialSuspiciousStew => {
- ResourceLocation::new("minecraft:crafting_special_suspiciousstew")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
+ "minecraft:crafting_special_firework_star" => {
+ RecipeData::CraftingSpecialFireworkStar(SimpleRecipe::read_from(buf)?)
}
- RecipeData::Smelting(recipe) => {
- ResourceLocation::new("minecraft:smelting")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
- recipe.write_into(buf)?;
+ "minecraft:crafting_special_firework_star_fade" => {
+ RecipeData::CraftingSpecialFireworkStarFade(SimpleRecipe::read_from(buf)?)
}
- RecipeData::Blasting(recipe) => {
- ResourceLocation::new("minecraft:blasting")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
- recipe.write_into(buf)?;
+ "minecraft:crafting_special_repairitem" => {
+ RecipeData::CraftingSpecialRepairItem(SimpleRecipe::read_from(buf)?)
}
- RecipeData::Smoking(recipe) => {
- ResourceLocation::new("minecraft:smoking")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
- recipe.write_into(buf)?;
+ "minecraft:crafting_special_tippedarrow" => {
+ RecipeData::CraftingSpecialTippedArrow(SimpleRecipe::read_from(buf)?)
}
- RecipeData::CampfireCooking(recipe) => {
- ResourceLocation::new("minecraft:campfire_cooking")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
- recipe.write_into(buf)?;
+ "minecraft:crafting_special_bannerduplicate" => {
+ RecipeData::CraftingSpecialBannerDuplicate(SimpleRecipe::read_from(buf)?)
}
- RecipeData::Stonecutting(recipe) => {
- ResourceLocation::new("minecraft:stonecutting")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
- recipe.write_into(buf)?;
+ "minecraft:crafting_special_banneraddpattern" => {
+ RecipeData::CraftingSpecialBannerAddPattern(SimpleRecipe::read_from(buf)?)
}
- RecipeData::Smithing(recipe) => {
- ResourceLocation::new("minecraft:smithing")
- .unwrap()
- .write_into(buf)?;
- self.identifier.write_into(buf)?;
- recipe.write_into(buf)?;
+ "minecraft:crafting_special_shielddecoration" => {
+ RecipeData::CraftingSpecialShieldDecoration(SimpleRecipe::read_from(buf)?)
+ }
+ "minecraft:crafting_special_shulkerboxcoloring" => {
+ RecipeData::CraftingSpecialShulkerBoxColoring(SimpleRecipe::read_from(buf)?)
+ }
+ "minecraft:crafting_special_suspiciousstew" => {
+ RecipeData::CraftingSpecialSuspiciousStew(SimpleRecipe::read_from(buf)?)
+ }
+ "minecraft:smelting" => RecipeData::Smelting(CookingRecipe::read_from(buf)?),
+ "minecraft:blasting" => RecipeData::Blasting(CookingRecipe::read_from(buf)?),
+ "minecraft:smoking" => RecipeData::Smoking(CookingRecipe::read_from(buf)?),
+ "minecraft:campfire_cooking" => {
+ RecipeData::CampfireCooking(CookingRecipe::read_from(buf)?)
+ }
+ "minecraft:stonecutting" => {
+ RecipeData::Stonecutting(StoneCutterRecipe::read_from(buf)?)
+ }
+ "minecraft:smithing" => RecipeData::Smithing(SmithingRecipe::read_from(buf)?),
+ _ => {
+ return Err(BufReadError::UnexpectedStringEnumVariant {
+ id: recipe_type.to_string(),
+ });
}
- };
- Ok(())
- }
-}
-
-impl McBufReadable for Recipe {
- fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
- let recipe_type = ResourceLocation::read_from(buf)?;
- let identifier = ResourceLocation::read_from(buf)?;
-
- // rust doesn't let us match ResourceLocation so we have to do a big
- // if-else chain :(
- let data = if recipe_type == ResourceLocation::new("minecraft:crafting_shapeless").unwrap()
- {
- RecipeData::CraftingShapeless(ShapelessRecipe::read_from(buf)?)
- } else if recipe_type == ResourceLocation::new("minecraft:crafting_shaped").unwrap() {
- RecipeData::CraftingShaped(ShapedRecipe::read_from(buf)?)
- } else if recipe_type
- == ResourceLocation::new("minecraft:crafting_special_armordye").unwrap()
- {
- RecipeData::CraftingSpecialArmorDye
- } else if recipe_type
- == ResourceLocation::new("minecraft:crafting_special_bookcloning").unwrap()
- {
- RecipeData::CraftingSpecialBookCloning
- } else if recipe_type
- == ResourceLocation::new("minecraft:crafting_special_mapcloning").unwrap()
- {
- RecipeData::CraftingSpecialMapCloning
- } else if recipe_type
- == ResourceLocation::new("minecraft:crafting_special_mapextending").unwrap()
- {
- RecipeData::CraftingSpecialMapExtending
- } else if recipe_type
- == ResourceLocation::new("minecraft:crafting_special_firework_rocket").unwrap()
- {
- RecipeData::CraftingSpecialFireworkRocket
- } else if recipe_type
- == ResourceLocation::new("minecraft:crafting_special_firework_star").unwrap()
- {
- RecipeData::CraftingSpecialFireworkStar
- } else if recipe_type
- == ResourceLocation::new("minecraft:crafting_special_firework_star_fade").unwrap()
- {
- RecipeData::CraftingSpecialFireworkStarFade
- } else if recipe_type
- == ResourceLocation::new("minecraft:crafting_special_repairitem").unwrap()
- {
- RecipeData::CraftingSpecialRepairItem
- } else if recipe_type
- == ResourceLocation::new("minecraft:crafting_special_tippedarrow").unwrap()
- {
- RecipeData::CraftingSpecialTippedArrow
- } else if recipe_type
- == ResourceLocation::new("minecraft:crafting_special_bannerduplicate").unwrap()
- {
- RecipeData::CraftingSpecialBannerDuplicate
- } else if recipe_type
- == ResourceLocation::new("minecraft:crafting_special_banneraddpattern").unwrap()
- {
- RecipeData::CraftingSpecialBannerAddPattern
- } else if recipe_type
- == ResourceLocation::new("minecraft:crafting_special_shielddecoration").unwrap()
- {
- RecipeData::CraftingSpecialShieldDecoration
- } else if recipe_type
- == ResourceLocation::new("minecraft:crafting_special_shulkerboxcoloring").unwrap()
- {
- RecipeData::CraftingSpecialShulkerBoxColoring
- } else if recipe_type
- == ResourceLocation::new("minecraft:crafting_special_suspiciousstew").unwrap()
- {
- RecipeData::CraftingSpecialSuspiciousStew
- } else if recipe_type == ResourceLocation::new("minecraft:smelting").unwrap() {
- RecipeData::Smelting(CookingRecipe::read_from(buf)?)
- } else if recipe_type == ResourceLocation::new("minecraft:blasting").unwrap() {
- RecipeData::Blasting(CookingRecipe::read_from(buf)?)
- } else if recipe_type == ResourceLocation::new("minecraft:smoking").unwrap() {
- RecipeData::Smoking(CookingRecipe::read_from(buf)?)
- } else if recipe_type == ResourceLocation::new("minecraft:campfire_cooking").unwrap() {
- RecipeData::CampfireCooking(CookingRecipe::read_from(buf)?)
- } else if recipe_type == ResourceLocation::new("minecraft:stonecutting").unwrap() {
- RecipeData::Stonecutting(StoneCuttingRecipe::read_from(buf)?)
- } else if recipe_type == ResourceLocation::new("minecraft:smithing").unwrap() {
- RecipeData::Smithing(SmithingRecipe::read_from(buf)?)
- } else {
- return Err(BufReadError::UnexpectedStringEnumVariant {
- id: recipe_type.to_string(),
- });
};
let recipe = Recipe { identifier, data };