ghast-protocol 0.5.6

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
// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
// (data/pc/26.1/protocol.json + codegen/protocol/delta/776.json + codegen/protocol/delta/777.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 play 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(feature = "v26_3")]
/// `teleport_confirm` (serverbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct TeleportConfirm<const V: i32> {
    /// `teleportId`
    pub teleport_id: i32,
    /// `x`
    pub x: f64,
    /// `y`
    pub y: f64,
    /// `z`
    pub z: f64,
    /// `yaw`
    pub yaw: f32,
    /// `pitch`
    pub pitch: f32,
}
#[cfg(feature = "v26_3")]
impl<const V: i32> Decode for TeleportConfirm<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_varint()?;
            let v2 = r.read_f64()?;
            let v3 = r.read_f64()?;
            let v4 = r.read_f64()?;
            let v5 = r.read_f32()?;
            let v6 = r.read_f32()?;
            Self {
                teleport_id: v1,
                x: v2,
                y: v3,
                z: v4,
                yaw: v5,
                pitch: v6,
            }
        })
    }
}
#[cfg(feature = "v26_3")]
impl<const V: i32> Encode for TeleportConfirm<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_varint((*self).teleport_id);
        w.put_f64((*self).x);
        w.put_f64((*self).y);
        w.put_f64((*self).z);
        w.put_f32((*self).yaw);
        w.put_f32((*self).pitch);
        Ok(())
    }
}
#[cfg(feature = "v26_3")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for TeleportConfirm<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
            let v2 = g.f64();
            let v3 = g.f64();
            let v4 = g.f64();
            let v5 = g.f32();
            let v6 = g.f32();
            Self {
                teleport_id: v1,
                x: v2,
                y: v3,
                z: v4,
                yaw: v5,
                pitch: v6,
            }
        }
    }
}

#[cfg(feature = "v26_3")]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct WindowClickChangedSlots {
    /// `location`
    pub location: i16,
    /// `item`
    pub item: Option<crate::defs::p777::types::HashedSlot>,
}

#[cfg(feature = "v26_3")]
/// `window_click` (serverbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct WindowClick<const V: i32> {
    /// `windowId`
    pub window_id: i32,
    /// `stateId`
    pub state_id: i32,
    /// `slot`
    pub slot: i16,
    /// `mouseButton`
    pub mouse_button: i8,
    /// `mode`
    pub mode: i32,
    /// `changedSlots`
    pub changed_slots: Vec<crate::defs::p777::play::serverbound::WindowClickChangedSlots>,
    /// `cursorItem`
    pub cursor_item: Option<crate::defs::p777::types::HashedSlot>,
}
#[cfg(feature = "v26_3")]
impl<const V: i32> Decode for WindowClick<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_varint()?;
            let v2 = r.read_varint()?;
            let v3 = r.read_i16()?;
            let v4 = r.read_i8()?;
            let v5 = r.read_varint()?;
            let v6 = {
                let v7 = {
                    let c = r.read_varint()?;
                    r.check_count(i64::from(c), 3)?
                };
                let mut v8 = Vec::with_capacity(v7.min(crate::codec::PREALLOC_LIMIT));
                for _ in 0..v7 {
                    v8.push({
                        let v9 = r.read_i16()?;
                        let v10 = if r.read_bool()? {
                            Some(<crate::defs::p777::types::HashedSlot as Decode>::decode(r)?)
                        } else {
                            None
                        };
                        crate::defs::p777::play::serverbound::WindowClickChangedSlots {
                            location: v9,
                            item: v10,
                        }
                    });
                }
                v8
            };
            let v11 = if r.read_bool()? {
                Some(<crate::defs::p777::types::HashedSlot as Decode>::decode(r)?)
            } else {
                None
            };
            Self {
                window_id: v1,
                state_id: v2,
                slot: v3,
                mouse_button: v4,
                mode: v5,
                changed_slots: v6,
                cursor_item: v11,
            }
        })
    }
}
#[cfg(feature = "v26_3")]
impl<const V: i32> Encode for WindowClick<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_varint((*self).window_id);
        w.put_varint((*self).state_id);
        w.put_i16((*self).slot);
        w.put_i8((*self).mouse_button);
        w.put_varint((*self).mode);
        w.put_len_varint((*self).changed_slots.len())?;
        for v1 in (*self).changed_slots.iter() {
            w.put_i16((*v1).location);
            match &(*v1).item {
                Some(v2) => {
                    w.put_u8(1);
                    (*v2).encode(w)?;
                }
                None => w.put_u8(0),
            }
        }
        match &(*self).cursor_item {
            Some(v3) => {
                w.put_u8(1);
                (*v3).encode(w)?;
            }
            None => w.put_u8(0),
        }
        Ok(())
    }
}
#[cfg(feature = "v26_3")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for WindowClick<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
            let v3 = (g.int_in(-32768, 32767, &[]) as i16);
            let v4 = (g.int_in(-128, 127, &[]) as i8);
            let v5 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
            let v6 = {
                let v7 = g.count();
                let mut v8 = Vec::with_capacity(v7.min(crate::codec::PREALLOC_LIMIT));
                for _ in 0..v7 {
                    v8.push({
                        let v9 = (g.int_in(-32768, 32767, &[]) as i16);
                        let v10 = if g.bool() {
                            Some(<crate::defs::p777::types::HashedSlot as Generate>::generate(g))
                        } else {
                            None
                        };
                        crate::defs::p777::play::serverbound::WindowClickChangedSlots {
                            location: v9,
                            item: v10,
                        }
                    });
                }
                v8
            };
            let v11 = if g.bool() {
                Some(<crate::defs::p777::types::HashedSlot as Generate>::generate(g))
            } else {
                None
            };
            Self {
                window_id: v1,
                state_id: v2,
                slot: v3,
                mouse_button: v4,
                mode: v5,
                changed_slots: v6,
                cursor_item: v11,
            }
        }
    }
}

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

