chunkedge_protocol/packets/play/
container_click_c2s.rs

1use std::borrow::Cow;
2
3use chunkedge_binary::{Decode, Encode, VarInt};
4use chunkedge_item::{HashedItemStack, ItemStack};
5
6use crate::Packet;
7
8#[derive(Clone, Debug, Encode, Decode, Packet)]
9pub struct ContainerClickC2s<'a> {
10    pub window_id: VarInt,
11    pub state_id: VarInt,
12    pub slot_idx: i16,
13    /// The button used to click the slot. An enum can't easily be used for this
14    /// because the meaning of this value depends on the mode.
15    pub button: i8,
16    pub mode: ClickMode,
17    pub slot_changes: Cow<'a, [HashedSlotChange]>,
18    pub carried_item: HashedItemStack,
19}
20
21#[derive(Copy, Clone, Debug, PartialEq, Eq, Encode, Decode)]
22pub enum ClickMode {
23    Click,
24    ShiftClick,
25    Hotbar,
26    CreativeMiddleClick,
27    DropKey,
28    Drag,
29    DoubleClick,
30}
31
32#[derive(Clone, Debug, Encode, Decode)]
33pub struct HashedSlotChange {
34    pub idx: i16,
35    pub stack: HashedItemStack,
36}
37
38#[derive(Clone, Debug, Encode, Decode)]
39pub struct SlotChange {
40    pub idx: i16,
41    pub stack: ItemStack,
42}
43
44impl From<SlotChange> for HashedSlotChange {
45    fn from(value: SlotChange) -> Self {
46        HashedSlotChange {
47            idx: value.idx,
48            stack: value.stack.into(),
49        }
50    }
51}