add serverbound packet SContainerClose

This commit is contained in:
Edvin Bryntesson 2024-08-23 11:51:37 +02:00
parent 98fcd412c2
commit e1a7d4e7ee
No known key found for this signature in database
4 changed files with 57 additions and 0 deletions

View File

@ -52,3 +52,37 @@ impl WindowType {
"WINDOW TITLE" "WINDOW TITLE"
} }
} }
impl TryFrom<u8> for WindowType {
type Error = ();
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(WindowType::Generic9x1),
1 => Ok(WindowType::Generic9x2),
2 => Ok(WindowType::Generic9x3),
3 => Ok(WindowType::Generic9x4),
4 => Ok(WindowType::Generic9x5),
5 => Ok(WindowType::Generic9x6),
6 => Ok(WindowType::Generic3x3),
7 => Ok(WindowType::Craft3x3),
8 => Ok(WindowType::Anvil),
9 => Ok(WindowType::Beacon),
10 => Ok(WindowType::BlastFurnace),
11 => Ok(WindowType::BrewingStand),
12 => Ok(WindowType::CraftingTable),
13 => Ok(WindowType::EnchantmentTable),
14 => Ok(WindowType::Furnace),
15 => Ok(WindowType::Grindstone),
16 => Ok(WindowType::Hopper),
17 => Ok(WindowType::Lectern),
18 => Ok(WindowType::Loom),
19 => Ok(WindowType::Merchant),
20 => Ok(WindowType::ShulkerBox),
21 => Ok(WindowType::SmithingTable),
22 => Ok(WindowType::Smoker),
23 => Ok(WindowType::CartographyTable),
24 => Ok(WindowType::Stonecutter),
_ => Err(()),
}
}
}

View File

@ -1,6 +1,7 @@
mod s_chat_command; mod s_chat_command;
mod s_chat_message; mod s_chat_message;
mod s_client_information; mod s_client_information;
mod s_close_container;
mod s_confirm_teleport; mod s_confirm_teleport;
mod s_interact; mod s_interact;
mod s_ping_request; mod s_ping_request;
@ -17,6 +18,7 @@ mod s_use_item_on;
pub use s_chat_command::*; pub use s_chat_command::*;
pub use s_chat_message::*; pub use s_chat_message::*;
pub use s_client_information::*; pub use s_client_information::*;
pub use s_close_container::*;
pub use s_confirm_teleport::*; pub use s_confirm_teleport::*;
pub use s_interact::*; pub use s_interact::*;
pub use s_ping_request::*; pub use s_ping_request::*;

View File

@ -0,0 +1,8 @@
use pumpkin_macros::packet;
use serde::Serialize;
#[derive(Serialize)]
#[packet(0x0F)]
pub struct SCloseContainer {
pub window_id: u8,
}

View File

@ -9,6 +9,8 @@ use crate::{
use num_traits::FromPrimitive; use num_traits::FromPrimitive;
use pumpkin_core::text::TextComponent; use pumpkin_core::text::TextComponent;
use pumpkin_entity::EntityId; use pumpkin_entity::EntityId;
use pumpkin_inventory::WindowType;
use pumpkin_protocol::server::play::SCloseContainer;
use pumpkin_protocol::{ use pumpkin_protocol::{
client::play::{ client::play::{
Animation, CAcknowledgeBlockChange, CBlockUpdate, CEntityAnimation, CEntityVelocity, Animation, CAcknowledgeBlockChange, CBlockUpdate, CEntityAnimation, CEntityVelocity,
@ -414,4 +416,15 @@ impl Client {
inventory.set_slot(packet.slot as usize, packet.clicked_item.to_item(), false); inventory.set_slot(packet.slot as usize, packet.clicked_item.to_item(), false);
} }
// TODO:
// This function will in the future be used to keep track of if the client is in a valid state.
// But this is not possible yet
pub fn handle_close_container(&mut self, packet: SCloseContainer) {
// window_id 0 represents both 9x1 Generic AND inventory here
let Ok(_window_type) = WindowType::try_from(packet.window_id) else {
self.kick("Invalid window ID");
return;
};
}
} }