Skip to main content

ghast_protocol/generated/defs/p340/play/
clientbound.rs

1// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
2// (data/pc/1.12.2/protocol.json). Do not edit; run `cargo run -p ghast-codegen-protocol`.
3// minecraft-data is MIT licensed, Copyright (c) 2015 PrismarineJS; see the NOTICE file
4// in crates/ghast-protocol/src/generated/.
5
6//! Clientbound packets of the play state.
7
8#![allow(
9    unused_imports,
10    unused_variables,
11    unused_mut,
12    unused_parens,
13    unused_braces,
14    clippy::all,
15    clippy::pedantic,
16    non_camel_case_types,
17    non_snake_case
18)]
19use crate::codec::{Decode, DecodeResult, Encode, EncodeResult, McWrite, Reader, decode_exact};
20use crate::error::{DecodeError, EncodeError};
21use crate::nbt::{AnonNbt, RawNbt};
22use crate::packet::{Direction, PacketSet, RawPacket, State};
23#[cfg(feature = "testgen")]
24use crate::testgen::{Gen, Generate};
25use crate::types::{BlockPos, ByteString, Holder, HolderSet, LpVec3, PositionLayout, Uuid};
26use bytes::{BufMut, Bytes, BytesMut};
27
28#[cfg(feature = "v1_12_2")]
29/// `spawn_entity` (clientbound play).
30#[derive(Debug, Clone, PartialEq)]
31pub struct SpawnEntity<const V: i32> {
32    /// `entityId`
33    pub entity_id: i32,
34    /// `objectUUID`
35    pub object_uuid: Uuid,
36    /// `type`
37    pub r#type: i8,
38    /// `x`
39    pub x: f64,
40    /// `y`
41    pub y: f64,
42    /// `z`
43    pub z: f64,
44    /// `pitch`
45    pub pitch: i8,
46    /// `yaw`
47    pub yaw: i8,
48    /// `objectData`
49    pub object_data: i32,
50    /// `velocity`
51    pub velocity: crate::defs::p47::types::Vec3i16,
52}
53#[cfg(feature = "v1_12_2")]
54impl<const V: i32> Decode for SpawnEntity<V> {
55    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
56        Ok({
57            let v1 = r.read_varint()?;
58            let v2 = r.read_uuid()?;
59            let v3 = r.read_i8()?;
60            let v4 = r.read_f64()?;
61            let v5 = r.read_f64()?;
62            let v6 = r.read_f64()?;
63            let v7 = r.read_i8()?;
64            let v8 = r.read_i8()?;
65            let v9 = r.read_i32()?;
66            let v10 = <crate::defs::p47::types::Vec3i16 as Decode>::decode(r)?;
67            Self {
68                entity_id: v1,
69                object_uuid: v2,
70                r#type: v3,
71                x: v4,
72                y: v5,
73                z: v6,
74                pitch: v7,
75                yaw: v8,
76                object_data: v9,
77                velocity: v10,
78            }
79        })
80    }
81}
82#[cfg(feature = "v1_12_2")]
83impl<const V: i32> Encode for SpawnEntity<V> {
84    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
85        w.put_varint((*self).entity_id);
86        w.put_uuid(&(*self).object_uuid);
87        w.put_i8((*self).r#type);
88        w.put_f64((*self).x);
89        w.put_f64((*self).y);
90        w.put_f64((*self).z);
91        w.put_i8((*self).pitch);
92        w.put_i8((*self).yaw);
93        w.put_i32((*self).object_data);
94        (*self).velocity.encode(w)?;
95        Ok(())
96    }
97}
98#[cfg(feature = "v1_12_2")]
99#[cfg(feature = "testgen")]
100impl<const V: i32> Generate for SpawnEntity<V> {
101    fn generate(g: &mut Gen) -> Self {
102        {
103            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
104            let v2 = g.uuid();
105            let v3 = (g.int_in(-128, 127, &[]) as i8);
106            let v4 = g.f64();
107            let v5 = g.f64();
108            let v6 = g.f64();
109            let v7 = (g.int_in(-128, 127, &[]) as i8);
110            let v8 = (g.int_in(-128, 127, &[]) as i8);
111            let v9 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
112            let v10 = <crate::defs::p47::types::Vec3i16 as Generate>::generate(g);
113            Self {
114                entity_id: v1,
115                object_uuid: v2,
116                r#type: v3,
117                x: v4,
118                y: v5,
119                z: v6,
120                pitch: v7,
121                yaw: v8,
122                object_data: v9,
123                velocity: v10,
124            }
125        }
126    }
127}
128
129#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
130/// `spawn_entity_experience_orb` (clientbound play).
131#[derive(Debug, Clone, PartialEq)]
132pub struct SpawnEntityExperienceOrb<const V: i32> {
133    /// `entityId`
134    pub entity_id: i32,
135    /// `x`
136    pub x: f64,
137    /// `y`
138    pub y: f64,
139    /// `z`
140    pub z: f64,
141    /// `count`
142    pub count: i16,
143}
144#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
145impl<const V: i32> Decode for SpawnEntityExperienceOrb<V> {
146    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
147        Ok({
148            let v1 = r.read_varint()?;
149            let v2 = r.read_f64()?;
150            let v3 = r.read_f64()?;
151            let v4 = r.read_f64()?;
152            let v5 = r.read_i16()?;
153            Self {
154                entity_id: v1,
155                x: v2,
156                y: v3,
157                z: v4,
158                count: v5,
159            }
160        })
161    }
162}
163#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
164impl<const V: i32> Encode for SpawnEntityExperienceOrb<V> {
165    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
166        w.put_varint((*self).entity_id);
167        w.put_f64((*self).x);
168        w.put_f64((*self).y);
169        w.put_f64((*self).z);
170        w.put_i16((*self).count);
171        Ok(())
172    }
173}
174#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
175#[cfg(feature = "testgen")]
176impl<const V: i32> Generate for SpawnEntityExperienceOrb<V> {
177    fn generate(g: &mut Gen) -> Self {
178        {
179            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
180            let v2 = g.f64();
181            let v3 = g.f64();
182            let v4 = g.f64();
183            let v5 = (g.int_in(-32768, 32767, &[]) as i16);
184            Self {
185                entity_id: v1,
186                x: v2,
187                y: v3,
188                z: v4,
189                count: v5,
190            }
191        }
192    }
193}
194
195#[cfg(feature = "v1_12_2")]
196/// `spawn_entity_weather` (clientbound play).
197#[derive(Debug, Clone, PartialEq)]
198pub struct SpawnEntityWeather<const V: i32> {
199    /// `entityId`
200    pub entity_id: i32,
201    /// `type`
202    pub r#type: i8,
203    /// `x`
204    pub x: f64,
205    /// `y`
206    pub y: f64,
207    /// `z`
208    pub z: f64,
209}
210#[cfg(feature = "v1_12_2")]
211impl<const V: i32> Decode for SpawnEntityWeather<V> {
212    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
213        Ok({
214            let v1 = r.read_varint()?;
215            let v2 = r.read_i8()?;
216            let v3 = r.read_f64()?;
217            let v4 = r.read_f64()?;
218            let v5 = r.read_f64()?;
219            Self {
220                entity_id: v1,
221                r#type: v2,
222                x: v3,
223                y: v4,
224                z: v5,
225            }
226        })
227    }
228}
229#[cfg(feature = "v1_12_2")]
230impl<const V: i32> Encode for SpawnEntityWeather<V> {
231    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
232        w.put_varint((*self).entity_id);
233        w.put_i8((*self).r#type);
234        w.put_f64((*self).x);
235        w.put_f64((*self).y);
236        w.put_f64((*self).z);
237        Ok(())
238    }
239}
240#[cfg(feature = "v1_12_2")]
241#[cfg(feature = "testgen")]
242impl<const V: i32> Generate for SpawnEntityWeather<V> {
243    fn generate(g: &mut Gen) -> Self {
244        {
245            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
246            let v2 = (g.int_in(-128, 127, &[]) as i8);
247            let v3 = g.f64();
248            let v4 = g.f64();
249            let v5 = g.f64();
250            Self {
251                entity_id: v1,
252                r#type: v2,
253                x: v3,
254                y: v4,
255                z: v5,
256            }
257        }
258    }
259}
260
261#[cfg(feature = "v1_12_2")]
262/// `spawn_entity_living` (clientbound play).
263#[derive(Debug, Clone, PartialEq)]
264pub struct SpawnEntityLiving<const V: i32> {
265    /// `entityId`
266    pub entity_id: i32,
267    /// `entityUUID`
268    pub entity_uuid: Uuid,
269    /// `type`
270    pub r#type: i32,
271    /// `x`
272    pub x: f64,
273    /// `y`
274    pub y: f64,
275    /// `z`
276    pub z: f64,
277    /// `yaw`
278    pub yaw: i8,
279    /// `pitch`
280    pub pitch: i8,
281    /// `headPitch`
282    pub head_pitch: i8,
283    /// `velocity`
284    pub velocity: crate::defs::p47::types::Vec3i16,
285    /// `metadata`
286    pub metadata: Vec<crate::defs::p340::types::EntityMetadataEntry>,
287}
288#[cfg(feature = "v1_12_2")]
289impl<const V: i32> Decode for SpawnEntityLiving<V> {
290    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
291        Ok({
292            let v1 = r.read_varint()?;
293            let v2 = r.read_uuid()?;
294            let v3 = r.read_varint()?;
295            let v4 = r.read_f64()?;
296            let v5 = r.read_f64()?;
297            let v6 = r.read_f64()?;
298            let v7 = r.read_i8()?;
299            let v8 = r.read_i8()?;
300            let v9 = r.read_i8()?;
301            let v10 = <crate::defs::p47::types::Vec3i16 as Decode>::decode(r)?;
302            let v11 = {
303                let mut v12 = Vec::new();
304                loop {
305                    if r.peek_u8()? == 255 {
306                        r.skip(1)?;
307                        break;
308                    }
309                    v12.push({
310                        let v13 = r.read_u8()?;
311                        let v14 = r.read_i8()?;
312                        let v15 = (if (v14 == 0) {
313                            crate::defs::p340::types::EntityMetadataValue::Byte(r.read_i8()?)
314                        } else if (v14 == 1) {
315                            crate::defs::p340::types::EntityMetadataValue::VarInt(r.read_varint()?)
316                        } else if (v14 == 2) {
317                            crate::defs::p340::types::EntityMetadataValue::Float(r.read_f32()?)
318                        } else if (v14 == 3) {
319                            crate::defs::p340::types::EntityMetadataValue::String(r.read_string()?)
320                        } else if (v14 == 4) {
321                            crate::defs::p340::types::EntityMetadataValue::Chat(r.read_string()?)
322                        } else if (v14 == 5) {
323                            crate::defs::p340::types::EntityMetadataValue::Slot(
324                                <crate::types::slot::legacy::Slot as Decode>::decode(r)?,
325                            )
326                        } else if (v14 == 6) {
327                            crate::defs::p340::types::EntityMetadataValue::Boolean(r.read_bool()?)
328                        } else if (v14 == 7) {
329                            crate::defs::p340::types::EntityMetadataValue::Rotation({
330                                let v16 = r.read_f32()?;
331                                let v17 = r.read_f32()?;
332                                let v18 = r.read_f32()?;
333                                crate::defs::p47::types::EntityMetadataValueRotation {
334                                    pitch: v16,
335                                    yaw: v17,
336                                    roll: v18,
337                                }
338                            })
339                        } else if (v14 == 8) {
340                            crate::defs::p340::types::EntityMetadataValue::Position(BlockPos::read(
341                                r,
342                                PositionLayout::Xyz,
343                            )?)
344                        } else if (v14 == 9) {
345                            crate::defs::p340::types::EntityMetadataValue::OptPosition(
346                                if r.read_bool()? {
347                                    Some(BlockPos::read(r, PositionLayout::Xyz)?)
348                                } else {
349                                    None
350                                },
351                            )
352                        } else if (v14 == 10) {
353                            crate::defs::p340::types::EntityMetadataValue::Direction(
354                                r.read_varint()?,
355                            )
356                        } else if (v14 == 11) {
357                            crate::defs::p340::types::EntityMetadataValue::OptUuid(
358                                if r.read_bool()? {
359                                    Some(r.read_uuid()?)
360                                } else {
361                                    None
362                                },
363                            )
364                        } else if (v14 == 12) {
365                            crate::defs::p340::types::EntityMetadataValue::BlockState(
366                                r.read_varint()?,
367                            )
368                        } else if (v14 == 13) {
369                            crate::defs::p340::types::EntityMetadataValue::Nbt(RawNbt::read(r)?)
370                        } else {
371                            crate::defs::p340::types::EntityMetadataValue::Other
372                        });
373                        crate::defs::p340::types::EntityMetadataEntry {
374                            key: v13,
375                            r#type: v14,
376                            value: v15,
377                        }
378                    });
379                }
380                v12
381            };
382            Self {
383                entity_id: v1,
384                entity_uuid: v2,
385                r#type: v3,
386                x: v4,
387                y: v5,
388                z: v6,
389                yaw: v7,
390                pitch: v8,
391                head_pitch: v9,
392                velocity: v10,
393                metadata: v11,
394            }
395        })
396    }
397}
398#[cfg(feature = "v1_12_2")]
399impl<const V: i32> Encode for SpawnEntityLiving<V> {
400    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
401        w.put_varint((*self).entity_id);
402        w.put_uuid(&(*self).entity_uuid);
403        w.put_varint((*self).r#type);
404        w.put_f64((*self).x);
405        w.put_f64((*self).y);
406        w.put_f64((*self).z);
407        w.put_i8((*self).yaw);
408        w.put_i8((*self).pitch);
409        w.put_i8((*self).head_pitch);
410        (*self).velocity.encode(w)?;
411        for v1 in (*self).metadata.iter() {
412            let v2 = w.len();
413            w.put_u8((*v1).key);
414            w.put_i8((*v1).r#type);
415            match &(*v1).value {
416                crate::defs::p340::types::EntityMetadataValue::Byte(v3) => {
417                    if !((*v1).r#type == 0) {
418                        return Err(EncodeError::SwitchMismatch(
419                            "play.clientbound.spawn_entity_living.metadata.value",
420                        ));
421                    }
422                    w.put_i8((*v3));
423                }
424                crate::defs::p340::types::EntityMetadataValue::VarInt(v4) => {
425                    if !((*v1).r#type == 1) {
426                        return Err(EncodeError::SwitchMismatch(
427                            "play.clientbound.spawn_entity_living.metadata.value",
428                        ));
429                    }
430                    w.put_varint((*v4));
431                }
432                crate::defs::p340::types::EntityMetadataValue::Float(v5) => {
433                    if !((*v1).r#type == 2) {
434                        return Err(EncodeError::SwitchMismatch(
435                            "play.clientbound.spawn_entity_living.metadata.value",
436                        ));
437                    }
438                    w.put_f32((*v5));
439                }
440                crate::defs::p340::types::EntityMetadataValue::String(v6) => {
441                    if !((*v1).r#type == 3) {
442                        return Err(EncodeError::SwitchMismatch(
443                            "play.clientbound.spawn_entity_living.metadata.value",
444                        ));
445                    }
446                    w.put_string(&(*v6))?;
447                }
448                crate::defs::p340::types::EntityMetadataValue::Chat(v7) => {
449                    if !((*v1).r#type == 4) {
450                        return Err(EncodeError::SwitchMismatch(
451                            "play.clientbound.spawn_entity_living.metadata.value",
452                        ));
453                    }
454                    w.put_string(&(*v7))?;
455                }
456                crate::defs::p340::types::EntityMetadataValue::Slot(v8) => {
457                    if !((*v1).r#type == 5) {
458                        return Err(EncodeError::SwitchMismatch(
459                            "play.clientbound.spawn_entity_living.metadata.value",
460                        ));
461                    }
462                    (*v8).encode(w)?;
463                }
464                crate::defs::p340::types::EntityMetadataValue::Boolean(v9) => {
465                    if !((*v1).r#type == 6) {
466                        return Err(EncodeError::SwitchMismatch(
467                            "play.clientbound.spawn_entity_living.metadata.value",
468                        ));
469                    }
470                    w.put_bool((*v9));
471                }
472                crate::defs::p340::types::EntityMetadataValue::Rotation(v10) => {
473                    if !((*v1).r#type == 7) {
474                        return Err(EncodeError::SwitchMismatch(
475                            "play.clientbound.spawn_entity_living.metadata.value",
476                        ));
477                    }
478                    w.put_f32((*v10).pitch);
479                    w.put_f32((*v10).yaw);
480                    w.put_f32((*v10).roll);
481                }
482                crate::defs::p340::types::EntityMetadataValue::Position(v11) => {
483                    if !((*v1).r#type == 8) {
484                        return Err(EncodeError::SwitchMismatch(
485                            "play.clientbound.spawn_entity_living.metadata.value",
486                        ));
487                    }
488                    (*v11).write(w, PositionLayout::Xyz)?;
489                }
490                crate::defs::p340::types::EntityMetadataValue::OptPosition(v12) => {
491                    if !((*v1).r#type == 9) {
492                        return Err(EncodeError::SwitchMismatch(
493                            "play.clientbound.spawn_entity_living.metadata.value",
494                        ));
495                    }
496                    match &(*v12) {
497                        Some(v13) => {
498                            w.put_u8(1);
499                            (*v13).write(w, PositionLayout::Xyz)?;
500                        }
501                        None => w.put_u8(0),
502                    }
503                }
504                crate::defs::p340::types::EntityMetadataValue::Direction(v14) => {
505                    if !((*v1).r#type == 10) {
506                        return Err(EncodeError::SwitchMismatch(
507                            "play.clientbound.spawn_entity_living.metadata.value",
508                        ));
509                    }
510                    w.put_varint((*v14));
511                }
512                crate::defs::p340::types::EntityMetadataValue::OptUuid(v15) => {
513                    if !((*v1).r#type == 11) {
514                        return Err(EncodeError::SwitchMismatch(
515                            "play.clientbound.spawn_entity_living.metadata.value",
516                        ));
517                    }
518                    match &(*v15) {
519                        Some(v16) => {
520                            w.put_u8(1);
521                            w.put_uuid(&(*v16));
522                        }
523                        None => w.put_u8(0),
524                    }
525                }
526                crate::defs::p340::types::EntityMetadataValue::BlockState(v17) => {
527                    if !((*v1).r#type == 12) {
528                        return Err(EncodeError::SwitchMismatch(
529                            "play.clientbound.spawn_entity_living.metadata.value",
530                        ));
531                    }
532                    w.put_varint((*v17));
533                }
534                crate::defs::p340::types::EntityMetadataValue::Nbt(v18) => {
535                    if !((*v1).r#type == 13) {
536                        return Err(EncodeError::SwitchMismatch(
537                            "play.clientbound.spawn_entity_living.metadata.value",
538                        ));
539                    }
540                    (*v18).write(w);
541                }
542                crate::defs::p340::types::EntityMetadataValue::Other => {
543                    if !(!(((*v1).r#type == 0)
544                        || ((*v1).r#type == 1)
545                        || ((*v1).r#type == 2)
546                        || ((*v1).r#type == 3)
547                        || ((*v1).r#type == 4)
548                        || ((*v1).r#type == 5)
549                        || ((*v1).r#type == 6)
550                        || ((*v1).r#type == 7)
551                        || ((*v1).r#type == 8)
552                        || ((*v1).r#type == 9)
553                        || ((*v1).r#type == 10)
554                        || ((*v1).r#type == 11)
555                        || ((*v1).r#type == 12)
556                        || ((*v1).r#type == 13)))
557                    {
558                        return Err(EncodeError::SwitchMismatch(
559                            "play.clientbound.spawn_entity_living.metadata.value",
560                        ));
561                    }
562                }
563            }
564            if w.get(v2) == Some(&255) {
565                return Err(EncodeError::OutOfRange(
566                    "play.clientbound.spawn_entity_living.metadata",
567                ));
568            }
569        }
570        w.put_u8(255);
571        Ok(())
572    }
573}
574#[cfg(feature = "v1_12_2")]
575#[cfg(feature = "testgen")]
576impl<const V: i32> Generate for SpawnEntityLiving<V> {
577    fn generate(g: &mut Gen) -> Self {
578        {
579            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
580            let v2 = g.uuid();
581            let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
582            let v4 = g.f64();
583            let v5 = g.f64();
584            let v6 = g.f64();
585            let v7 = (g.int_in(-128, 127, &[]) as i8);
586            let v8 = (g.int_in(-128, 127, &[]) as i8);
587            let v9 = (g.int_in(-128, 127, &[]) as i8);
588            let v10 = <crate::defs::p47::types::Vec3i16 as Generate>::generate(g);
589            let v11 = {
590                let n = g.count();
591                let mut v12 = Vec::with_capacity(n);
592                for _ in 0..n {
593                    v12.push(loop { let v13 = { let v14 = (g.int_in(0, 255, &[]) as u8);let v15 = (g.int_in(-128, 127, &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) as i8);let v16 = (if (v15 == 0) { crate::defs::p340::types::EntityMetadataValue::Byte((g.int_in(-128, 127, &[]) as i8)) } else if (v15 == 1) { crate::defs::p340::types::EntityMetadataValue::VarInt((g.int_in(-2147483648, 2147483647, &[]) as i32)) } else if (v15 == 2) { crate::defs::p340::types::EntityMetadataValue::Float(g.f32()) } else if (v15 == 3) { crate::defs::p340::types::EntityMetadataValue::String(g.string()) } else if (v15 == 4) { crate::defs::p340::types::EntityMetadataValue::Chat(g.string()) } else if (v15 == 5) { crate::defs::p340::types::EntityMetadataValue::Slot(<crate::types::slot::legacy::Slot as Generate>::generate(g)) } else if (v15 == 6) { crate::defs::p340::types::EntityMetadataValue::Boolean(g.bool()) } else if (v15 == 7) { crate::defs::p340::types::EntityMetadataValue::Rotation({ let v17 = g.f32();let v18 = g.f32();let v19 = g.f32(); crate::defs::p47::types::EntityMetadataValueRotation { pitch: v17, yaw: v18, roll: v19 } }) } else if (v15 == 8) { crate::defs::p340::types::EntityMetadataValue::Position(g.position()) } else if (v15 == 9) { crate::defs::p340::types::EntityMetadataValue::OptPosition(if g.bool() { Some(g.position()) } else { None }) } else if (v15 == 10) { crate::defs::p340::types::EntityMetadataValue::Direction((g.int_in(-2147483648, 2147483647, &[]) as i32)) } else if (v15 == 11) { crate::defs::p340::types::EntityMetadataValue::OptUuid(if g.bool() { Some(g.uuid()) } else { None }) } else if (v15 == 12) { crate::defs::p340::types::EntityMetadataValue::BlockState((g.int_in(-2147483648, 2147483647, &[]) as i32)) } else if (v15 == 13) { crate::defs::p340::types::EntityMetadataValue::Nbt(g.nbt()) } else { crate::defs::p340::types::EntityMetadataValue::Other }); crate::defs::p340::types::EntityMetadataEntry { key: v14, r#type: v15, value: v16 } }; if crate::testgen::first_byte_ok(|w: &mut BytesMut| -> EncodeResult { w.put_u8(v13.key);w.put_i8(v13.r#type);match &v13.value { crate::defs::p340::types::EntityMetadataValue::Byte(v20) => { if !((v13.r#type == 0)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_i8((*v20)); }crate::defs::p340::types::EntityMetadataValue::VarInt(v21) => { if !((v13.r#type == 1)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_varint((*v21)); }crate::defs::p340::types::EntityMetadataValue::Float(v22) => { if !((v13.r#type == 2)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_f32((*v22)); }crate::defs::p340::types::EntityMetadataValue::String(v23) => { if !((v13.r#type == 3)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_string(&(*v23))?; }crate::defs::p340::types::EntityMetadataValue::Chat(v24) => { if !((v13.r#type == 4)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_string(&(*v24))?; }crate::defs::p340::types::EntityMetadataValue::Slot(v25) => { if !((v13.r#type == 5)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } (*v25).encode(w)?; }crate::defs::p340::types::EntityMetadataValue::Boolean(v26) => { if !((v13.r#type == 6)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_bool((*v26)); }crate::defs::p340::types::EntityMetadataValue::Rotation(v27) => { if !((v13.r#type == 7)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_f32((*v27).pitch);w.put_f32((*v27).yaw);w.put_f32((*v27).roll); }crate::defs::p340::types::EntityMetadataValue::Position(v28) => { if !((v13.r#type == 8)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } (*v28).write(w, PositionLayout::Xyz)?; }crate::defs::p340::types::EntityMetadataValue::OptPosition(v29) => { if !((v13.r#type == 9)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } match &(*v29) { Some(v30) => { w.put_u8(1); (*v30).write(w, PositionLayout::Xyz)?; } None => w.put_u8(0), } }crate::defs::p340::types::EntityMetadataValue::Direction(v31) => { if !((v13.r#type == 10)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_varint((*v31)); }crate::defs::p340::types::EntityMetadataValue::OptUuid(v32) => { if !((v13.r#type == 11)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } match &(*v32) { Some(v33) => { w.put_u8(1); w.put_uuid(&(*v33)); } None => w.put_u8(0), } }crate::defs::p340::types::EntityMetadataValue::BlockState(v34) => { if !((v13.r#type == 12)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_varint((*v34)); }crate::defs::p340::types::EntityMetadataValue::Nbt(v35) => { if !((v13.r#type == 13)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } (*v35).write(w); }crate::defs::p340::types::EntityMetadataValue::Other => { if !(!((v13.r#type == 0) || (v13.r#type == 1) || (v13.r#type == 2) || (v13.r#type == 3) || (v13.r#type == 4) || (v13.r#type == 5) || (v13.r#type == 6) || (v13.r#type == 7) || (v13.r#type == 8) || (v13.r#type == 9) || (v13.r#type == 10) || (v13.r#type == 11) || (v13.r#type == 12) || (v13.r#type == 13))) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } } } Ok(()) }, |b| b != 255) { break v13; } });
594                }
595                v12
596            };
597            Self {
598                entity_id: v1,
599                entity_uuid: v2,
600                r#type: v3,
601                x: v4,
602                y: v5,
603                z: v6,
604                yaw: v7,
605                pitch: v8,
606                head_pitch: v9,
607                velocity: v10,
608                metadata: v11,
609            }
610        }
611    }
612}
613
614#[cfg(feature = "v1_12_2")]
615/// `spawn_entity_painting` (clientbound play).
616#[derive(Debug, Clone, PartialEq)]
617pub struct SpawnEntityPainting<const V: i32> {
618    /// `entityId`
619    pub entity_id: i32,
620    /// `entityUUID`
621    pub entity_uuid: Uuid,
622    /// `title`
623    pub title: ByteString,
624    /// `location`
625    pub location: BlockPos,
626    /// `direction`
627    pub direction: u8,
628}
629#[cfg(feature = "v1_12_2")]
630impl<const V: i32> Decode for SpawnEntityPainting<V> {
631    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
632        Ok({
633            let v1 = r.read_varint()?;
634            let v2 = r.read_uuid()?;
635            let v3 = r.read_string()?;
636            let v4 = BlockPos::read(r, PositionLayout::Xyz)?;
637            let v5 = r.read_u8()?;
638            Self {
639                entity_id: v1,
640                entity_uuid: v2,
641                title: v3,
642                location: v4,
643                direction: v5,
644            }
645        })
646    }
647}
648#[cfg(feature = "v1_12_2")]
649impl<const V: i32> Encode for SpawnEntityPainting<V> {
650    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
651        w.put_varint((*self).entity_id);
652        w.put_uuid(&(*self).entity_uuid);
653        w.put_string(&(*self).title)?;
654        (*self).location.write(w, PositionLayout::Xyz)?;
655        w.put_u8((*self).direction);
656        Ok(())
657    }
658}
659#[cfg(feature = "v1_12_2")]
660#[cfg(feature = "testgen")]
661impl<const V: i32> Generate for SpawnEntityPainting<V> {
662    fn generate(g: &mut Gen) -> Self {
663        {
664            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
665            let v2 = g.uuid();
666            let v3 = g.string();
667            let v4 = g.position();
668            let v5 = (g.int_in(0, 255, &[]) as u8);
669            Self {
670                entity_id: v1,
671                entity_uuid: v2,
672                title: v3,
673                location: v4,
674                direction: v5,
675            }
676        }
677    }
678}
679
680#[cfg(feature = "v1_12_2")]
681/// `named_entity_spawn` (clientbound play).
682#[derive(Debug, Clone, PartialEq)]
683pub struct NamedEntitySpawn<const V: i32> {
684    /// `entityId`
685    pub entity_id: i32,
686    /// `playerUUID`
687    pub player_uuid: Uuid,
688    /// `x`
689    pub x: f64,
690    /// `y`
691    pub y: f64,
692    /// `z`
693    pub z: f64,
694    /// `yaw`
695    pub yaw: i8,
696    /// `pitch`
697    pub pitch: i8,
698    /// `metadata`
699    pub metadata: Vec<crate::defs::p340::types::EntityMetadataEntry>,
700}
701#[cfg(feature = "v1_12_2")]
702impl<const V: i32> Decode for NamedEntitySpawn<V> {
703    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
704        Ok({
705            let v1 = r.read_varint()?;
706            let v2 = r.read_uuid()?;
707            let v3 = r.read_f64()?;
708            let v4 = r.read_f64()?;
709            let v5 = r.read_f64()?;
710            let v6 = r.read_i8()?;
711            let v7 = r.read_i8()?;
712            let v8 = {
713                let mut v9 = Vec::new();
714                loop {
715                    if r.peek_u8()? == 255 {
716                        r.skip(1)?;
717                        break;
718                    }
719                    v9.push({
720                        let v10 = r.read_u8()?;
721                        let v11 = r.read_i8()?;
722                        let v12 = (if (v11 == 0) {
723                            crate::defs::p340::types::EntityMetadataValue::Byte(r.read_i8()?)
724                        } else if (v11 == 1) {
725                            crate::defs::p340::types::EntityMetadataValue::VarInt(r.read_varint()?)
726                        } else if (v11 == 2) {
727                            crate::defs::p340::types::EntityMetadataValue::Float(r.read_f32()?)
728                        } else if (v11 == 3) {
729                            crate::defs::p340::types::EntityMetadataValue::String(r.read_string()?)
730                        } else if (v11 == 4) {
731                            crate::defs::p340::types::EntityMetadataValue::Chat(r.read_string()?)
732                        } else if (v11 == 5) {
733                            crate::defs::p340::types::EntityMetadataValue::Slot(
734                                <crate::types::slot::legacy::Slot as Decode>::decode(r)?,
735                            )
736                        } else if (v11 == 6) {
737                            crate::defs::p340::types::EntityMetadataValue::Boolean(r.read_bool()?)
738                        } else if (v11 == 7) {
739                            crate::defs::p340::types::EntityMetadataValue::Rotation({
740                                let v13 = r.read_f32()?;
741                                let v14 = r.read_f32()?;
742                                let v15 = r.read_f32()?;
743                                crate::defs::p47::types::EntityMetadataValueRotation {
744                                    pitch: v13,
745                                    yaw: v14,
746                                    roll: v15,
747                                }
748                            })
749                        } else if (v11 == 8) {
750                            crate::defs::p340::types::EntityMetadataValue::Position(BlockPos::read(
751                                r,
752                                PositionLayout::Xyz,
753                            )?)
754                        } else if (v11 == 9) {
755                            crate::defs::p340::types::EntityMetadataValue::OptPosition(
756                                if r.read_bool()? {
757                                    Some(BlockPos::read(r, PositionLayout::Xyz)?)
758                                } else {
759                                    None
760                                },
761                            )
762                        } else if (v11 == 10) {
763                            crate::defs::p340::types::EntityMetadataValue::Direction(
764                                r.read_varint()?,
765                            )
766                        } else if (v11 == 11) {
767                            crate::defs::p340::types::EntityMetadataValue::OptUuid(
768                                if r.read_bool()? {
769                                    Some(r.read_uuid()?)
770                                } else {
771                                    None
772                                },
773                            )
774                        } else if (v11 == 12) {
775                            crate::defs::p340::types::EntityMetadataValue::BlockState(
776                                r.read_varint()?,
777                            )
778                        } else if (v11 == 13) {
779                            crate::defs::p340::types::EntityMetadataValue::Nbt(RawNbt::read(r)?)
780                        } else {
781                            crate::defs::p340::types::EntityMetadataValue::Other
782                        });
783                        crate::defs::p340::types::EntityMetadataEntry {
784                            key: v10,
785                            r#type: v11,
786                            value: v12,
787                        }
788                    });
789                }
790                v9
791            };
792            Self {
793                entity_id: v1,
794                player_uuid: v2,
795                x: v3,
796                y: v4,
797                z: v5,
798                yaw: v6,
799                pitch: v7,
800                metadata: v8,
801            }
802        })
803    }
804}
805#[cfg(feature = "v1_12_2")]
806impl<const V: i32> Encode for NamedEntitySpawn<V> {
807    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
808        w.put_varint((*self).entity_id);
809        w.put_uuid(&(*self).player_uuid);
810        w.put_f64((*self).x);
811        w.put_f64((*self).y);
812        w.put_f64((*self).z);
813        w.put_i8((*self).yaw);
814        w.put_i8((*self).pitch);
815        for v1 in (*self).metadata.iter() {
816            let v2 = w.len();
817            w.put_u8((*v1).key);
818            w.put_i8((*v1).r#type);
819            match &(*v1).value {
820                crate::defs::p340::types::EntityMetadataValue::Byte(v3) => {
821                    if !((*v1).r#type == 0) {
822                        return Err(EncodeError::SwitchMismatch(
823                            "play.clientbound.named_entity_spawn.metadata.value",
824                        ));
825                    }
826                    w.put_i8((*v3));
827                }
828                crate::defs::p340::types::EntityMetadataValue::VarInt(v4) => {
829                    if !((*v1).r#type == 1) {
830                        return Err(EncodeError::SwitchMismatch(
831                            "play.clientbound.named_entity_spawn.metadata.value",
832                        ));
833                    }
834                    w.put_varint((*v4));
835                }
836                crate::defs::p340::types::EntityMetadataValue::Float(v5) => {
837                    if !((*v1).r#type == 2) {
838                        return Err(EncodeError::SwitchMismatch(
839                            "play.clientbound.named_entity_spawn.metadata.value",
840                        ));
841                    }
842                    w.put_f32((*v5));
843                }
844                crate::defs::p340::types::EntityMetadataValue::String(v6) => {
845                    if !((*v1).r#type == 3) {
846                        return Err(EncodeError::SwitchMismatch(
847                            "play.clientbound.named_entity_spawn.metadata.value",
848                        ));
849                    }
850                    w.put_string(&(*v6))?;
851                }
852                crate::defs::p340::types::EntityMetadataValue::Chat(v7) => {
853                    if !((*v1).r#type == 4) {
854                        return Err(EncodeError::SwitchMismatch(
855                            "play.clientbound.named_entity_spawn.metadata.value",
856                        ));
857                    }
858                    w.put_string(&(*v7))?;
859                }
860                crate::defs::p340::types::EntityMetadataValue::Slot(v8) => {
861                    if !((*v1).r#type == 5) {
862                        return Err(EncodeError::SwitchMismatch(
863                            "play.clientbound.named_entity_spawn.metadata.value",
864                        ));
865                    }
866                    (*v8).encode(w)?;
867                }
868                crate::defs::p340::types::EntityMetadataValue::Boolean(v9) => {
869                    if !((*v1).r#type == 6) {
870                        return Err(EncodeError::SwitchMismatch(
871                            "play.clientbound.named_entity_spawn.metadata.value",
872                        ));
873                    }
874                    w.put_bool((*v9));
875                }
876                crate::defs::p340::types::EntityMetadataValue::Rotation(v10) => {
877                    if !((*v1).r#type == 7) {
878                        return Err(EncodeError::SwitchMismatch(
879                            "play.clientbound.named_entity_spawn.metadata.value",
880                        ));
881                    }
882                    w.put_f32((*v10).pitch);
883                    w.put_f32((*v10).yaw);
884                    w.put_f32((*v10).roll);
885                }
886                crate::defs::p340::types::EntityMetadataValue::Position(v11) => {
887                    if !((*v1).r#type == 8) {
888                        return Err(EncodeError::SwitchMismatch(
889                            "play.clientbound.named_entity_spawn.metadata.value",
890                        ));
891                    }
892                    (*v11).write(w, PositionLayout::Xyz)?;
893                }
894                crate::defs::p340::types::EntityMetadataValue::OptPosition(v12) => {
895                    if !((*v1).r#type == 9) {
896                        return Err(EncodeError::SwitchMismatch(
897                            "play.clientbound.named_entity_spawn.metadata.value",
898                        ));
899                    }
900                    match &(*v12) {
901                        Some(v13) => {
902                            w.put_u8(1);
903                            (*v13).write(w, PositionLayout::Xyz)?;
904                        }
905                        None => w.put_u8(0),
906                    }
907                }
908                crate::defs::p340::types::EntityMetadataValue::Direction(v14) => {
909                    if !((*v1).r#type == 10) {
910                        return Err(EncodeError::SwitchMismatch(
911                            "play.clientbound.named_entity_spawn.metadata.value",
912                        ));
913                    }
914                    w.put_varint((*v14));
915                }
916                crate::defs::p340::types::EntityMetadataValue::OptUuid(v15) => {
917                    if !((*v1).r#type == 11) {
918                        return Err(EncodeError::SwitchMismatch(
919                            "play.clientbound.named_entity_spawn.metadata.value",
920                        ));
921                    }
922                    match &(*v15) {
923                        Some(v16) => {
924                            w.put_u8(1);
925                            w.put_uuid(&(*v16));
926                        }
927                        None => w.put_u8(0),
928                    }
929                }
930                crate::defs::p340::types::EntityMetadataValue::BlockState(v17) => {
931                    if !((*v1).r#type == 12) {
932                        return Err(EncodeError::SwitchMismatch(
933                            "play.clientbound.named_entity_spawn.metadata.value",
934                        ));
935                    }
936                    w.put_varint((*v17));
937                }
938                crate::defs::p340::types::EntityMetadataValue::Nbt(v18) => {
939                    if !((*v1).r#type == 13) {
940                        return Err(EncodeError::SwitchMismatch(
941                            "play.clientbound.named_entity_spawn.metadata.value",
942                        ));
943                    }
944                    (*v18).write(w);
945                }
946                crate::defs::p340::types::EntityMetadataValue::Other => {
947                    if !(!(((*v1).r#type == 0)
948                        || ((*v1).r#type == 1)
949                        || ((*v1).r#type == 2)
950                        || ((*v1).r#type == 3)
951                        || ((*v1).r#type == 4)
952                        || ((*v1).r#type == 5)
953                        || ((*v1).r#type == 6)
954                        || ((*v1).r#type == 7)
955                        || ((*v1).r#type == 8)
956                        || ((*v1).r#type == 9)
957                        || ((*v1).r#type == 10)
958                        || ((*v1).r#type == 11)
959                        || ((*v1).r#type == 12)
960                        || ((*v1).r#type == 13)))
961                    {
962                        return Err(EncodeError::SwitchMismatch(
963                            "play.clientbound.named_entity_spawn.metadata.value",
964                        ));
965                    }
966                }
967            }
968            if w.get(v2) == Some(&255) {
969                return Err(EncodeError::OutOfRange(
970                    "play.clientbound.named_entity_spawn.metadata",
971                ));
972            }
973        }
974        w.put_u8(255);
975        Ok(())
976    }
977}
978#[cfg(feature = "v1_12_2")]
979#[cfg(feature = "testgen")]
980impl<const V: i32> Generate for NamedEntitySpawn<V> {
981    fn generate(g: &mut Gen) -> Self {
982        {
983            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
984            let v2 = g.uuid();
985            let v3 = g.f64();
986            let v4 = g.f64();
987            let v5 = g.f64();
988            let v6 = (g.int_in(-128, 127, &[]) as i8);
989            let v7 = (g.int_in(-128, 127, &[]) as i8);
990            let v8 = {
991                let n = g.count();
992                let mut v9 = Vec::with_capacity(n);
993                for _ in 0..n {
994                    v9.push(loop { let v10 = { let v11 = (g.int_in(0, 255, &[]) as u8);let v12 = (g.int_in(-128, 127, &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) as i8);let v13 = (if (v12 == 0) { crate::defs::p340::types::EntityMetadataValue::Byte((g.int_in(-128, 127, &[]) as i8)) } else if (v12 == 1) { crate::defs::p340::types::EntityMetadataValue::VarInt((g.int_in(-2147483648, 2147483647, &[]) as i32)) } else if (v12 == 2) { crate::defs::p340::types::EntityMetadataValue::Float(g.f32()) } else if (v12 == 3) { crate::defs::p340::types::EntityMetadataValue::String(g.string()) } else if (v12 == 4) { crate::defs::p340::types::EntityMetadataValue::Chat(g.string()) } else if (v12 == 5) { crate::defs::p340::types::EntityMetadataValue::Slot(<crate::types::slot::legacy::Slot as Generate>::generate(g)) } else if (v12 == 6) { crate::defs::p340::types::EntityMetadataValue::Boolean(g.bool()) } else if (v12 == 7) { crate::defs::p340::types::EntityMetadataValue::Rotation({ let v14 = g.f32();let v15 = g.f32();let v16 = g.f32(); crate::defs::p47::types::EntityMetadataValueRotation { pitch: v14, yaw: v15, roll: v16 } }) } else if (v12 == 8) { crate::defs::p340::types::EntityMetadataValue::Position(g.position()) } else if (v12 == 9) { crate::defs::p340::types::EntityMetadataValue::OptPosition(if g.bool() { Some(g.position()) } else { None }) } else if (v12 == 10) { crate::defs::p340::types::EntityMetadataValue::Direction((g.int_in(-2147483648, 2147483647, &[]) as i32)) } else if (v12 == 11) { crate::defs::p340::types::EntityMetadataValue::OptUuid(if g.bool() { Some(g.uuid()) } else { None }) } else if (v12 == 12) { crate::defs::p340::types::EntityMetadataValue::BlockState((g.int_in(-2147483648, 2147483647, &[]) as i32)) } else if (v12 == 13) { crate::defs::p340::types::EntityMetadataValue::Nbt(g.nbt()) } else { crate::defs::p340::types::EntityMetadataValue::Other }); crate::defs::p340::types::EntityMetadataEntry { key: v11, r#type: v12, value: v13 } }; if crate::testgen::first_byte_ok(|w: &mut BytesMut| -> EncodeResult { w.put_u8(v10.key);w.put_i8(v10.r#type);match &v10.value { crate::defs::p340::types::EntityMetadataValue::Byte(v17) => { if !((v10.r#type == 0)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_i8((*v17)); }crate::defs::p340::types::EntityMetadataValue::VarInt(v18) => { if !((v10.r#type == 1)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_varint((*v18)); }crate::defs::p340::types::EntityMetadataValue::Float(v19) => { if !((v10.r#type == 2)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_f32((*v19)); }crate::defs::p340::types::EntityMetadataValue::String(v20) => { if !((v10.r#type == 3)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_string(&(*v20))?; }crate::defs::p340::types::EntityMetadataValue::Chat(v21) => { if !((v10.r#type == 4)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_string(&(*v21))?; }crate::defs::p340::types::EntityMetadataValue::Slot(v22) => { if !((v10.r#type == 5)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } (*v22).encode(w)?; }crate::defs::p340::types::EntityMetadataValue::Boolean(v23) => { if !((v10.r#type == 6)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_bool((*v23)); }crate::defs::p340::types::EntityMetadataValue::Rotation(v24) => { if !((v10.r#type == 7)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_f32((*v24).pitch);w.put_f32((*v24).yaw);w.put_f32((*v24).roll); }crate::defs::p340::types::EntityMetadataValue::Position(v25) => { if !((v10.r#type == 8)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } (*v25).write(w, PositionLayout::Xyz)?; }crate::defs::p340::types::EntityMetadataValue::OptPosition(v26) => { if !((v10.r#type == 9)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } match &(*v26) { Some(v27) => { w.put_u8(1); (*v27).write(w, PositionLayout::Xyz)?; } None => w.put_u8(0), } }crate::defs::p340::types::EntityMetadataValue::Direction(v28) => { if !((v10.r#type == 10)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_varint((*v28)); }crate::defs::p340::types::EntityMetadataValue::OptUuid(v29) => { if !((v10.r#type == 11)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } match &(*v29) { Some(v30) => { w.put_u8(1); w.put_uuid(&(*v30)); } None => w.put_u8(0), } }crate::defs::p340::types::EntityMetadataValue::BlockState(v31) => { if !((v10.r#type == 12)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_varint((*v31)); }crate::defs::p340::types::EntityMetadataValue::Nbt(v32) => { if !((v10.r#type == 13)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } (*v32).write(w); }crate::defs::p340::types::EntityMetadataValue::Other => { if !(!((v10.r#type == 0) || (v10.r#type == 1) || (v10.r#type == 2) || (v10.r#type == 3) || (v10.r#type == 4) || (v10.r#type == 5) || (v10.r#type == 6) || (v10.r#type == 7) || (v10.r#type == 8) || (v10.r#type == 9) || (v10.r#type == 10) || (v10.r#type == 11) || (v10.r#type == 12) || (v10.r#type == 13))) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } } } Ok(()) }, |b| b != 255) { break v10; } });
995                }
996                v9
997            };
998            Self {
999                entity_id: v1,
1000                player_uuid: v2,
1001                x: v3,
1002                y: v4,
1003                z: v5,
1004                yaw: v6,
1005                pitch: v7,
1006                metadata: v8,
1007            }
1008        }
1009    }
1010}
1011
1012#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1013/// `boss_bar` (clientbound play).
1014#[derive(Debug, Clone, PartialEq)]
1015pub struct BossBar<const V: i32> {
1016    /// `entityUUID`
1017    pub entity_uuid: Uuid,
1018    /// `action`
1019    pub action: i32,
1020    /// `title`
1021    pub title: Option<ByteString>,
1022    /// `health`
1023    pub health: Option<f32>,
1024    /// `color`
1025    pub color: Option<i32>,
1026    /// `dividers`
1027    pub dividers: Option<i32>,
1028    /// `flags`
1029    pub flags: Option<u8>,
1030}
1031#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1032impl<const V: i32> Decode for BossBar<V> {
1033    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1034        Ok({
1035            let v1 = r.read_uuid()?;
1036            let v2 = r.read_varint()?;
1037            let v3 = if (v2 == 0) || (v2 == 3) {
1038                Some(r.read_string()?)
1039            } else {
1040                None
1041            };
1042            let v4 = if (v2 == 0) || (v2 == 2) {
1043                Some(r.read_f32()?)
1044            } else {
1045                None
1046            };
1047            let v5 = if (v2 == 0) || (v2 == 4) {
1048                Some(r.read_varint()?)
1049            } else {
1050                None
1051            };
1052            let v6 = if (v2 == 0) || (v2 == 4) {
1053                Some(r.read_varint()?)
1054            } else {
1055                None
1056            };
1057            let v7 = if (v2 == 0) || (v2 == 5) {
1058                Some(r.read_u8()?)
1059            } else {
1060                None
1061            };
1062            Self {
1063                entity_uuid: v1,
1064                action: v2,
1065                title: v3,
1066                health: v4,
1067                color: v5,
1068                dividers: v6,
1069                flags: v7,
1070            }
1071        })
1072    }
1073}
1074#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1075impl<const V: i32> Encode for BossBar<V> {
1076    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1077        w.put_uuid(&(*self).entity_uuid);
1078        w.put_varint((*self).action);
1079        match (
1080            &(*self).title,
1081            ((*self).action == 0) || ((*self).action == 3),
1082        ) {
1083            (Some(v1), true) => {
1084                w.put_string(&(*v1))?;
1085            }
1086            (None, false) => {}
1087            _ => {
1088                return Err(EncodeError::SwitchMismatch(
1089                    "play.clientbound.boss_bar.title",
1090                ));
1091            }
1092        }
1093        match (
1094            &(*self).health,
1095            ((*self).action == 0) || ((*self).action == 2),
1096        ) {
1097            (Some(v2), true) => {
1098                w.put_f32((*v2));
1099            }
1100            (None, false) => {}
1101            _ => {
1102                return Err(EncodeError::SwitchMismatch(
1103                    "play.clientbound.boss_bar.health",
1104                ));
1105            }
1106        }
1107        match (
1108            &(*self).color,
1109            ((*self).action == 0) || ((*self).action == 4),
1110        ) {
1111            (Some(v3), true) => {
1112                w.put_varint((*v3));
1113            }
1114            (None, false) => {}
1115            _ => {
1116                return Err(EncodeError::SwitchMismatch(
1117                    "play.clientbound.boss_bar.color",
1118                ));
1119            }
1120        }
1121        match (
1122            &(*self).dividers,
1123            ((*self).action == 0) || ((*self).action == 4),
1124        ) {
1125            (Some(v4), true) => {
1126                w.put_varint((*v4));
1127            }
1128            (None, false) => {}
1129            _ => {
1130                return Err(EncodeError::SwitchMismatch(
1131                    "play.clientbound.boss_bar.dividers",
1132                ));
1133            }
1134        }
1135        match (
1136            &(*self).flags,
1137            ((*self).action == 0) || ((*self).action == 5),
1138        ) {
1139            (Some(v5), true) => {
1140                w.put_u8((*v5));
1141            }
1142            (None, false) => {}
1143            _ => {
1144                return Err(EncodeError::SwitchMismatch(
1145                    "play.clientbound.boss_bar.flags",
1146                ));
1147            }
1148        }
1149        Ok(())
1150    }
1151}
1152#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1153#[cfg(feature = "testgen")]
1154impl<const V: i32> Generate for BossBar<V> {
1155    fn generate(g: &mut Gen) -> Self {
1156        {
1157            let v1 = g.uuid();
1158            let v2 = (g.int_in(-2147483648, 2147483647, &[0, 3, 0, 2, 0, 4, 0, 4, 0, 5]) as i32);
1159            let v3 = if (v2 == 0) || (v2 == 3) {
1160                Some(g.string())
1161            } else {
1162                None
1163            };
1164            let v4 = if (v2 == 0) || (v2 == 2) {
1165                Some(g.f32())
1166            } else {
1167                None
1168            };
1169            let v5 = if (v2 == 0) || (v2 == 4) {
1170                Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
1171            } else {
1172                None
1173            };
1174            let v6 = if (v2 == 0) || (v2 == 4) {
1175                Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
1176            } else {
1177                None
1178            };
1179            let v7 = if (v2 == 0) || (v2 == 5) {
1180                Some((g.int_in(0, 255, &[]) as u8))
1181            } else {
1182                None
1183            };
1184            Self {
1185                entity_uuid: v1,
1186                action: v2,
1187                title: v3,
1188                health: v4,
1189                color: v5,
1190                dividers: v6,
1191                flags: v7,
1192            }
1193        }
1194    }
1195}
1196
1197#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1198/// `set_cooldown` (clientbound play).
1199#[derive(Debug, Clone, PartialEq)]
1200pub struct SetCooldown<const V: i32> {
1201    /// `itemID`
1202    pub item_id: i32,
1203    /// `cooldownTicks`
1204    pub cooldown_ticks: i32,
1205}
1206#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1207impl<const V: i32> Decode for SetCooldown<V> {
1208    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1209        Ok({
1210            let v1 = r.read_varint()?;
1211            let v2 = r.read_varint()?;
1212            Self {
1213                item_id: v1,
1214                cooldown_ticks: v2,
1215            }
1216        })
1217    }
1218}
1219#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1220impl<const V: i32> Encode for SetCooldown<V> {
1221    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1222        w.put_varint((*self).item_id);
1223        w.put_varint((*self).cooldown_ticks);
1224        Ok(())
1225    }
1226}
1227#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1228#[cfg(feature = "testgen")]
1229impl<const V: i32> Generate for SetCooldown<V> {
1230    fn generate(g: &mut Gen) -> Self {
1231        {
1232            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1233            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1234            Self {
1235                item_id: v1,
1236                cooldown_ticks: v2,
1237            }
1238        }
1239    }
1240}
1241
1242#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1243/// `named_sound_effect` (clientbound play).
1244#[derive(Debug, Clone, PartialEq)]
1245pub struct NamedSoundEffect<const V: i32> {
1246    /// `soundName`
1247    pub sound_name: ByteString,
1248    /// `soundCategory`
1249    pub sound_category: i32,
1250    /// `x`
1251    pub x: i32,
1252    /// `y`
1253    pub y: i32,
1254    /// `z`
1255    pub z: i32,
1256    /// `volume`
1257    pub volume: f32,
1258    /// `pitch`
1259    pub pitch: f32,
1260}
1261#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1262impl<const V: i32> Decode for NamedSoundEffect<V> {
1263    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1264        Ok({
1265            let v1 = r.read_string()?;
1266            let v2 = r.read_varint()?;
1267            let v3 = r.read_i32()?;
1268            let v4 = r.read_i32()?;
1269            let v5 = r.read_i32()?;
1270            let v6 = r.read_f32()?;
1271            let v7 = r.read_f32()?;
1272            Self {
1273                sound_name: v1,
1274                sound_category: v2,
1275                x: v3,
1276                y: v4,
1277                z: v5,
1278                volume: v6,
1279                pitch: v7,
1280            }
1281        })
1282    }
1283}
1284#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1285impl<const V: i32> Encode for NamedSoundEffect<V> {
1286    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1287        w.put_string(&(*self).sound_name)?;
1288        w.put_varint((*self).sound_category);
1289        w.put_i32((*self).x);
1290        w.put_i32((*self).y);
1291        w.put_i32((*self).z);
1292        w.put_f32((*self).volume);
1293        w.put_f32((*self).pitch);
1294        Ok(())
1295    }
1296}
1297#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1298#[cfg(feature = "testgen")]
1299impl<const V: i32> Generate for NamedSoundEffect<V> {
1300    fn generate(g: &mut Gen) -> Self {
1301        {
1302            let v1 = g.string();
1303            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1304            let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1305            let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1306            let v5 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1307            let v6 = g.f32();
1308            let v7 = g.f32();
1309            Self {
1310                sound_name: v1,
1311                sound_category: v2,
1312                x: v3,
1313                y: v4,
1314                z: v5,
1315                volume: v6,
1316                pitch: v7,
1317            }
1318        }
1319    }
1320}
1321
1322#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1323/// `unload_chunk` (clientbound play).
1324#[derive(Debug, Clone, PartialEq)]
1325pub struct UnloadChunk<const V: i32> {
1326    /// `chunkX`
1327    pub chunk_x: i32,
1328    /// `chunkZ`
1329    pub chunk_z: i32,
1330}
1331#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1332impl<const V: i32> Decode for UnloadChunk<V> {
1333    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1334        Ok({
1335            let v1 = r.read_i32()?;
1336            let v2 = r.read_i32()?;
1337            Self {
1338                chunk_x: v1,
1339                chunk_z: v2,
1340            }
1341        })
1342    }
1343}
1344#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1345impl<const V: i32> Encode for UnloadChunk<V> {
1346    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1347        w.put_i32((*self).chunk_x);
1348        w.put_i32((*self).chunk_z);
1349        Ok(())
1350    }
1351}
1352#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1353#[cfg(feature = "testgen")]
1354impl<const V: i32> Generate for UnloadChunk<V> {
1355    fn generate(g: &mut Gen) -> Self {
1356        {
1357            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1358            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1359            Self {
1360                chunk_x: v1,
1361                chunk_z: v2,
1362            }
1363        }
1364    }
1365}
1366
1367#[cfg(any(
1368    feature = "v1_12_2",
1369    feature = "v1_16_5",
1370    feature = "v26_1",
1371    feature = "v26_2"
1372))]
1373/// `keep_alive` (clientbound play).
1374#[derive(Debug, Clone, PartialEq)]
1375pub struct KeepAlive<const V: i32> {
1376    /// `keepAliveId`
1377    pub keep_alive_id: i64,
1378}
1379#[cfg(any(
1380    feature = "v1_12_2",
1381    feature = "v1_16_5",
1382    feature = "v26_1",
1383    feature = "v26_2"
1384))]
1385impl<const V: i32> Decode for KeepAlive<V> {
1386    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1387        Ok({
1388            let v1 = r.read_i64()?;
1389            Self { keep_alive_id: v1 }
1390        })
1391    }
1392}
1393#[cfg(any(
1394    feature = "v1_12_2",
1395    feature = "v1_16_5",
1396    feature = "v26_1",
1397    feature = "v26_2"
1398))]
1399impl<const V: i32> Encode for KeepAlive<V> {
1400    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1401        w.put_i64((*self).keep_alive_id);
1402        Ok(())
1403    }
1404}
1405#[cfg(any(
1406    feature = "v1_12_2",
1407    feature = "v1_16_5",
1408    feature = "v26_1",
1409    feature = "v26_2"
1410))]
1411#[cfg(feature = "testgen")]
1412impl<const V: i32> Generate for KeepAlive<V> {
1413    fn generate(g: &mut Gen) -> Self {
1414        {
1415            let v1 = g.i64();
1416            Self { keep_alive_id: v1 }
1417        }
1418    }
1419}
1420
1421#[cfg(feature = "v1_12_2")]
1422/// `map_chunk` (clientbound play).
1423#[derive(Debug, Clone, PartialEq)]
1424pub struct MapChunk<const V: i32> {
1425    /// `x`
1426    pub x: i32,
1427    /// `z`
1428    pub z: i32,
1429    /// `groundUp`
1430    pub ground_up: bool,
1431    /// `bitMap`
1432    pub bit_map: i32,
1433    /// `chunkData`
1434    pub chunk_data: Bytes,
1435    /// `blockEntities`
1436    pub block_entities: Vec<RawNbt>,
1437}
1438#[cfg(feature = "v1_12_2")]
1439impl<const V: i32> Decode for MapChunk<V> {
1440    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1441        Ok({
1442            let v1 = r.read_i32()?;
1443            let v2 = r.read_i32()?;
1444            let v3 = r.read_bool()?;
1445            let v4 = r.read_varint()?;
1446            let v5 = r.read_byte_array()?;
1447            let v6 = {
1448                let v7 = {
1449                    let c = r.read_varint()?;
1450                    r.check_count(i64::from(c), 1)?
1451                };
1452                let mut v8 = Vec::with_capacity(v7.min(crate::codec::PREALLOC_LIMIT));
1453                for _ in 0..v7 {
1454                    v8.push(RawNbt::read(r)?);
1455                }
1456                v8
1457            };
1458            Self {
1459                x: v1,
1460                z: v2,
1461                ground_up: v3,
1462                bit_map: v4,
1463                chunk_data: v5,
1464                block_entities: v6,
1465            }
1466        })
1467    }
1468}
1469#[cfg(feature = "v1_12_2")]
1470impl<const V: i32> Encode for MapChunk<V> {
1471    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1472        w.put_i32((*self).x);
1473        w.put_i32((*self).z);
1474        w.put_bool((*self).ground_up);
1475        w.put_varint((*self).bit_map);
1476        w.put_byte_array(&(*self).chunk_data)?;
1477        w.put_len_varint((*self).block_entities.len())?;
1478        for v1 in (*self).block_entities.iter() {
1479            (*v1).write(w);
1480        }
1481        Ok(())
1482    }
1483}
1484#[cfg(feature = "v1_12_2")]
1485#[cfg(feature = "testgen")]
1486impl<const V: i32> Generate for MapChunk<V> {
1487    fn generate(g: &mut Gen) -> Self {
1488        {
1489            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1490            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1491            let v3 = g.bool();
1492            let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1493            let v5 = g.bytes();
1494            let v6 = {
1495                let v7 = g.count();
1496                let mut v8 = Vec::with_capacity(v7.min(crate::codec::PREALLOC_LIMIT));
1497                for _ in 0..v7 {
1498                    v8.push(g.nbt());
1499                }
1500                v8
1501            };
1502            Self {
1503                x: v1,
1504                z: v2,
1505                ground_up: v3,
1506                bit_map: v4,
1507                chunk_data: v5,
1508                block_entities: v6,
1509            }
1510        }
1511    }
1512}
1513
1514#[cfg(feature = "v1_12_2")]
1515/// `login` (clientbound play).
1516#[derive(Debug, Clone, PartialEq)]
1517pub struct Login<const V: i32> {
1518    /// `entityId`
1519    pub entity_id: i32,
1520    /// `gameMode`
1521    pub game_mode: u8,
1522    /// `dimension`
1523    pub dimension: i32,
1524    /// `difficulty`
1525    pub difficulty: u8,
1526    /// `maxPlayers`
1527    pub max_players: u8,
1528    /// `levelType`
1529    pub level_type: ByteString,
1530    /// `reducedDebugInfo`
1531    pub reduced_debug_info: bool,
1532}
1533#[cfg(feature = "v1_12_2")]
1534impl<const V: i32> Decode for Login<V> {
1535    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1536        Ok({
1537            let v1 = r.read_i32()?;
1538            let v2 = r.read_u8()?;
1539            let v3 = r.read_i32()?;
1540            let v4 = r.read_u8()?;
1541            let v5 = r.read_u8()?;
1542            let v6 = r.read_string()?;
1543            let v7 = r.read_bool()?;
1544            Self {
1545                entity_id: v1,
1546                game_mode: v2,
1547                dimension: v3,
1548                difficulty: v4,
1549                max_players: v5,
1550                level_type: v6,
1551                reduced_debug_info: v7,
1552            }
1553        })
1554    }
1555}
1556#[cfg(feature = "v1_12_2")]
1557impl<const V: i32> Encode for Login<V> {
1558    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1559        w.put_i32((*self).entity_id);
1560        w.put_u8((*self).game_mode);
1561        w.put_i32((*self).dimension);
1562        w.put_u8((*self).difficulty);
1563        w.put_u8((*self).max_players);
1564        w.put_string(&(*self).level_type)?;
1565        w.put_bool((*self).reduced_debug_info);
1566        Ok(())
1567    }
1568}
1569#[cfg(feature = "v1_12_2")]
1570#[cfg(feature = "testgen")]
1571impl<const V: i32> Generate for Login<V> {
1572    fn generate(g: &mut Gen) -> Self {
1573        {
1574            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1575            let v2 = (g.int_in(0, 255, &[]) as u8);
1576            let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1577            let v4 = (g.int_in(0, 255, &[]) as u8);
1578            let v5 = (g.int_in(0, 255, &[]) as u8);
1579            let v6 = g.string();
1580            let v7 = g.bool();
1581            Self {
1582                entity_id: v1,
1583                game_mode: v2,
1584                dimension: v3,
1585                difficulty: v4,
1586                max_players: v5,
1587                level_type: v6,
1588                reduced_debug_info: v7,
1589            }
1590        }
1591    }
1592}
1593
1594#[cfg(feature = "v1_12_2")]
1595/// `map` (clientbound play).
1596#[derive(Debug, Clone, PartialEq)]
1597pub struct Map<const V: i32> {
1598    /// `itemDamage`
1599    pub item_damage: i32,
1600    /// `scale`
1601    pub scale: i8,
1602    /// `trackingPosition`
1603    pub tracking_position: bool,
1604    /// `icons`
1605    pub icons: Vec<crate::defs::p47::play::clientbound::MapIcons>,
1606    /// `columns`
1607    pub columns: i8,
1608    /// `rows`
1609    pub rows: Option<i8>,
1610    /// `x`
1611    pub x: Option<i8>,
1612    /// `y`
1613    pub y: Option<i8>,
1614    /// `data`
1615    pub data: Option<Bytes>,
1616}
1617#[cfg(feature = "v1_12_2")]
1618impl<const V: i32> Decode for Map<V> {
1619    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1620        Ok({
1621            let v1 = r.read_varint()?;
1622            let v2 = r.read_i8()?;
1623            let v3 = r.read_bool()?;
1624            let v4 = {
1625                let v5 = {
1626                    let c = r.read_varint()?;
1627                    r.check_count(i64::from(c), 3)?
1628                };
1629                let mut v6 = Vec::with_capacity(v5.min(crate::codec::PREALLOC_LIMIT));
1630                for _ in 0..v5 {
1631                    v6.push({
1632                        let v7 = r.read_i8()?;
1633                        let v8 = r.read_i8()?;
1634                        let v9 = r.read_i8()?;
1635                        crate::defs::p47::play::clientbound::MapIcons {
1636                            direction_and_type: v7,
1637                            x: v8,
1638                            z: v9,
1639                        }
1640                    });
1641                }
1642                v6
1643            };
1644            let v10 = r.read_i8()?;
1645            let v11 = if !(v10 == 0) {
1646                Some(r.read_i8()?)
1647            } else {
1648                None
1649            };
1650            let v12 = if !(v10 == 0) {
1651                Some(r.read_i8()?)
1652            } else {
1653                None
1654            };
1655            let v13 = if !(v10 == 0) {
1656                Some(r.read_i8()?)
1657            } else {
1658                None
1659            };
1660            let v14 = if !(v10 == 0) {
1661                Some(r.read_byte_array()?)
1662            } else {
1663                None
1664            };
1665            Self {
1666                item_damage: v1,
1667                scale: v2,
1668                tracking_position: v3,
1669                icons: v4,
1670                columns: v10,
1671                rows: v11,
1672                x: v12,
1673                y: v13,
1674                data: v14,
1675            }
1676        })
1677    }
1678}
1679#[cfg(feature = "v1_12_2")]
1680impl<const V: i32> Encode for Map<V> {
1681    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1682        w.put_varint((*self).item_damage);
1683        w.put_i8((*self).scale);
1684        w.put_bool((*self).tracking_position);
1685        w.put_len_varint((*self).icons.len())?;
1686        for v1 in (*self).icons.iter() {
1687            w.put_i8((*v1).direction_and_type);
1688            w.put_i8((*v1).x);
1689            w.put_i8((*v1).z);
1690        }
1691        w.put_i8((*self).columns);
1692        match (&(*self).rows, !((*self).columns == 0)) {
1693            (Some(v2), true) => {
1694                w.put_i8((*v2));
1695            }
1696            (None, false) => {}
1697            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.rows")),
1698        }
1699        match (&(*self).x, !((*self).columns == 0)) {
1700            (Some(v3), true) => {
1701                w.put_i8((*v3));
1702            }
1703            (None, false) => {}
1704            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.x")),
1705        }
1706        match (&(*self).y, !((*self).columns == 0)) {
1707            (Some(v4), true) => {
1708                w.put_i8((*v4));
1709            }
1710            (None, false) => {}
1711            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.y")),
1712        }
1713        match (&(*self).data, !((*self).columns == 0)) {
1714            (Some(v5), true) => {
1715                w.put_byte_array(&(*v5))?;
1716            }
1717            (None, false) => {}
1718            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.data")),
1719        }
1720        Ok(())
1721    }
1722}
1723#[cfg(feature = "v1_12_2")]
1724#[cfg(feature = "testgen")]
1725impl<const V: i32> Generate for Map<V> {
1726    fn generate(g: &mut Gen) -> Self {
1727        {
1728            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1729            let v2 = (g.int_in(-128, 127, &[]) as i8);
1730            let v3 = g.bool();
1731            let v4 = {
1732                let v5 = g.count();
1733                let mut v6 = Vec::with_capacity(v5.min(crate::codec::PREALLOC_LIMIT));
1734                for _ in 0..v5 {
1735                    v6.push({
1736                        let v7 = (g.int_in(-128, 127, &[]) as i8);
1737                        let v8 = (g.int_in(-128, 127, &[]) as i8);
1738                        let v9 = (g.int_in(-128, 127, &[]) as i8);
1739                        crate::defs::p47::play::clientbound::MapIcons {
1740                            direction_and_type: v7,
1741                            x: v8,
1742                            z: v9,
1743                        }
1744                    });
1745                }
1746                v6
1747            };
1748            let v10 = (g.int_in(-128, 127, &[0, 0, 0, 0]) as i8);
1749            let v11 = if !(v10 == 0) {
1750                Some((g.int_in(-128, 127, &[]) as i8))
1751            } else {
1752                None
1753            };
1754            let v12 = if !(v10 == 0) {
1755                Some((g.int_in(-128, 127, &[]) as i8))
1756            } else {
1757                None
1758            };
1759            let v13 = if !(v10 == 0) {
1760                Some((g.int_in(-128, 127, &[]) as i8))
1761            } else {
1762                None
1763            };
1764            let v14 = if !(v10 == 0) { Some(g.bytes()) } else { None };
1765            Self {
1766                item_damage: v1,
1767                scale: v2,
1768                tracking_position: v3,
1769                icons: v4,
1770                columns: v10,
1771                rows: v11,
1772                x: v12,
1773                y: v13,
1774                data: v14,
1775            }
1776        }
1777    }
1778}
1779
1780#[cfg(any(
1781    feature = "v1_12_2",
1782    feature = "v1_16_5",
1783    feature = "v26_1",
1784    feature = "v26_2"
1785))]
1786/// `rel_entity_move` (clientbound play).
1787#[derive(Debug, Clone, PartialEq)]
1788pub struct RelEntityMove<const V: i32> {
1789    /// `entityId`
1790    pub entity_id: i32,
1791    /// `dX`
1792    pub d_x: i16,
1793    /// `dY`
1794    pub d_y: i16,
1795    /// `dZ`
1796    pub d_z: i16,
1797    /// `onGround`
1798    pub on_ground: bool,
1799}
1800#[cfg(any(
1801    feature = "v1_12_2",
1802    feature = "v1_16_5",
1803    feature = "v26_1",
1804    feature = "v26_2"
1805))]
1806impl<const V: i32> Decode for RelEntityMove<V> {
1807    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1808        Ok({
1809            let v1 = r.read_varint()?;
1810            let v2 = r.read_i16()?;
1811            let v3 = r.read_i16()?;
1812            let v4 = r.read_i16()?;
1813            let v5 = r.read_bool()?;
1814            Self {
1815                entity_id: v1,
1816                d_x: v2,
1817                d_y: v3,
1818                d_z: v4,
1819                on_ground: v5,
1820            }
1821        })
1822    }
1823}
1824#[cfg(any(
1825    feature = "v1_12_2",
1826    feature = "v1_16_5",
1827    feature = "v26_1",
1828    feature = "v26_2"
1829))]
1830impl<const V: i32> Encode for RelEntityMove<V> {
1831    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1832        w.put_varint((*self).entity_id);
1833        w.put_i16((*self).d_x);
1834        w.put_i16((*self).d_y);
1835        w.put_i16((*self).d_z);
1836        w.put_bool((*self).on_ground);
1837        Ok(())
1838    }
1839}
1840#[cfg(any(
1841    feature = "v1_12_2",
1842    feature = "v1_16_5",
1843    feature = "v26_1",
1844    feature = "v26_2"
1845))]
1846#[cfg(feature = "testgen")]
1847impl<const V: i32> Generate for RelEntityMove<V> {
1848    fn generate(g: &mut Gen) -> Self {
1849        {
1850            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1851            let v2 = (g.int_in(-32768, 32767, &[]) as i16);
1852            let v3 = (g.int_in(-32768, 32767, &[]) as i16);
1853            let v4 = (g.int_in(-32768, 32767, &[]) as i16);
1854            let v5 = g.bool();
1855            Self {
1856                entity_id: v1,
1857                d_x: v2,
1858                d_y: v3,
1859                d_z: v4,
1860                on_ground: v5,
1861            }
1862        }
1863    }
1864}
1865
1866#[cfg(any(
1867    feature = "v1_12_2",
1868    feature = "v1_16_5",
1869    feature = "v26_1",
1870    feature = "v26_2"
1871))]
1872/// `entity_move_look` (clientbound play).
1873#[derive(Debug, Clone, PartialEq)]
1874pub struct EntityMoveLook<const V: i32> {
1875    /// `entityId`
1876    pub entity_id: i32,
1877    /// `dX`
1878    pub d_x: i16,
1879    /// `dY`
1880    pub d_y: i16,
1881    /// `dZ`
1882    pub d_z: i16,
1883    /// `yaw`
1884    pub yaw: i8,
1885    /// `pitch`
1886    pub pitch: i8,
1887    /// `onGround`
1888    pub on_ground: bool,
1889}
1890#[cfg(any(
1891    feature = "v1_12_2",
1892    feature = "v1_16_5",
1893    feature = "v26_1",
1894    feature = "v26_2"
1895))]
1896impl<const V: i32> Decode for EntityMoveLook<V> {
1897    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1898        Ok({
1899            let v1 = r.read_varint()?;
1900            let v2 = r.read_i16()?;
1901            let v3 = r.read_i16()?;
1902            let v4 = r.read_i16()?;
1903            let v5 = r.read_i8()?;
1904            let v6 = r.read_i8()?;
1905            let v7 = r.read_bool()?;
1906            Self {
1907                entity_id: v1,
1908                d_x: v2,
1909                d_y: v3,
1910                d_z: v4,
1911                yaw: v5,
1912                pitch: v6,
1913                on_ground: v7,
1914            }
1915        })
1916    }
1917}
1918#[cfg(any(
1919    feature = "v1_12_2",
1920    feature = "v1_16_5",
1921    feature = "v26_1",
1922    feature = "v26_2"
1923))]
1924impl<const V: i32> Encode for EntityMoveLook<V> {
1925    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1926        w.put_varint((*self).entity_id);
1927        w.put_i16((*self).d_x);
1928        w.put_i16((*self).d_y);
1929        w.put_i16((*self).d_z);
1930        w.put_i8((*self).yaw);
1931        w.put_i8((*self).pitch);
1932        w.put_bool((*self).on_ground);
1933        Ok(())
1934    }
1935}
1936#[cfg(any(
1937    feature = "v1_12_2",
1938    feature = "v1_16_5",
1939    feature = "v26_1",
1940    feature = "v26_2"
1941))]
1942#[cfg(feature = "testgen")]
1943impl<const V: i32> Generate for EntityMoveLook<V> {
1944    fn generate(g: &mut Gen) -> Self {
1945        {
1946            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1947            let v2 = (g.int_in(-32768, 32767, &[]) as i16);
1948            let v3 = (g.int_in(-32768, 32767, &[]) as i16);
1949            let v4 = (g.int_in(-32768, 32767, &[]) as i16);
1950            let v5 = (g.int_in(-128, 127, &[]) as i8);
1951            let v6 = (g.int_in(-128, 127, &[]) as i8);
1952            let v7 = g.bool();
1953            Self {
1954                entity_id: v1,
1955                d_x: v2,
1956                d_y: v3,
1957                d_z: v4,
1958                yaw: v5,
1959                pitch: v6,
1960                on_ground: v7,
1961            }
1962        }
1963    }
1964}
1965
1966#[cfg(any(
1967    feature = "v1_12_2",
1968    feature = "v1_16_5",
1969    feature = "v26_1",
1970    feature = "v26_2"
1971))]
1972/// `vehicle_move` (clientbound play).
1973#[derive(Debug, Clone, PartialEq)]
1974pub struct VehicleMove<const V: i32> {
1975    /// `x`
1976    pub x: f64,
1977    /// `y`
1978    pub y: f64,
1979    /// `z`
1980    pub z: f64,
1981    /// `yaw`
1982    pub yaw: f32,
1983    /// `pitch`
1984    pub pitch: f32,
1985}
1986#[cfg(any(
1987    feature = "v1_12_2",
1988    feature = "v1_16_5",
1989    feature = "v26_1",
1990    feature = "v26_2"
1991))]
1992impl<const V: i32> Decode for VehicleMove<V> {
1993    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1994        Ok({
1995            let v1 = r.read_f64()?;
1996            let v2 = r.read_f64()?;
1997            let v3 = r.read_f64()?;
1998            let v4 = r.read_f32()?;
1999            let v5 = r.read_f32()?;
2000            Self {
2001                x: v1,
2002                y: v2,
2003                z: v3,
2004                yaw: v4,
2005                pitch: v5,
2006            }
2007        })
2008    }
2009}
2010#[cfg(any(
2011    feature = "v1_12_2",
2012    feature = "v1_16_5",
2013    feature = "v26_1",
2014    feature = "v26_2"
2015))]
2016impl<const V: i32> Encode for VehicleMove<V> {
2017    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2018        w.put_f64((*self).x);
2019        w.put_f64((*self).y);
2020        w.put_f64((*self).z);
2021        w.put_f32((*self).yaw);
2022        w.put_f32((*self).pitch);
2023        Ok(())
2024    }
2025}
2026#[cfg(any(
2027    feature = "v1_12_2",
2028    feature = "v1_16_5",
2029    feature = "v26_1",
2030    feature = "v26_2"
2031))]
2032#[cfg(feature = "testgen")]
2033impl<const V: i32> Generate for VehicleMove<V> {
2034    fn generate(g: &mut Gen) -> Self {
2035        {
2036            let v1 = g.f64();
2037            let v2 = g.f64();
2038            let v3 = g.f64();
2039            let v4 = g.f32();
2040            let v5 = g.f32();
2041            Self {
2042                x: v1,
2043                y: v2,
2044                z: v3,
2045                yaw: v4,
2046                pitch: v5,
2047            }
2048        }
2049    }
2050}
2051
2052#[cfg(feature = "v1_12_2")]
2053/// `craft_recipe_response` (clientbound play).
2054#[derive(Debug, Clone, PartialEq)]
2055pub struct CraftRecipeResponse<const V: i32> {
2056    /// `windowId`
2057    pub window_id: i8,
2058    /// `recipe`
2059    pub recipe: i32,
2060}
2061#[cfg(feature = "v1_12_2")]
2062impl<const V: i32> Decode for CraftRecipeResponse<V> {
2063    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2064        Ok({
2065            let v1 = r.read_i8()?;
2066            let v2 = r.read_varint()?;
2067            Self {
2068                window_id: v1,
2069                recipe: v2,
2070            }
2071        })
2072    }
2073}
2074#[cfg(feature = "v1_12_2")]
2075impl<const V: i32> Encode for CraftRecipeResponse<V> {
2076    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2077        w.put_i8((*self).window_id);
2078        w.put_varint((*self).recipe);
2079        Ok(())
2080    }
2081}
2082#[cfg(feature = "v1_12_2")]
2083#[cfg(feature = "testgen")]
2084impl<const V: i32> Generate for CraftRecipeResponse<V> {
2085    fn generate(g: &mut Gen) -> Self {
2086        {
2087            let v1 = (g.int_in(-128, 127, &[]) as i8);
2088            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2089            Self {
2090                window_id: v1,
2091                recipe: v2,
2092            }
2093        }
2094    }
2095}
2096
2097#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
2098/// `position` (clientbound play).
2099#[derive(Debug, Clone, PartialEq)]
2100pub struct Position<const V: i32> {
2101    /// `x`
2102    pub x: f64,
2103    /// `y`
2104    pub y: f64,
2105    /// `z`
2106    pub z: f64,
2107    /// `yaw`
2108    pub yaw: f32,
2109    /// `pitch`
2110    pub pitch: f32,
2111    /// `flags`
2112    pub flags: i8,
2113    /// `teleportId`
2114    pub teleport_id: i32,
2115}
2116#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
2117impl<const V: i32> Decode for Position<V> {
2118    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2119        Ok({
2120            let v1 = r.read_f64()?;
2121            let v2 = r.read_f64()?;
2122            let v3 = r.read_f64()?;
2123            let v4 = r.read_f32()?;
2124            let v5 = r.read_f32()?;
2125            let v6 = r.read_i8()?;
2126            let v7 = r.read_varint()?;
2127            Self {
2128                x: v1,
2129                y: v2,
2130                z: v3,
2131                yaw: v4,
2132                pitch: v5,
2133                flags: v6,
2134                teleport_id: v7,
2135            }
2136        })
2137    }
2138}
2139#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
2140impl<const V: i32> Encode for Position<V> {
2141    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2142        w.put_f64((*self).x);
2143        w.put_f64((*self).y);
2144        w.put_f64((*self).z);
2145        w.put_f32((*self).yaw);
2146        w.put_f32((*self).pitch);
2147        w.put_i8((*self).flags);
2148        w.put_varint((*self).teleport_id);
2149        Ok(())
2150    }
2151}
2152#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
2153#[cfg(feature = "testgen")]
2154impl<const V: i32> Generate for Position<V> {
2155    fn generate(g: &mut Gen) -> Self {
2156        {
2157            let v1 = g.f64();
2158            let v2 = g.f64();
2159            let v3 = g.f64();
2160            let v4 = g.f32();
2161            let v5 = g.f32();
2162            let v6 = (g.int_in(-128, 127, &[]) as i8);
2163            let v7 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2164            Self {
2165                x: v1,
2166                y: v2,
2167                z: v3,
2168                yaw: v4,
2169                pitch: v5,
2170                flags: v6,
2171                teleport_id: v7,
2172            }
2173        }
2174    }
2175}
2176
2177#[cfg(feature = "v1_12_2")]
2178/// `unlock_recipes` (clientbound play).
2179#[derive(Debug, Clone, PartialEq)]
2180pub struct UnlockRecipes<const V: i32> {
2181    /// `action`
2182    pub action: i32,
2183    /// `craftingBookOpen`
2184    pub crafting_book_open: bool,
2185    /// `filteringCraftable`
2186    pub filtering_craftable: bool,
2187    /// `recipes1`
2188    pub recipes1: Vec<i32>,
2189    /// `recipes2`
2190    pub recipes2: Option<Vec<i32>>,
2191}
2192#[cfg(feature = "v1_12_2")]
2193impl<const V: i32> Decode for UnlockRecipes<V> {
2194    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2195        Ok({
2196            let v1 = r.read_varint()?;
2197            let v2 = r.read_bool()?;
2198            let v3 = r.read_bool()?;
2199            let v4 = {
2200                let v5 = {
2201                    let c = r.read_varint()?;
2202                    r.check_count(i64::from(c), 1)?
2203                };
2204                let mut v6 = Vec::with_capacity(v5.min(crate::codec::PREALLOC_LIMIT));
2205                for _ in 0..v5 {
2206                    v6.push(r.read_varint()?);
2207                }
2208                v6
2209            };
2210            let v7 = if (v1 == 0) {
2211                Some({
2212                    let v8 = {
2213                        let c = r.read_varint()?;
2214                        r.check_count(i64::from(c), 1)?
2215                    };
2216                    let mut v9 = Vec::with_capacity(v8.min(crate::codec::PREALLOC_LIMIT));
2217                    for _ in 0..v8 {
2218                        v9.push(r.read_varint()?);
2219                    }
2220                    v9
2221                })
2222            } else {
2223                None
2224            };
2225            Self {
2226                action: v1,
2227                crafting_book_open: v2,
2228                filtering_craftable: v3,
2229                recipes1: v4,
2230                recipes2: v7,
2231            }
2232        })
2233    }
2234}
2235#[cfg(feature = "v1_12_2")]
2236impl<const V: i32> Encode for UnlockRecipes<V> {
2237    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2238        w.put_varint((*self).action);
2239        w.put_bool((*self).crafting_book_open);
2240        w.put_bool((*self).filtering_craftable);
2241        w.put_len_varint((*self).recipes1.len())?;
2242        for v1 in (*self).recipes1.iter() {
2243            w.put_varint((*v1));
2244        }
2245        match (&(*self).recipes2, ((*self).action == 0)) {
2246            (Some(v2), true) => {
2247                w.put_len_varint((*v2).len())?;
2248                for v3 in (*v2).iter() {
2249                    w.put_varint((*v3));
2250                }
2251            }
2252            (None, false) => {}
2253            _ => {
2254                return Err(EncodeError::SwitchMismatch(
2255                    "play.clientbound.unlock_recipes.recipes2",
2256                ));
2257            }
2258        }
2259        Ok(())
2260    }
2261}
2262#[cfg(feature = "v1_12_2")]
2263#[cfg(feature = "testgen")]
2264impl<const V: i32> Generate for UnlockRecipes<V> {
2265    fn generate(g: &mut Gen) -> Self {
2266        {
2267            let v1 = (g.int_in(-2147483648, 2147483647, &[0]) as i32);
2268            let v2 = g.bool();
2269            let v3 = g.bool();
2270            let v4 = {
2271                let v5 = g.count();
2272                let mut v6 = Vec::with_capacity(v5.min(crate::codec::PREALLOC_LIMIT));
2273                for _ in 0..v5 {
2274                    v6.push((g.int_in(-2147483648, 2147483647, &[]) as i32));
2275                }
2276                v6
2277            };
2278            let v7 = if (v1 == 0) {
2279                Some({
2280                    let v8 = g.count();
2281                    let mut v9 = Vec::with_capacity(v8.min(crate::codec::PREALLOC_LIMIT));
2282                    for _ in 0..v8 {
2283                        v9.push((g.int_in(-2147483648, 2147483647, &[]) as i32));
2284                    }
2285                    v9
2286                })
2287            } else {
2288                None
2289            };
2290            Self {
2291                action: v1,
2292                crafting_book_open: v2,
2293                filtering_craftable: v3,
2294                recipes1: v4,
2295                recipes2: v7,
2296            }
2297        }
2298    }
2299}
2300
2301#[cfg(any(
2302    feature = "v1_12_2",
2303    feature = "v1_16_5",
2304    feature = "v26_1",
2305    feature = "v26_2"
2306))]
2307/// `select_advancement_tab` (clientbound play).
2308#[derive(Debug, Clone, PartialEq)]
2309pub struct SelectAdvancementTab<const V: i32> {
2310    /// `id`
2311    pub id: Option<ByteString>,
2312}
2313#[cfg(any(
2314    feature = "v1_12_2",
2315    feature = "v1_16_5",
2316    feature = "v26_1",
2317    feature = "v26_2"
2318))]
2319impl<const V: i32> Decode for SelectAdvancementTab<V> {
2320    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2321        Ok({
2322            let v1 = if r.read_bool()? {
2323                Some(r.read_string()?)
2324            } else {
2325                None
2326            };
2327            Self { id: v1 }
2328        })
2329    }
2330}
2331#[cfg(any(
2332    feature = "v1_12_2",
2333    feature = "v1_16_5",
2334    feature = "v26_1",
2335    feature = "v26_2"
2336))]
2337impl<const V: i32> Encode for SelectAdvancementTab<V> {
2338    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2339        match &(*self).id {
2340            Some(v1) => {
2341                w.put_u8(1);
2342                w.put_string(&(*v1))?;
2343            }
2344            None => w.put_u8(0),
2345        }
2346        Ok(())
2347    }
2348}
2349#[cfg(any(
2350    feature = "v1_12_2",
2351    feature = "v1_16_5",
2352    feature = "v26_1",
2353    feature = "v26_2"
2354))]
2355#[cfg(feature = "testgen")]
2356impl<const V: i32> Generate for SelectAdvancementTab<V> {
2357    fn generate(g: &mut Gen) -> Self {
2358        {
2359            let v1 = if g.bool() { Some(g.string()) } else { None };
2360            Self { id: v1 }
2361        }
2362    }
2363}
2364
2365#[cfg(feature = "v1_12_2")]
2366/// `entity_metadata` (clientbound play).
2367#[derive(Debug, Clone, PartialEq)]
2368pub struct EntityMetadata<const V: i32> {
2369    /// `entityId`
2370    pub entity_id: i32,
2371    /// `metadata`
2372    pub metadata: Vec<crate::defs::p340::types::EntityMetadataEntry>,
2373}
2374#[cfg(feature = "v1_12_2")]
2375impl<const V: i32> Decode for EntityMetadata<V> {
2376    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2377        Ok({
2378            let v1 = r.read_varint()?;
2379            let v2 = {
2380                let mut v3 = Vec::new();
2381                loop {
2382                    if r.peek_u8()? == 255 {
2383                        r.skip(1)?;
2384                        break;
2385                    }
2386                    v3.push({
2387                        let v4 = r.read_u8()?;
2388                        let v5 = r.read_i8()?;
2389                        let v6 = (if (v5 == 0) {
2390                            crate::defs::p340::types::EntityMetadataValue::Byte(r.read_i8()?)
2391                        } else if (v5 == 1) {
2392                            crate::defs::p340::types::EntityMetadataValue::VarInt(r.read_varint()?)
2393                        } else if (v5 == 2) {
2394                            crate::defs::p340::types::EntityMetadataValue::Float(r.read_f32()?)
2395                        } else if (v5 == 3) {
2396                            crate::defs::p340::types::EntityMetadataValue::String(r.read_string()?)
2397                        } else if (v5 == 4) {
2398                            crate::defs::p340::types::EntityMetadataValue::Chat(r.read_string()?)
2399                        } else if (v5 == 5) {
2400                            crate::defs::p340::types::EntityMetadataValue::Slot(
2401                                <crate::types::slot::legacy::Slot as Decode>::decode(r)?,
2402                            )
2403                        } else if (v5 == 6) {
2404                            crate::defs::p340::types::EntityMetadataValue::Boolean(r.read_bool()?)
2405                        } else if (v5 == 7) {
2406                            crate::defs::p340::types::EntityMetadataValue::Rotation({
2407                                let v7 = r.read_f32()?;
2408                                let v8 = r.read_f32()?;
2409                                let v9 = r.read_f32()?;
2410                                crate::defs::p47::types::EntityMetadataValueRotation {
2411                                    pitch: v7,
2412                                    yaw: v8,
2413                                    roll: v9,
2414                                }
2415                            })
2416                        } else if (v5 == 8) {
2417                            crate::defs::p340::types::EntityMetadataValue::Position(BlockPos::read(
2418                                r,
2419                                PositionLayout::Xyz,
2420                            )?)
2421                        } else if (v5 == 9) {
2422                            crate::defs::p340::types::EntityMetadataValue::OptPosition(
2423                                if r.read_bool()? {
2424                                    Some(BlockPos::read(r, PositionLayout::Xyz)?)
2425                                } else {
2426                                    None
2427                                },
2428                            )
2429                        } else if (v5 == 10) {
2430                            crate::defs::p340::types::EntityMetadataValue::Direction(
2431                                r.read_varint()?,
2432                            )
2433                        } else if (v5 == 11) {
2434                            crate::defs::p340::types::EntityMetadataValue::OptUuid(
2435                                if r.read_bool()? {
2436                                    Some(r.read_uuid()?)
2437                                } else {
2438                                    None
2439                                },
2440                            )
2441                        } else if (v5 == 12) {
2442                            crate::defs::p340::types::EntityMetadataValue::BlockState(
2443                                r.read_varint()?,
2444                            )
2445                        } else if (v5 == 13) {
2446                            crate::defs::p340::types::EntityMetadataValue::Nbt(RawNbt::read(r)?)
2447                        } else {
2448                            crate::defs::p340::types::EntityMetadataValue::Other
2449                        });
2450                        crate::defs::p340::types::EntityMetadataEntry {
2451                            key: v4,
2452                            r#type: v5,
2453                            value: v6,
2454                        }
2455                    });
2456                }
2457                v3
2458            };
2459            Self {
2460                entity_id: v1,
2461                metadata: v2,
2462            }
2463        })
2464    }
2465}
2466#[cfg(feature = "v1_12_2")]
2467impl<const V: i32> Encode for EntityMetadata<V> {
2468    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2469        w.put_varint((*self).entity_id);
2470        for v1 in (*self).metadata.iter() {
2471            let v2 = w.len();
2472            w.put_u8((*v1).key);
2473            w.put_i8((*v1).r#type);
2474            match &(*v1).value {
2475                crate::defs::p340::types::EntityMetadataValue::Byte(v3) => {
2476                    if !((*v1).r#type == 0) {
2477                        return Err(EncodeError::SwitchMismatch(
2478                            "play.clientbound.entity_metadata.metadata.value",
2479                        ));
2480                    }
2481                    w.put_i8((*v3));
2482                }
2483                crate::defs::p340::types::EntityMetadataValue::VarInt(v4) => {
2484                    if !((*v1).r#type == 1) {
2485                        return Err(EncodeError::SwitchMismatch(
2486                            "play.clientbound.entity_metadata.metadata.value",
2487                        ));
2488                    }
2489                    w.put_varint((*v4));
2490                }
2491                crate::defs::p340::types::EntityMetadataValue::Float(v5) => {
2492                    if !((*v1).r#type == 2) {
2493                        return Err(EncodeError::SwitchMismatch(
2494                            "play.clientbound.entity_metadata.metadata.value",
2495                        ));
2496                    }
2497                    w.put_f32((*v5));
2498                }
2499                crate::defs::p340::types::EntityMetadataValue::String(v6) => {
2500                    if !((*v1).r#type == 3) {
2501                        return Err(EncodeError::SwitchMismatch(
2502                            "play.clientbound.entity_metadata.metadata.value",
2503                        ));
2504                    }
2505                    w.put_string(&(*v6))?;
2506                }
2507                crate::defs::p340::types::EntityMetadataValue::Chat(v7) => {
2508                    if !((*v1).r#type == 4) {
2509                        return Err(EncodeError::SwitchMismatch(
2510                            "play.clientbound.entity_metadata.metadata.value",
2511                        ));
2512                    }
2513                    w.put_string(&(*v7))?;
2514                }
2515                crate::defs::p340::types::EntityMetadataValue::Slot(v8) => {
2516                    if !((*v1).r#type == 5) {
2517                        return Err(EncodeError::SwitchMismatch(
2518                            "play.clientbound.entity_metadata.metadata.value",
2519                        ));
2520                    }
2521                    (*v8).encode(w)?;
2522                }
2523                crate::defs::p340::types::EntityMetadataValue::Boolean(v9) => {
2524                    if !((*v1).r#type == 6) {
2525                        return Err(EncodeError::SwitchMismatch(
2526                            "play.clientbound.entity_metadata.metadata.value",
2527                        ));
2528                    }
2529                    w.put_bool((*v9));
2530                }
2531                crate::defs::p340::types::EntityMetadataValue::Rotation(v10) => {
2532                    if !((*v1).r#type == 7) {
2533                        return Err(EncodeError::SwitchMismatch(
2534                            "play.clientbound.entity_metadata.metadata.value",
2535                        ));
2536                    }
2537                    w.put_f32((*v10).pitch);
2538                    w.put_f32((*v10).yaw);
2539                    w.put_f32((*v10).roll);
2540                }
2541                crate::defs::p340::types::EntityMetadataValue::Position(v11) => {
2542                    if !((*v1).r#type == 8) {
2543                        return Err(EncodeError::SwitchMismatch(
2544                            "play.clientbound.entity_metadata.metadata.value",
2545                        ));
2546                    }
2547                    (*v11).write(w, PositionLayout::Xyz)?;
2548                }
2549                crate::defs::p340::types::EntityMetadataValue::OptPosition(v12) => {
2550                    if !((*v1).r#type == 9) {
2551                        return Err(EncodeError::SwitchMismatch(
2552                            "play.clientbound.entity_metadata.metadata.value",
2553                        ));
2554                    }
2555                    match &(*v12) {
2556                        Some(v13) => {
2557                            w.put_u8(1);
2558                            (*v13).write(w, PositionLayout::Xyz)?;
2559                        }
2560                        None => w.put_u8(0),
2561                    }
2562                }
2563                crate::defs::p340::types::EntityMetadataValue::Direction(v14) => {
2564                    if !((*v1).r#type == 10) {
2565                        return Err(EncodeError::SwitchMismatch(
2566                            "play.clientbound.entity_metadata.metadata.value",
2567                        ));
2568                    }
2569                    w.put_varint((*v14));
2570                }
2571                crate::defs::p340::types::EntityMetadataValue::OptUuid(v15) => {
2572                    if !((*v1).r#type == 11) {
2573                        return Err(EncodeError::SwitchMismatch(
2574                            "play.clientbound.entity_metadata.metadata.value",
2575                        ));
2576                    }
2577                    match &(*v15) {
2578                        Some(v16) => {
2579                            w.put_u8(1);
2580                            w.put_uuid(&(*v16));
2581                        }
2582                        None => w.put_u8(0),
2583                    }
2584                }
2585                crate::defs::p340::types::EntityMetadataValue::BlockState(v17) => {
2586                    if !((*v1).r#type == 12) {
2587                        return Err(EncodeError::SwitchMismatch(
2588                            "play.clientbound.entity_metadata.metadata.value",
2589                        ));
2590                    }
2591                    w.put_varint((*v17));
2592                }
2593                crate::defs::p340::types::EntityMetadataValue::Nbt(v18) => {
2594                    if !((*v1).r#type == 13) {
2595                        return Err(EncodeError::SwitchMismatch(
2596                            "play.clientbound.entity_metadata.metadata.value",
2597                        ));
2598                    }
2599                    (*v18).write(w);
2600                }
2601                crate::defs::p340::types::EntityMetadataValue::Other => {
2602                    if !(!(((*v1).r#type == 0)
2603                        || ((*v1).r#type == 1)
2604                        || ((*v1).r#type == 2)
2605                        || ((*v1).r#type == 3)
2606                        || ((*v1).r#type == 4)
2607                        || ((*v1).r#type == 5)
2608                        || ((*v1).r#type == 6)
2609                        || ((*v1).r#type == 7)
2610                        || ((*v1).r#type == 8)
2611                        || ((*v1).r#type == 9)
2612                        || ((*v1).r#type == 10)
2613                        || ((*v1).r#type == 11)
2614                        || ((*v1).r#type == 12)
2615                        || ((*v1).r#type == 13)))
2616                    {
2617                        return Err(EncodeError::SwitchMismatch(
2618                            "play.clientbound.entity_metadata.metadata.value",
2619                        ));
2620                    }
2621                }
2622            }
2623            if w.get(v2) == Some(&255) {
2624                return Err(EncodeError::OutOfRange(
2625                    "play.clientbound.entity_metadata.metadata",
2626                ));
2627            }
2628        }
2629        w.put_u8(255);
2630        Ok(())
2631    }
2632}
2633#[cfg(feature = "v1_12_2")]
2634#[cfg(feature = "testgen")]
2635impl<const V: i32> Generate for EntityMetadata<V> {
2636    fn generate(g: &mut Gen) -> Self {
2637        {
2638            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2639            let v2 = {
2640                let n = g.count();
2641                let mut v3 = Vec::with_capacity(n);
2642                for _ in 0..n {
2643                    v3.push(loop {
2644                        let v4 = {
2645                            let v5 = (g.int_in(0, 255, &[]) as u8);
2646                            let v6 = (g.int_in(
2647                                -128,
2648                                127,
2649                                &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
2650                            ) as i8);
2651                            let v7 = (if (v6 == 0) {
2652                                crate::defs::p340::types::EntityMetadataValue::Byte(
2653                                    (g.int_in(-128, 127, &[]) as i8),
2654                                )
2655                            } else if (v6 == 1) {
2656                                crate::defs::p340::types::EntityMetadataValue::VarInt(
2657                                    (g.int_in(-2147483648, 2147483647, &[]) as i32),
2658                                )
2659                            } else if (v6 == 2) {
2660                                crate::defs::p340::types::EntityMetadataValue::Float(g.f32())
2661                            } else if (v6 == 3) {
2662                                crate::defs::p340::types::EntityMetadataValue::String(g.string())
2663                            } else if (v6 == 4) {
2664                                crate::defs::p340::types::EntityMetadataValue::Chat(g.string())
2665                            } else if (v6 == 5) {
2666                                crate::defs::p340::types::EntityMetadataValue::Slot(
2667                                    <crate::types::slot::legacy::Slot as Generate>::generate(g),
2668                                )
2669                            } else if (v6 == 6) {
2670                                crate::defs::p340::types::EntityMetadataValue::Boolean(g.bool())
2671                            } else if (v6 == 7) {
2672                                crate::defs::p340::types::EntityMetadataValue::Rotation({
2673                                    let v8 = g.f32();
2674                                    let v9 = g.f32();
2675                                    let v10 = g.f32();
2676                                    crate::defs::p47::types::EntityMetadataValueRotation {
2677                                        pitch: v8,
2678                                        yaw: v9,
2679                                        roll: v10,
2680                                    }
2681                                })
2682                            } else if (v6 == 8) {
2683                                crate::defs::p340::types::EntityMetadataValue::Position(
2684                                    g.position(),
2685                                )
2686                            } else if (v6 == 9) {
2687                                crate::defs::p340::types::EntityMetadataValue::OptPosition(
2688                                    if g.bool() { Some(g.position()) } else { None },
2689                                )
2690                            } else if (v6 == 10) {
2691                                crate::defs::p340::types::EntityMetadataValue::Direction(
2692                                    (g.int_in(-2147483648, 2147483647, &[]) as i32),
2693                                )
2694                            } else if (v6 == 11) {
2695                                crate::defs::p340::types::EntityMetadataValue::OptUuid(
2696                                    if g.bool() { Some(g.uuid()) } else { None },
2697                                )
2698                            } else if (v6 == 12) {
2699                                crate::defs::p340::types::EntityMetadataValue::BlockState(
2700                                    (g.int_in(-2147483648, 2147483647, &[]) as i32),
2701                                )
2702                            } else if (v6 == 13) {
2703                                crate::defs::p340::types::EntityMetadataValue::Nbt(g.nbt())
2704                            } else {
2705                                crate::defs::p340::types::EntityMetadataValue::Other
2706                            });
2707                            crate::defs::p340::types::EntityMetadataEntry {
2708                                key: v5,
2709                                r#type: v6,
2710                                value: v7,
2711                            }
2712                        };
2713                        if crate::testgen::first_byte_ok(
2714                            |w: &mut BytesMut| -> EncodeResult {
2715                                w.put_u8(v4.key);
2716                                w.put_i8(v4.r#type);
2717                                match &v4.value {
2718                                    crate::defs::p340::types::EntityMetadataValue::Byte(v11) => {
2719                                        if !(v4.r#type == 0) {
2720                                            return Err(EncodeError::SwitchMismatch(
2721                                                "play.clientbound.entity_metadata.metadata.value",
2722                                            ));
2723                                        }
2724                                        w.put_i8((*v11));
2725                                    }
2726                                    crate::defs::p340::types::EntityMetadataValue::VarInt(v12) => {
2727                                        if !(v4.r#type == 1) {
2728                                            return Err(EncodeError::SwitchMismatch(
2729                                                "play.clientbound.entity_metadata.metadata.value",
2730                                            ));
2731                                        }
2732                                        w.put_varint((*v12));
2733                                    }
2734                                    crate::defs::p340::types::EntityMetadataValue::Float(v13) => {
2735                                        if !(v4.r#type == 2) {
2736                                            return Err(EncodeError::SwitchMismatch(
2737                                                "play.clientbound.entity_metadata.metadata.value",
2738                                            ));
2739                                        }
2740                                        w.put_f32((*v13));
2741                                    }
2742                                    crate::defs::p340::types::EntityMetadataValue::String(v14) => {
2743                                        if !(v4.r#type == 3) {
2744                                            return Err(EncodeError::SwitchMismatch(
2745                                                "play.clientbound.entity_metadata.metadata.value",
2746                                            ));
2747                                        }
2748                                        w.put_string(&(*v14))?;
2749                                    }
2750                                    crate::defs::p340::types::EntityMetadataValue::Chat(v15) => {
2751                                        if !(v4.r#type == 4) {
2752                                            return Err(EncodeError::SwitchMismatch(
2753                                                "play.clientbound.entity_metadata.metadata.value",
2754                                            ));
2755                                        }
2756                                        w.put_string(&(*v15))?;
2757                                    }
2758                                    crate::defs::p340::types::EntityMetadataValue::Slot(v16) => {
2759                                        if !(v4.r#type == 5) {
2760                                            return Err(EncodeError::SwitchMismatch(
2761                                                "play.clientbound.entity_metadata.metadata.value",
2762                                            ));
2763                                        }
2764                                        (*v16).encode(w)?;
2765                                    }
2766                                    crate::defs::p340::types::EntityMetadataValue::Boolean(v17) => {
2767                                        if !(v4.r#type == 6) {
2768                                            return Err(EncodeError::SwitchMismatch(
2769                                                "play.clientbound.entity_metadata.metadata.value",
2770                                            ));
2771                                        }
2772                                        w.put_bool((*v17));
2773                                    }
2774                                    crate::defs::p340::types::EntityMetadataValue::Rotation(
2775                                        v18,
2776                                    ) => {
2777                                        if !(v4.r#type == 7) {
2778                                            return Err(EncodeError::SwitchMismatch(
2779                                                "play.clientbound.entity_metadata.metadata.value",
2780                                            ));
2781                                        }
2782                                        w.put_f32((*v18).pitch);
2783                                        w.put_f32((*v18).yaw);
2784                                        w.put_f32((*v18).roll);
2785                                    }
2786                                    crate::defs::p340::types::EntityMetadataValue::Position(
2787                                        v19,
2788                                    ) => {
2789                                        if !(v4.r#type == 8) {
2790                                            return Err(EncodeError::SwitchMismatch(
2791                                                "play.clientbound.entity_metadata.metadata.value",
2792                                            ));
2793                                        }
2794                                        (*v19).write(w, PositionLayout::Xyz)?;
2795                                    }
2796                                    crate::defs::p340::types::EntityMetadataValue::OptPosition(
2797                                        v20,
2798                                    ) => {
2799                                        if !(v4.r#type == 9) {
2800                                            return Err(EncodeError::SwitchMismatch(
2801                                                "play.clientbound.entity_metadata.metadata.value",
2802                                            ));
2803                                        }
2804                                        match &(*v20) {
2805                                            Some(v21) => {
2806                                                w.put_u8(1);
2807                                                (*v21).write(w, PositionLayout::Xyz)?;
2808                                            }
2809                                            None => w.put_u8(0),
2810                                        }
2811                                    }
2812                                    crate::defs::p340::types::EntityMetadataValue::Direction(
2813                                        v22,
2814                                    ) => {
2815                                        if !(v4.r#type == 10) {
2816                                            return Err(EncodeError::SwitchMismatch(
2817                                                "play.clientbound.entity_metadata.metadata.value",
2818                                            ));
2819                                        }
2820                                        w.put_varint((*v22));
2821                                    }
2822                                    crate::defs::p340::types::EntityMetadataValue::OptUuid(v23) => {
2823                                        if !(v4.r#type == 11) {
2824                                            return Err(EncodeError::SwitchMismatch(
2825                                                "play.clientbound.entity_metadata.metadata.value",
2826                                            ));
2827                                        }
2828                                        match &(*v23) {
2829                                            Some(v24) => {
2830                                                w.put_u8(1);
2831                                                w.put_uuid(&(*v24));
2832                                            }
2833                                            None => w.put_u8(0),
2834                                        }
2835                                    }
2836                                    crate::defs::p340::types::EntityMetadataValue::BlockState(
2837                                        v25,
2838                                    ) => {
2839                                        if !(v4.r#type == 12) {
2840                                            return Err(EncodeError::SwitchMismatch(
2841                                                "play.clientbound.entity_metadata.metadata.value",
2842                                            ));
2843                                        }
2844                                        w.put_varint((*v25));
2845                                    }
2846                                    crate::defs::p340::types::EntityMetadataValue::Nbt(v26) => {
2847                                        if !(v4.r#type == 13) {
2848                                            return Err(EncodeError::SwitchMismatch(
2849                                                "play.clientbound.entity_metadata.metadata.value",
2850                                            ));
2851                                        }
2852                                        (*v26).write(w);
2853                                    }
2854                                    crate::defs::p340::types::EntityMetadataValue::Other => {
2855                                        if !(!((v4.r#type == 0)
2856                                            || (v4.r#type == 1)
2857                                            || (v4.r#type == 2)
2858                                            || (v4.r#type == 3)
2859                                            || (v4.r#type == 4)
2860                                            || (v4.r#type == 5)
2861                                            || (v4.r#type == 6)
2862                                            || (v4.r#type == 7)
2863                                            || (v4.r#type == 8)
2864                                            || (v4.r#type == 9)
2865                                            || (v4.r#type == 10)
2866                                            || (v4.r#type == 11)
2867                                            || (v4.r#type == 12)
2868                                            || (v4.r#type == 13)))
2869                                        {
2870                                            return Err(EncodeError::SwitchMismatch(
2871                                                "play.clientbound.entity_metadata.metadata.value",
2872                                            ));
2873                                        }
2874                                    }
2875                                }
2876                                Ok(())
2877                            },
2878                            |b| b != 255,
2879                        ) {
2880                            break v4;
2881                        }
2882                    });
2883                }
2884                v3
2885            };
2886            Self {
2887                entity_id: v1,
2888                metadata: v2,
2889            }
2890        }
2891    }
2892}
2893
2894#[cfg(any(
2895    feature = "v1_12_2",
2896    feature = "v1_16_5",
2897    feature = "v26_1",
2898    feature = "v26_2"
2899))]
2900/// `attach_entity` (clientbound play).
2901#[derive(Debug, Clone, PartialEq)]
2902pub struct AttachEntity<const V: i32> {
2903    /// `entityId`
2904    pub entity_id: i32,
2905    /// `vehicleId`
2906    pub vehicle_id: i32,
2907}
2908#[cfg(any(
2909    feature = "v1_12_2",
2910    feature = "v1_16_5",
2911    feature = "v26_1",
2912    feature = "v26_2"
2913))]
2914impl<const V: i32> Decode for AttachEntity<V> {
2915    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2916        Ok({
2917            let v1 = r.read_i32()?;
2918            let v2 = r.read_i32()?;
2919            Self {
2920                entity_id: v1,
2921                vehicle_id: v2,
2922            }
2923        })
2924    }
2925}
2926#[cfg(any(
2927    feature = "v1_12_2",
2928    feature = "v1_16_5",
2929    feature = "v26_1",
2930    feature = "v26_2"
2931))]
2932impl<const V: i32> Encode for AttachEntity<V> {
2933    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2934        w.put_i32((*self).entity_id);
2935        w.put_i32((*self).vehicle_id);
2936        Ok(())
2937    }
2938}
2939#[cfg(any(
2940    feature = "v1_12_2",
2941    feature = "v1_16_5",
2942    feature = "v26_1",
2943    feature = "v26_2"
2944))]
2945#[cfg(feature = "testgen")]
2946impl<const V: i32> Generate for AttachEntity<V> {
2947    fn generate(g: &mut Gen) -> Self {
2948        {
2949            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2950            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2951            Self {
2952                entity_id: v1,
2953                vehicle_id: v2,
2954            }
2955        }
2956    }
2957}
2958
2959#[cfg(feature = "v1_12_2")]
2960/// `entity_equipment` (clientbound play).
2961#[derive(Debug, Clone, PartialEq)]
2962pub struct EntityEquipment<const V: i32> {
2963    /// `entityId`
2964    pub entity_id: i32,
2965    /// `slot`
2966    pub slot: i32,
2967    /// `item`
2968    pub item: crate::types::slot::legacy::Slot,
2969}
2970#[cfg(feature = "v1_12_2")]
2971impl<const V: i32> Decode for EntityEquipment<V> {
2972    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2973        Ok({
2974            let v1 = r.read_varint()?;
2975            let v2 = r.read_varint()?;
2976            let v3 = <crate::types::slot::legacy::Slot as Decode>::decode(r)?;
2977            Self {
2978                entity_id: v1,
2979                slot: v2,
2980                item: v3,
2981            }
2982        })
2983    }
2984}
2985#[cfg(feature = "v1_12_2")]
2986impl<const V: i32> Encode for EntityEquipment<V> {
2987    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2988        w.put_varint((*self).entity_id);
2989        w.put_varint((*self).slot);
2990        (*self).item.encode(w)?;
2991        Ok(())
2992    }
2993}
2994#[cfg(feature = "v1_12_2")]
2995#[cfg(feature = "testgen")]
2996impl<const V: i32> Generate for EntityEquipment<V> {
2997    fn generate(g: &mut Gen) -> Self {
2998        {
2999            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3000            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3001            let v3 = <crate::types::slot::legacy::Slot as Generate>::generate(g);
3002            Self {
3003                entity_id: v1,
3004                slot: v2,
3005                item: v3,
3006            }
3007        }
3008    }
3009}
3010
3011#[cfg(any(
3012    feature = "v1_12_2",
3013    feature = "v1_16_5",
3014    feature = "v26_1",
3015    feature = "v26_2"
3016))]
3017/// `set_passengers` (clientbound play).
3018#[derive(Debug, Clone, PartialEq)]
3019pub struct SetPassengers<const V: i32> {
3020    /// `entityId`
3021    pub entity_id: i32,
3022    /// `passengers`
3023    pub passengers: Vec<i32>,
3024}
3025#[cfg(any(
3026    feature = "v1_12_2",
3027    feature = "v1_16_5",
3028    feature = "v26_1",
3029    feature = "v26_2"
3030))]
3031impl<const V: i32> Decode for SetPassengers<V> {
3032    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3033        Ok({
3034            let v1 = r.read_varint()?;
3035            let v2 = {
3036                let v3 = {
3037                    let c = r.read_varint()?;
3038                    r.check_count(i64::from(c), 1)?
3039                };
3040                let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
3041                for _ in 0..v3 {
3042                    v4.push(r.read_varint()?);
3043                }
3044                v4
3045            };
3046            Self {
3047                entity_id: v1,
3048                passengers: v2,
3049            }
3050        })
3051    }
3052}
3053#[cfg(any(
3054    feature = "v1_12_2",
3055    feature = "v1_16_5",
3056    feature = "v26_1",
3057    feature = "v26_2"
3058))]
3059impl<const V: i32> Encode for SetPassengers<V> {
3060    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3061        w.put_varint((*self).entity_id);
3062        w.put_len_varint((*self).passengers.len())?;
3063        for v1 in (*self).passengers.iter() {
3064            w.put_varint((*v1));
3065        }
3066        Ok(())
3067    }
3068}
3069#[cfg(any(
3070    feature = "v1_12_2",
3071    feature = "v1_16_5",
3072    feature = "v26_1",
3073    feature = "v26_2"
3074))]
3075#[cfg(feature = "testgen")]
3076impl<const V: i32> Generate for SetPassengers<V> {
3077    fn generate(g: &mut Gen) -> Self {
3078        {
3079            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3080            let v2 = {
3081                let v3 = g.count();
3082                let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
3083                for _ in 0..v3 {
3084                    v4.push((g.int_in(-2147483648, 2147483647, &[]) as i32));
3085                }
3086                v4
3087            };
3088            Self {
3089                entity_id: v1,
3090                passengers: v2,
3091            }
3092        }
3093    }
3094}
3095
3096#[cfg(feature = "v1_12_2")]
3097/// `teams` (clientbound play).
3098#[derive(Debug, Clone, PartialEq)]
3099pub struct Teams<const V: i32> {
3100    /// `team`
3101    pub team: ByteString,
3102    /// `mode`
3103    pub mode: i8,
3104    /// `name`
3105    pub name: Option<ByteString>,
3106    /// `prefix`
3107    pub prefix: Option<ByteString>,
3108    /// `suffix`
3109    pub suffix: Option<ByteString>,
3110    /// `friendlyFire`
3111    pub friendly_fire: Option<i8>,
3112    /// `nameTagVisibility`
3113    pub name_tag_visibility: Option<ByteString>,
3114    /// `collisionRule`
3115    pub collision_rule: Option<ByteString>,
3116    /// `color`
3117    pub color: Option<i8>,
3118    /// `players`
3119    pub players: Option<Vec<ByteString>>,
3120}
3121#[cfg(feature = "v1_12_2")]
3122impl<const V: i32> Decode for Teams<V> {
3123    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3124        Ok({
3125            let v1 = r.read_string()?;
3126            let v2 = r.read_i8()?;
3127            let v3 = if (v2 == 0) || (v2 == 2) {
3128                Some(r.read_string()?)
3129            } else {
3130                None
3131            };
3132            let v4 = if (v2 == 0) || (v2 == 2) {
3133                Some(r.read_string()?)
3134            } else {
3135                None
3136            };
3137            let v5 = if (v2 == 0) || (v2 == 2) {
3138                Some(r.read_string()?)
3139            } else {
3140                None
3141            };
3142            let v6 = if (v2 == 0) || (v2 == 2) {
3143                Some(r.read_i8()?)
3144            } else {
3145                None
3146            };
3147            let v7 = if (v2 == 0) || (v2 == 2) {
3148                Some(r.read_string()?)
3149            } else {
3150                None
3151            };
3152            let v8 = if (v2 == 0) || (v2 == 2) {
3153                Some(r.read_string()?)
3154            } else {
3155                None
3156            };
3157            let v9 = if (v2 == 0) || (v2 == 2) {
3158                Some(r.read_i8()?)
3159            } else {
3160                None
3161            };
3162            let v10 = if (v2 == 0) || (v2 == 3) || (v2 == 4) {
3163                Some({
3164                    let v11 = {
3165                        let c = r.read_varint()?;
3166                        r.check_count(i64::from(c), 1)?
3167                    };
3168                    let mut v12 = Vec::with_capacity(v11.min(crate::codec::PREALLOC_LIMIT));
3169                    for _ in 0..v11 {
3170                        v12.push(r.read_string()?);
3171                    }
3172                    v12
3173                })
3174            } else {
3175                None
3176            };
3177            Self {
3178                team: v1,
3179                mode: v2,
3180                name: v3,
3181                prefix: v4,
3182                suffix: v5,
3183                friendly_fire: v6,
3184                name_tag_visibility: v7,
3185                collision_rule: v8,
3186                color: v9,
3187                players: v10,
3188            }
3189        })
3190    }
3191}
3192#[cfg(feature = "v1_12_2")]
3193impl<const V: i32> Encode for Teams<V> {
3194    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3195        w.put_string(&(*self).team)?;
3196        w.put_i8((*self).mode);
3197        match (&(*self).name, ((*self).mode == 0) || ((*self).mode == 2)) {
3198            (Some(v1), true) => {
3199                w.put_string(&(*v1))?;
3200            }
3201            (None, false) => {}
3202            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.teams.name")),
3203        }
3204        match (&(*self).prefix, ((*self).mode == 0) || ((*self).mode == 2)) {
3205            (Some(v2), true) => {
3206                w.put_string(&(*v2))?;
3207            }
3208            (None, false) => {}
3209            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.teams.prefix")),
3210        }
3211        match (&(*self).suffix, ((*self).mode == 0) || ((*self).mode == 2)) {
3212            (Some(v3), true) => {
3213                w.put_string(&(*v3))?;
3214            }
3215            (None, false) => {}
3216            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.teams.suffix")),
3217        }
3218        match (
3219            &(*self).friendly_fire,
3220            ((*self).mode == 0) || ((*self).mode == 2),
3221        ) {
3222            (Some(v4), true) => {
3223                w.put_i8((*v4));
3224            }
3225            (None, false) => {}
3226            _ => {
3227                return Err(EncodeError::SwitchMismatch(
3228                    "play.clientbound.teams.friendlyFire",
3229                ));
3230            }
3231        }
3232        match (
3233            &(*self).name_tag_visibility,
3234            ((*self).mode == 0) || ((*self).mode == 2),
3235        ) {
3236            (Some(v5), true) => {
3237                w.put_string(&(*v5))?;
3238            }
3239            (None, false) => {}
3240            _ => {
3241                return Err(EncodeError::SwitchMismatch(
3242                    "play.clientbound.teams.nameTagVisibility",
3243                ));
3244            }
3245        }
3246        match (
3247            &(*self).collision_rule,
3248            ((*self).mode == 0) || ((*self).mode == 2),
3249        ) {
3250            (Some(v6), true) => {
3251                w.put_string(&(*v6))?;
3252            }
3253            (None, false) => {}
3254            _ => {
3255                return Err(EncodeError::SwitchMismatch(
3256                    "play.clientbound.teams.collisionRule",
3257                ));
3258            }
3259        }
3260        match (&(*self).color, ((*self).mode == 0) || ((*self).mode == 2)) {
3261            (Some(v7), true) => {
3262                w.put_i8((*v7));
3263            }
3264            (None, false) => {}
3265            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.teams.color")),
3266        }
3267        match (
3268            &(*self).players,
3269            ((*self).mode == 0) || ((*self).mode == 3) || ((*self).mode == 4),
3270        ) {
3271            (Some(v8), true) => {
3272                w.put_len_varint((*v8).len())?;
3273                for v9 in (*v8).iter() {
3274                    w.put_string(&(*v9))?;
3275                }
3276            }
3277            (None, false) => {}
3278            _ => {
3279                return Err(EncodeError::SwitchMismatch(
3280                    "play.clientbound.teams.players",
3281                ));
3282            }
3283        }
3284        Ok(())
3285    }
3286}
3287#[cfg(feature = "v1_12_2")]
3288#[cfg(feature = "testgen")]
3289impl<const V: i32> Generate for Teams<V> {
3290    fn generate(g: &mut Gen) -> Self {
3291        {
3292            let v1 = g.string();
3293            let v2 = (g.int_in(
3294                -128,
3295                127,
3296                &[0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 3, 4],
3297            ) as i8);
3298            let v3 = if (v2 == 0) || (v2 == 2) {
3299                Some(g.string())
3300            } else {
3301                None
3302            };
3303            let v4 = if (v2 == 0) || (v2 == 2) {
3304                Some(g.string())
3305            } else {
3306                None
3307            };
3308            let v5 = if (v2 == 0) || (v2 == 2) {
3309                Some(g.string())
3310            } else {
3311                None
3312            };
3313            let v6 = if (v2 == 0) || (v2 == 2) {
3314                Some((g.int_in(-128, 127, &[]) as i8))
3315            } else {
3316                None
3317            };
3318            let v7 = if (v2 == 0) || (v2 == 2) {
3319                Some(g.string())
3320            } else {
3321                None
3322            };
3323            let v8 = if (v2 == 0) || (v2 == 2) {
3324                Some(g.string())
3325            } else {
3326                None
3327            };
3328            let v9 = if (v2 == 0) || (v2 == 2) {
3329                Some((g.int_in(-128, 127, &[]) as i8))
3330            } else {
3331                None
3332            };
3333            let v10 = if (v2 == 0) || (v2 == 3) || (v2 == 4) {
3334                Some({
3335                    let v11 = g.count();
3336                    let mut v12 = Vec::with_capacity(v11.min(crate::codec::PREALLOC_LIMIT));
3337                    for _ in 0..v11 {
3338                        v12.push(g.string());
3339                    }
3340                    v12
3341                })
3342            } else {
3343                None
3344            };
3345            Self {
3346                team: v1,
3347                mode: v2,
3348                name: v3,
3349                prefix: v4,
3350                suffix: v5,
3351                friendly_fire: v6,
3352                name_tag_visibility: v7,
3353                collision_rule: v8,
3354                color: v9,
3355                players: v10,
3356            }
3357        }
3358    }
3359}
3360
3361#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3362/// `title` (clientbound play).
3363#[derive(Debug, Clone, PartialEq)]
3364pub struct Title<const V: i32> {
3365    /// `action`
3366    pub action: i32,
3367    /// `text`
3368    pub text: Option<ByteString>,
3369    /// `fadeIn`
3370    pub fade_in: Option<i32>,
3371    /// `stay`
3372    pub stay: Option<i32>,
3373    /// `fadeOut`
3374    pub fade_out: Option<i32>,
3375}
3376#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3377impl<const V: i32> Decode for Title<V> {
3378    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3379        Ok({
3380            let v1 = r.read_varint()?;
3381            let v2 = if (v1 == 0) || (v1 == 1) || (v1 == 2) {
3382                Some(r.read_string()?)
3383            } else {
3384                None
3385            };
3386            let v3 = if (v1 == 3) { Some(r.read_i32()?) } else { None };
3387            let v4 = if (v1 == 3) { Some(r.read_i32()?) } else { None };
3388            let v5 = if (v1 == 3) { Some(r.read_i32()?) } else { None };
3389            Self {
3390                action: v1,
3391                text: v2,
3392                fade_in: v3,
3393                stay: v4,
3394                fade_out: v5,
3395            }
3396        })
3397    }
3398}
3399#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3400impl<const V: i32> Encode for Title<V> {
3401    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3402        w.put_varint((*self).action);
3403        match (
3404            &(*self).text,
3405            ((*self).action == 0) || ((*self).action == 1) || ((*self).action == 2),
3406        ) {
3407            (Some(v1), true) => {
3408                w.put_string(&(*v1))?;
3409            }
3410            (None, false) => {}
3411            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.title.text")),
3412        }
3413        match (&(*self).fade_in, ((*self).action == 3)) {
3414            (Some(v2), true) => {
3415                w.put_i32((*v2));
3416            }
3417            (None, false) => {}
3418            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.title.fadeIn")),
3419        }
3420        match (&(*self).stay, ((*self).action == 3)) {
3421            (Some(v3), true) => {
3422                w.put_i32((*v3));
3423            }
3424            (None, false) => {}
3425            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.title.stay")),
3426        }
3427        match (&(*self).fade_out, ((*self).action == 3)) {
3428            (Some(v4), true) => {
3429                w.put_i32((*v4));
3430            }
3431            (None, false) => {}
3432            _ => {
3433                return Err(EncodeError::SwitchMismatch(
3434                    "play.clientbound.title.fadeOut",
3435                ));
3436            }
3437        }
3438        Ok(())
3439    }
3440}
3441#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3442#[cfg(feature = "testgen")]
3443impl<const V: i32> Generate for Title<V> {
3444    fn generate(g: &mut Gen) -> Self {
3445        {
3446            let v1 = (g.int_in(-2147483648, 2147483647, &[0, 1, 2, 3, 3, 3]) as i32);
3447            let v2 = if (v1 == 0) || (v1 == 1) || (v1 == 2) {
3448                Some(g.string())
3449            } else {
3450                None
3451            };
3452            let v3 = if (v1 == 3) {
3453                Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
3454            } else {
3455                None
3456            };
3457            let v4 = if (v1 == 3) {
3458                Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
3459            } else {
3460                None
3461            };
3462            let v5 = if (v1 == 3) {
3463                Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
3464            } else {
3465                None
3466            };
3467            Self {
3468                action: v1,
3469                text: v2,
3470                fade_in: v3,
3471                stay: v4,
3472                fade_out: v5,
3473            }
3474        }
3475    }
3476}
3477
3478#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3479/// `sound_effect` (clientbound play).
3480#[derive(Debug, Clone, PartialEq)]
3481pub struct SoundEffect<const V: i32> {
3482    /// `soundId`
3483    pub sound_id: i32,
3484    /// `soundCategory`
3485    pub sound_category: i32,
3486    /// `x`
3487    pub x: i32,
3488    /// `y`
3489    pub y: i32,
3490    /// `z`
3491    pub z: i32,
3492    /// `volume`
3493    pub volume: f32,
3494    /// `pitch`
3495    pub pitch: f32,
3496}
3497#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3498impl<const V: i32> Decode for SoundEffect<V> {
3499    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3500        Ok({
3501            let v1 = r.read_varint()?;
3502            let v2 = r.read_varint()?;
3503            let v3 = r.read_i32()?;
3504            let v4 = r.read_i32()?;
3505            let v5 = r.read_i32()?;
3506            let v6 = r.read_f32()?;
3507            let v7 = r.read_f32()?;
3508            Self {
3509                sound_id: v1,
3510                sound_category: v2,
3511                x: v3,
3512                y: v4,
3513                z: v5,
3514                volume: v6,
3515                pitch: v7,
3516            }
3517        })
3518    }
3519}
3520#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3521impl<const V: i32> Encode for SoundEffect<V> {
3522    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3523        w.put_varint((*self).sound_id);
3524        w.put_varint((*self).sound_category);
3525        w.put_i32((*self).x);
3526        w.put_i32((*self).y);
3527        w.put_i32((*self).z);
3528        w.put_f32((*self).volume);
3529        w.put_f32((*self).pitch);
3530        Ok(())
3531    }
3532}
3533#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3534#[cfg(feature = "testgen")]
3535impl<const V: i32> Generate for SoundEffect<V> {
3536    fn generate(g: &mut Gen) -> Self {
3537        {
3538            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3539            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3540            let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3541            let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3542            let v5 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3543            let v6 = g.f32();
3544            let v7 = g.f32();
3545            Self {
3546                sound_id: v1,
3547                sound_category: v2,
3548                x: v3,
3549                y: v4,
3550                z: v5,
3551                volume: v6,
3552                pitch: v7,
3553            }
3554        }
3555    }
3556}
3557
3558#[cfg(any(
3559    feature = "v1_12_2",
3560    feature = "v1_16_5",
3561    feature = "v26_1",
3562    feature = "v26_2"
3563))]
3564/// `collect` (clientbound play).
3565#[derive(Debug, Clone, PartialEq)]
3566pub struct Collect<const V: i32> {
3567    /// `collectedEntityId`
3568    pub collected_entity_id: i32,
3569    /// `collectorEntityId`
3570    pub collector_entity_id: i32,
3571    /// `pickupItemCount`
3572    pub pickup_item_count: i32,
3573}
3574#[cfg(any(
3575    feature = "v1_12_2",
3576    feature = "v1_16_5",
3577    feature = "v26_1",
3578    feature = "v26_2"
3579))]
3580impl<const V: i32> Decode for Collect<V> {
3581    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3582        Ok({
3583            let v1 = r.read_varint()?;
3584            let v2 = r.read_varint()?;
3585            let v3 = r.read_varint()?;
3586            Self {
3587                collected_entity_id: v1,
3588                collector_entity_id: v2,
3589                pickup_item_count: v3,
3590            }
3591        })
3592    }
3593}
3594#[cfg(any(
3595    feature = "v1_12_2",
3596    feature = "v1_16_5",
3597    feature = "v26_1",
3598    feature = "v26_2"
3599))]
3600impl<const V: i32> Encode for Collect<V> {
3601    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3602        w.put_varint((*self).collected_entity_id);
3603        w.put_varint((*self).collector_entity_id);
3604        w.put_varint((*self).pickup_item_count);
3605        Ok(())
3606    }
3607}
3608#[cfg(any(
3609    feature = "v1_12_2",
3610    feature = "v1_16_5",
3611    feature = "v26_1",
3612    feature = "v26_2"
3613))]
3614#[cfg(feature = "testgen")]
3615impl<const V: i32> Generate for Collect<V> {
3616    fn generate(g: &mut Gen) -> Self {
3617        {
3618            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3619            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3620            let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3621            Self {
3622                collected_entity_id: v1,
3623                collector_entity_id: v2,
3624                pickup_item_count: v3,
3625            }
3626        }
3627    }
3628}
3629
3630#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3631/// `entity_teleport` (clientbound play).
3632#[derive(Debug, Clone, PartialEq)]
3633pub struct EntityTeleport<const V: i32> {
3634    /// `entityId`
3635    pub entity_id: i32,
3636    /// `x`
3637    pub x: f64,
3638    /// `y`
3639    pub y: f64,
3640    /// `z`
3641    pub z: f64,
3642    /// `yaw`
3643    pub yaw: i8,
3644    /// `pitch`
3645    pub pitch: i8,
3646    /// `onGround`
3647    pub on_ground: bool,
3648}
3649#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3650impl<const V: i32> Decode for EntityTeleport<V> {
3651    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3652        Ok({
3653            let v1 = r.read_varint()?;
3654            let v2 = r.read_f64()?;
3655            let v3 = r.read_f64()?;
3656            let v4 = r.read_f64()?;
3657            let v5 = r.read_i8()?;
3658            let v6 = r.read_i8()?;
3659            let v7 = r.read_bool()?;
3660            Self {
3661                entity_id: v1,
3662                x: v2,
3663                y: v3,
3664                z: v4,
3665                yaw: v5,
3666                pitch: v6,
3667                on_ground: v7,
3668            }
3669        })
3670    }
3671}
3672#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3673impl<const V: i32> Encode for EntityTeleport<V> {
3674    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3675        w.put_varint((*self).entity_id);
3676        w.put_f64((*self).x);
3677        w.put_f64((*self).y);
3678        w.put_f64((*self).z);
3679        w.put_i8((*self).yaw);
3680        w.put_i8((*self).pitch);
3681        w.put_bool((*self).on_ground);
3682        Ok(())
3683    }
3684}
3685#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3686#[cfg(feature = "testgen")]
3687impl<const V: i32> Generate for EntityTeleport<V> {
3688    fn generate(g: &mut Gen) -> Self {
3689        {
3690            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3691            let v2 = g.f64();
3692            let v3 = g.f64();
3693            let v4 = g.f64();
3694            let v5 = (g.int_in(-128, 127, &[]) as i8);
3695            let v6 = (g.int_in(-128, 127, &[]) as i8);
3696            let v7 = g.bool();
3697            Self {
3698                entity_id: v1,
3699                x: v2,
3700                y: v3,
3701                z: v4,
3702                yaw: v5,
3703                pitch: v6,
3704                on_ground: v7,
3705            }
3706        }
3707    }
3708}
3709
3710#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3711/// Packed bit field.
3712#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
3713pub struct AdvancementsAdvancementMappingValueDisplayDataFlags {
3714    /// `_unused` (29 bits)
3715    pub _unused: u32,
3716    /// `hidden` (1 bits)
3717    pub hidden: u8,
3718    /// `show_toast` (1 bits)
3719    pub show_toast: u8,
3720    /// `has_background_texture` (1 bits)
3721    pub has_background_texture: u8,
3722}
3723
3724#[cfg(feature = "v1_12_2")]
3725/// Nested container.
3726#[derive(Debug, Clone, PartialEq)]
3727pub struct AdvancementsAdvancementMappingValueDisplayData {
3728    /// `title`
3729    pub title: ByteString,
3730    /// `description`
3731    pub description: ByteString,
3732    /// `icon`
3733    pub icon: crate::types::slot::legacy::Slot,
3734    /// `frameType`
3735    pub frame_type: i32,
3736    /// `flags`
3737    pub flags:
3738        crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueDisplayDataFlags,
3739    /// `backgroundTexture`
3740    pub background_texture: Option<ByteString>,
3741    /// `xCord`
3742    pub x_cord: f32,
3743    /// `yCord`
3744    pub y_cord: f32,
3745}
3746
3747#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3748/// Nested container.
3749#[derive(Debug, Clone, PartialEq)]
3750pub struct AdvancementsAdvancementMappingValueCriteria {
3751    /// `key`
3752    pub key: ByteString,
3753}
3754
3755#[cfg(feature = "v1_12_2")]
3756/// Nested container.
3757#[derive(Debug, Clone, PartialEq)]
3758pub struct AdvancementsAdvancementMappingValue {
3759    /// `parentId`
3760    pub parent_id: Option<ByteString>,
3761    /// `displayData`
3762    pub display_data: Option<
3763        crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueDisplayData,
3764    >,
3765    /// `criteria`
3766    pub criteria:
3767        Vec<crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueCriteria>,
3768    /// `requirements`
3769    pub requirements: Vec<Vec<ByteString>>,
3770}
3771
3772#[cfg(feature = "v1_12_2")]
3773/// Nested container.
3774#[derive(Debug, Clone, PartialEq)]
3775pub struct AdvancementsAdvancementMapping {
3776    /// `key`
3777    pub key: ByteString,
3778    /// `value`
3779    pub value: crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValue,
3780}
3781
3782#[cfg(any(
3783    feature = "v1_12_2",
3784    feature = "v1_16_5",
3785    feature = "v26_1",
3786    feature = "v26_2"
3787))]
3788/// Nested container.
3789#[derive(Debug, Clone, PartialEq)]
3790pub struct AdvancementsProgressMappingValue {
3791    /// `criterionIdentifier`
3792    pub criterion_identifier: ByteString,
3793    /// `criterionProgress`
3794    pub criterion_progress: Option<i64>,
3795}
3796
3797#[cfg(any(
3798    feature = "v1_12_2",
3799    feature = "v1_16_5",
3800    feature = "v26_1",
3801    feature = "v26_2"
3802))]
3803/// Nested container.
3804#[derive(Debug, Clone, PartialEq)]
3805pub struct AdvancementsProgressMapping {
3806    /// `key`
3807    pub key: ByteString,
3808    /// `value`
3809    pub value: Vec<crate::defs::p340::play::clientbound::AdvancementsProgressMappingValue>,
3810}
3811
3812#[cfg(feature = "v1_12_2")]
3813/// `advancements` (clientbound play).
3814#[derive(Debug, Clone, PartialEq)]
3815pub struct Advancements<const V: i32> {
3816    /// `reset`
3817    pub reset: bool,
3818    /// `advancementMapping`
3819    pub advancement_mapping:
3820        Vec<crate::defs::p340::play::clientbound::AdvancementsAdvancementMapping>,
3821    /// `identifiers`
3822    pub identifiers: Vec<ByteString>,
3823    /// `progressMapping`
3824    pub progress_mapping: Vec<crate::defs::p340::play::clientbound::AdvancementsProgressMapping>,
3825}
3826#[cfg(feature = "v1_12_2")]
3827impl<const V: i32> Decode for Advancements<V> {
3828    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3829        Ok({
3830            let v1 = r.read_bool()?;
3831            let v2 = {
3832                let v3 = {
3833                    let c = r.read_varint()?;
3834                    r.check_count(i64::from(c), 5)?
3835                };
3836                let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
3837                for _ in 0..v3 {
3838                    v4.push({ let v5 = r.read_string()?;let v6 = { let v7 = if r.read_bool()? { Some(r.read_string()?) } else { None };let v8 = if r.read_bool()? { Some({ let v9 = r.read_string()?;let v10 = r.read_string()?;let v11 = <crate::types::slot::legacy::Slot as Decode>::decode(r)?;let v12 = r.read_varint()?;let v13 = { let v14 = u64::from(r.read_i32()? as u32); crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueDisplayDataFlags { _unused: (((v14 >> 3) & 0x1fffffff) as u32), hidden: (((v14 >> 2) & 0x1) as u8), show_toast: (((v14 >> 1) & 0x1) as u8), has_background_texture: (((v14 >> 0) & 0x1) as u8) } };let v15 = if (v13.has_background_texture == 1) { Some(r.read_string()?) } else { None };let v16 = r.read_f32()?;let v17 = r.read_f32()?; crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueDisplayData { title: v9, description: v10, icon: v11, frame_type: v12, flags: v13, background_texture: v15, x_cord: v16, y_cord: v17 } }) } else { None };let v18 = { let v19 = { let c = r.read_varint()?; r.check_count(i64::from(c), 1)? }; let mut v20 = Vec::with_capacity(v19.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v19 { v20.push({ let v21 = r.read_string()?; crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueCriteria { key: v21 } }); } v20 };let v23 = { let v24 = { let c = r.read_varint()?; r.check_count(i64::from(c), 1)? }; let mut v25 = Vec::with_capacity(v24.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v24 { v25.push({ let v26 = { let c = r.read_varint()?; r.check_count(i64::from(c), 1)? }; let mut v27 = Vec::with_capacity(v26.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v26 { v27.push(r.read_string()?); } v27 }); } v25 }; crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValue { parent_id: v7, display_data: v8, criteria: v18, requirements: v23 } }; crate::defs::p340::play::clientbound::AdvancementsAdvancementMapping { key: v5, value: v6 } });
3839                }
3840                v4
3841            };
3842            let v28 = {
3843                let v29 = {
3844                    let c = r.read_varint()?;
3845                    r.check_count(i64::from(c), 1)?
3846                };
3847                let mut v30 = Vec::with_capacity(v29.min(crate::codec::PREALLOC_LIMIT));
3848                for _ in 0..v29 {
3849                    v30.push(r.read_string()?);
3850                }
3851                v30
3852            };
3853            let v31 = {
3854                let v32 = {
3855                    let c = r.read_varint()?;
3856                    r.check_count(i64::from(c), 2)?
3857                };
3858                let mut v33 = Vec::with_capacity(v32.min(crate::codec::PREALLOC_LIMIT));
3859                for _ in 0..v32 {
3860                    v33.push({ let v34 = r.read_string()?;let v35 = { let v36 = { let c = r.read_varint()?; r.check_count(i64::from(c), 2)? }; let mut v37 = Vec::with_capacity(v36.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v36 { v37.push({ let v38 = r.read_string()?;let v39 = if r.read_bool()? { Some(r.read_i64()?) } else { None }; crate::defs::p340::play::clientbound::AdvancementsProgressMappingValue { criterion_identifier: v38, criterion_progress: v39 } }); } v37 }; crate::defs::p340::play::clientbound::AdvancementsProgressMapping { key: v34, value: v35 } });
3861                }
3862                v33
3863            };
3864            Self {
3865                reset: v1,
3866                advancement_mapping: v2,
3867                identifiers: v28,
3868                progress_mapping: v31,
3869            }
3870        })
3871    }
3872}
3873#[cfg(feature = "v1_12_2")]
3874impl<const V: i32> Encode for Advancements<V> {
3875    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3876        w.put_bool((*self).reset);
3877        w.put_len_varint((*self).advancement_mapping.len())?;
3878        for v1 in (*self).advancement_mapping.iter() {
3879            w.put_string(&(*v1).key)?;
3880            match &(*v1).value.parent_id {
3881                Some(v2) => {
3882                    w.put_u8(1);
3883                    w.put_string(&(*v2))?;
3884                }
3885                None => w.put_u8(0),
3886            }
3887            match &(*v1).value.display_data {
3888                Some(v3) => {
3889                    w.put_u8(1);
3890                    w.put_string(&(*v3).title)?;
3891                    w.put_string(&(*v3).description)?;
3892                    (*v3).icon.encode(w)?;
3893                    w.put_varint((*v3).frame_type);
3894                    {
3895                        let mut bits: u64 = 0;
3896                        {
3897                            let x = i128::from((*v3).flags._unused);
3898                            if x < 0 || x > 536870911 {
3899                                return Err(EncodeError::OutOfRange("_unused"));
3900                            }
3901                            bits = (bits << 29) | ((x as u64) & 0x1fffffff);
3902                        }
3903                        {
3904                            let x = i128::from((*v3).flags.hidden);
3905                            if x < 0 || x > 1 {
3906                                return Err(EncodeError::OutOfRange("hidden"));
3907                            }
3908                            bits = (bits << 1) | ((x as u64) & 0x1);
3909                        }
3910                        {
3911                            let x = i128::from((*v3).flags.show_toast);
3912                            if x < 0 || x > 1 {
3913                                return Err(EncodeError::OutOfRange("show_toast"));
3914                            }
3915                            bits = (bits << 1) | ((x as u64) & 0x1);
3916                        }
3917                        {
3918                            let x = i128::from((*v3).flags.has_background_texture);
3919                            if x < 0 || x > 1 {
3920                                return Err(EncodeError::OutOfRange("has_background_texture"));
3921                            }
3922                            bits = (bits << 1) | ((x as u64) & 0x1);
3923                        }
3924                        w.put_u32(bits as u32);
3925                    }
3926                    match (
3927                        &(*v3).background_texture,
3928                        ((*v3).flags.has_background_texture == 1),
3929                    ) {
3930                        (Some(v4), true) => {
3931                            w.put_string(&(*v4))?;
3932                        }
3933                        (None, false) => {}
3934                        _ => {
3935                            return Err(EncodeError::SwitchMismatch(
3936                                "play.clientbound.advancements.advancementMapping.value.displayData.backgroundTexture",
3937                            ));
3938                        }
3939                    }
3940                    w.put_f32((*v3).x_cord);
3941                    w.put_f32((*v3).y_cord);
3942                }
3943                None => w.put_u8(0),
3944            }
3945            w.put_len_varint((*v1).value.criteria.len())?;
3946            for v5 in (*v1).value.criteria.iter() {
3947                w.put_string(&(*v5).key)?;
3948            }
3949            w.put_len_varint((*v1).value.requirements.len())?;
3950            for v6 in (*v1).value.requirements.iter() {
3951                w.put_len_varint((*v6).len())?;
3952                for v7 in (*v6).iter() {
3953                    w.put_string(&(*v7))?;
3954                }
3955            }
3956        }
3957        w.put_len_varint((*self).identifiers.len())?;
3958        for v8 in (*self).identifiers.iter() {
3959            w.put_string(&(*v8))?;
3960        }
3961        w.put_len_varint((*self).progress_mapping.len())?;
3962        for v9 in (*self).progress_mapping.iter() {
3963            w.put_string(&(*v9).key)?;
3964            w.put_len_varint((*v9).value.len())?;
3965            for v10 in (*v9).value.iter() {
3966                w.put_string(&(*v10).criterion_identifier)?;
3967                match &(*v10).criterion_progress {
3968                    Some(v11) => {
3969                        w.put_u8(1);
3970                        w.put_i64((*v11));
3971                    }
3972                    None => w.put_u8(0),
3973                }
3974            }
3975        }
3976        Ok(())
3977    }
3978}
3979#[cfg(feature = "v1_12_2")]
3980#[cfg(feature = "testgen")]
3981impl<const V: i32> Generate for Advancements<V> {
3982    fn generate(g: &mut Gen) -> Self {
3983        {
3984            let v1 = g.bool();
3985            let v2 = {
3986                let v3 = g.count();
3987                let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
3988                for _ in 0..v3 {
3989                    v4.push({ let v5 = g.string();let v6 = { let v7 = if g.bool() { Some(g.string()) } else { None };let v8 = if g.bool() { Some({ let v9 = g.string();let v10 = g.string();let v11 = <crate::types::slot::legacy::Slot as Generate>::generate(g);let v12 = (g.int_in(-2147483648, 2147483647, &[]) as i32);let v13 = {  crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueDisplayDataFlags { _unused: (g.int_in(0, 536870911, &[]) as u32), hidden: (g.int_in(0, 1, &[]) as u8), show_toast: (g.int_in(0, 1, &[]) as u8), has_background_texture: (g.int_in(0, 1, &[1]) as u8) } };let v15 = if (v13.has_background_texture == 1) { Some(g.string()) } else { None };let v16 = g.f32();let v17 = g.f32(); crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueDisplayData { title: v9, description: v10, icon: v11, frame_type: v12, flags: v13, background_texture: v15, x_cord: v16, y_cord: v17 } }) } else { None };let v18 = { let v19 = g.count(); let mut v20 = Vec::with_capacity(v19.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v19 { v20.push({ let v21 = g.string(); crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueCriteria { key: v21 } }); } v20 };let v23 = { let v24 = g.count(); let mut v25 = Vec::with_capacity(v24.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v24 { v25.push({ let v26 = g.count(); let mut v27 = Vec::with_capacity(v26.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v26 { v27.push(g.string()); } v27 }); } v25 }; crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValue { parent_id: v7, display_data: v8, criteria: v18, requirements: v23 } }; crate::defs::p340::play::clientbound::AdvancementsAdvancementMapping { key: v5, value: v6 } });
3990                }
3991                v4
3992            };
3993            let v28 = {
3994                let v29 = g.count();
3995                let mut v30 = Vec::with_capacity(v29.min(crate::codec::PREALLOC_LIMIT));
3996                for _ in 0..v29 {
3997                    v30.push(g.string());
3998                }
3999                v30
4000            };
4001            let v31 = {
4002                let v32 = g.count();
4003                let mut v33 = Vec::with_capacity(v32.min(crate::codec::PREALLOC_LIMIT));
4004                for _ in 0..v32 {
4005                    v33.push({ let v34 = g.string();let v35 = { let v36 = g.count(); let mut v37 = Vec::with_capacity(v36.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v36 { v37.push({ let v38 = g.string();let v39 = if g.bool() { Some(g.i64()) } else { None }; crate::defs::p340::play::clientbound::AdvancementsProgressMappingValue { criterion_identifier: v38, criterion_progress: v39 } }); } v37 }; crate::defs::p340::play::clientbound::AdvancementsProgressMapping { key: v34, value: v35 } });
4006                }
4007                v33
4008            };
4009            Self {
4010                reset: v1,
4011                advancement_mapping: v2,
4012                identifiers: v28,
4013                progress_mapping: v31,
4014            }
4015        }
4016    }
4017}
4018
4019#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4020/// Nested container.
4021#[derive(Debug, Clone, PartialEq)]
4022pub struct EntityUpdateAttributesPropertiesModifiers {
4023    /// `uuid`
4024    pub uuid: Uuid,
4025    /// `amount`
4026    pub amount: f64,
4027    /// `operation`
4028    pub operation: i8,
4029}
4030
4031#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4032/// Nested container.
4033#[derive(Debug, Clone, PartialEq)]
4034pub struct EntityUpdateAttributesProperties {
4035    /// `key`
4036    pub key: ByteString,
4037    /// `value`
4038    pub value: f64,
4039    /// `modifiers`
4040    pub modifiers:
4041        Vec<crate::defs::p340::play::clientbound::EntityUpdateAttributesPropertiesModifiers>,
4042}
4043
4044#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4045/// `entity_update_attributes` (clientbound play).
4046#[derive(Debug, Clone, PartialEq)]
4047pub struct EntityUpdateAttributes<const V: i32> {
4048    /// `entityId`
4049    pub entity_id: i32,
4050    /// `properties`
4051    pub properties: Vec<crate::defs::p340::play::clientbound::EntityUpdateAttributesProperties>,
4052}
4053#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4054impl<const V: i32> Decode for EntityUpdateAttributes<V> {
4055    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
4056        Ok({
4057            let v1 = r.read_varint()?;
4058            let v2 = {
4059                let v3 = {
4060                    let c = r.read_i32()?;
4061                    r.check_count(i64::from(c), 10)?
4062                };
4063                let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
4064                for _ in 0..v3 {
4065                    v4.push({ let v5 = r.read_string()?;let v6 = r.read_f64()?;let v7 = { let v8 = { let c = r.read_varint()?; r.check_count(i64::from(c), 25)? }; let mut v9 = Vec::with_capacity(v8.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v8 { v9.push({ let v10 = r.read_uuid()?;let v11 = r.read_f64()?;let v12 = r.read_i8()?; crate::defs::p340::play::clientbound::EntityUpdateAttributesPropertiesModifiers { uuid: v10, amount: v11, operation: v12 } }); } v9 }; crate::defs::p340::play::clientbound::EntityUpdateAttributesProperties { key: v5, value: v6, modifiers: v7 } });
4066                }
4067                v4
4068            };
4069            Self {
4070                entity_id: v1,
4071                properties: v2,
4072            }
4073        })
4074    }
4075}
4076#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4077impl<const V: i32> Encode for EntityUpdateAttributes<V> {
4078    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
4079        w.put_varint((*self).entity_id);
4080        w.put_i32(crate::codec::count_i32((*self).properties.len())?);
4081        for v1 in (*self).properties.iter() {
4082            w.put_string(&(*v1).key)?;
4083            w.put_f64((*v1).value);
4084            w.put_len_varint((*v1).modifiers.len())?;
4085            for v2 in (*v1).modifiers.iter() {
4086                w.put_uuid(&(*v2).uuid);
4087                w.put_f64((*v2).amount);
4088                w.put_i8((*v2).operation);
4089            }
4090        }
4091        Ok(())
4092    }
4093}
4094#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4095#[cfg(feature = "testgen")]
4096impl<const V: i32> Generate for EntityUpdateAttributes<V> {
4097    fn generate(g: &mut Gen) -> Self {
4098        {
4099            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
4100            let v2 = {
4101                let v3 = g.count();
4102                let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
4103                for _ in 0..v3 {
4104                    v4.push({ let v5 = g.string();let v6 = g.f64();let v7 = { let v8 = g.count(); let mut v9 = Vec::with_capacity(v8.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v8 { v9.push({ let v10 = g.uuid();let v11 = g.f64();let v12 = (g.int_in(-128, 127, &[]) as i8); crate::defs::p340::play::clientbound::EntityUpdateAttributesPropertiesModifiers { uuid: v10, amount: v11, operation: v12 } }); } v9 }; crate::defs::p340::play::clientbound::EntityUpdateAttributesProperties { key: v5, value: v6, modifiers: v7 } });
4105                }
4106                v4
4107            };
4108            Self {
4109                entity_id: v1,
4110                properties: v2,
4111            }
4112        }
4113    }
4114}
4115
4116#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4117/// `entity_effect` (clientbound play).
4118#[derive(Debug, Clone, PartialEq)]
4119pub struct EntityEffect<const V: i32> {
4120    /// `entityId`
4121    pub entity_id: i32,
4122    /// `effectId`
4123    pub effect_id: i8,
4124    /// `amplifier`
4125    pub amplifier: i8,
4126    /// `duration`
4127    pub duration: i32,
4128    /// `hideParticles`
4129    pub hide_particles: i8,
4130}
4131#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4132impl<const V: i32> Decode for EntityEffect<V> {
4133    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
4134        Ok({
4135            let v1 = r.read_varint()?;
4136            let v2 = r.read_i8()?;
4137            let v3 = r.read_i8()?;
4138            let v4 = r.read_varint()?;
4139            let v5 = r.read_i8()?;
4140            Self {
4141                entity_id: v1,
4142                effect_id: v2,
4143                amplifier: v3,
4144                duration: v4,
4145                hide_particles: v5,
4146            }
4147        })
4148    }
4149}
4150#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4151impl<const V: i32> Encode for EntityEffect<V> {
4152    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
4153        w.put_varint((*self).entity_id);
4154        w.put_i8((*self).effect_id);
4155        w.put_i8((*self).amplifier);
4156        w.put_varint((*self).duration);
4157        w.put_i8((*self).hide_particles);
4158        Ok(())
4159    }
4160}
4161#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4162#[cfg(feature = "testgen")]
4163impl<const V: i32> Generate for EntityEffect<V> {
4164    fn generate(g: &mut Gen) -> Self {
4165        {
4166            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
4167            let v2 = (g.int_in(-128, 127, &[]) as i8);
4168            let v3 = (g.int_in(-128, 127, &[]) as i8);
4169            let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
4170            let v5 = (g.int_in(-128, 127, &[]) as i8);
4171            Self {
4172                entity_id: v1,
4173                effect_id: v2,
4174                amplifier: v3,
4175                duration: v4,
4176                hide_particles: v5,
4177            }
4178        }
4179    }
4180}