azalea_protocol/packets/game/
c_container_set_content.rs

1use azalea_buf::AzBuf;
2use azalea_inventory::ItemStack;
3use azalea_protocol_macros::ClientboundGamePacket;
4
5#[derive(Clone, Debug, AzBuf, ClientboundGamePacket, 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::AzaleaRead;
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 = ClientboundContainerSetContent::azalea_read(&mut buf).unwrap();
32        println!("{:?}", packet);
33
34        assert_eq!(buf.position(), contents.len() as u64);
35
36        let mut buf = Vec::new();
37        packet.write(&mut buf).unwrap();
38        assert_eq!(buf, contents);
39    }
40}