basalt_mc_protocol/packets/
configuration.rs1use basalt_derive::{Decode, Encode, EncodedSize, packet};
7use basalt_types::Decode as _;
8use basalt_types::{NbtCompound, Uuid};
9
10use crate::error::{Error, Result};
11
12#[derive(Debug, Clone, Default, PartialEq)]
15#[packet(id = 0x02)]
16pub struct ServerboundConfigurationCustomPayload {
17 pub channel: String,
18 #[field(rest)]
19 pub data: Vec<u8>,
20}
21
22#[derive(Debug, Clone, Default, PartialEq)]
23#[packet(id = 0x03)]
24pub struct ServerboundConfigurationFinishConfiguration;
25
26#[derive(Debug, Clone, Default, PartialEq)]
27#[packet(id = 0x04)]
28pub struct ServerboundConfigurationKeepAlive {
29 pub keep_alive_id: i64,
30}
31
32#[derive(Debug, Clone, Default, PartialEq)]
33#[packet(id = 0x05)]
34pub struct ServerboundConfigurationPong {
35 pub id: i32,
36}
37
38#[derive(Debug, Clone, Default, PartialEq)]
39#[packet(id = 0x06)]
40pub struct ServerboundConfigurationResourcePackReceive {
41 pub uuid: Uuid,
42 #[field(varint)]
43 pub result: i32,
44}
45
46#[derive(Debug, Clone, Default, PartialEq)]
49#[packet(id = 0x01)]
50pub struct ClientboundConfigurationCustomPayload {
51 pub channel: String,
52 #[field(rest)]
53 pub data: Vec<u8>,
54}
55
56#[derive(Debug, Clone, Default, PartialEq)]
57#[packet(id = 0x02)]
58pub struct ClientboundConfigurationDisconnect {
59 pub reason: NbtCompound,
60}
61
62#[derive(Debug, Clone, Default, PartialEq)]
63#[packet(id = 0x0c)]
64pub struct ClientboundConfigurationFeatureFlags {
65 #[field(length = "varint")]
66 pub features: Vec<String>,
67}
68
69#[derive(Debug, Clone, Default, PartialEq)]
70#[packet(id = 0x03)]
71pub struct ClientboundConfigurationFinishConfiguration;
72
73#[derive(Debug, Clone, Default, PartialEq)]
74#[packet(id = 0x04)]
75pub struct ClientboundConfigurationKeepAlive {
76 pub keep_alive_id: i64,
77}
78
79#[derive(Debug, Clone, Default, PartialEq)]
80#[packet(id = 0x05)]
81pub struct ClientboundConfigurationPing {
82 pub id: i32,
83}
84
85#[derive(Debug, Clone, Default, PartialEq, Encode, Decode, EncodedSize)]
87pub struct ClientboundConfigurationRegistryDataEntries {
88 pub key: String,
89 #[field(optional)]
90 pub value: Option<NbtCompound>,
91}
92
93#[derive(Debug, Clone, Default, PartialEq)]
94#[packet(id = 0x07)]
95pub struct ClientboundConfigurationRegistryData {
96 pub id: String,
97 #[field(length = "varint")]
98 pub entries: Vec<ClientboundConfigurationRegistryDataEntries>,
99}
100
101#[derive(Debug, Clone, Default, PartialEq)]
102#[packet(id = 0x06)]
103pub struct ClientboundConfigurationResetChat;
104
105#[derive(Debug, Clone, Default, PartialEq, Encode, Decode, EncodedSize)]
107pub struct ClientboundConfigurationTagsTagsTags {
108 pub tag_name: String,
109 #[field(length = "varint", element = "varint")]
110 pub entries: Vec<i32>,
111}
112
113#[derive(Debug, Clone, Default, PartialEq, Encode, Decode, EncodedSize)]
115pub struct ClientboundConfigurationTagsTags {
116 pub tag_type: String,
117 #[field(length = "varint")]
118 pub tags: Vec<ClientboundConfigurationTagsTagsTags>,
119}
120
121#[derive(Debug, Clone, Default, PartialEq)]
122#[packet(id = 0x0d)]
123pub struct ClientboundConfigurationTags {
124 #[field(length = "varint")]
125 pub tags: Vec<ClientboundConfigurationTagsTags>,
126}
127
128#[derive(Debug, Clone, PartialEq)]
130pub enum ServerboundConfigurationPacket {
131 CustomPayload(ServerboundConfigurationCustomPayload),
132 FinishConfiguration(ServerboundConfigurationFinishConfiguration),
133 KeepAlive(ServerboundConfigurationKeepAlive),
134 Pong(ServerboundConfigurationPong),
135 ResourcePackReceive(ServerboundConfigurationResourcePackReceive),
136}
137
138impl ServerboundConfigurationPacket {
139 pub fn decode_by_id(id: i32, buf: &mut &[u8]) -> Result<Self> {
141 match id {
142 ServerboundConfigurationCustomPayload::PACKET_ID => Ok(Self::CustomPayload(
143 ServerboundConfigurationCustomPayload::decode(buf)?,
144 )),
145 ServerboundConfigurationFinishConfiguration::PACKET_ID => {
146 Ok(Self::FinishConfiguration(
147 ServerboundConfigurationFinishConfiguration::decode(buf)?,
148 ))
149 }
150 ServerboundConfigurationKeepAlive::PACKET_ID => Ok(Self::KeepAlive(
151 ServerboundConfigurationKeepAlive::decode(buf)?,
152 )),
153 ServerboundConfigurationPong::PACKET_ID => {
154 Ok(Self::Pong(ServerboundConfigurationPong::decode(buf)?))
155 }
156 ServerboundConfigurationResourcePackReceive::PACKET_ID => {
157 Ok(Self::ResourcePackReceive(
158 ServerboundConfigurationResourcePackReceive::decode(buf)?,
159 ))
160 }
161 _ => Err(Error::UnknownPacket {
162 id,
163 state: "configuration",
164 }),
165 }
166 }
167}
168
169#[derive(Debug, Clone, PartialEq)]
171pub enum ClientboundConfigurationPacket {
172 CustomPayload(ClientboundConfigurationCustomPayload),
173 Disconnect(ClientboundConfigurationDisconnect),
174 FeatureFlags(ClientboundConfigurationFeatureFlags),
175 FinishConfiguration(ClientboundConfigurationFinishConfiguration),
176 KeepAlive(ClientboundConfigurationKeepAlive),
177 Ping(ClientboundConfigurationPing),
178 RegistryData(ClientboundConfigurationRegistryData),
179 ResetChat(ClientboundConfigurationResetChat),
180 Tags(ClientboundConfigurationTags),
181}
182
183impl ClientboundConfigurationPacket {
184 pub fn decode_by_id(id: i32, buf: &mut &[u8]) -> Result<Self> {
186 match id {
187 ClientboundConfigurationCustomPayload::PACKET_ID => Ok(Self::CustomPayload(
188 ClientboundConfigurationCustomPayload::decode(buf)?,
189 )),
190 ClientboundConfigurationDisconnect::PACKET_ID => Ok(Self::Disconnect(
191 ClientboundConfigurationDisconnect::decode(buf)?,
192 )),
193 ClientboundConfigurationFeatureFlags::PACKET_ID => Ok(Self::FeatureFlags(
194 ClientboundConfigurationFeatureFlags::decode(buf)?,
195 )),
196 ClientboundConfigurationFinishConfiguration::PACKET_ID => {
197 Ok(Self::FinishConfiguration(
198 ClientboundConfigurationFinishConfiguration::decode(buf)?,
199 ))
200 }
201 ClientboundConfigurationKeepAlive::PACKET_ID => Ok(Self::KeepAlive(
202 ClientboundConfigurationKeepAlive::decode(buf)?,
203 )),
204 ClientboundConfigurationPing::PACKET_ID => {
205 Ok(Self::Ping(ClientboundConfigurationPing::decode(buf)?))
206 }
207 ClientboundConfigurationRegistryData::PACKET_ID => Ok(Self::RegistryData(
208 ClientboundConfigurationRegistryData::decode(buf)?,
209 )),
210 ClientboundConfigurationResetChat::PACKET_ID => Ok(Self::ResetChat(
211 ClientboundConfigurationResetChat::decode(buf)?,
212 )),
213 ClientboundConfigurationTags::PACKET_ID => {
214 Ok(Self::Tags(ClientboundConfigurationTags::decode(buf)?))
215 }
216 _ => Err(Error::UnknownPacket {
217 id,
218 state: "configuration",
219 }),
220 }
221 }
222}