ghast-protocol 0.4.5

Minecraft Java Edition network protocol for the ghast client library: generated per-version packets, framing, compression, encryption, NBT
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
// (data/pc/26.1/protocol.json). Do not edit; run `cargo run -p ghast-codegen-protocol`.
// minecraft-data is MIT licensed, Copyright (c) 2015 PrismarineJS; see the NOTICE file
// in crates/ghast-protocol/src/generated/.

//! Serverbound packets of the configuration state.

#![allow(
    unused_imports,
    unused_variables,
    unused_mut,
    unused_parens,
    unused_braces,
    clippy::all,
    clippy::pedantic,
    non_camel_case_types,
    non_snake_case
)]
use crate::codec::{Decode, DecodeResult, Encode, EncodeResult, McWrite, Reader, decode_exact};
use crate::error::{DecodeError, EncodeError};
use crate::nbt::{AnonNbt, RawNbt};
use crate::packet::{Direction, PacketSet, RawPacket, State};
#[cfg(feature = "testgen")]
use crate::testgen::{Gen, Generate};
use crate::types::{BlockPos, ByteString, Holder, HolderSet, LpVec3, PositionLayout, Uuid};
use bytes::{BufMut, Bytes, BytesMut};

#[cfg(any(feature = "v26_1", feature = "v26_2"))]
/// Mapped `i32` value; unknown values are kept as-is.
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
pub struct SettingsParticleStatus(pub i32);
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl SettingsParticleStatus {
    /// `all`
    pub const ALL: Self = Self(0);
    /// `decreased`
    pub const DECREASED: Self = Self(1);
    /// `minimal`
    pub const MINIMAL: Self = Self(2);
    /// minecraft-data name of the value, if known.
    pub const fn name(self) -> Option<&'static str> {
        match self.0 {
            0 => Some("all"),
            1 => Some("decreased"),
            2 => Some("minimal"),
            _ => None,
        }
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl std::fmt::Debug for SettingsParticleStatus {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self.name() {
            Some(n) => write!(f, "SettingsParticleStatus::{n}"),
            None => write!(f, "SettingsParticleStatus({})", self.0),
        }
    }
}

#[cfg(any(feature = "v26_1", feature = "v26_2"))]
/// `settings` (serverbound configuration).
#[derive(Debug, Clone, PartialEq)]
pub struct Settings<const V: i32> {
    /// `locale`
    pub locale: ByteString,
    /// `viewDistance`
    pub view_distance: i8,
    /// `chatFlags`
    pub chat_flags: i32,
    /// `chatColors`
    pub chat_colors: bool,
    /// `skinParts`
    pub skin_parts: u8,
    /// `mainHand`
    pub main_hand: i32,
    /// `enableTextFiltering`
    pub enable_text_filtering: bool,
    /// `enableServerListing`
    pub enable_server_listing: bool,
    /// `particleStatus`
    pub particle_status: crate::defs::p775::configuration::serverbound::SettingsParticleStatus,
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for Settings<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_string()?;
            let v2 = r.read_i8()?;
            let v3 = r.read_varint()?;
            let v4 = r.read_bool()?;
            let v5 = r.read_u8()?;
            let v6 = r.read_varint()?;
            let v7 = r.read_bool()?;
            let v8 = r.read_bool()?;
            let v9 = crate::defs::p775::configuration::serverbound::SettingsParticleStatus(
                r.read_varint()?,
            );
            Self {
                locale: v1,
                view_distance: v2,
                chat_flags: v3,
                chat_colors: v4,
                skin_parts: v5,
                main_hand: v6,
                enable_text_filtering: v7,
                enable_server_listing: v8,
                particle_status: v9,
            }
        })
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for Settings<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_string(&(*self).locale)?;
        w.put_i8((*self).view_distance);
        w.put_varint((*self).chat_flags);
        w.put_bool((*self).chat_colors);
        w.put_u8((*self).skin_parts);
        w.put_varint((*self).main_hand);
        w.put_bool((*self).enable_text_filtering);
        w.put_bool((*self).enable_server_listing);
        w.put_varint((*self).particle_status.0);
        Ok(())
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Settings<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = g.string();
            let v2 = (g.int_in(-128, 127, &[]) as i8);
            let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
            let v4 = g.bool();
            let v5 = (g.int_in(0, 255, &[]) as u8);
            let v6 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
            let v7 = g.bool();
            let v8 = g.bool();
            let v9 = crate::defs::p775::configuration::serverbound::SettingsParticleStatus(
                g.int_in(-2147483648, 2147483647, &[0, 1, 2]) as i32,
            );
            Self {
                locale: v1,
                view_distance: v2,
                chat_flags: v3,
                chat_colors: v4,
                skin_parts: v5,
                main_hand: v6,
                enable_text_filtering: v7,
                enable_server_listing: v8,
                particle_status: v9,
            }
        }
    }
}

