Skip to main content

ghast_protocol/generated/defs/p340/play/
serverbound.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//! Serverbound 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(any(
29    feature = "v1_12_2",
30    feature = "v1_16_5",
31    feature = "v26_1",
32    feature = "v26_2"
33))]
34/// `teleport_confirm` (serverbound play).
35#[derive(Debug, Clone, PartialEq)]
36pub struct TeleportConfirm<const V: i32> {
37    /// `teleportId`
38    pub teleport_id: i32,
39}
40#[cfg(any(
41    feature = "v1_12_2",
42    feature = "v1_16_5",
43    feature = "v26_1",
44    feature = "v26_2"
45))]
46impl<const V: i32> Decode for TeleportConfirm<V> {
47    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
48        Ok({
49            let v1 = r.read_varint()?;
50            Self { teleport_id: v1 }
51        })
52    }
53}
54#[cfg(any(
55    feature = "v1_12_2",
56    feature = "v1_16_5",
57    feature = "v26_1",
58    feature = "v26_2"
59))]
60impl<const V: i32> Encode for TeleportConfirm<V> {
61    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
62        w.put_varint((*self).teleport_id);
63        Ok(())
64    }
65}
66#[cfg(any(
67    feature = "v1_12_2",
68    feature = "v1_16_5",
69    feature = "v26_1",
70    feature = "v26_2"
71))]
72#[cfg(feature = "testgen")]
73impl<const V: i32> Generate for TeleportConfirm<V> {
74    fn generate(g: &mut Gen) -> Self {
75        {
76            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
77            Self { teleport_id: v1 }
78        }
79    }
80}
81
82#[cfg(feature = "v1_12_2")]
83/// `tab_complete` (serverbound play).
84#[derive(Debug, Clone, PartialEq)]
85pub struct TabComplete<const V: i32> {
86    /// `text`
87    pub text: ByteString,
88    /// `assumeCommand`
89    pub assume_command: bool,
90    /// `lookedAtBlock`
91    pub looked_at_block: Option<BlockPos>,
92}
93#[cfg(feature = "v1_12_2")]
94impl<const V: i32> Decode for TabComplete<V> {
95    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
96        Ok({
97            let v1 = r.read_string()?;
98            let v2 = r.read_bool()?;
99            let v3 = if r.read_bool()? {
100                Some(BlockPos::read(r, PositionLayout::Xyz)?)
101            } else {
102                None
103            };
104            Self {
105                text: v1,
106                assume_command: v2,
107                looked_at_block: v3,
108            }
109        })
110    }
111}
112#[cfg(feature = "v1_12_2")]
113impl<const V: i32> Encode for TabComplete<V> {
114    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
115        w.put_string(&(*self).text)?;
116        w.put_bool((*self).assume_command);
117        match &(*self).looked_at_block {
118            Some(v1) => {
119                w.put_u8(1);
120                (*v1).write(w, PositionLayout::Xyz)?;
121            }
122            None => w.put_u8(0),
123        }
124        Ok(())
125    }
126}
127#[cfg(feature = "v1_12_2")]
128#[cfg(feature = "testgen")]
129impl<const V: i32> Generate for TabComplete<V> {
130    fn generate(g: &mut Gen) -> Self {
131        {
132            let v1 = g.string();
133            let v2 = g.bool();
134            let v3 = if g.bool() { Some(g.position()) } else { None };
135            Self {
136                text: v1,
137                assume_command: v2,
138                looked_at_block: v3,
139            }
140        }
141    }
142}
143
144#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
145/// Mapped `i32` value; unknown values are kept as-is.
146#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
147pub struct ClientCommandActionId(pub i32);
148#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
149impl ClientCommandActionId {
150    /// `perform_respawn`
151    pub const PERFORM_RESPAWN: Self = Self(0);
152    /// `request_stats`
153    pub const REQUEST_STATS: Self = Self(1);
154    /// minecraft-data name of the value, if known.
155    pub const fn name(self) -> Option<&'static str> {
156        match self.0 {
157            0 => Some("perform_respawn"),
158            1 => Some("request_stats"),
159            _ => None,
160        }
161    }
162}
163#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
164impl std::fmt::Debug for ClientCommandActionId {
165    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
166        match self.name() {
167            Some(n) => write!(f, "ClientCommandActionId::{n}"),
168            None => write!(f, "ClientCommandActionId({})", self.0),
169        }
170    }
171}
172
173#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
174/// `client_command` (serverbound play).
175#[derive(Debug, Clone, PartialEq)]
176pub struct ClientCommand<const V: i32> {
177    /// `actionId`
178    pub action_id: crate::defs::p340::play::serverbound::ClientCommandActionId,
179}
180#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
181impl<const V: i32> Decode for ClientCommand<V> {
182    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
183        Ok({
184            let v1 = crate::defs::p340::play::serverbound::ClientCommandActionId(r.read_varint()?);
185            Self { action_id: v1 }
186        })
187    }
188}
189#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
190impl<const V: i32> Encode for ClientCommand<V> {
191    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
192        w.put_varint((*self).action_id.0);
193        Ok(())
194    }
195}
196#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
197#[cfg(feature = "testgen")]
198impl<const V: i32> Generate for ClientCommand<V> {
199    fn generate(g: &mut Gen) -> Self {
200        {
201            let v1 = crate::defs::p340::play::serverbound::ClientCommandActionId(g.int_in(
202                -2147483648,
203                2147483647,
204                &[0, 1],
205            )
206                as i32);
207            Self { action_id: v1 }
208        }
209    }
210}
211
212#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
213/// `settings` (serverbound play).
214#[derive(Debug, Clone, PartialEq)]
215pub struct Settings<const V: i32> {
216    /// `locale`
217    pub locale: ByteString,
218    /// `viewDistance`
219    pub view_distance: i8,
220    /// `chatFlags`
221    pub chat_flags: i32,
222    /// `chatColors`
223    pub chat_colors: bool,
224    /// `skinParts`
225    pub skin_parts: u8,
226    /// `mainHand`
227    pub main_hand: i32,
228}
229#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
230impl<const V: i32> Decode for Settings<V> {
231    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
232        Ok({
233            let v1 = r.read_string()?;
234            let v2 = r.read_i8()?;
235            let v3 = r.read_varint()?;
236            let v4 = r.read_bool()?;
237            let v5 = r.read_u8()?;
238            let v6 = r.read_varint()?;
239            Self {
240                locale: v1,
241                view_distance: v2,
242                chat_flags: v3,
243                chat_colors: v4,
244                skin_parts: v5,
245                main_hand: v6,
246            }
247        })
248    }
249}
250#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
251impl<const V: i32> Encode for Settings<V> {
252    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
253        w.put_string(&(*self).locale)?;
254        w.put_i8((*self).view_distance);
255        w.put_varint((*self).chat_flags);
256        w.put_bool((*self).chat_colors);
257        w.put_u8((*self).skin_parts);
258        w.put_varint((*self).main_hand);
259        Ok(())
260    }
261}
262#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
263#[cfg(feature = "testgen")]
264impl<const V: i32> Generate for Settings<V> {
265    fn generate(g: &mut Gen) -> Self {
266        {
267            let v1 = g.string();
268            let v2 = (g.int_in(-128, 127, &[]) as i8);
269            let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
270            let v4 = g.bool();
271            let v5 = (g.int_in(0, 255, &[]) as u8);
272            let v6 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
273            Self {
274                locale: v1,
275                view_distance: v2,
276                chat_flags: v3,
277                chat_colors: v4,
278                skin_parts: v5,
279                main_hand: v6,
280            }
281        }
282    }
283}
284
285#[cfg(feature = "v1_12_2")]
286/// `use_entity` (serverbound play).
287#[derive(Debug, Clone, PartialEq)]
288pub struct UseEntity<const V: i32> {
289    /// `target`
290    pub target: i32,
291    /// `mouse`
292    pub mouse: i32,
293    /// `x`
294    pub x: Option<f32>,
295    /// `y`
296    pub y: Option<f32>,
297    /// `z`
298    pub z: Option<f32>,
299    /// `hand`
300    pub hand: Option<i32>,
301}
302#[cfg(feature = "v1_12_2")]
303impl<const V: i32> Decode for UseEntity<V> {
304    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
305        Ok({
306            let v1 = r.read_varint()?;
307            let v2 = r.read_varint()?;
308            let v3 = if (v2 == 2) { Some(r.read_f32()?) } else { None };
309            let v4 = if (v2 == 2) { Some(r.read_f32()?) } else { None };
310            let v5 = if (v2 == 2) { Some(r.read_f32()?) } else { None };
311            let v6 = if (v2 == 0) || (v2 == 2) {
312                Some(r.read_varint()?)
313            } else {
314                None
315            };
316            Self {
317                target: v1,
318                mouse: v2,
319                x: v3,
320                y: v4,
321                z: v5,
322                hand: v6,
323            }
324        })
325    }
326}
327#[cfg(feature = "v1_12_2")]
328impl<const V: i32> Encode for UseEntity<V> {
329    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
330        w.put_varint((*self).target);
331        w.put_varint((*self).mouse);
332        match (&(*self).x, ((*self).mouse == 2)) {
333            (Some(v1), true) => {
334                w.put_f32((*v1));
335            }
336            (None, false) => {}
337            _ => return Err(EncodeError::SwitchMismatch("play.serverbound.use_entity.x")),
338        }
339        match (&(*self).y, ((*self).mouse == 2)) {
340            (Some(v2), true) => {
341                w.put_f32((*v2));
342            }
343            (None, false) => {}
344            _ => return Err(EncodeError::SwitchMismatch("play.serverbound.use_entity.y")),
345        }
346        match (&(*self).z, ((*self).mouse == 2)) {
347            (Some(v3), true) => {
348                w.put_f32((*v3));
349            }
350            (None, false) => {}
351            _ => return Err(EncodeError::SwitchMismatch("play.serverbound.use_entity.z")),
352        }
353        match (&(*self).hand, ((*self).mouse == 0) || ((*self).mouse == 2)) {
354            (Some(v4), true) => {
355                w.put_varint((*v4));
356            }
357            (None, false) => {}
358            _ => {
359                return Err(EncodeError::SwitchMismatch(
360                    "play.serverbound.use_entity.hand",
361                ));
362            }
363        }
364        Ok(())
365    }
366}
367#[cfg(feature = "v1_12_2")]
368#[cfg(feature = "testgen")]
369impl<const V: i32> Generate for UseEntity<V> {
370    fn generate(g: &mut Gen) -> Self {
371        {
372            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
373            let v2 = (g.int_in(-2147483648, 2147483647, &[2, 2, 2, 0, 2]) as i32);
374            let v3 = if (v2 == 2) { Some(g.f32()) } else { None };
375            let v4 = if (v2 == 2) { Some(g.f32()) } else { None };
376            let v5 = if (v2 == 2) { Some(g.f32()) } else { None };
377            let v6 = if (v2 == 0) || (v2 == 2) {
378                Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
379            } else {
380                None
381            };
382            Self {
383                target: v1,
384                mouse: v2,
385                x: v3,
386                y: v4,
387                z: v5,
388                hand: v6,
389            }
390        }
391    }
392}
393
394#[cfg(any(
395    feature = "v1_12_2",
396    feature = "v1_16_5",
397    feature = "v26_1",
398    feature = "v26_2"
399))]
400/// `keep_alive` (serverbound play).
401#[derive(Debug, Clone, PartialEq)]
402pub struct KeepAlive<const V: i32> {
403    /// `keepAliveId`
404    pub keep_alive_id: i64,
405}
406#[cfg(any(
407    feature = "v1_12_2",
408    feature = "v1_16_5",
409    feature = "v26_1",
410    feature = "v26_2"
411))]
412impl<const V: i32> Decode for KeepAlive<V> {
413    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
414        Ok({
415            let v1 = r.read_i64()?;
416            Self { keep_alive_id: v1 }
417        })
418    }
419}
420#[cfg(any(
421    feature = "v1_12_2",
422    feature = "v1_16_5",
423    feature = "v26_1",
424    feature = "v26_2"
425))]
426impl<const V: i32> Encode for KeepAlive<V> {
427    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
428        w.put_i64((*self).keep_alive_id);
429        Ok(())
430    }
431}
432#[cfg(any(
433    feature = "v1_12_2",
434    feature = "v1_16_5",
435    feature = "v26_1",
436    feature = "v26_2"
437))]
438#[cfg(feature = "testgen")]
439impl<const V: i32> Generate for KeepAlive<V> {
440    fn generate(g: &mut Gen) -> Self {
441        {
442            let v1 = g.i64();
443            Self { keep_alive_id: v1 }
444        }
445    }
446}
447
448#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
449/// `vehicle_move` (serverbound play).
450#[derive(Debug, Clone, PartialEq)]
451pub struct VehicleMove<const V: i32> {
452    /// `x`
453    pub x: f64,
454    /// `y`
455    pub y: f64,
456    /// `z`
457    pub z: f64,
458    /// `yaw`
459    pub yaw: f32,
460    /// `pitch`
461    pub pitch: f32,
462}
463#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
464impl<const V: i32> Decode for VehicleMove<V> {
465    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
466        Ok({
467            let v1 = r.read_f64()?;
468            let v2 = r.read_f64()?;
469            let v3 = r.read_f64()?;
470            let v4 = r.read_f32()?;
471            let v5 = r.read_f32()?;
472            Self {
473                x: v1,
474                y: v2,
475                z: v3,
476                yaw: v4,
477                pitch: v5,
478            }
479        })
480    }
481}
482#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
483impl<const V: i32> Encode for VehicleMove<V> {
484    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
485        w.put_f64((*self).x);
486        w.put_f64((*self).y);
487        w.put_f64((*self).z);
488        w.put_f32((*self).yaw);
489        w.put_f32((*self).pitch);
490        Ok(())
491    }
492}
493#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
494#[cfg(feature = "testgen")]
495impl<const V: i32> Generate for VehicleMove<V> {
496    fn generate(g: &mut Gen) -> Self {
497        {
498            let v1 = g.f64();
499            let v2 = g.f64();
500            let v3 = g.f64();
501            let v4 = g.f32();
502            let v5 = g.f32();
503            Self {
504                x: v1,
505                y: v2,
506                z: v3,
507                yaw: v4,
508                pitch: v5,
509            }
510        }
511    }
512}
513
514#[cfg(any(
515    feature = "v1_12_2",
516    feature = "v1_16_5",
517    feature = "v26_1",
518    feature = "v26_2"
519))]
520/// `steer_boat` (serverbound play).
521#[derive(Debug, Clone, PartialEq)]
522pub struct SteerBoat<const V: i32> {
523    /// `leftPaddle`
524    pub left_paddle: bool,
525    /// `rightPaddle`
526    pub right_paddle: bool,
527}
528#[cfg(any(
529    feature = "v1_12_2",
530    feature = "v1_16_5",
531    feature = "v26_1",
532    feature = "v26_2"
533))]
534impl<const V: i32> Decode for SteerBoat<V> {
535    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
536        Ok({
537            let v1 = r.read_bool()?;
538            let v2 = r.read_bool()?;
539            Self {
540                left_paddle: v1,
541                right_paddle: v2,
542            }
543        })
544    }
545}
546#[cfg(any(
547    feature = "v1_12_2",
548    feature = "v1_16_5",
549    feature = "v26_1",
550    feature = "v26_2"
551))]
552impl<const V: i32> Encode for SteerBoat<V> {
553    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
554        w.put_bool((*self).left_paddle);
555        w.put_bool((*self).right_paddle);
556        Ok(())
557    }
558}
559#[cfg(any(
560    feature = "v1_12_2",
561    feature = "v1_16_5",
562    feature = "v26_1",
563    feature = "v26_2"
564))]
565#[cfg(feature = "testgen")]
566impl<const V: i32> Generate for SteerBoat<V> {
567    fn generate(g: &mut Gen) -> Self {
568        {
569            let v1 = g.bool();
570            let v2 = g.bool();
571            Self {
572                left_paddle: v1,
573                right_paddle: v2,
574            }
575        }
576    }
577}
578
579#[cfg(feature = "v1_12_2")]
580/// `craft_recipe_request` (serverbound play).
581#[derive(Debug, Clone, PartialEq)]
582pub struct CraftRecipeRequest<const V: i32> {
583    /// `windowId`
584    pub window_id: i8,
585    /// `recipe`
586    pub recipe: i32,
587    /// `makeAll`
588    pub make_all: bool,
589}
590#[cfg(feature = "v1_12_2")]
591impl<const V: i32> Decode for CraftRecipeRequest<V> {
592    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
593        Ok({
594            let v1 = r.read_i8()?;
595            let v2 = r.read_varint()?;
596            let v3 = r.read_bool()?;
597            Self {
598                window_id: v1,
599                recipe: v2,
600                make_all: v3,
601            }
602        })
603    }
604}
605#[cfg(feature = "v1_12_2")]
606impl<const V: i32> Encode for CraftRecipeRequest<V> {
607    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
608        w.put_i8((*self).window_id);
609        w.put_varint((*self).recipe);
610        w.put_bool((*self).make_all);
611        Ok(())
612    }
613}
614#[cfg(feature = "v1_12_2")]
615#[cfg(feature = "testgen")]
616impl<const V: i32> Generate for CraftRecipeRequest<V> {
617    fn generate(g: &mut Gen) -> Self {
618        {
619            let v1 = (g.int_in(-128, 127, &[]) as i8);
620            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
621            let v3 = g.bool();
622            Self {
623                window_id: v1,
624                recipe: v2,
625                make_all: v3,
626            }
627        }
628    }
629}
630
631#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
632/// Mapped `i32` value; unknown values are kept as-is.
633#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
634pub struct EntityActionActionId(pub i32);
635#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
636impl EntityActionActionId {
637    /// `start_sneaking`
638    pub const START_SNEAKING: Self = Self(0);
639    /// `stop_sneaking`
640    pub const STOP_SNEAKING: Self = Self(1);
641    /// `stop_sleeping`
642    pub const STOP_SLEEPING: Self = Self(2);
643    /// `start_sprinting`
644    pub const START_SPRINTING: Self = Self(3);
645    /// `stop_sprinting`
646    pub const STOP_SPRINTING: Self = Self(4);
647    /// `start_riding_jump`
648    pub const START_RIDING_JUMP: Self = Self(5);
649    /// `stop_riding_jump`
650    pub const STOP_RIDING_JUMP: Self = Self(6);
651    /// `open_inventory`
652    pub const OPEN_INVENTORY: Self = Self(7);
653    /// `start_fall_flying`
654    pub const START_FALL_FLYING: Self = Self(8);
655    /// minecraft-data name of the value, if known.
656    pub const fn name(self) -> Option<&'static str> {
657        match self.0 {
658            0 => Some("start_sneaking"),
659            1 => Some("stop_sneaking"),
660            2 => Some("stop_sleeping"),
661            3 => Some("start_sprinting"),
662            4 => Some("stop_sprinting"),
663            5 => Some("start_riding_jump"),
664            6 => Some("stop_riding_jump"),
665            7 => Some("open_inventory"),
666            8 => Some("start_fall_flying"),
667            _ => None,
668        }
669    }
670}
671#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
672impl std::fmt::Debug for EntityActionActionId {
673    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
674        match self.name() {
675            Some(n) => write!(f, "EntityActionActionId::{n}"),
676            None => write!(f, "EntityActionActionId({})", self.0),
677        }
678    }
679}
680
681#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
682/// `entity_action` (serverbound play).
683#[derive(Debug, Clone, PartialEq)]
684pub struct EntityAction<const V: i32> {
685    /// `entityId`
686    pub entity_id: i32,
687    /// `actionId`
688    pub action_id: crate::defs::p340::play::serverbound::EntityActionActionId,
689    /// `jumpBoost`
690    pub jump_boost: i32,
691}
692#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
693impl<const V: i32> Decode for EntityAction<V> {
694    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
695        Ok({
696            let v1 = r.read_varint()?;
697            let v2 = crate::defs::p340::play::serverbound::EntityActionActionId(r.read_varint()?);
698            let v3 = r.read_varint()?;
699            Self {
700                entity_id: v1,
701                action_id: v2,
702                jump_boost: v3,
703            }
704        })
705    }
706}
707#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
708impl<const V: i32> Encode for EntityAction<V> {
709    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
710        w.put_varint((*self).entity_id);
711        w.put_varint((*self).action_id.0);
712        w.put_varint((*self).jump_boost);
713        Ok(())
714    }
715}
716#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
717#[cfg(feature = "testgen")]
718impl<const V: i32> Generate for EntityAction<V> {
719    fn generate(g: &mut Gen) -> Self {
720        {
721            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
722            let v2 = crate::defs::p340::play::serverbound::EntityActionActionId(g.int_in(
723                -2147483648,
724                2147483647,
725                &[0, 1, 2, 3, 4, 5, 6, 7, 8],
726            )
727                as i32);
728            let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
729            Self {
730                entity_id: v1,
731                action_id: v2,
732                jump_boost: v3,
733            }
734        }
735    }
736}
737
738#[cfg(feature = "v1_12_2")]
739/// Nested container.
740#[derive(Debug, Clone, PartialEq)]
741pub struct CraftingBookDataBodyCase0 {
742    /// `displayedRecipe`
743    pub displayed_recipe: i32,
744}
745
746#[cfg(feature = "v1_12_2")]
747/// Nested container.
748#[derive(Debug, Clone, PartialEq)]
749pub struct CraftingBookDataBodyCase1 {
750    /// `craftingBookOpen`
751    pub crafting_book_open: bool,
752    /// `craftingFilter`
753    pub crafting_filter: bool,
754}
755
756#[cfg(feature = "v1_12_2")]
757/// Switch on `type`.
758#[derive(Debug, Clone, PartialEq)]
759pub enum CraftingBookDataBody {
760    /// Case(s) `0`.
761    Case0(crate::defs::p340::play::serverbound::CraftingBookDataBodyCase0),
762    /// Case(s) `1`.
763    Case1(crate::defs::p340::play::serverbound::CraftingBookDataBodyCase1),
764    /// Any other value.
765    Other,
766}
767
768#[cfg(feature = "v1_12_2")]
769/// `crafting_book_data` (serverbound play).
770#[derive(Debug, Clone, PartialEq)]
771pub struct CraftingBookData<const V: i32> {
772    /// `type`
773    pub r#type: i32,
774    /// Anonymous switch
775    pub body: crate::defs::p340::play::serverbound::CraftingBookDataBody,
776}
777#[cfg(feature = "v1_12_2")]
778impl<const V: i32> Decode for CraftingBookData<V> {
779    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
780        Ok({
781            let v1 = r.read_varint()?;
782            let v2 = (if (v1 == 0) {
783                crate::defs::p340::play::serverbound::CraftingBookDataBody::Case0({
784                    let v3 = r.read_i32()?;
785                    crate::defs::p340::play::serverbound::CraftingBookDataBodyCase0 {
786                        displayed_recipe: v3,
787                    }
788                })
789            } else if (v1 == 1) {
790                crate::defs::p340::play::serverbound::CraftingBookDataBody::Case1({
791                    let v4 = r.read_bool()?;
792                    let v5 = r.read_bool()?;
793                    crate::defs::p340::play::serverbound::CraftingBookDataBodyCase1 {
794                        crafting_book_open: v4,
795                        crafting_filter: v5,
796                    }
797                })
798            } else {
799                crate::defs::p340::play::serverbound::CraftingBookDataBody::Other
800            });
801            Self {
802                r#type: v1,
803                body: v2,
804            }
805        })
806    }
807}
808#[cfg(feature = "v1_12_2")]
809impl<const V: i32> Encode for CraftingBookData<V> {
810    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
811        w.put_varint((*self).r#type);
812        match &(*self).body {
813            crate::defs::p340::play::serverbound::CraftingBookDataBody::Case0(v1) => {
814                if !((*self).r#type == 0) {
815                    return Err(EncodeError::SwitchMismatch(
816                        "play.serverbound.crafting_book_data.body",
817                    ));
818                }
819                w.put_i32((*v1).displayed_recipe);
820            }
821            crate::defs::p340::play::serverbound::CraftingBookDataBody::Case1(v2) => {
822                if !((*self).r#type == 1) {
823                    return Err(EncodeError::SwitchMismatch(
824                        "play.serverbound.crafting_book_data.body",
825                    ));
826                }
827                w.put_bool((*v2).crafting_book_open);
828                w.put_bool((*v2).crafting_filter);
829            }
830            crate::defs::p340::play::serverbound::CraftingBookDataBody::Other => {
831                if !(!(((*self).r#type == 0) || ((*self).r#type == 1))) {
832                    return Err(EncodeError::SwitchMismatch(
833                        "play.serverbound.crafting_book_data.body",
834                    ));
835                }
836            }
837        }
838        Ok(())
839    }
840}
841#[cfg(feature = "v1_12_2")]
842#[cfg(feature = "testgen")]
843impl<const V: i32> Generate for CraftingBookData<V> {
844    fn generate(g: &mut Gen) -> Self {
845        {
846            let v1 = (g.int_in(-2147483648, 2147483647, &[0, 1]) as i32);
847            let v2 = (if (v1 == 0) {
848                crate::defs::p340::play::serverbound::CraftingBookDataBody::Case0({
849                    let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
850                    crate::defs::p340::play::serverbound::CraftingBookDataBodyCase0 {
851                        displayed_recipe: v3,
852                    }
853                })
854            } else if (v1 == 1) {
855                crate::defs::p340::play::serverbound::CraftingBookDataBody::Case1({
856                    let v4 = g.bool();
857                    let v5 = g.bool();
858                    crate::defs::p340::play::serverbound::CraftingBookDataBodyCase1 {
859                        crafting_book_open: v4,
860                        crafting_filter: v5,
861                    }
862                })
863            } else {
864                crate::defs::p340::play::serverbound::CraftingBookDataBody::Other
865            });
866            Self {
867                r#type: v1,
868                body: v2,
869            }
870        }
871    }
872}
873
874#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
875/// `resource_pack_receive` (serverbound play).
876#[derive(Debug, Clone, PartialEq)]
877pub struct ResourcePackReceive<const V: i32> {
878    /// `result`
879    pub result: i32,
880}
881#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
882impl<const V: i32> Decode for ResourcePackReceive<V> {
883    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
884        Ok({
885            let v1 = r.read_varint()?;
886            Self { result: v1 }
887        })
888    }
889}
890#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
891impl<const V: i32> Encode for ResourcePackReceive<V> {
892    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
893        w.put_varint((*self).result);
894        Ok(())
895    }
896}
897#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
898#[cfg(feature = "testgen")]
899impl<const V: i32> Generate for ResourcePackReceive<V> {
900    fn generate(g: &mut Gen) -> Self {
901        {
902            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
903            Self { result: v1 }
904        }
905    }
906}
907
908#[cfg(any(
909    feature = "v1_12_2",
910    feature = "v1_16_5",
911    feature = "v26_1",
912    feature = "v26_2"
913))]
914/// `advancement_tab` (serverbound play).
915#[derive(Debug, Clone, PartialEq)]
916pub struct AdvancementTab<const V: i32> {
917    /// `action`
918    pub action: i32,
919    /// `tabId`
920    pub tab_id: Option<ByteString>,
921}
922#[cfg(any(
923    feature = "v1_12_2",
924    feature = "v1_16_5",
925    feature = "v26_1",
926    feature = "v26_2"
927))]
928impl<const V: i32> Decode for AdvancementTab<V> {
929    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
930        Ok({
931            let v1 = r.read_varint()?;
932            let v2 = if (v1 == 0) {
933                Some(r.read_string()?)
934            } else {
935                None
936            };
937            Self {
938                action: v1,
939                tab_id: v2,
940            }
941        })
942    }
943}
944#[cfg(any(
945    feature = "v1_12_2",
946    feature = "v1_16_5",
947    feature = "v26_1",
948    feature = "v26_2"
949))]
950impl<const V: i32> Encode for AdvancementTab<V> {
951    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
952        w.put_varint((*self).action);
953        match (&(*self).tab_id, ((*self).action == 0)) {
954            (Some(v1), true) => {
955                w.put_string(&(*v1))?;
956            }
957            (None, false) => {}
958            _ => {
959                return Err(EncodeError::SwitchMismatch(
960                    "play.serverbound.advancement_tab.tabId",
961                ));
962            }
963        }
964        Ok(())
965    }
966}
967#[cfg(any(
968    feature = "v1_12_2",
969    feature = "v1_16_5",
970    feature = "v26_1",
971    feature = "v26_2"
972))]
973#[cfg(feature = "testgen")]
974impl<const V: i32> Generate for AdvancementTab<V> {
975    fn generate(g: &mut Gen) -> Self {
976        {
977            let v1 = (g.int_in(-2147483648, 2147483647, &[0, 1]) as i32);
978            let v2 = if (v1 == 0) { Some(g.string()) } else { None };
979            Self {
980                action: v1,
981                tab_id: v2,
982            }
983        }
984    }
985}
986
987#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
988/// `arm_animation` (serverbound play).
989#[derive(Debug, Clone, PartialEq)]
990pub struct ArmAnimation<const V: i32> {
991    /// `hand`
992    pub hand: i32,
993}
994#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
995impl<const V: i32> Decode for ArmAnimation<V> {
996    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
997        Ok({
998            let v1 = r.read_varint()?;
999            Self { hand: v1 }
1000        })
1001    }
1002}
1003#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1004impl<const V: i32> Encode for ArmAnimation<V> {
1005    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1006        w.put_varint((*self).hand);
1007        Ok(())
1008    }
1009}
1010#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1011#[cfg(feature = "testgen")]
1012impl<const V: i32> Generate for ArmAnimation<V> {
1013    fn generate(g: &mut Gen) -> Self {
1014        {
1015            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1016            Self { hand: v1 }
1017        }
1018    }
1019}
1020
1021#[cfg(feature = "v1_12_2")]
1022/// `block_place` (serverbound play).
1023#[derive(Debug, Clone, PartialEq)]
1024pub struct BlockPlace<const V: i32> {
1025    /// `location`
1026    pub location: BlockPos,
1027    /// `direction`
1028    pub direction: i32,
1029    /// `hand`
1030    pub hand: i32,
1031    /// `cursorX`
1032    pub cursor_x: f32,
1033    /// `cursorY`
1034    pub cursor_y: f32,
1035    /// `cursorZ`
1036    pub cursor_z: f32,
1037}
1038#[cfg(feature = "v1_12_2")]
1039impl<const V: i32> Decode for BlockPlace<V> {
1040    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1041        Ok({
1042            let v1 = BlockPos::read(r, PositionLayout::Xyz)?;
1043            let v2 = r.read_varint()?;
1044            let v3 = r.read_varint()?;
1045            let v4 = r.read_f32()?;
1046            let v5 = r.read_f32()?;
1047            let v6 = r.read_f32()?;
1048            Self {
1049                location: v1,
1050                direction: v2,
1051                hand: v3,
1052                cursor_x: v4,
1053                cursor_y: v5,
1054                cursor_z: v6,
1055            }
1056        })
1057    }
1058}
1059#[cfg(feature = "v1_12_2")]
1060impl<const V: i32> Encode for BlockPlace<V> {
1061    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1062        (*self).location.write(w, PositionLayout::Xyz)?;
1063        w.put_varint((*self).direction);
1064        w.put_varint((*self).hand);
1065        w.put_f32((*self).cursor_x);
1066        w.put_f32((*self).cursor_y);
1067        w.put_f32((*self).cursor_z);
1068        Ok(())
1069    }
1070}
1071#[cfg(feature = "v1_12_2")]
1072#[cfg(feature = "testgen")]
1073impl<const V: i32> Generate for BlockPlace<V> {
1074    fn generate(g: &mut Gen) -> Self {
1075        {
1076            let v1 = g.position();
1077            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1078            let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1079            let v4 = g.f32();
1080            let v5 = g.f32();
1081            let v6 = g.f32();
1082            Self {
1083                location: v1,
1084                direction: v2,
1085                hand: v3,
1086                cursor_x: v4,
1087                cursor_y: v5,
1088                cursor_z: v6,
1089            }
1090        }
1091    }
1092}
1093
1094#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1095/// `use_item` (serverbound play).
1096#[derive(Debug, Clone, PartialEq)]
1097pub struct UseItem<const V: i32> {
1098    /// `hand`
1099    pub hand: i32,
1100}
1101#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1102impl<const V: i32> Decode for UseItem<V> {
1103    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1104        Ok({
1105            let v1 = r.read_varint()?;
1106            Self { hand: v1 }
1107        })
1108    }
1109}
1110#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1111impl<const V: i32> Encode for UseItem<V> {
1112    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1113        w.put_varint((*self).hand);
1114        Ok(())
1115    }
1116}
1117#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1118#[cfg(feature = "testgen")]
1119impl<const V: i32> Generate for UseItem<V> {
1120    fn generate(g: &mut Gen) -> Self {
1121        {
1122            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1123            Self { hand: v1 }
1124        }
1125    }
1126}