add serverbound packet SContainerClose
This commit is contained in:
parent
98fcd412c2
commit
e1a7d4e7ee
@ -52,3 +52,37 @@ impl WindowType {
|
||||
"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(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
mod s_chat_command;
|
||||
mod s_chat_message;
|
||||
mod s_client_information;
|
||||
mod s_close_container;
|
||||
mod s_confirm_teleport;
|
||||
mod s_interact;
|
||||
mod s_ping_request;
|
||||
@ -17,6 +18,7 @@ mod s_use_item_on;
|
||||
pub use s_chat_command::*;
|
||||
pub use s_chat_message::*;
|
||||
pub use s_client_information::*;
|
||||
pub use s_close_container::*;
|
||||
pub use s_confirm_teleport::*;
|
||||
pub use s_interact::*;
|
||||
pub use s_ping_request::*;
|
||||
|
||||
8
pumpkin-protocol/src/server/play/s_close_container.rs
Normal file
8
pumpkin-protocol/src/server/play/s_close_container.rs
Normal file
@ -0,0 +1,8 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x0F)]
|
||||
pub struct SCloseContainer {
|
||||
pub window_id: u8,
|
||||
}
|
||||
@ -9,6 +9,8 @@ use crate::{
|
||||
use num_traits::FromPrimitive;
|
||||
use pumpkin_core::text::TextComponent;
|
||||
use pumpkin_entity::EntityId;
|
||||
use pumpkin_inventory::WindowType;
|
||||
use pumpkin_protocol::server::play::SCloseContainer;
|
||||
use pumpkin_protocol::{
|
||||
client::play::{
|
||||
Animation, CAcknowledgeBlockChange, CBlockUpdate, CEntityAnimation, CEntityVelocity,
|
||||
@ -414,4 +416,15 @@ impl Client {
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user