#[cfg(any(feature = "v26_1", feature = "v26_2"))]
/// `cookie_response` (serverbound configuration).
#[derive(Debug, Clone, PartialEq)]
pub struct CookieResponse<const V: i32> {
    /// `key`
    pub key: ByteString,
    /// `value`
    pub value: Option<Bytes>,
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for CookieResponse<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_string()?;
            let v2 = if r.read_bool()? {
                Some(r.read_byte_array()?)
            } else {
                None
            };
            Self { key: v1, value: v2 }
        })
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for CookieResponse<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_string(&(*self).key)?;
        match &(*self).value {
            Some(v1) => {
                w.put_u8(1);
                w.put_byte_array(&(*v1))?;
            }
            None => w.put_u8(0),
        }
        Ok(())
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for CookieResponse<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = g.string();
            let v2 = if g.bool() { Some(g.bytes()) } else { None };
            Self { key: v1, value: v2 }
        }
    }
}

#[cfg(any(feature = "v26_1", feature = "v26_2"))]
/// `custom_payload` (serverbound configuration).
#[derive(Debug, Clone, PartialEq)]
pub struct CustomPayload<const V: i32> {
    /// `channel`
    pub channel: ByteString,
    /// `data`
    pub data: Bytes,
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for CustomPayload<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_string()?;
            let v2 = r.read_rest();
            Self {
                channel: v1,
                data: v2,
            }
        })
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for CustomPayload<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_string(&(*self).channel)?;
        w.put_slice(&(*self).data);
        Ok(())
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for CustomPayload<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = g.string();
            let v2 = g.bytes();
            Self {
                channel: v1,
                data: v2,
            }
        }
    }
}

#[cfg(any(feature = "v26_1", feature = "v26_2"))]
/// `finish_configuration` (serverbound configuration).
#[derive(Debug, Clone, PartialEq)]
pub struct FinishConfiguration<const V: i32> {}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for FinishConfiguration<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({ Self {} })
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for FinishConfiguration<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        Ok(())
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for FinishConfiguration<V> {
    fn generate(g: &mut Gen) -> Self {
        { Self {} }
    }
}

#[cfg(any(feature = "v26_1", feature = "v26_2"))]
/// `keep_alive` (serverbound configuration).
#[derive(Debug, Clone, PartialEq)]
pub struct KeepAlive<const V: i32> {
    /// `keepAliveId`
    pub keep_alive_id: i64,
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for KeepAlive<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_i64()?;
            Self { keep_alive_id: v1 }
        })
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for KeepAlive<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_i64((*self).keep_alive_id);
        Ok(())
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for KeepAlive<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = g.i64();
            Self { keep_alive_id: v1 }
        }
    }
}

#[cfg(any(feature = "v26_1", feature = "v26_2"))]
/// `pong` (serverbound configuration).
#[derive(Debug, Clone, PartialEq)]
pub struct Pong<const V: i32> {
    /// `id`
    pub id: i32,
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for Pong<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_i32()?;
            Self { id: v1 }
        })
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for Pong<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_i32((*self).id);
        Ok(())
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Pong<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
            Self { id: v1 }
        }
    }
}

