steel_protocol/packets/game/
c_open_screen.rs1use std::io::{Result, Write};
2
3use steel_macros::ClientPacket;
4use steel_registry::{RegistryEntry, menu_type::MenuTypeRef, packets::play::C_OPEN_SCREEN};
5use steel_utils::{codec::VarInt, serial::WriteTo};
6use text_components::{TextComponent, resolving::TextResolutor};
7
8#[derive(ClientPacket, Clone, Debug)]
9#[packet_id(Play = C_OPEN_SCREEN)]
10pub struct COpenScreen {
11 pub container_id: i32,
12 pub menu_type: MenuTypeRef,
13 pub title: TextComponent,
14}
15
16impl COpenScreen {
17 pub fn new<T: TextResolutor>(
18 container_id: i32,
19 menu_type: MenuTypeRef,
20 title: &TextComponent,
21 player: &T,
22 ) -> Self {
23 Self {
24 container_id,
25 menu_type,
26 title: title.resolve(player),
27 }
28 }
29}
30
31impl WriteTo for COpenScreen {
32 fn write(&self, writer: &mut impl Write) -> Result<()> {
33 VarInt(self.container_id).write(writer)?;
34 VarInt(self.menu_type.id() as i32).write(writer)?;
35 self.title.write(writer)?;
36 Ok(())
37 }
38}