steel_protocol/packets/game/
c_command_suggestions.rs1use steel_macros::{ClientPacket, WriteTo};
2use steel_registry::packets::play::C_COMMAND_SUGGESTIONS;
3use text_components::TextComponent;
4
5#[derive(ClientPacket, WriteTo, Clone, Debug)]
7#[packet_id(Play = C_COMMAND_SUGGESTIONS)]
8pub struct CCommandSuggestions {
9 #[write(as = VarInt)]
11 pub id: i32,
12 #[write(as = VarInt)]
14 pub start: i32,
15 #[write(as = VarInt)]
17 pub length: i32,
18 #[write(as = Prefixed(VarInt))]
20 pub suggestions: Vec<SuggestionEntry>,
21}
22
23#[derive(WriteTo, Clone, Debug)]
25pub struct SuggestionEntry {
26 #[write(as = Prefixed(VarInt))]
28 pub text: String,
29 pub tooltip: Option<TextComponent>,
31}
32
33impl SuggestionEntry {
34 pub fn new(text: impl Into<String>) -> Self {
36 Self {
37 text: text.into(),
38 tooltip: None,
39 }
40 }
41
42 pub fn with_tooltip(text: impl Into<String>, tooltip: impl Into<TextComponent>) -> Self {
44 Self {
45 text: text.into(),
46 tooltip: Some(tooltip.into()),
47 }
48 }
49}
50
51impl CCommandSuggestions {
52 #[must_use]
54 pub const fn new(id: i32, start: i32, length: i32, suggestions: Vec<SuggestionEntry>) -> Self {
55 Self {
56 id,
57 start,
58 length,
59 suggestions,
60 }
61 }
62}