#[cfg(any(feature = "v26_1", feature = "v26_2"))]
/// `resource_pack_receive` (serverbound configuration).
#[derive(Debug, Clone, PartialEq)]
pub struct ResourcePackReceive<const V: i32> {
    /// `uuid`
    pub uuid: Uuid,
    /// `result`
    pub result: i32,
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for ResourcePackReceive<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_uuid()?;
            let v2 = r.read_varint()?;
            Self {
                uuid: v1,
                result: v2,
            }
        })
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for ResourcePackReceive<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_uuid(&(*self).uuid);
        w.put_varint((*self).result);
        Ok(())
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for ResourcePackReceive<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = g.uuid();
            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
            Self {
                uuid: v1,
                result: v2,
            }
        }
    }
}

#[cfg(any(feature = "v26_1", feature = "v26_2"))]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct SelectKnownPacksPacks {
    /// `namespace`
    pub namespace: ByteString,
    /// `id`
    pub id: ByteString,
    /// `version`
    pub version: ByteString,
}

#[cfg(any(feature = "v26_1", feature = "v26_2"))]
/// `select_known_packs` (serverbound configuration).
#[derive(Debug, Clone, PartialEq)]
pub struct SelectKnownPacks<const V: i32> {
    /// `packs`
    pub packs: Vec<crate::defs::p775::configuration::serverbound::SelectKnownPacksPacks>,
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for SelectKnownPacks<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = {
                let v2 = {
                    let c = r.read_varint()?;
                    r.check_count(i64::from(c), 3)?
                };
                let mut v3 = Vec::with_capacity(v2.min(crate::codec::PREALLOC_LIMIT));
                for _ in 0..v2 {
                    v3.push({
                        let v4 = r.read_string()?;
                        let v5 = r.read_string()?;
                        let v6 = r.read_string()?;
                        crate::defs::p775::configuration::serverbound::SelectKnownPacksPacks {
                            namespace: v4,
                            id: v5,
                            version: v6,
                        }
                    });
                }
                v3
            };
            Self { packs: v1 }
        })
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for SelectKnownPacks<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_len_varint((*self).packs.len())?;
        for v1 in (*self).packs.iter() {
            w.put_string(&(*v1).namespace)?;
            w.put_string(&(*v1).id)?;
            w.put_string(&(*v1).version)?;
        }
        Ok(())
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for SelectKnownPacks<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = {
                let v2 = g.count();
                let mut v3 = Vec::with_capacity(v2.min(crate::codec::PREALLOC_LIMIT));
                for _ in 0..v2 {
                    v3.push({
                        let v4 = g.string();
                        let v5 = g.string();
                        let v6 = g.string();
                        crate::defs::p775::configuration::serverbound::SelectKnownPacksPacks {
                            namespace: v4,
                            id: v5,
                            version: v6,
                        }
                    });
                }
                v3
            };
            Self { packs: v1 }
        }
    }
}

#[cfg(any(feature = "v26_1", feature = "v26_2"))]
/// `custom_click_action` (serverbound configuration).
#[derive(Debug, Clone, PartialEq)]
pub struct CustomClickAction<const V: i32> {
    /// `id`
    pub id: ByteString,
    /// `nbt`
    pub nbt: Option<AnonNbt>,
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for CustomClickAction<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_string()?;
            let v2 = if r.read_bool()? {
                Some(AnonNbt::read(r)?)
            } else {
                None
            };
            Self { id: v1, nbt: v2 }
        })
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for CustomClickAction<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_string(&(*self).id)?;
        match &(*self).nbt {
            Some(v1) => {
                w.put_u8(1);
                (*v1).write(w);
            }
            None => w.put_u8(0),
        }
        Ok(())
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for CustomClickAction<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = g.string();
            let v2 = if g.bool() { Some(g.anon_nbt()) } else { None };
            Self { id: v1, nbt: v2 }
        }
    }
}

#[cfg(any(feature = "v26_1", feature = "v26_2"))]
/// `accept_code_of_conduct` (serverbound configuration).
#[derive(Debug, Clone, PartialEq)]
pub struct AcceptCodeOfConduct<const V: i32> {}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Decode for AcceptCodeOfConduct<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({ Self {} })
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
impl<const V: i32> Encode for AcceptCodeOfConduct<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        Ok(())
    }
}
#[cfg(any(feature = "v26_1", feature = "v26_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for AcceptCodeOfConduct<V> {
    fn generate(g: &mut Gen) -> Self {
        { Self {} }
    }
}