From 7c2b650bdb391a0d5c6cabb2df7478f60ad11b99 Mon Sep 17 00:00:00 2001 From: Edvin Bryntesson Date: Fri, 23 Aug 2024 10:32:00 +0200 Subject: [PATCH] add clientbound packet: CCloseContainer --- .../src/client/play/c_close_container.rs | 16 ++++++++++++++++ pumpkin-protocol/src/client/play/mod.rs | 2 ++ pumpkin/src/client/container.rs | 10 +++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 pumpkin-protocol/src/client/play/c_close_container.rs diff --git a/pumpkin-protocol/src/client/play/c_close_container.rs b/pumpkin-protocol/src/client/play/c_close_container.rs new file mode 100644 index 000000000..56c3bb457 --- /dev/null +++ b/pumpkin-protocol/src/client/play/c_close_container.rs @@ -0,0 +1,16 @@ +use serde::Serialize; +use pumpkin_macros::packet; + +#[derive(Serialize)] +#[packet(0x12)] +pub struct CCloseContainer { + window_id: u8 +} + +impl CCloseContainer { + pub const fn new(window_id: u8) -> Self { + Self { + window_id + } + } +} \ No newline at end of file diff --git a/pumpkin-protocol/src/client/play/mod.rs b/pumpkin-protocol/src/client/play/mod.rs index 2e15aa978..65a5ba8d0 100644 --- a/pumpkin-protocol/src/client/play/mod.rs +++ b/pumpkin-protocol/src/client/play/mod.rs @@ -36,6 +36,7 @@ mod c_update_entity_pos; mod c_update_entity_rot; mod c_worldevent; mod player_action; +mod c_close_container; pub use c_acknowledge_block::*; pub use c_actionbar::*; @@ -75,3 +76,4 @@ pub use c_update_entity_pos::*; pub use c_update_entity_rot::*; pub use c_worldevent::*; pub use player_action::*; +pub use c_close_container::*; \ No newline at end of file diff --git a/pumpkin/src/client/container.rs b/pumpkin/src/client/container.rs index b8a242dbd..ead7eb502 100644 --- a/pumpkin/src/client/container.rs +++ b/pumpkin/src/client/container.rs @@ -1,6 +1,6 @@ use pumpkin_core::text::TextComponent; use pumpkin_inventory::WindowType; -use pumpkin_protocol::client::play::{COpenScreen, CSetContainerContent, CSetContainerSlot}; +use pumpkin_protocol::client::play::{CCloseContainer, COpenScreen, CSetContainerContent, CSetContainerSlot}; use pumpkin_protocol::slot::Slot; use pumpkin_world::item::Item; @@ -82,4 +82,12 @@ impl super::Client { &item.into(), )) } + + /// The official Minecraft client is weird, and will always just close *any* window that is opened when this gets sent + pub fn close_container( + &mut self, + window_type: WindowType + ) { + self.send_packet(&CCloseContainer::new(window_type as u8)) + } }