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    feature = "v26_3"
1373))]
1374/// `keep_alive` (clientbound play).
1375#[derive(Debug, Clone, PartialEq)]
1376pub struct KeepAlive<const V: i32> {
1377    /// `keepAliveId`
1378    pub keep_alive_id: i64,
1379}
1380#[cfg(any(
1381    feature = "v1_12_2",
1382    feature = "v1_16_5",
1383    feature = "v26_1",
1384    feature = "v26_2",
1385    feature = "v26_3"
1386))]
1387impl<const V: i32> Decode for KeepAlive<V> {
1388    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1389        Ok({
1390            let v1 = r.read_i64()?;
1391            Self { keep_alive_id: v1 }
1392        })
1393    }
1394}
1395#[cfg(any(
1396    feature = "v1_12_2",
1397    feature = "v1_16_5",
1398    feature = "v26_1",
1399    feature = "v26_2",
1400    feature = "v26_3"
1401))]
1402impl<const V: i32> Encode for KeepAlive<V> {
1403    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1404        w.put_i64((*self).keep_alive_id);
1405        Ok(())
1406    }
1407}
1408#[cfg(any(
1409    feature = "v1_12_2",
1410    feature = "v1_16_5",
1411    feature = "v26_1",
1412    feature = "v26_2",
1413    feature = "v26_3"
1414))]
1415#[cfg(feature = "testgen")]
1416impl<const V: i32> Generate for KeepAlive<V> {
1417    fn generate(g: &mut Gen) -> Self {
1418        {
1419            let v1 = g.i64();
1420            Self { keep_alive_id: v1 }
1421        }
1422    }
1423}
1424
1425#[cfg(feature = "v1_12_2")]
1426/// `map_chunk` (clientbound play).
1427#[derive(Debug, Clone, PartialEq)]
1428pub struct MapChunk<const V: i32> {
1429    /// `x`
1430    pub x: i32,
1431    /// `z`
1432    pub z: i32,
1433    /// `groundUp`
1434    pub ground_up: bool,
1435    /// `bitMap`
1436    pub bit_map: i32,
1437    /// `chunkData`
1438    pub chunk_data: Bytes,
1439    /// `blockEntities`
1440    pub block_entities: Vec<RawNbt>,
1441}
1442#[cfg(feature = "v1_12_2")]
1443impl<const V: i32> Decode for MapChunk<V> {
1444    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1445        Ok({
1446            let v1 = r.read_i32()?;
1447            let v2 = r.read_i32()?;
1448            let v3 = r.read_bool()?;
1449            let v4 = r.read_varint()?;
1450            let v5 = r.read_byte_array()?;
1451            let v6 = {
1452                let v7 = {
1453                    let c = r.read_varint()?;
1454                    r.check_count(i64::from(c), 1)?
1455                };
1456                let mut v8 = Vec::with_capacity(v7.min(crate::codec::PREALLOC_LIMIT));
1457                for _ in 0..v7 {
1458                    v8.push(RawNbt::read(r)?);
1459                }
1460                v8
1461            };
1462            Self {
1463                x: v1,
1464                z: v2,
1465                ground_up: v3,
1466                bit_map: v4,
1467                chunk_data: v5,
1468                block_entities: v6,
1469            }
1470        })
1471    }
1472}
1473#[cfg(feature = "v1_12_2")]
1474impl<const V: i32> Encode for MapChunk<V> {
1475    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1476        w.put_i32((*self).x);
1477        w.put_i32((*self).z);
1478        w.put_bool((*self).ground_up);
1479        w.put_varint((*self).bit_map);
1480        w.put_byte_array(&(*self).chunk_data)?;
1481        w.put_len_varint((*self).block_entities.len())?;
1482        for v1 in (*self).block_entities.iter() {
1483            (*v1).write(w);
1484        }
1485        Ok(())
1486    }
1487}
1488#[cfg(feature = "v1_12_2")]
1489#[cfg(feature = "testgen")]
1490impl<const V: i32> Generate for MapChunk<V> {
1491    fn generate(g: &mut Gen) -> Self {
1492        {
1493            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1494            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1495            let v3 = g.bool();
1496            let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1497            let v5 = g.bytes();
1498            let v6 = {
1499                let v7 = g.count();
1500                let mut v8 = Vec::with_capacity(v7.min(crate::codec::PREALLOC_LIMIT));
1501                for _ in 0..v7 {
1502                    v8.push(g.nbt());
1503                }
1504                v8
1505            };
1506            Self {
1507                x: v1,
1508                z: v2,
1509                ground_up: v3,
1510                bit_map: v4,
1511                chunk_data: v5,
1512                block_entities: v6,
1513            }
1514        }
1515    }
1516}
1517
1518#[cfg(feature = "v1_12_2")]
1519/// `login` (clientbound play).
1520#[derive(Debug, Clone, PartialEq)]
1521pub struct Login<const V: i32> {
1522    /// `entityId`
1523    pub entity_id: i32,
1524    /// `gameMode`
1525    pub game_mode: u8,
1526    /// `dimension`
1527    pub dimension: i32,
1528    /// `difficulty`
1529    pub difficulty: u8,
1530    /// `maxPlayers`
1531    pub max_players: u8,
1532    /// `levelType`
1533    pub level_type: ByteString,
1534    /// `reducedDebugInfo`
1535    pub reduced_debug_info: bool,
1536}
1537#[cfg(feature = "v1_12_2")]
1538impl<const V: i32> Decode for Login<V> {
1539    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1540        Ok({
1541            let v1 = r.read_i32()?;
1542            let v2 = r.read_u8()?;
1543            let v3 = r.read_i32()?;
1544            let v4 = r.read_u8()?;
1545            let v5 = r.read_u8()?;
1546            let v6 = r.read_string()?;
1547            let v7 = r.read_bool()?;
1548            Self {
1549                entity_id: v1,
1550                game_mode: v2,
1551                dimension: v3,
1552                difficulty: v4,
1553                max_players: v5,
1554                level_type: v6,
1555                reduced_debug_info: v7,
1556            }
1557        })
1558    }
1559}
1560#[cfg(feature = "v1_12_2")]
1561impl<const V: i32> Encode for Login<V> {
1562    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1563        w.put_i32((*self).entity_id);
1564        w.put_u8((*self).game_mode);
1565        w.put_i32((*self).dimension);
1566        w.put_u8((*self).difficulty);
1567        w.put_u8((*self).max_players);
1568        w.put_string(&(*self).level_type)?;
1569        w.put_bool((*self).reduced_debug_info);
1570        Ok(())
1571    }
1572}
1573#[cfg(feature = "v1_12_2")]
1574#[cfg(feature = "testgen")]
1575impl<const V: i32> Generate for Login<V> {
1576    fn generate(g: &mut Gen) -> Self {
1577        {
1578            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1579            let v2 = (g.int_in(0, 255, &[]) as u8);
1580            let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1581            let v4 = (g.int_in(0, 255, &[]) as u8);
1582            let v5 = (g.int_in(0, 255, &[]) as u8);
1583            let v6 = g.string();
1584            let v7 = g.bool();
1585            Self {
1586                entity_id: v1,
1587                game_mode: v2,
1588                dimension: v3,
1589                difficulty: v4,
1590                max_players: v5,
1591                level_type: v6,
1592                reduced_debug_info: v7,
1593            }
1594        }
1595    }
1596}
1597
1598#[cfg(feature = "v1_12_2")]
1599/// `map` (clientbound play).
1600#[derive(Debug, Clone, PartialEq)]
1601pub struct Map<const V: i32> {
1602    /// `itemDamage`
1603    pub item_damage: i32,
1604    /// `scale`
1605    pub scale: i8,
1606    /// `trackingPosition`
1607    pub tracking_position: bool,
1608    /// `icons`
1609    pub icons: Vec<crate::defs::p47::play::clientbound::MapIcons>,
1610    /// `columns`
1611    pub columns: i8,
1612    /// `rows`
1613    pub rows: Option<i8>,
1614    /// `x`
1615    pub x: Option<i8>,
1616    /// `y`
1617    pub y: Option<i8>,
1618    /// `data`
1619    pub data: Option<Bytes>,
1620}
1621#[cfg(feature = "v1_12_2")]
1622impl<const V: i32> Decode for Map<V> {
1623    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1624        Ok({
1625            let v1 = r.read_varint()?;
1626            let v2 = r.read_i8()?;
1627            let v3 = r.read_bool()?;
1628            let v4 = {
1629                let v5 = {
1630                    let c = r.read_varint()?;
1631                    r.check_count(i64::from(c), 3)?
1632                };
1633                let mut v6 = Vec::with_capacity(v5.min(crate::codec::PREALLOC_LIMIT));
1634                for _ in 0..v5 {
1635                    v6.push({
1636                        let v7 = r.read_i8()?;
1637                        let v8 = r.read_i8()?;
1638                        let v9 = r.read_i8()?;
1639                        crate::defs::p47::play::clientbound::MapIcons {
1640                            direction_and_type: v7,
1641                            x: v8,
1642                            z: v9,
1643                        }
1644                    });
1645                }
1646                v6
1647            };
1648            let v10 = r.read_i8()?;
1649            let v11 = if !(v10 == 0) {
1650                Some(r.read_i8()?)
1651            } else {
1652                None
1653            };
1654            let v12 = if !(v10 == 0) {
1655                Some(r.read_i8()?)
1656            } else {
1657                None
1658            };
1659            let v13 = if !(v10 == 0) {
1660                Some(r.read_i8()?)
1661            } else {
1662                None
1663            };
1664            let v14 = if !(v10 == 0) {
1665                Some(r.read_byte_array()?)
1666            } else {
1667                None
1668            };
1669            Self {
1670                item_damage: v1,
1671                scale: v2,
1672                tracking_position: v3,
1673                icons: v4,
1674                columns: v10,
1675                rows: v11,
1676                x: v12,
1677                y: v13,
1678                data: v14,
1679            }
1680        })
1681    }
1682}
1683#[cfg(feature = "v1_12_2")]
1684impl<const V: i32> Encode for Map<V> {
1685    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1686        w.put_varint((*self).item_damage);
1687        w.put_i8((*self).scale);
1688        w.put_bool((*self).tracking_position);
1689        w.put_len_varint((*self).icons.len())?;
1690        for v1 in (*self).icons.iter() {
1691            w.put_i8((*v1).direction_and_type);
1692            w.put_i8((*v1).x);
1693            w.put_i8((*v1).z);
1694        }
1695        w.put_i8((*self).columns);
1696        match (&(*self).rows, !((*self).columns == 0)) {
1697            (Some(v2), true) => {
1698                w.put_i8((*v2));
1699            }
1700            (None, false) => {}
1701            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.rows")),
1702        }
1703        match (&(*self).x, !((*self).columns == 0)) {
1704            (Some(v3), true) => {
1705                w.put_i8((*v3));
1706            }
1707            (None, false) => {}
1708            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.x")),
1709        }
1710        match (&(*self).y, !((*self).columns == 0)) {
1711            (Some(v4), true) => {
1712                w.put_i8((*v4));
1713            }
1714            (None, false) => {}
1715            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.y")),
1716        }
1717        match (&(*self).data, !((*self).columns == 0)) {
1718            (Some(v5), true) => {
1719                w.put_byte_array(&(*v5))?;
1720            }
1721            (None, false) => {}
1722            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.data")),
1723        }
1724        Ok(())
1725    }
1726}
1727#[cfg(feature = "v1_12_2")]
1728#[cfg(feature = "testgen")]
1729impl<const V: i32> Generate for Map<V> {
1730    fn generate(g: &mut Gen) -> Self {
1731        {
1732            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1733            let v2 = (g.int_in(-128, 127, &[]) as i8);
1734            let v3 = g.bool();
1735            let v4 = {
1736                let v5 = g.count();
1737                let mut v6 = Vec::with_capacity(v5.min(crate::codec::PREALLOC_LIMIT));
1738                for _ in 0..v5 {
1739                    v6.push({
1740                        let v7 = (g.int_in(-128, 127, &[]) as i8);
1741                        let v8 = (g.int_in(-128, 127, &[]) as i8);
1742                        let v9 = (g.int_in(-128, 127, &[]) as i8);
1743                        crate::defs::p47::play::clientbound::MapIcons {
1744                            direction_and_type: v7,
1745                            x: v8,
1746                            z: v9,
1747                        }
1748                    });
1749                }
1750                v6
1751            };
1752            let v10 = (g.int_in(-128, 127, &[0, 0, 0, 0]) as i8);
1753            let v11 = if !(v10 == 0) {
1754                Some((g.int_in(-128, 127, &[]) as i8))
1755            } else {
1756                None
1757            };
1758            let v12 = if !(v10 == 0) {
1759                Some((g.int_in(-128, 127, &[]) as i8))
1760            } else {
1761                None
1762            };
1763            let v13 = if !(v10 == 0) {
1764                Some((g.int_in(-128, 127, &[]) as i8))
1765            } else {
1766                None
1767            };
1768            let v14 = if !(v10 == 0) { Some(g.bytes()) } else { None };
1769            Self {
1770                item_damage: v1,
1771                scale: v2,
1772                tracking_position: v3,
1773                icons: v4,
1774                columns: v10,
1775                rows: v11,
1776                x: v12,
1777                y: v13,
1778                data: v14,
1779            }
1780        }
1781    }
1782}
1783
1784#[cfg(any(
1785    feature = "v1_12_2",
1786    feature = "v1_16_5",
1787    feature = "v26_1",
1788    feature = "v26_2"
1789))]
1790/// `rel_entity_move` (clientbound play).
1791#[derive(Debug, Clone, PartialEq)]
1792pub struct RelEntityMove<const V: i32> {
1793    /// `entityId`
1794    pub entity_id: i32,
1795    /// `dX`
1796    pub d_x: i16,
1797    /// `dY`
1798    pub d_y: i16,
1799    /// `dZ`
1800    pub d_z: i16,
1801    /// `onGround`
1802    pub on_ground: bool,
1803}
1804#[cfg(any(
1805    feature = "v1_12_2",
1806    feature = "v1_16_5",
1807    feature = "v26_1",
1808    feature = "v26_2"
1809))]
1810impl<const V: i32> Decode for RelEntityMove<V> {
1811    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1812        Ok({
1813            let v1 = r.read_varint()?;
1814            let v2 = r.read_i16()?;
1815            let v3 = r.read_i16()?;
1816            let v4 = r.read_i16()?;
1817            let v5 = r.read_bool()?;
1818            Self {
1819                entity_id: v1,
1820                d_x: v2,
1821                d_y: v3,
1822                d_z: v4,
1823                on_ground: v5,
1824            }
1825        })
1826    }
1827}
1828#[cfg(any(
1829    feature = "v1_12_2",
1830    feature = "v1_16_5",
1831    feature = "v26_1",
1832    feature = "v26_2"
1833))]
1834impl<const V: i32> Encode for RelEntityMove<V> {
1835    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1836        w.put_varint((*self).entity_id);
1837        w.put_i16((*self).d_x);
1838        w.put_i16((*self).d_y);
1839        w.put_i16((*self).d_z);
1840        w.put_bool((*self).on_ground);
1841        Ok(())
1842    }
1843}
1844#[cfg(any(
1845    feature = "v1_12_2",
1846    feature = "v1_16_5",
1847    feature = "v26_1",
1848    feature = "v26_2"
1849))]
1850#[cfg(feature = "testgen")]
1851impl<const V: i32> Generate for RelEntityMove<V> {
1852    fn generate(g: &mut Gen) -> Self {
1853        {
1854            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1855            let v2 = (g.int_in(-32768, 32767, &[]) as i16);
1856            let v3 = (g.int_in(-32768, 32767, &[]) as i16);
1857            let v4 = (g.int_in(-32768, 32767, &[]) as i16);
1858            let v5 = g.bool();
1859            Self {
1860                entity_id: v1,
1861                d_x: v2,
1862                d_y: v3,
1863                d_z: v4,
1864                on_ground: v5,
1865            }
1866        }
1867    }
1868}
1869
1870#[cfg(any(
1871    feature = "v1_12_2",
1872    feature = "v1_16_5",
1873    feature = "v26_1",
1874    feature = "v26_2"
1875))]
1876/// `entity_move_look` (clientbound play).
1877#[derive(Debug, Clone, PartialEq)]
1878pub struct EntityMoveLook<const V: i32> {
1879    /// `entityId`
1880    pub entity_id: i32,
1881    /// `dX`
1882    pub d_x: i16,
1883    /// `dY`
1884    pub d_y: i16,
1885    /// `dZ`
1886    pub d_z: i16,
1887    /// `yaw`
1888    pub yaw: i8,
1889    /// `pitch`
1890    pub pitch: i8,
1891    /// `onGround`
1892    pub on_ground: bool,
1893}
1894#[cfg(any(
1895    feature = "v1_12_2",
1896    feature = "v1_16_5",
1897    feature = "v26_1",
1898    feature = "v26_2"
1899))]
1900impl<const V: i32> Decode for EntityMoveLook<V> {
1901    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1902        Ok({
1903            let v1 = r.read_varint()?;
1904            let v2 = r.read_i16()?;
1905            let v3 = r.read_i16()?;
1906            let v4 = r.read_i16()?;
1907            let v5 = r.read_i8()?;
1908            let v6 = r.read_i8()?;
1909            let v7 = r.read_bool()?;
1910            Self {
1911                entity_id: v1,
1912                d_x: v2,
1913                d_y: v3,
1914                d_z: v4,
1915                yaw: v5,
1916                pitch: v6,
1917                on_ground: v7,
1918            }
1919        })
1920    }
1921}
1922#[cfg(any(
1923    feature = "v1_12_2",
1924    feature = "v1_16_5",
1925    feature = "v26_1",
1926    feature = "v26_2"
1927))]
1928impl<const V: i32> Encode for EntityMoveLook<V> {
1929    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1930        w.put_varint((*self).entity_id);
1931        w.put_i16((*self).d_x);
1932        w.put_i16((*self).d_y);
1933        w.put_i16((*self).d_z);
1934        w.put_i8((*self).yaw);
1935        w.put_i8((*self).pitch);
1936        w.put_bool((*self).on_ground);
1937        Ok(())
1938    }
1939}
1940#[cfg(any(
1941    feature = "v1_12_2",
1942    feature = "v1_16_5",
1943    feature = "v26_1",
1944    feature = "v26_2"
1945))]
1946#[cfg(feature = "testgen")]
1947impl<const V: i32> Generate for EntityMoveLook<V> {
1948    fn generate(g: &mut Gen) -> Self {
1949        {
1950            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1951            let v2 = (g.int_in(-32768, 32767, &[]) as i16);
1952            let v3 = (g.int_in(-32768, 32767, &[]) as i16);
1953            let v4 = (g.int_in(-32768, 32767, &[]) as i16);
1954            let v5 = (g.int_in(-128, 127, &[]) as i8);
1955            let v6 = (g.int_in(-128, 127, &[]) as i8);
1956            let v7 = g.bool();
1957            Self {
1958                entity_id: v1,
1959                d_x: v2,
1960                d_y: v3,
1961                d_z: v4,
1962                yaw: v5,
1963                pitch: v6,
1964                on_ground: v7,
1965            }
1966        }
1967    }
1968}
1969
1970#[cfg(any(
1971    feature = "v1_12_2",
1972    feature = "v1_16_5",
1973    feature = "v26_1",
1974    feature = "v26_2",
1975    feature = "v26_3"
1976))]
1977/// `vehicle_move` (clientbound play).
1978#[derive(Debug, Clone, PartialEq)]
1979pub struct VehicleMove<const V: i32> {
1980    /// `x`
1981    pub x: f64,
1982    /// `y`
1983    pub y: f64,
1984    /// `z`
1985    pub z: f64,
1986    /// `yaw`
1987    pub yaw: f32,
1988    /// `pitch`
1989    pub pitch: f32,
1990}
1991#[cfg(any(
1992    feature = "v1_12_2",
1993    feature = "v1_16_5",
1994    feature = "v26_1",
1995    feature = "v26_2",
1996    feature = "v26_3"
1997))]
1998impl<const V: i32> Decode for VehicleMove<V> {
1999    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2000        Ok({
2001            let v1 = r.read_f64()?;
2002            let v2 = r.read_f64()?;
2003            let v3 = r.read_f64()?;
2004            let v4 = r.read_f32()?;
2005            let v5 = r.read_f32()?;
2006            Self {
2007                x: v1,
2008                y: v2,
2009                z: v3,
2010                yaw: v4,
2011                pitch: v5,
2012            }
2013        })
2014    }
2015}
2016#[cfg(any(
2017    feature = "v1_12_2",
2018    feature = "v1_16_5",
2019    feature = "v26_1",
2020    feature = "v26_2",
2021    feature = "v26_3"
2022))]
2023impl<const V: i32> Encode for VehicleMove<V> {
2024    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2025        w.put_f64((*self).x);
2026        w.put_f64((*self).y);
2027        w.put_f64((*self).z);
2028        w.put_f32((*self).yaw);
2029        w.put_f32((*self).pitch);
2030        Ok(())
2031    }
2032}
2033#[cfg(any(
2034    feature = "v1_12_2",
2035    feature = "v1_16_5",
2036    feature = "v26_1",
2037    feature = "v26_2",
2038    feature = "v26_3"
2039))]
2040#[cfg(feature = "testgen")]
2041impl<const V: i32> Generate for VehicleMove<V> {
2042    fn generate(g: &mut Gen) -> Self {
2043        {
2044            let v1 = g.f64();
2045            let v2 = g.f64();
2046            let v3 = g.f64();
2047            let v4 = g.f32();
2048            let v5 = g.f32();
2049            Self {
2050                x: v1,
2051                y: v2,
2052                z: v3,
2053                yaw: v4,
2054                pitch: v5,
2055            }
2056        }
2057    }
2058}
2059
2060#[cfg(feature = "v1_12_2")]
2061/// `craft_recipe_response` (clientbound play).
2062#[derive(Debug, Clone, PartialEq)]
2063pub struct CraftRecipeResponse<const V: i32> {
2064    /// `windowId`
2065    pub window_id: i8,
2066    /// `recipe`
2067    pub recipe: i32,
2068}
2069#[cfg(feature = "v1_12_2")]
2070impl<const V: i32> Decode for CraftRecipeResponse<V> {
2071    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2072        Ok({
2073            let v1 = r.read_i8()?;
2074            let v2 = r.read_varint()?;
2075            Self {
2076                window_id: v1,
2077                recipe: v2,
2078            }
2079        })
2080    }
2081}
2082#[cfg(feature = "v1_12_2")]
2083impl<const V: i32> Encode for CraftRecipeResponse<V> {
2084    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2085        w.put_i8((*self).window_id);
2086        w.put_varint((*self).recipe);
2087        Ok(())
2088    }
2089}
2090#[cfg(feature = "v1_12_2")]
2091#[cfg(feature = "testgen")]
2092impl<const V: i32> Generate for CraftRecipeResponse<V> {
2093    fn generate(g: &mut Gen) -> Self {
2094        {
2095            let v1 = (g.int_in(-128, 127, &[]) as i8);
2096            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2097            Self {
2098                window_id: v1,
2099                recipe: v2,
2100            }
2101        }
2102    }
2103}
2104
2105#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
2106/// `position` (clientbound play).
2107#[derive(Debug, Clone, PartialEq)]
2108pub struct Position<const V: i32> {
2109    /// `x`
2110    pub x: f64,
2111    /// `y`
2112    pub y: f64,
2113    /// `z`
2114    pub z: f64,
2115    /// `yaw`
2116    pub yaw: f32,
2117    /// `pitch`
2118    pub pitch: f32,
2119    /// `flags`
2120    pub flags: i8,
2121    /// `teleportId`
2122    pub teleport_id: i32,
2123}
2124#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
2125impl<const V: i32> Decode for Position<V> {
2126    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2127        Ok({
2128            let v1 = r.read_f64()?;
2129            let v2 = r.read_f64()?;
2130            let v3 = r.read_f64()?;
2131            let v4 = r.read_f32()?;
2132            let v5 = r.read_f32()?;
2133            let v6 = r.read_i8()?;
2134            let v7 = r.read_varint()?;
2135            Self {
2136                x: v1,
2137                y: v2,
2138                z: v3,
2139                yaw: v4,
2140                pitch: v5,
2141                flags: v6,
2142                teleport_id: v7,
2143            }
2144        })
2145    }
2146}
2147#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
2148impl<const V: i32> Encode for Position<V> {
2149    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2150        w.put_f64((*self).x);
2151        w.put_f64((*self).y);
2152        w.put_f64((*self).z);
2153        w.put_f32((*self).yaw);
2154        w.put_f32((*self).pitch);
2155        w.put_i8((*self).flags);
2156        w.put_varint((*self).teleport_id);
2157        Ok(())
2158    }
2159}
2160#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
2161#[cfg(feature = "testgen")]
2162impl<const V: i32> Generate for Position<V> {
2163    fn generate(g: &mut Gen) -> Self {
2164        {
2165            let v1 = g.f64();
2166            let v2 = g.f64();
2167            let v3 = g.f64();
2168            let v4 = g.f32();
2169            let v5 = g.f32();
2170            let v6 = (g.int_in(-128, 127, &[]) as i8);
2171            let v7 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2172            Self {
2173                x: v1,
2174                y: v2,
2175                z: v3,
2176                yaw: v4,
2177                pitch: v5,
2178                flags: v6,
2179                teleport_id: v7,
2180            }
2181        }
2182    }
2183}
2184
2185#[cfg(feature = "v1_12_2")]
2186/// `unlock_recipes` (clientbound play).
2187#[derive(Debug, Clone, PartialEq)]
2188pub struct UnlockRecipes<const V: i32> {
2189    /// `action`
2190    pub action: i32,
2191    /// `craftingBookOpen`
2192    pub crafting_book_open: bool,
2193    /// `filteringCraftable`
2194    pub filtering_craftable: bool,
2195    /// `recipes1`
2196    pub recipes1: Vec<i32>,
2197    /// `recipes2`
2198    pub recipes2: Option<Vec<i32>>,
2199}
2200#[cfg(feature = "v1_12_2")]
2201impl<const V: i32> Decode for UnlockRecipes<V> {
2202    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2203        Ok({
2204            let v1 = r.read_varint()?;
2205            let v2 = r.read_bool()?;
2206            let v3 = r.read_bool()?;
2207            let v4 = {
2208                let v5 = {
2209                    let c = r.read_varint()?;
2210                    r.check_count(i64::from(c), 1)?
2211                };
2212                let mut v6 = Vec::with_capacity(v5.min(crate::codec::PREALLOC_LIMIT));
2213                for _ in 0..v5 {
2214                    v6.push(r.read_varint()?);
2215                }
2216                v6
2217            };
2218            let v7 = if (v1 == 0) {
2219                Some({
2220                    let v8 = {
2221                        let c = r.read_varint()?;
2222                        r.check_count(i64::from(c), 1)?
2223                    };
2224                    let mut v9 = Vec::with_capacity(v8.min(crate::codec::PREALLOC_LIMIT));
2225                    for _ in 0..v8 {
2226                        v9.push(r.read_varint()?);
2227                    }
2228                    v9
2229                })
2230            } else {
2231                None
2232            };
2233            Self {
2234                action: v1,
2235                crafting_book_open: v2,
2236                filtering_craftable: v3,
2237                recipes1: v4,
2238                recipes2: v7,
2239            }
2240        })
2241    }
2242}
2243#[cfg(feature = "v1_12_2")]
2244impl<const V: i32> Encode for UnlockRecipes<V> {
2245    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2246        w.put_varint((*self).action);
2247        w.put_bool((*self).crafting_book_open);
2248        w.put_bool((*self).filtering_craftable);
2249        w.put_len_varint((*self).recipes1.len())?;
2250        for v1 in (*self).recipes1.iter() {
2251            w.put_varint((*v1));
2252        }
2253        match (&(*self).recipes2, ((*self).action == 0)) {
2254            (Some(v2), true) => {
2255                w.put_len_varint((*v2).len())?;
2256                for v3 in (*v2).iter() {
2257                    w.put_varint((*v3));
2258                }
2259            }
2260            (None, false) => {}
2261            _ => {
2262                return Err(EncodeError::SwitchMismatch(
2263                    "play.clientbound.unlock_recipes.recipes2",
2264                ));
2265            }
2266        }
2267        Ok(())
2268    }
2269}
2270#[cfg(feature = "v1_12_2")]
2271#[cfg(feature = "testgen")]
2272impl<const V: i32> Generate for UnlockRecipes<V> {
2273    fn generate(g: &mut Gen) -> Self {
2274        {
2275            let v1 = (g.int_in(-2147483648, 2147483647, &[0]) as i32);
2276            let v2 = g.bool();
2277            let v3 = g.bool();
2278            let v4 = {
2279                let v5 = g.count();
2280                let mut v6 = Vec::with_capacity(v5.min(crate::codec::PREALLOC_LIMIT));
2281                for _ in 0..v5 {
2282                    v6.push((g.int_in(-2147483648, 2147483647, &[]) as i32));
2283                }
2284                v6
2285            };
2286            let v7 = if (v1 == 0) {
2287                Some({
2288                    let v8 = g.count();
2289                    let mut v9 = Vec::with_capacity(v8.min(crate::codec::PREALLOC_LIMIT));
2290                    for _ in 0..v8 {
2291                        v9.push((g.int_in(-2147483648, 2147483647, &[]) as i32));
2292                    }
2293                    v9
2294                })
2295            } else {
2296                None
2297            };
2298            Self {
2299                action: v1,
2300                crafting_book_open: v2,
2301                filtering_craftable: v3,
2302                recipes1: v4,
2303                recipes2: v7,
2304            }
2305        }
2306    }
2307}
2308
2309#[cfg(any(
2310    feature = "v1_12_2",
2311    feature = "v1_16_5",
2312    feature = "v26_1",
2313    feature = "v26_2",
2314    feature = "v26_3"
2315))]
2316/// `select_advancement_tab` (clientbound play).
2317#[derive(Debug, Clone, PartialEq)]
2318pub struct SelectAdvancementTab<const V: i32> {
2319    /// `id`
2320    pub id: Option<ByteString>,
2321}
2322#[cfg(any(
2323    feature = "v1_12_2",
2324    feature = "v1_16_5",
2325    feature = "v26_1",
2326    feature = "v26_2",
2327    feature = "v26_3"
2328))]
2329impl<const V: i32> Decode for SelectAdvancementTab<V> {
2330    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2331        Ok({
2332            let v1 = if r.read_bool()? {
2333                Some(r.read_string()?)
2334            } else {
2335                None
2336            };
2337            Self { id: v1 }
2338        })
2339    }
2340}
2341#[cfg(any(
2342    feature = "v1_12_2",
2343    feature = "v1_16_5",
2344    feature = "v26_1",
2345    feature = "v26_2",
2346    feature = "v26_3"
2347))]
2348impl<const V: i32> Encode for SelectAdvancementTab<V> {
2349    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2350        match &(*self).id {
2351            Some(v1) => {
2352                w.put_u8(1);
2353                w.put_string(&(*v1))?;
2354            }
2355            None => w.put_u8(0),
2356        }
2357        Ok(())
2358    }
2359}
2360#[cfg(any(
2361    feature = "v1_12_2",
2362    feature = "v1_16_5",
2363    feature = "v26_1",
2364    feature = "v26_2",
2365    feature = "v26_3"
2366))]
2367#[cfg(feature = "testgen")]
2368impl<const V: i32> Generate for SelectAdvancementTab<V> {
2369    fn generate(g: &mut Gen) -> Self {
2370        {
2371            let v1 = if g.bool() { Some(g.string()) } else { None };
2372            Self { id: v1 }
2373        }
2374    }
2375}
2376
2377#[cfg(feature = "v1_12_2")]
2378/// `entity_metadata` (clientbound play).
2379#[derive(Debug, Clone, PartialEq)]
2380pub struct EntityMetadata<const V: i32> {
2381    /// `entityId`
2382    pub entity_id: i32,
2383    /// `metadata`
2384    pub metadata: Vec<crate::defs::p340::types::EntityMetadataEntry>,
2385}
2386#[cfg(feature = "v1_12_2")]
2387impl<const V: i32> Decode for EntityMetadata<V> {
2388    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2389        Ok({
2390            let v1 = r.read_varint()?;
2391            let v2 = {
2392                let mut v3 = Vec::new();
2393                loop {
2394                    if r.peek_u8()? == 255 {
2395                        r.skip(1)?;
2396                        break;
2397                    }
2398                    v3.push({
2399                        let v4 = r.read_u8()?;
2400                        let v5 = r.read_i8()?;
2401                        let v6 = (if (v5 == 0) {
2402                            crate::defs::p340::types::EntityMetadataValue::Byte(r.read_i8()?)
2403                        } else if (v5 == 1) {
2404                            crate::defs::p340::types::EntityMetadataValue::VarInt(r.read_varint()?)
2405                        } else if (v5 == 2) {
2406                            crate::defs::p340::types::EntityMetadataValue::Float(r.read_f32()?)
2407                        } else if (v5 == 3) {
2408                            crate::defs::p340::types::EntityMetadataValue::String(r.read_string()?)
2409                        } else if (v5 == 4) {
2410                            crate::defs::p340::types::EntityMetadataValue::Chat(r.read_string()?)
2411                        } else if (v5 == 5) {
2412                            crate::defs::p340::types::EntityMetadataValue::Slot(
2413                                <crate::types::slot::legacy::Slot as Decode>::decode(r)?,
2414                            )
2415                        } else if (v5 == 6) {
2416                            crate::defs::p340::types::EntityMetadataValue::Boolean(r.read_bool()?)
2417                        } else if (v5 == 7) {
2418                            crate::defs::p340::types::EntityMetadataValue::Rotation({
2419                                let v7 = r.read_f32()?;
2420                                let v8 = r.read_f32()?;
2421                                let v9 = r.read_f32()?;
2422                                crate::defs::p47::types::EntityMetadataValueRotation {
2423                                    pitch: v7,
2424                                    yaw: v8,
2425                                    roll: v9,
2426                                }
2427                            })
2428                        } else if (v5 == 8) {
2429                            crate::defs::p340::types::EntityMetadataValue::Position(BlockPos::read(
2430                                r,
2431                                PositionLayout::Xyz,
2432                            )?)
2433                        } else if (v5 == 9) {
2434                            crate::defs::p340::types::EntityMetadataValue::OptPosition(
2435                                if r.read_bool()? {
2436                                    Some(BlockPos::read(r, PositionLayout::Xyz)?)
2437                                } else {
2438                                    None
2439                                },
2440                            )
2441                        } else if (v5 == 10) {
2442                            crate::defs::p340::types::EntityMetadataValue::Direction(
2443                                r.read_varint()?,
2444                            )
2445                        } else if (v5 == 11) {
2446                            crate::defs::p340::types::EntityMetadataValue::OptUuid(
2447                                if r.read_bool()? {
2448                                    Some(r.read_uuid()?)
2449                                } else {
2450                                    None
2451                                },
2452                            )
2453                        } else if (v5 == 12) {
2454                            crate::defs::p340::types::EntityMetadataValue::BlockState(
2455                                r.read_varint()?,
2456                            )
2457                        } else if (v5 == 13) {
2458                            crate::defs::p340::types::EntityMetadataValue::Nbt(RawNbt::read(r)?)
2459                        } else {
2460                            crate::defs::p340::types::EntityMetadataValue::Other
2461                        });
2462                        crate::defs::p340::types::EntityMetadataEntry {
2463                            key: v4,
2464                            r#type: v5,
2465                            value: v6,
2466                        }
2467                    });
2468                }
2469                v3
2470            };
2471            Self {
2472                entity_id: v1,
2473                metadata: v2,
2474            }
2475        })
2476    }
2477}
2478#[cfg(feature = "v1_12_2")]
2479impl<const V: i32> Encode for EntityMetadata<V> {
2480    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2481        w.put_varint((*self).entity_id);
2482        for v1 in (*self).metadata.iter() {
2483            let v2 = w.len();
2484            w.put_u8((*v1).key);
2485            w.put_i8((*v1).r#type);
2486            match &(*v1).value {
2487                crate::defs::p340::types::EntityMetadataValue::Byte(v3) => {
2488                    if !((*v1).r#type == 0) {
2489                        return Err(EncodeError::SwitchMismatch(
2490                            "play.clientbound.entity_metadata.metadata.value",
2491                        ));
2492                    }
2493                    w.put_i8((*v3));
2494                }
2495                crate::defs::p340::types::EntityMetadataValue::VarInt(v4) => {
2496                    if !((*v1).r#type == 1) {
2497                        return Err(EncodeError::SwitchMismatch(
2498                            "play.clientbound.entity_metadata.metadata.value",
2499                        ));
2500                    }
2501                    w.put_varint((*v4));
2502                }
2503                crate::defs::p340::types::EntityMetadataValue::Float(v5) => {
2504                    if !((*v1).r#type == 2) {
2505                        return Err(EncodeError::SwitchMismatch(
2506                            "play.clientbound.entity_metadata.metadata.value",
2507                        ));
2508                    }
2509                    w.put_f32((*v5));
2510                }
2511                crate::defs::p340::types::EntityMetadataValue::String(v6) => {
2512                    if !((*v1).r#type == 3) {
2513                        return Err(EncodeError::SwitchMismatch(
2514                            "play.clientbound.entity_metadata.metadata.value",
2515                        ));
2516                    }
2517                    w.put_string(&(*v6))?;
2518                }
2519                crate::defs::p340::types::EntityMetadataValue::Chat(v7) => {
2520                    if !((*v1).r#type == 4) {
2521                        return Err(EncodeError::SwitchMismatch(
2522                            "play.clientbound.entity_metadata.metadata.value",
2523                        ));
2524                    }
2525                    w.put_string(&(*v7))?;
2526                }
2527                crate::defs::p340::types::EntityMetadataValue::Slot(v8) => {
2528                    if !((*v1).r#type == 5) {
2529                        return Err(EncodeError::SwitchMismatch(
2530                            "play.clientbound.entity_metadata.metadata.value",
2531                        ));
2532                    }
2533                    (*v8).encode(w)?;
2534                }
2535                crate::defs::p340::types::EntityMetadataValue::Boolean(v9) => {
2536                    if !((*v1).r#type == 6) {
2537                        return Err(EncodeError::SwitchMismatch(
2538                            "play.clientbound.entity_metadata.metadata.value",
2539                        ));
2540                    }
2541                    w.put_bool((*v9));
2542                }
2543                crate::defs::p340::types::EntityMetadataValue::Rotation(v10) => {
2544                    if !((*v1).r#type == 7) {
2545                        return Err(EncodeError::SwitchMismatch(
2546                            "play.clientbound.entity_metadata.metadata.value",
2547                        ));
2548                    }
2549                    w.put_f32((*v10).pitch);
2550                    w.put_f32((*v10).yaw);
2551                    w.put_f32((*v10).roll);
2552                }
2553                crate::defs::p340::types::EntityMetadataValue::Position(v11) => {
2554                    if !((*v1).r#type == 8) {
2555                        return Err(EncodeError::SwitchMismatch(
2556                            "play.clientbound.entity_metadata.metadata.value",
2557                        ));
2558                    }
2559                    (*v11).write(w, PositionLayout::Xyz)?;
2560                }
2561                crate::defs::p340::types::EntityMetadataValue::OptPosition(v12) => {
2562                    if !((*v1).r#type == 9) {
2563                        return Err(EncodeError::SwitchMismatch(
2564                            "play.clientbound.entity_metadata.metadata.value",
2565                        ));
2566                    }
2567                    match &(*v12) {
2568                        Some(v13) => {
2569                            w.put_u8(1);
2570                            (*v13).write(w, PositionLayout::Xyz)?;
2571                        }
2572                        None => w.put_u8(0),
2573                    }
2574                }
2575                crate::defs::p340::types::EntityMetadataValue::Direction(v14) => {
2576                    if !((*v1).r#type == 10) {
2577                        return Err(EncodeError::SwitchMismatch(
2578                            "play.clientbound.entity_metadata.metadata.value",
2579                        ));
2580                    }
2581                    w.put_varint((*v14));
2582                }
2583                crate::defs::p340::types::EntityMetadataValue::OptUuid(v15) => {
2584                    if !((*v1).r#type == 11) {
2585                        return Err(EncodeError::SwitchMismatch(
2586                            "play.clientbound.entity_metadata.metadata.value",
2587                        ));
2588                    }
2589                    match &(*v15) {
2590                        Some(v16) => {
2591                            w.put_u8(1);
2592                            w.put_uuid(&(*v16));
2593                        }
2594                        None => w.put_u8(0),
2595                    }
2596                }
2597                crate::defs::p340::types::EntityMetadataValue::BlockState(v17) => {
2598                    if !((*v1).r#type == 12) {
2599                        return Err(EncodeError::SwitchMismatch(
2600                            "play.clientbound.entity_metadata.metadata.value",
2601                        ));
2602                    }
2603                    w.put_varint((*v17));
2604                }
2605                crate::defs::p340::types::EntityMetadataValue::Nbt(v18) => {
2606                    if !((*v1).r#type == 13) {
2607                        return Err(EncodeError::SwitchMismatch(
2608                            "play.clientbound.entity_metadata.metadata.value",
2609                        ));
2610                    }
2611                    (*v18).write(w);
2612                }
2613                crate::defs::p340::types::EntityMetadataValue::Other => {
2614                    if !(!(((*v1).r#type == 0)
2615                        || ((*v1).r#type == 1)
2616                        || ((*v1).r#type == 2)
2617                        || ((*v1).r#type == 3)
2618                        || ((*v1).r#type == 4)
2619                        || ((*v1).r#type == 5)
2620                        || ((*v1).r#type == 6)
2621                        || ((*v1).r#type == 7)
2622                        || ((*v1).r#type == 8)
2623                        || ((*v1).r#type == 9)
2624                        || ((*v1).r#type == 10)
2625                        || ((*v1).r#type == 11)
2626                        || ((*v1).r#type == 12)
2627                        || ((*v1).r#type == 13)))
2628                    {
2629                        return Err(EncodeError::SwitchMismatch(
2630                            "play.clientbound.entity_metadata.metadata.value",
2631                        ));
2632                    }
2633                }
2634            }
2635            if w.get(v2) == Some(&255) {
2636                return Err(EncodeError::OutOfRange(
2637                    "play.clientbound.entity_metadata.metadata",
2638                ));
2639            }
2640        }
2641        w.put_u8(255);
2642        Ok(())
2643    }
2644}
2645#[cfg(feature = "v1_12_2")]
2646#[cfg(feature = "testgen")]
2647impl<const V: i32> Generate for EntityMetadata<V> {
2648    fn generate(g: &mut Gen) -> Self {
2649        {
2650            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2651            let v2 = {
2652                let n = g.count();
2653                let mut v3 = Vec::with_capacity(n);
2654                for _ in 0..n {
2655                    v3.push(loop {
2656                        let v4 = {
2657                            let v5 = (g.int_in(0, 255, &[]) as u8);
2658                            let v6 = (g.int_in(
2659                                -128,
2660                                127,
2661                                &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
2662                            ) as i8);
2663                            let v7 = (if (v6 == 0) {
2664                                crate::defs::p340::types::EntityMetadataValue::Byte(
2665                                    (g.int_in(-128, 127, &[]) as i8),
2666                                )
2667                            } else if (v6 == 1) {
2668                                crate::defs::p340::types::EntityMetadataValue::VarInt(
2669                                    (g.int_in(-2147483648, 2147483647, &[]) as i32),
2670                                )
2671                            } else if (v6 == 2) {
2672                                crate::defs::p340::types::EntityMetadataValue::Float(g.f32())
2673                            } else if (v6 == 3) {
2674                                crate::defs::p340::types::EntityMetadataValue::String(g.string())
2675                            } else if (v6 == 4) {
2676                                crate::defs::p340::types::EntityMetadataValue::Chat(g.string())
2677                            } else if (v6 == 5) {
2678                                crate::defs::p340::types::EntityMetadataValue::Slot(
2679                                    <crate::types::slot::legacy::Slot as Generate>::generate(g),
2680                                )
2681                            } else if (v6 == 6) {
2682                                crate::defs::p340::types::EntityMetadataValue::Boolean(g.bool())
2683                            } else if (v6 == 7) {
2684                                crate::defs::p340::types::EntityMetadataValue::Rotation({
2685                                    let v8 = g.f32();
2686                                    let v9 = g.f32();
2687                                    let v10 = g.f32();
2688                                    crate::defs::p47::types::EntityMetadataValueRotation {
2689                                        pitch: v8,
2690                                        yaw: v9,
2691                                        roll: v10,
2692                                    }
2693                                })
2694                            } else if (v6 == 8) {
2695                                crate::defs::p340::types::EntityMetadataValue::Position(
2696                                    g.position(),
2697                                )
2698                            } else if (v6 == 9) {
2699                                crate::defs::p340::types::EntityMetadataValue::OptPosition(
2700                                    if g.bool() { Some(g.position()) } else { None },
2701                                )
2702                            } else if (v6 == 10) {
2703                                crate::defs::p340::types::EntityMetadataValue::Direction(
2704                                    (g.int_in(-2147483648, 2147483647, &[]) as i32),
2705                                )
2706                            } else if (v6 == 11) {
2707                                crate::defs::p340::types::EntityMetadataValue::OptUuid(
2708                                    if g.bool() { Some(g.uuid()) } else { None },
2709                                )
2710                            } else if (v6 == 12) {
2711                                crate::defs::p340::types::EntityMetadataValue::BlockState(
2712                                    (g.int_in(-2147483648, 2147483647, &[]) as i32),
2713                                )
2714                            } else if (v6 == 13) {
2715                                crate::defs::p340::types::EntityMetadataValue::Nbt(g.nbt())
2716                            } else {
2717                                crate::defs::p340::types::EntityMetadataValue::Other
2718                            });
2719                            crate::defs::p340::types::EntityMetadataEntry {
2720                                key: v5,
2721                                r#type: v6,
2722                                value: v7,
2723                            }
2724                        };
2725                        if crate::testgen::first_byte_ok(
2726                            |w: &mut BytesMut| -> EncodeResult {
2727                                w.put_u8(v4.key);
2728                                w.put_i8(v4.r#type);
2729                                match &v4.value {
2730                                    crate::defs::p340::types::EntityMetadataValue::Byte(v11) => {
2731                                        if !(v4.r#type == 0) {
2732                                            return Err(EncodeError::SwitchMismatch(
2733                                                "play.clientbound.entity_metadata.metadata.value",
2734                                            ));
2735                                        }
2736                                        w.put_i8((*v11));
2737                                    }
2738                                    crate::defs::p340::types::EntityMetadataValue::VarInt(v12) => {
2739                                        if !(v4.r#type == 1) {
2740                                            return Err(EncodeError::SwitchMismatch(
2741                                                "play.clientbound.entity_metadata.metadata.value",
2742                                            ));
2743                                        }
2744                                        w.put_varint((*v12));
2745                                    }
2746                                    crate::defs::p340::types::EntityMetadataValue::Float(v13) => {
2747                                        if !(v4.r#type == 2) {
2748                                            return Err(EncodeError::SwitchMismatch(
2749                                                "play.clientbound.entity_metadata.metadata.value",
2750                                            ));
2751                                        }
2752                                        w.put_f32((*v13));
2753                                    }
2754                                    crate::defs::p340::types::EntityMetadataValue::String(v14) => {
2755                                        if !(v4.r#type == 3) {
2756                                            return Err(EncodeError::SwitchMismatch(
2757                                                "play.clientbound.entity_metadata.metadata.value",
2758                                            ));
2759                                        }
2760                                        w.put_string(&(*v14))?;
2761                                    }
2762                                    crate::defs::p340::types::EntityMetadataValue::Chat(v15) => {
2763                                        if !(v4.r#type == 4) {
2764                                            return Err(EncodeError::SwitchMismatch(
2765                                                "play.clientbound.entity_metadata.metadata.value",
2766                                            ));
2767                                        }
2768                                        w.put_string(&(*v15))?;
2769                                    }
2770                                    crate::defs::p340::types::EntityMetadataValue::Slot(v16) => {
2771                                        if !(v4.r#type == 5) {
2772                                            return Err(EncodeError::SwitchMismatch(
2773                                                "play.clientbound.entity_metadata.metadata.value",
2774                                            ));
2775                                        }
2776                                        (*v16).encode(w)?;
2777                                    }
2778                                    crate::defs::p340::types::EntityMetadataValue::Boolean(v17) => {
2779                                        if !(v4.r#type == 6) {
2780                                            return Err(EncodeError::SwitchMismatch(
2781                                                "play.clientbound.entity_metadata.metadata.value",
2782                                            ));
2783                                        }
2784                                        w.put_bool((*v17));
2785                                    }
2786                                    crate::defs::p340::types::EntityMetadataValue::Rotation(
2787                                        v18,
2788                                    ) => {
2789                                        if !(v4.r#type == 7) {
2790                                            return Err(EncodeError::SwitchMismatch(
2791                                                "play.clientbound.entity_metadata.metadata.value",
2792                                            ));
2793                                        }
2794                                        w.put_f32((*v18).pitch);
2795                                        w.put_f32((*v18).yaw);
2796                                        w.put_f32((*v18).roll);
2797                                    }
2798                                    crate::defs::p340::types::EntityMetadataValue::Position(
2799                                        v19,
2800                                    ) => {
2801                                        if !(v4.r#type == 8) {
2802                                            return Err(EncodeError::SwitchMismatch(
2803                                                "play.clientbound.entity_metadata.metadata.value",
2804                                            ));
2805                                        }
2806                                        (*v19).write(w, PositionLayout::Xyz)?;
2807                                    }
2808                                    crate::defs::p340::types::EntityMetadataValue::OptPosition(
2809                                        v20,
2810                                    ) => {
2811                                        if !(v4.r#type == 9) {
2812                                            return Err(EncodeError::SwitchMismatch(
2813                                                "play.clientbound.entity_metadata.metadata.value",
2814                                            ));
2815                                        }
2816                                        match &(*v20) {
2817                                            Some(v21) => {
2818                                                w.put_u8(1);
2819                                                (*v21).write(w, PositionLayout::Xyz)?;
2820                                            }
2821                                            None => w.put_u8(0),
2822                                        }
2823                                    }
2824                                    crate::defs::p340::types::EntityMetadataValue::Direction(
2825                                        v22,
2826                                    ) => {
2827                                        if !(v4.r#type == 10) {
2828                                            return Err(EncodeError::SwitchMismatch(
2829                                                "play.clientbound.entity_metadata.metadata.value",
2830                                            ));
2831                                        }
2832                                        w.put_varint((*v22));
2833                                    }
2834                                    crate::defs::p340::types::EntityMetadataValue::OptUuid(v23) => {
2835                                        if !(v4.r#type == 11) {
2836                                            return Err(EncodeError::SwitchMismatch(
2837                                                "play.clientbound.entity_metadata.metadata.value",
2838                                            ));
2839                                        }
2840                                        match &(*v23) {
2841                                            Some(v24) => {
2842                                                w.put_u8(1);
2843                                                w.put_uuid(&(*v24));
2844                                            }
2845                                            None => w.put_u8(0),
2846                                        }
2847                                    }
2848                                    crate::defs::p340::types::EntityMetadataValue::BlockState(
2849                                        v25,
2850                                    ) => {
2851                                        if !(v4.r#type == 12) {
2852                                            return Err(EncodeError::SwitchMismatch(
2853                                                "play.clientbound.entity_metadata.metadata.value",
2854                                            ));
2855                                        }
2856                                        w.put_varint((*v25));
2857                                    }
2858                                    crate::defs::p340::types::EntityMetadataValue::Nbt(v26) => {
2859                                        if !(v4.r#type == 13) {
2860                                            return Err(EncodeError::SwitchMismatch(
2861                                                "play.clientbound.entity_metadata.metadata.value",
2862                                            ));
2863                                        }
2864                                        (*v26).write(w);
2865                                    }
2866                                    crate::defs::p340::types::EntityMetadataValue::Other => {
2867                                        if !(!((v4.r#type == 0)
2868                                            || (v4.r#type == 1)
2869                                            || (v4.r#type == 2)
2870                                            || (v4.r#type == 3)
2871                                            || (v4.r#type == 4)
2872                                            || (v4.r#type == 5)
2873                                            || (v4.r#type == 6)
2874                                            || (v4.r#type == 7)
2875                                            || (v4.r#type == 8)
2876                                            || (v4.r#type == 9)
2877                                            || (v4.r#type == 10)
2878                                            || (v4.r#type == 11)
2879                                            || (v4.r#type == 12)
2880                                            || (v4.r#type == 13)))
2881                                        {
2882                                            return Err(EncodeError::SwitchMismatch(
2883                                                "play.clientbound.entity_metadata.metadata.value",
2884                                            ));
2885                                        }
2886                                    }
2887                                }
2888                                Ok(())
2889                            },
2890                            |b| b != 255,
2891                        ) {
2892                            break v4;
2893                        }
2894                    });
2895                }
2896                v3
2897            };
2898            Self {
2899                entity_id: v1,
2900                metadata: v2,
2901            }
2902        }
2903    }
2904}
2905
2906#[cfg(any(
2907    feature = "v1_12_2",
2908    feature = "v1_16_5",
2909    feature = "v26_1",
2910    feature = "v26_2",
2911    feature = "v26_3"
2912))]
2913/// `attach_entity` (clientbound play).
2914#[derive(Debug, Clone, PartialEq)]
2915pub struct AttachEntity<const V: i32> {
2916    /// `entityId`
2917    pub entity_id: i32,
2918    /// `vehicleId`
2919    pub vehicle_id: i32,
2920}
2921#[cfg(any(
2922    feature = "v1_12_2",
2923    feature = "v1_16_5",
2924    feature = "v26_1",
2925    feature = "v26_2",
2926    feature = "v26_3"
2927))]
2928impl<const V: i32> Decode for AttachEntity<V> {
2929    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2930        Ok({
2931            let v1 = r.read_i32()?;
2932            let v2 = r.read_i32()?;
2933            Self {
2934                entity_id: v1,
2935                vehicle_id: v2,
2936            }
2937        })
2938    }
2939}
2940#[cfg(any(
2941    feature = "v1_12_2",
2942    feature = "v1_16_5",
2943    feature = "v26_1",
2944    feature = "v26_2",
2945    feature = "v26_3"
2946))]
2947impl<const V: i32> Encode for AttachEntity<V> {
2948    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2949        w.put_i32((*self).entity_id);
2950        w.put_i32((*self).vehicle_id);
2951        Ok(())
2952    }
2953}
2954#[cfg(any(
2955    feature = "v1_12_2",
2956    feature = "v1_16_5",
2957    feature = "v26_1",
2958    feature = "v26_2",
2959    feature = "v26_3"
2960))]
2961#[cfg(feature = "testgen")]
2962impl<const V: i32> Generate for AttachEntity<V> {
2963    fn generate(g: &mut Gen) -> Self {
2964        {
2965            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2966            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2967            Self {
2968                entity_id: v1,
2969                vehicle_id: v2,
2970            }
2971        }
2972    }
2973}
2974
2975#[cfg(feature = "v1_12_2")]
2976/// `entity_equipment` (clientbound play).
2977#[derive(Debug, Clone, PartialEq)]
2978pub struct EntityEquipment<const V: i32> {
2979    /// `entityId`
2980    pub entity_id: i32,
2981    /// `slot`
2982    pub slot: i32,
2983    /// `item`
2984    pub item: crate::types::slot::legacy::Slot,
2985}
2986#[cfg(feature = "v1_12_2")]
2987impl<const V: i32> Decode for EntityEquipment<V> {
2988    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2989        Ok({
2990            let v1 = r.read_varint()?;
2991            let v2 = r.read_varint()?;
2992            let v3 = <crate::types::slot::legacy::Slot as Decode>::decode(r)?;
2993            Self {
2994                entity_id: v1,
2995                slot: v2,
2996                item: v3,
2997            }
2998        })
2999    }
3000}
3001#[cfg(feature = "v1_12_2")]
3002impl<const V: i32> Encode for EntityEquipment<V> {
3003    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3004        w.put_varint((*self).entity_id);
3005        w.put_varint((*self).slot);
3006        (*self).item.encode(w)?;
3007        Ok(())
3008    }
3009}
3010#[cfg(feature = "v1_12_2")]
3011#[cfg(feature = "testgen")]
3012impl<const V: i32> Generate for EntityEquipment<V> {
3013    fn generate(g: &mut Gen) -> Self {
3014        {
3015            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3016            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3017            let v3 = <crate::types::slot::legacy::Slot as Generate>::generate(g);
3018            Self {
3019                entity_id: v1,
3020                slot: v2,
3021                item: v3,
3022            }
3023        }
3024    }
3025}
3026
3027#[cfg(any(
3028    feature = "v1_12_2",
3029    feature = "v1_16_5",
3030    feature = "v26_1",
3031    feature = "v26_2",
3032    feature = "v26_3"
3033))]
3034/// `set_passengers` (clientbound play).
3035#[derive(Debug, Clone, PartialEq)]
3036pub struct SetPassengers<const V: i32> {
3037    /// `entityId`
3038    pub entity_id: i32,
3039    /// `passengers`
3040    pub passengers: Vec<i32>,
3041}
3042#[cfg(any(
3043    feature = "v1_12_2",
3044    feature = "v1_16_5",
3045    feature = "v26_1",
3046    feature = "v26_2",
3047    feature = "v26_3"
3048))]
3049impl<const V: i32> Decode for SetPassengers<V> {
3050    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3051        Ok({
3052            let v1 = r.read_varint()?;
3053            let v2 = {
3054                let v3 = {
3055                    let c = r.read_varint()?;
3056                    r.check_count(i64::from(c), 1)?
3057                };
3058                let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
3059                for _ in 0..v3 {
3060                    v4.push(r.read_varint()?);
3061                }
3062                v4
3063            };
3064            Self {
3065                entity_id: v1,
3066                passengers: v2,
3067            }
3068        })
3069    }
3070}
3071#[cfg(any(
3072    feature = "v1_12_2",
3073    feature = "v1_16_5",
3074    feature = "v26_1",
3075    feature = "v26_2",
3076    feature = "v26_3"
3077))]
3078impl<const V: i32> Encode for SetPassengers<V> {
3079    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3080        w.put_varint((*self).entity_id);
3081        w.put_len_varint((*self).passengers.len())?;
3082        for v1 in (*self).passengers.iter() {
3083            w.put_varint((*v1));
3084        }
3085        Ok(())
3086    }
3087}
3088#[cfg(any(
3089    feature = "v1_12_2",
3090    feature = "v1_16_5",
3091    feature = "v26_1",
3092    feature = "v26_2",
3093    feature = "v26_3"
3094))]
3095#[cfg(feature = "testgen")]
3096impl<const V: i32> Generate for SetPassengers<V> {
3097    fn generate(g: &mut Gen) -> Self {
3098        {
3099            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3100            let v2 = {
3101                let v3 = g.count();
3102                let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
3103                for _ in 0..v3 {
3104                    v4.push((g.int_in(-2147483648, 2147483647, &[]) as i32));
3105                }
3106                v4
3107            };
3108            Self {
3109                entity_id: v1,
3110                passengers: v2,
3111            }
3112        }
3113    }
3114}
3115
3116#[cfg(feature = "v1_12_2")]
3117/// `teams` (clientbound play).
3118#[derive(Debug, Clone, PartialEq)]
3119pub struct Teams<const V: i32> {
3120    /// `team`
3121    pub team: ByteString,
3122    /// `mode`
3123    pub mode: i8,
3124    /// `name`
3125    pub name: Option<ByteString>,
3126    /// `prefix`
3127    pub prefix: Option<ByteString>,
3128    /// `suffix`
3129    pub suffix: Option<ByteString>,
3130    /// `friendlyFire`
3131    pub friendly_fire: Option<i8>,
3132    /// `nameTagVisibility`
3133    pub name_tag_visibility: Option<ByteString>,
3134    /// `collisionRule`
3135    pub collision_rule: Option<ByteString>,
3136    /// `color`
3137    pub color: Option<i8>,
3138    /// `players`
3139    pub players: Option<Vec<ByteString>>,
3140}
3141#[cfg(feature = "v1_12_2")]
3142impl<const V: i32> Decode for Teams<V> {
3143    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3144        Ok({
3145            let v1 = r.read_string()?;
3146            let v2 = r.read_i8()?;
3147            let v3 = if (v2 == 0) || (v2 == 2) {
3148                Some(r.read_string()?)
3149            } else {
3150                None
3151            };
3152            let v4 = if (v2 == 0) || (v2 == 2) {
3153                Some(r.read_string()?)
3154            } else {
3155                None
3156            };
3157            let v5 = if (v2 == 0) || (v2 == 2) {
3158                Some(r.read_string()?)
3159            } else {
3160                None
3161            };
3162            let v6 = if (v2 == 0) || (v2 == 2) {
3163                Some(r.read_i8()?)
3164            } else {
3165                None
3166            };
3167            let v7 = if (v2 == 0) || (v2 == 2) {
3168                Some(r.read_string()?)
3169            } else {
3170                None
3171            };
3172            let v8 = if (v2 == 0) || (v2 == 2) {
3173                Some(r.read_string()?)
3174            } else {
3175                None
3176            };
3177            let v9 = if (v2 == 0) || (v2 == 2) {
3178                Some(r.read_i8()?)
3179            } else {
3180                None
3181            };
3182            let v10 = if (v2 == 0) || (v2 == 3) || (v2 == 4) {
3183                Some({
3184                    let v11 = {
3185                        let c = r.read_varint()?;
3186                        r.check_count(i64::from(c), 1)?
3187                    };
3188                    let mut v12 = Vec::with_capacity(v11.min(crate::codec::PREALLOC_LIMIT));
3189                    for _ in 0..v11 {
3190                        v12.push(r.read_string()?);
3191                    }
3192                    v12
3193                })
3194            } else {
3195                None
3196            };
3197            Self {
3198                team: v1,
3199                mode: v2,
3200                name: v3,
3201                prefix: v4,
3202                suffix: v5,
3203                friendly_fire: v6,
3204                name_tag_visibility: v7,
3205                collision_rule: v8,
3206                color: v9,
3207                players: v10,
3208            }
3209        })
3210    }
3211}
3212#[cfg(feature = "v1_12_2")]
3213impl<const V: i32> Encode for Teams<V> {
3214    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3215        w.put_string(&(*self).team)?;
3216        w.put_i8((*self).mode);
3217        match (&(*self).name, ((*self).mode == 0) || ((*self).mode == 2)) {
3218            (Some(v1), true) => {
3219                w.put_string(&(*v1))?;
3220            }
3221            (None, false) => {}
3222            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.teams.name")),
3223        }
3224        match (&(*self).prefix, ((*self).mode == 0) || ((*self).mode == 2)) {
3225            (Some(v2), true) => {
3226                w.put_string(&(*v2))?;
3227            }
3228            (None, false) => {}
3229            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.teams.prefix")),
3230        }
3231        match (&(*self).suffix, ((*self).mode == 0) || ((*self).mode == 2)) {
3232            (Some(v3), true) => {
3233                w.put_string(&(*v3))?;
3234            }
3235            (None, false) => {}
3236            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.teams.suffix")),
3237        }
3238        match (
3239            &(*self).friendly_fire,
3240            ((*self).mode == 0) || ((*self).mode == 2),
3241        ) {
3242            (Some(v4), true) => {
3243                w.put_i8((*v4));
3244            }
3245            (None, false) => {}
3246            _ => {
3247                return Err(EncodeError::SwitchMismatch(
3248                    "play.clientbound.teams.friendlyFire",
3249                ));
3250            }
3251        }
3252        match (
3253            &(*self).name_tag_visibility,
3254            ((*self).mode == 0) || ((*self).mode == 2),
3255        ) {
3256            (Some(v5), true) => {
3257                w.put_string(&(*v5))?;
3258            }
3259            (None, false) => {}
3260            _ => {
3261                return Err(EncodeError::SwitchMismatch(
3262                    "play.clientbound.teams.nameTagVisibility",
3263                ));
3264            }
3265        }
3266        match (
3267            &(*self).collision_rule,
3268            ((*self).mode == 0) || ((*self).mode == 2),
3269        ) {
3270            (Some(v6), true) => {
3271                w.put_string(&(*v6))?;
3272            }
3273            (None, false) => {}
3274            _ => {
3275                return Err(EncodeError::SwitchMismatch(
3276                    "play.clientbound.teams.collisionRule",
3277                ));
3278            }
3279        }
3280        match (&(*self).color, ((*self).mode == 0) || ((*self).mode == 2)) {
3281            (Some(v7), true) => {
3282                w.put_i8((*v7));
3283            }
3284            (None, false) => {}
3285            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.teams.color")),
3286        }
3287        match (
3288            &(*self).players,
3289            ((*self).mode == 0) || ((*self).mode == 3) || ((*self).mode == 4),
3290        ) {
3291            (Some(v8), true) => {
3292                w.put_len_varint((*v8).len())?;
3293                for v9 in (*v8).iter() {
3294                    w.put_string(&(*v9))?;
3295                }
3296            }
3297            (None, false) => {}
3298            _ => {
3299                return Err(EncodeError::SwitchMismatch(
3300                    "play.clientbound.teams.players",
3301                ));
3302            }
3303        }
3304        Ok(())
3305    }
3306}
3307#[cfg(feature = "v1_12_2")]
3308#[cfg(feature = "testgen")]
3309impl<const V: i32> Generate for Teams<V> {
3310    fn generate(g: &mut Gen) -> Self {
3311        {
3312            let v1 = g.string();
3313            let v2 = (g.int_in(
3314                -128,
3315                127,
3316                &[0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 3, 4],
3317            ) as i8);
3318            let v3 = if (v2 == 0) || (v2 == 2) {
3319                Some(g.string())
3320            } else {
3321                None
3322            };
3323            let v4 = if (v2 == 0) || (v2 == 2) {
3324                Some(g.string())
3325            } else {
3326                None
3327            };
3328            let v5 = if (v2 == 0) || (v2 == 2) {
3329                Some(g.string())
3330            } else {
3331                None
3332            };
3333            let v6 = if (v2 == 0) || (v2 == 2) {
3334                Some((g.int_in(-128, 127, &[]) as i8))
3335            } else {
3336                None
3337            };
3338            let v7 = if (v2 == 0) || (v2 == 2) {
3339                Some(g.string())
3340            } else {
3341                None
3342            };
3343            let v8 = if (v2 == 0) || (v2 == 2) {
3344                Some(g.string())
3345            } else {
3346                None
3347            };
3348            let v9 = if (v2 == 0) || (v2 == 2) {
3349                Some((g.int_in(-128, 127, &[]) as i8))
3350            } else {
3351                None
3352            };
3353            let v10 = if (v2 == 0) || (v2 == 3) || (v2 == 4) {
3354                Some({
3355                    let v11 = g.count();
3356                    let mut v12 = Vec::with_capacity(v11.min(crate::codec::PREALLOC_LIMIT));
3357                    for _ in 0..v11 {
3358                        v12.push(g.string());
3359                    }
3360                    v12
3361                })
3362            } else {
3363                None
3364            };
3365            Self {
3366                team: v1,
3367                mode: v2,
3368                name: v3,
3369                prefix: v4,
3370                suffix: v5,
3371                friendly_fire: v6,
3372                name_tag_visibility: v7,
3373                collision_rule: v8,
3374                color: v9,
3375                players: v10,
3376            }
3377        }
3378    }
3379}
3380
3381#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3382/// `title` (clientbound play).
3383#[derive(Debug, Clone, PartialEq)]
3384pub struct Title<const V: i32> {
3385    /// `action`
3386    pub action: i32,
3387    /// `text`
3388    pub text: Option<ByteString>,
3389    /// `fadeIn`
3390    pub fade_in: Option<i32>,
3391    /// `stay`
3392    pub stay: Option<i32>,
3393    /// `fadeOut`
3394    pub fade_out: Option<i32>,
3395}
3396#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3397impl<const V: i32> Decode for Title<V> {
3398    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3399        Ok({
3400            let v1 = r.read_varint()?;
3401            let v2 = if (v1 == 0) || (v1 == 1) || (v1 == 2) {
3402                Some(r.read_string()?)
3403            } else {
3404                None
3405            };
3406            let v3 = if (v1 == 3) { Some(r.read_i32()?) } else { None };
3407            let v4 = if (v1 == 3) { Some(r.read_i32()?) } else { None };
3408            let v5 = if (v1 == 3) { Some(r.read_i32()?) } else { None };
3409            Self {
3410                action: v1,
3411                text: v2,
3412                fade_in: v3,
3413                stay: v4,
3414                fade_out: v5,
3415            }
3416        })
3417    }
3418}
3419#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3420impl<const V: i32> Encode for Title<V> {
3421    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3422        w.put_varint((*self).action);
3423        match (
3424            &(*self).text,
3425            ((*self).action == 0) || ((*self).action == 1) || ((*self).action == 2),
3426        ) {
3427            (Some(v1), true) => {
3428                w.put_string(&(*v1))?;
3429            }
3430            (None, false) => {}
3431            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.title.text")),
3432        }
3433        match (&(*self).fade_in, ((*self).action == 3)) {
3434            (Some(v2), true) => {
3435                w.put_i32((*v2));
3436            }
3437            (None, false) => {}
3438            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.title.fadeIn")),
3439        }
3440        match (&(*self).stay, ((*self).action == 3)) {
3441            (Some(v3), true) => {
3442                w.put_i32((*v3));
3443            }
3444            (None, false) => {}
3445            _ => return Err(EncodeError::SwitchMismatch("play.clientbound.title.stay")),
3446        }
3447        match (&(*self).fade_out, ((*self).action == 3)) {
3448            (Some(v4), true) => {
3449                w.put_i32((*v4));
3450            }
3451            (None, false) => {}
3452            _ => {
3453                return Err(EncodeError::SwitchMismatch(
3454                    "play.clientbound.title.fadeOut",
3455                ));
3456            }
3457        }
3458        Ok(())
3459    }
3460}
3461#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3462#[cfg(feature = "testgen")]
3463impl<const V: i32> Generate for Title<V> {
3464    fn generate(g: &mut Gen) -> Self {
3465        {
3466            let v1 = (g.int_in(-2147483648, 2147483647, &[0, 1, 2, 3, 3, 3]) as i32);
3467            let v2 = if (v1 == 0) || (v1 == 1) || (v1 == 2) {
3468                Some(g.string())
3469            } else {
3470                None
3471            };
3472            let v3 = if (v1 == 3) {
3473                Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
3474            } else {
3475                None
3476            };
3477            let v4 = if (v1 == 3) {
3478                Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
3479            } else {
3480                None
3481            };
3482            let v5 = if (v1 == 3) {
3483                Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
3484            } else {
3485                None
3486            };
3487            Self {
3488                action: v1,
3489                text: v2,
3490                fade_in: v3,
3491                stay: v4,
3492                fade_out: v5,
3493            }
3494        }
3495    }
3496}
3497
3498#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3499/// `sound_effect` (clientbound play).
3500#[derive(Debug, Clone, PartialEq)]
3501pub struct SoundEffect<const V: i32> {
3502    /// `soundId`
3503    pub sound_id: i32,
3504    /// `soundCategory`
3505    pub sound_category: i32,
3506    /// `x`
3507    pub x: i32,
3508    /// `y`
3509    pub y: i32,
3510    /// `z`
3511    pub z: i32,
3512    /// `volume`
3513    pub volume: f32,
3514    /// `pitch`
3515    pub pitch: f32,
3516}
3517#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3518impl<const V: i32> Decode for SoundEffect<V> {
3519    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3520        Ok({
3521            let v1 = r.read_varint()?;
3522            let v2 = r.read_varint()?;
3523            let v3 = r.read_i32()?;
3524            let v4 = r.read_i32()?;
3525            let v5 = r.read_i32()?;
3526            let v6 = r.read_f32()?;
3527            let v7 = r.read_f32()?;
3528            Self {
3529                sound_id: v1,
3530                sound_category: v2,
3531                x: v3,
3532                y: v4,
3533                z: v5,
3534                volume: v6,
3535                pitch: v7,
3536            }
3537        })
3538    }
3539}
3540#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3541impl<const V: i32> Encode for SoundEffect<V> {
3542    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3543        w.put_varint((*self).sound_id);
3544        w.put_varint((*self).sound_category);
3545        w.put_i32((*self).x);
3546        w.put_i32((*self).y);
3547        w.put_i32((*self).z);
3548        w.put_f32((*self).volume);
3549        w.put_f32((*self).pitch);
3550        Ok(())
3551    }
3552}
3553#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3554#[cfg(feature = "testgen")]
3555impl<const V: i32> Generate for SoundEffect<V> {
3556    fn generate(g: &mut Gen) -> Self {
3557        {
3558            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3559            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3560            let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3561            let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3562            let v5 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3563            let v6 = g.f32();
3564            let v7 = g.f32();
3565            Self {
3566                sound_id: v1,
3567                sound_category: v2,
3568                x: v3,
3569                y: v4,
3570                z: v5,
3571                volume: v6,
3572                pitch: v7,
3573            }
3574        }
3575    }
3576}
3577
3578#[cfg(any(
3579    feature = "v1_12_2",
3580    feature = "v1_16_5",
3581    feature = "v26_1",
3582    feature = "v26_2",
3583    feature = "v26_3"
3584))]
3585/// `collect` (clientbound play).
3586#[derive(Debug, Clone, PartialEq)]
3587pub struct Collect<const V: i32> {
3588    /// `collectedEntityId`
3589    pub collected_entity_id: i32,
3590    /// `collectorEntityId`
3591    pub collector_entity_id: i32,
3592    /// `pickupItemCount`
3593    pub pickup_item_count: i32,
3594}
3595#[cfg(any(
3596    feature = "v1_12_2",
3597    feature = "v1_16_5",
3598    feature = "v26_1",
3599    feature = "v26_2",
3600    feature = "v26_3"
3601))]
3602impl<const V: i32> Decode for Collect<V> {
3603    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3604        Ok({
3605            let v1 = r.read_varint()?;
3606            let v2 = r.read_varint()?;
3607            let v3 = r.read_varint()?;
3608            Self {
3609                collected_entity_id: v1,
3610                collector_entity_id: v2,
3611                pickup_item_count: v3,
3612            }
3613        })
3614    }
3615}
3616#[cfg(any(
3617    feature = "v1_12_2",
3618    feature = "v1_16_5",
3619    feature = "v26_1",
3620    feature = "v26_2",
3621    feature = "v26_3"
3622))]
3623impl<const V: i32> Encode for Collect<V> {
3624    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3625        w.put_varint((*self).collected_entity_id);
3626        w.put_varint((*self).collector_entity_id);
3627        w.put_varint((*self).pickup_item_count);
3628        Ok(())
3629    }
3630}
3631#[cfg(any(
3632    feature = "v1_12_2",
3633    feature = "v1_16_5",
3634    feature = "v26_1",
3635    feature = "v26_2",
3636    feature = "v26_3"
3637))]
3638#[cfg(feature = "testgen")]
3639impl<const V: i32> Generate for Collect<V> {
3640    fn generate(g: &mut Gen) -> Self {
3641        {
3642            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3643            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3644            let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3645            Self {
3646                collected_entity_id: v1,
3647                collector_entity_id: v2,
3648                pickup_item_count: v3,
3649            }
3650        }
3651    }
3652}
3653
3654#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3655/// `entity_teleport` (clientbound play).
3656#[derive(Debug, Clone, PartialEq)]
3657pub struct EntityTeleport<const V: i32> {
3658    /// `entityId`
3659    pub entity_id: i32,
3660    /// `x`
3661    pub x: f64,
3662    /// `y`
3663    pub y: f64,
3664    /// `z`
3665    pub z: f64,
3666    /// `yaw`
3667    pub yaw: i8,
3668    /// `pitch`
3669    pub pitch: i8,
3670    /// `onGround`
3671    pub on_ground: bool,
3672}
3673#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3674impl<const V: i32> Decode for EntityTeleport<V> {
3675    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3676        Ok({
3677            let v1 = r.read_varint()?;
3678            let v2 = r.read_f64()?;
3679            let v3 = r.read_f64()?;
3680            let v4 = r.read_f64()?;
3681            let v5 = r.read_i8()?;
3682            let v6 = r.read_i8()?;
3683            let v7 = r.read_bool()?;
3684            Self {
3685                entity_id: v1,
3686                x: v2,
3687                y: v3,
3688                z: v4,
3689                yaw: v5,
3690                pitch: v6,
3691                on_ground: v7,
3692            }
3693        })
3694    }
3695}
3696#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3697impl<const V: i32> Encode for EntityTeleport<V> {
3698    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3699        w.put_varint((*self).entity_id);
3700        w.put_f64((*self).x);
3701        w.put_f64((*self).y);
3702        w.put_f64((*self).z);
3703        w.put_i8((*self).yaw);
3704        w.put_i8((*self).pitch);
3705        w.put_bool((*self).on_ground);
3706        Ok(())
3707    }
3708}
3709#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3710#[cfg(feature = "testgen")]
3711impl<const V: i32> Generate for EntityTeleport<V> {
3712    fn generate(g: &mut Gen) -> Self {
3713        {
3714            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3715            let v2 = g.f64();
3716            let v3 = g.f64();
3717            let v4 = g.f64();
3718            let v5 = (g.int_in(-128, 127, &[]) as i8);
3719            let v6 = (g.int_in(-128, 127, &[]) as i8);
3720            let v7 = g.bool();
3721            Self {
3722                entity_id: v1,
3723                x: v2,
3724                y: v3,
3725                z: v4,
3726                yaw: v5,
3727                pitch: v6,
3728                on_ground: v7,
3729            }
3730        }
3731    }
3732}
3733
3734#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3735/// Packed bit field.
3736#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
3737pub struct AdvancementsAdvancementMappingValueDisplayDataFlags {
3738    /// `_unused` (29 bits)
3739    pub _unused: u32,
3740    /// `hidden` (1 bits)
3741    pub hidden: u8,
3742    /// `show_toast` (1 bits)
3743    pub show_toast: u8,
3744    /// `has_background_texture` (1 bits)
3745    pub has_background_texture: u8,
3746}
3747
3748#[cfg(feature = "v1_12_2")]
3749/// Nested container.
3750#[derive(Debug, Clone, PartialEq)]
3751pub struct AdvancementsAdvancementMappingValueDisplayData {
3752    /// `title`
3753    pub title: ByteString,
3754    /// `description`
3755    pub description: ByteString,
3756    /// `icon`
3757    pub icon: crate::types::slot::legacy::Slot,
3758    /// `frameType`
3759    pub frame_type: i32,
3760    /// `flags`
3761    pub flags:
3762        crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueDisplayDataFlags,
3763    /// `backgroundTexture`
3764    pub background_texture: Option<ByteString>,
3765    /// `xCord`
3766    pub x_cord: f32,
3767    /// `yCord`
3768    pub y_cord: f32,
3769}
3770
3771#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3772/// Nested container.
3773#[derive(Debug, Clone, PartialEq)]
3774pub struct AdvancementsAdvancementMappingValueCriteria {
3775    /// `key`
3776    pub key: ByteString,
3777}
3778
3779#[cfg(feature = "v1_12_2")]
3780/// Nested container.
3781#[derive(Debug, Clone, PartialEq)]
3782pub struct AdvancementsAdvancementMappingValue {
3783    /// `parentId`
3784    pub parent_id: Option<ByteString>,
3785    /// `displayData`
3786    pub display_data: Option<
3787        crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueDisplayData,
3788    >,
3789    /// `criteria`
3790    pub criteria:
3791        Vec<crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueCriteria>,
3792    /// `requirements`
3793    pub requirements: Vec<Vec<ByteString>>,
3794}
3795
3796#[cfg(feature = "v1_12_2")]
3797/// Nested container.
3798#[derive(Debug, Clone, PartialEq)]
3799pub struct AdvancementsAdvancementMapping {
3800    /// `key`
3801    pub key: ByteString,
3802    /// `value`
3803    pub value: crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValue,
3804}
3805
3806#[cfg(any(
3807    feature = "v1_12_2",
3808    feature = "v1_16_5",
3809    feature = "v26_1",
3810    feature = "v26_2",
3811    feature = "v26_3"
3812))]
3813/// Nested container.
3814#[derive(Debug, Clone, PartialEq)]
3815pub struct AdvancementsProgressMappingValue {
3816    /// `criterionIdentifier`
3817    pub criterion_identifier: ByteString,
3818    /// `criterionProgress`
3819    pub criterion_progress: Option<i64>,
3820}
3821
3822#[cfg(any(
3823    feature = "v1_12_2",
3824    feature = "v1_16_5",
3825    feature = "v26_1",
3826    feature = "v26_2",
3827    feature = "v26_3"
3828))]
3829/// Nested container.
3830#[derive(Debug, Clone, PartialEq)]
3831pub struct AdvancementsProgressMapping {
3832    /// `key`
3833    pub key: ByteString,
3834    /// `value`
3835    pub value: Vec<crate::defs::p340::play::clientbound::AdvancementsProgressMappingValue>,
3836}
3837
3838#[cfg(feature = "v1_12_2")]
3839/// `advancements` (clientbound play).
3840#[derive(Debug, Clone, PartialEq)]
3841pub struct Advancements<const V: i32> {
3842    /// `reset`
3843    pub reset: bool,
3844    /// `advancementMapping`
3845    pub advancement_mapping:
3846        Vec<crate::defs::p340::play::clientbound::AdvancementsAdvancementMapping>,
3847    /// `identifiers`
3848    pub identifiers: Vec<ByteString>,
3849    /// `progressMapping`
3850    pub progress_mapping: Vec<crate::defs::p340::play::clientbound::AdvancementsProgressMapping>,
3851}
3852#[cfg(feature = "v1_12_2")]
3853impl<const V: i32> Decode for Advancements<V> {
3854    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3855        Ok({
3856            let v1 = r.read_bool()?;
3857            let v2 = {
3858                let v3 = {
3859                    let c = r.read_varint()?;
3860                    r.check_count(i64::from(c), 5)?
3861                };
3862                let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
3863                for _ in 0..v3 {
3864                    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 } });
3865                }
3866                v4
3867            };
3868            let v28 = {
3869                let v29 = {
3870                    let c = r.read_varint()?;
3871                    r.check_count(i64::from(c), 1)?
3872                };
3873                let mut v30 = Vec::with_capacity(v29.min(crate::codec::PREALLOC_LIMIT));
3874                for _ in 0..v29 {
3875                    v30.push(r.read_string()?);
3876                }
3877                v30
3878            };
3879            let v31 = {
3880                let v32 = {
3881                    let c = r.read_varint()?;
3882                    r.check_count(i64::from(c), 2)?
3883                };
3884                let mut v33 = Vec::with_capacity(v32.min(crate::codec::PREALLOC_LIMIT));
3885                for _ in 0..v32 {
3886                    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 } });
3887                }
3888                v33
3889            };
3890            Self {
3891                reset: v1,
3892                advancement_mapping: v2,
3893                identifiers: v28,
3894                progress_mapping: v31,
3895            }
3896        })
3897    }
3898}
3899#[cfg(feature = "v1_12_2")]
3900impl<const V: i32> Encode for Advancements<V> {
3901    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3902        w.put_bool((*self).reset);
3903        w.put_len_varint((*self).advancement_mapping.len())?;
3904        for v1 in (*self).advancement_mapping.iter() {
3905            w.put_string(&(*v1).key)?;
3906            match &(*v1).value.parent_id {
3907                Some(v2) => {
3908                    w.put_u8(1);
3909                    w.put_string(&(*v2))?;
3910                }
3911                None => w.put_u8(0),
3912            }
3913            match &(*v1).value.display_data {
3914                Some(v3) => {
3915                    w.put_u8(1);
3916                    w.put_string(&(*v3).title)?;
3917                    w.put_string(&(*v3).description)?;
3918                    (*v3).icon.encode(w)?;
3919                    w.put_varint((*v3).frame_type);
3920                    {
3921                        let mut bits: u64 = 0;
3922                        {
3923                            let x = i128::from((*v3).flags._unused);
3924                            if x < 0 || x > 536870911 {
3925                                return Err(EncodeError::OutOfRange("_unused"));
3926                            }
3927                            bits = (bits << 29) | ((x as u64) & 0x1fffffff);
3928                        }
3929                        {
3930                            let x = i128::from((*v3).flags.hidden);
3931                            if x < 0 || x > 1 {
3932                                return Err(EncodeError::OutOfRange("hidden"));
3933                            }
3934                            bits = (bits << 1) | ((x as u64) & 0x1);
3935                        }
3936                        {
3937                            let x = i128::from((*v3).flags.show_toast);
3938                            if x < 0 || x > 1 {
3939                                return Err(EncodeError::OutOfRange("show_toast"));
3940                            }
3941                            bits = (bits << 1) | ((x as u64) & 0x1);
3942                        }
3943                        {
3944                            let x = i128::from((*v3).flags.has_background_texture);
3945                            if x < 0 || x > 1 {
3946                                return Err(EncodeError::OutOfRange("has_background_texture"));
3947                            }
3948                            bits = (bits << 1) | ((x as u64) & 0x1);
3949                        }
3950                        w.put_u32(bits as u32);
3951                    }
3952                    match (
3953                        &(*v3).background_texture,
3954                        ((*v3).flags.has_background_texture == 1),
3955                    ) {
3956                        (Some(v4), true) => {
3957                            w.put_string(&(*v4))?;
3958                        }
3959                        (None, false) => {}
3960                        _ => {
3961                            return Err(EncodeError::SwitchMismatch(
3962                                "play.clientbound.advancements.advancementMapping.value.displayData.backgroundTexture",
3963                            ));
3964                        }
3965                    }
3966                    w.put_f32((*v3).x_cord);
3967                    w.put_f32((*v3).y_cord);
3968                }
3969                None => w.put_u8(0),
3970            }
3971            w.put_len_varint((*v1).value.criteria.len())?;
3972            for v5 in (*v1).value.criteria.iter() {
3973                w.put_string(&(*v5).key)?;
3974            }
3975            w.put_len_varint((*v1).value.requirements.len())?;
3976            for v6 in (*v1).value.requirements.iter() {
3977                w.put_len_varint((*v6).len())?;
3978                for v7 in (*v6).iter() {
3979                    w.put_string(&(*v7))?;
3980                }
3981            }
3982        }
3983        w.put_len_varint((*self).identifiers.len())?;
3984        for v8 in (*self).identifiers.iter() {
3985            w.put_string(&(*v8))?;
3986        }
3987        w.put_len_varint((*self).progress_mapping.len())?;
3988        for v9 in (*self).progress_mapping.iter() {
3989            w.put_string(&(*v9).key)?;
3990            w.put_len_varint((*v9).value.len())?;
3991            for v10 in (*v9).value.iter() {
3992                w.put_string(&(*v10).criterion_identifier)?;
3993                match &(*v10).criterion_progress {
3994                    Some(v11) => {
3995                        w.put_u8(1);
3996                        w.put_i64((*v11));
3997                    }
3998                    None => w.put_u8(0),
3999                }
4000            }
4001        }
4002        Ok(())
4003    }
4004}
4005#[cfg(feature = "v1_12_2")]
4006#[cfg(feature = "testgen")]
4007impl<const V: i32> Generate for Advancements<V> {
4008    fn generate(g: &mut Gen) -> Self {
4009        {
4010            let v1 = g.bool();
4011            let v2 = {
4012                let v3 = g.count();
4013                let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
4014                for _ in 0..v3 {
4015                    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 } });
4016                }
4017                v4
4018            };
4019            let v28 = {
4020                let v29 = g.count();
4021                let mut v30 = Vec::with_capacity(v29.min(crate::codec::PREALLOC_LIMIT));
4022                for _ in 0..v29 {
4023                    v30.push(g.string());
4024                }
4025                v30
4026            };
4027            let v31 = {
4028                let v32 = g.count();
4029                let mut v33 = Vec::with_capacity(v32.min(crate::codec::PREALLOC_LIMIT));
4030                for _ in 0..v32 {
4031                    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 } });
4032                }
4033                v33
4034            };
4035            Self {
4036                reset: v1,
4037                advancement_mapping: v2,
4038                identifiers: v28,
4039                progress_mapping: v31,
4040            }
4041        }
4042    }
4043}
4044
4045#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4046/// Nested container.
4047#[derive(Debug, Clone, PartialEq)]
4048pub struct EntityUpdateAttributesPropertiesModifiers {
4049    /// `uuid`
4050    pub uuid: Uuid,
4051    /// `amount`
4052    pub amount: f64,
4053    /// `operation`
4054    pub operation: i8,
4055}
4056
4057#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4058/// Nested container.
4059#[derive(Debug, Clone, PartialEq)]
4060pub struct EntityUpdateAttributesProperties {
4061    /// `key`
4062    pub key: ByteString,
4063    /// `value`
4064    pub value: f64,
4065    /// `modifiers`
4066    pub modifiers:
4067        Vec<crate::defs::p340::play::clientbound::EntityUpdateAttributesPropertiesModifiers>,
4068}
4069
4070#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4071/// `entity_update_attributes` (clientbound play).
4072#[derive(Debug, Clone, PartialEq)]
4073pub struct EntityUpdateAttributes<const V: i32> {
4074    /// `entityId`
4075    pub entity_id: i32,
4076    /// `properties`
4077    pub properties: Vec<crate::defs::p340::play::clientbound::EntityUpdateAttributesProperties>,
4078}
4079#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4080impl<const V: i32> Decode for EntityUpdateAttributes<V> {
4081    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
4082        Ok({
4083            let v1 = r.read_varint()?;
4084            let v2 = {
4085                let v3 = {
4086                    let c = r.read_i32()?;
4087                    r.check_count(i64::from(c), 10)?
4088                };
4089                let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
4090                for _ in 0..v3 {
4091                    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 } });
4092                }
4093                v4
4094            };
4095            Self {
4096                entity_id: v1,
4097                properties: v2,
4098            }
4099        })
4100    }
4101}
4102#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4103impl<const V: i32> Encode for EntityUpdateAttributes<V> {
4104    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
4105        w.put_varint((*self).entity_id);
4106        w.put_i32(crate::codec::count_i32((*self).properties.len())?);
4107        for v1 in (*self).properties.iter() {
4108            w.put_string(&(*v1).key)?;
4109            w.put_f64((*v1).value);
4110            w.put_len_varint((*v1).modifiers.len())?;
4111            for v2 in (*v1).modifiers.iter() {
4112                w.put_uuid(&(*v2).uuid);
4113                w.put_f64((*v2).amount);
4114                w.put_i8((*v2).operation);
4115            }
4116        }
4117        Ok(())
4118    }
4119}
4120#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4121#[cfg(feature = "testgen")]
4122impl<const V: i32> Generate for EntityUpdateAttributes<V> {
4123    fn generate(g: &mut Gen) -> Self {
4124        {
4125            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
4126            let v2 = {
4127                let v3 = g.count();
4128                let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
4129                for _ in 0..v3 {
4130                    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 } });
4131                }
4132                v4
4133            };
4134            Self {
4135                entity_id: v1,
4136                properties: v2,
4137            }
4138        }
4139    }
4140}
4141
4142#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4143/// `entity_effect` (clientbound play).
4144#[derive(Debug, Clone, PartialEq)]
4145pub struct EntityEffect<const V: i32> {
4146    /// `entityId`
4147    pub entity_id: i32,
4148    /// `effectId`
4149    pub effect_id: i8,
4150    /// `amplifier`
4151    pub amplifier: i8,
4152    /// `duration`
4153    pub duration: i32,
4154    /// `hideParticles`
4155    pub hide_particles: i8,
4156}
4157#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4158impl<const V: i32> Decode for EntityEffect<V> {
4159    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
4160        Ok({
4161            let v1 = r.read_varint()?;
4162            let v2 = r.read_i8()?;
4163            let v3 = r.read_i8()?;
4164            let v4 = r.read_varint()?;
4165            let v5 = r.read_i8()?;
4166            Self {
4167                entity_id: v1,
4168                effect_id: v2,
4169                amplifier: v3,
4170                duration: v4,
4171                hide_particles: v5,
4172            }
4173        })
4174    }
4175}
4176#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4177impl<const V: i32> Encode for EntityEffect<V> {
4178    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
4179        w.put_varint((*self).entity_id);
4180        w.put_i8((*self).effect_id);
4181        w.put_i8((*self).amplifier);
4182        w.put_varint((*self).duration);
4183        w.put_i8((*self).hide_particles);
4184        Ok(())
4185    }
4186}
4187#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
4188#[cfg(feature = "testgen")]
4189impl<const V: i32> Generate for EntityEffect<V> {
4190    fn generate(g: &mut Gen) -> Self {
4191        {
4192            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
4193            let v2 = (g.int_in(-128, 127, &[]) as i8);
4194            let v3 = (g.int_in(-128, 127, &[]) as i8);
4195            let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
4196            let v5 = (g.int_in(-128, 127, &[]) as i8);
4197            Self {
4198                entity_id: v1,
4199                effect_id: v2,
4200                amplifier: v3,
4201                duration: v4,
4202                hide_particles: v5,
4203            }
4204        }
4205    }
4206}