#[cfg(feature = "v26_3")]
/// `set_creative_slot` (serverbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct SetCreativeSlot<const V: i32> {
    /// `slot`
    pub slot: i16,
    /// `item`
    pub item: crate::defs::p777::types::UntrustedSlot,
}
#[cfg(feature = "v26_3")]
impl<const V: i32> Decode for SetCreativeSlot<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_i16()?;
            let v2 = <crate::defs::p777::types::UntrustedSlot as Decode>::decode(r)?;
            Self { slot: v1, item: v2 }
        })
    }
}
#[cfg(feature = "v26_3")]
impl<const V: i32> Encode for SetCreativeSlot<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_i16((*self).slot);
        (*self).item.encode(w)?;
        Ok(())
    }
}
#[cfg(feature = "v26_3")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for SetCreativeSlot<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = (g.int_in(-32768, 32767, &[]) as i16);
            let v2 = <crate::defs::p777::types::UntrustedSlot as Generate>::generate(g);
            Self { slot: v1, item: v2 }
        }
    }
}

#[cfg(feature = "v26_3")]
/// Mapped `i32` value; unknown values are kept as-is.
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
#[non_exhaustive]
pub struct UpdateSignSide(pub i32);
#[cfg(feature = "v26_3")]
impl UpdateSignSide {
    /// The value with wire number `v`.
    pub const fn new(v: i32) -> Self {
        Self(v)
    }
    /// `back`
    pub const BACK: Self = Self(0);
    /// `front`
    pub const FRONT: Self = Self(1);
    /// minecraft-data name of the value, if known.
    pub const fn name(self) -> Option<&'static str> {
        match self.0 {
            0 => Some("back"),
            1 => Some("front"),
            _ => None,
        }
    }
}
#[cfg(feature = "v26_3")]
impl std::fmt::Debug for UpdateSignSide {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self.name() {
            Some(n) => write!(f, "UpdateSignSide::{n}"),
            None => write!(f, "UpdateSignSide({})", self.0),
        }
    }
}

#[cfg(feature = "v26_3")]
/// `update_sign` (serverbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct UpdateSign<const V: i32> {
    /// `location`
    pub location: BlockPos,
    /// `text1`
    pub text1: ByteString,
    /// `text2`
    pub text2: ByteString,
    /// `text3`
    pub text3: ByteString,
    /// `text4`
    pub text4: ByteString,
    /// `side`
    pub side: crate::defs::p777::play::serverbound::UpdateSignSide,
}
#[cfg(feature = "v26_3")]
impl<const V: i32> Decode for UpdateSign<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = BlockPos::read(r, PositionLayout::Xzy)?;
            let v2 = r.read_string()?;
            let v3 = r.read_string()?;
            let v4 = r.read_string()?;
            let v5 = r.read_string()?;
            let v6 = crate::defs::p777::play::serverbound::UpdateSignSide(r.read_varint()?);
            Self {
                location: v1,
                text1: v2,
                text2: v3,
                text3: v4,
                text4: v5,
                side: v6,
            }
        })
    }
}
#[cfg(feature = "v26_3")]
impl<const V: i32> Encode for UpdateSign<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        (*self).location.write(w, PositionLayout::Xzy)?;
        w.put_string(&(*self).text1)?;
        w.put_string(&(*self).text2)?;
        w.put_string(&(*self).text3)?;
        w.put_string(&(*self).text4)?;
        w.put_varint((*self).side.0);
        Ok(())
    }
}
#[cfg(feature = "v26_3")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for UpdateSign<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = g.position();
            let v2 = g.string();
            let v3 = g.string();
            let v4 = g.string();
            let v5 = g.string();
            let v6 = crate::defs::p777::play::serverbound::UpdateSignSide(g.int_in(
                -2147483648,
                2147483647,
                &[0, 1],
            ) as i32);
            Self {
                location: v1,
                text1: v2,
                text2: v3,
                text3: v4,
                text4: v5,
                side: v6,
            }
        }
    }
}