add clientbound packet: CCloseContainer

This commit is contained in:
Edvin Bryntesson 2024-08-23 10:32:00 +02:00
parent f9134b580d
commit 7c2b650bdb
No known key found for this signature in database
3 changed files with 27 additions and 1 deletions

View File

@ -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
}
}
}

View File

@ -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::*;

View File

@ -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))
}
}