azalea_protocol/packets/game/
c_merchant_offers.rs1use std::fmt::Debug;
2
3use azalea_buf::AzBuf;
4use azalea_protocol_macros::ClientboundGamePacket;
5use azalea_registry::{
6 builtin::ItemKind,
7 item::{
8 ItemStack, ItemStackData,
9 components::{DataComponent, patch::DataComponentPatch},
10 },
11};
12
13#[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)]
14pub struct ClientboundMerchantOffers {
15 #[var]
16 pub container_id: i32,
17 pub offers: Vec<MerchantOffer>,
18 #[var]
19 pub villager_level: u32,
20 #[var]
21 pub villager_xp: u32,
22 pub show_progress: bool,
23 pub can_restock: bool,
24}
25
26#[derive(AzBuf, Clone, Debug, PartialEq)]
27pub struct MerchantOffer {
28 pub base_cost_a: ItemCost,
29 pub result: ItemStack,
30 pub cost_b: Option<ItemCost>,
31 pub out_of_stock: bool,
32 pub uses: i32,
33 pub max_uses: i32,
34 pub xp: i32,
35 pub special_price_diff: i32,
36 pub price_multiplier: f32,
37 pub demand: i32,
38}
39
40#[derive(AzBuf, Clone, Debug, PartialEq)]
45pub struct ItemCost {
46 pub item: ItemKind,
47 #[var]
48 pub count: i32,
49 pub components: DataComponentExactPredicate,
50}
51impl ItemCost {
52 pub fn into_item_stack(self) -> ItemStackData {
53 let mut component_patch = DataComponentPatch::default();
54
55 for component in self.components.expected {
56 component_patch.insert_component(component.kind(), Some(component));
57 }
58 ItemStackData {
62 kind: self.item,
63 count: self.count,
64 component_patch,
65 }
66 }
67}
68
69#[derive(AzBuf, Clone, Debug, PartialEq)]
75pub struct DataComponentExactPredicate {
76 pub expected: Vec<DataComponent>,
77}