Skip to main content

azalea_protocol/packets/game/
c_container_set_content.rs

1use azalea_buf::AzBuf;
2use azalea_protocol_macros::ClientboundGamePacket;
3use azalea_registry::item::ItemStack;
4
5#[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)]
6pub struct ClientboundContainerSetContent {
7    #[var]
8    pub container_id: i32,
9    #[var]
10    pub state_id: u32,
11    pub items: Vec<ItemStack>,
12    pub carried_item: ItemStack,
13}
14
15#[cfg(test)]
16mod tests {
17    use std::io::Cursor;
18
19    use azalea_buf::AzBuf;
20
21    use super::ClientboundContainerSetContent;
22
23    #[test]
24    fn test_read_write_container_set_content() {
25        let contents = [
26            1, 2, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
27            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
28            0, 0, 0, 0, 0, 0, 0, 1, 196, 6, 0, 0, 0,
29        ];
30        let mut buf = Cursor::new(contents.as_slice());
31        let packet =
32            ClientboundContainerSetContent::azalea_read(Default::default(), &mut buf).unwrap();
33        println!("{packet:?}");
34
35        assert_eq!(buf.position(), contents.len() as u64);
36
37        let mut buf = Vec::new();
38        packet.write(Default::default(), &mut buf).unwrap();
39        assert_eq!(buf, contents);
40    }
41}