steel_protocol/packets/game/
c_tab_list.rs1use steel_macros::ClientPacket;
2use steel_registry::packets::play::C_TAB_LIST;
3use text_components::{TextComponent, resolving::TextResolutor};
4
5#[derive(ClientPacket, Debug, Clone)]
8#[packet_id(Play = C_TAB_LIST)]
9pub struct CTabList {
10 pub header: TextComponent,
12 pub footer: TextComponent,
14}
15
16impl CTabList {
17 #[must_use]
19 pub fn new<T: TextResolutor>(
20 header: &TextComponent,
21 footer: &TextComponent,
22 player: &T,
23 ) -> Self {
24 Self {
25 header: header.resolve(player),
26 footer: footer.resolve(player),
27 }
28 }
29
30 #[must_use]
32 pub const fn empty() -> Self {
33 Self {
34 header: TextComponent::new(),
35 footer: TextComponent::new(),
36 }
37 }
38
39 #[must_use]
41 pub fn header_only<T: TextResolutor>(header: &TextComponent, player: &T) -> Self {
42 Self {
43 header: header.resolve(player),
44 footer: TextComponent::new(),
45 }
46 }
47
48 #[must_use]
50 pub fn footer_only<T: TextResolutor>(footer: &TextComponent, player: &T) -> Self {
51 Self {
52 header: TextComponent::new(),
53 footer: footer.resolve(player),
54 }
55 }
56}
57
58impl steel_utils::serial::WriteTo for CTabList {
59 fn write(&self, writer: &mut impl std::io::Write) -> std::io::Result<()> {
60 self.header.write(writer)?;
61 self.footer.write(writer)?;
62 Ok(())
63 }
64}