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