1#![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#[derive(Debug, Clone, PartialEq)]
31pub struct TeleportConfirm<const V: i32> {
32 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#[derive(Debug, Clone, PartialEq)]
65pub struct TabComplete<const V: i32> {
66 pub text: ByteString,
68 pub assume_command: bool,
70 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#[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 pub const PERFORM_RESPAWN: Self = Self(0);
132 pub const REQUEST_STATS: Self = Self(1);
134 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#[derive(Debug, Clone, PartialEq)]
156pub struct ClientCommand<const V: i32> {
157 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#[derive(Debug, Clone, PartialEq)]
195pub struct Settings<const V: i32> {
196 pub locale: ByteString,
198 pub view_distance: i8,
200 pub chat_flags: i32,
202 pub chat_colors: bool,
204 pub skin_parts: u8,
206 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#[derive(Debug, Clone, PartialEq)]
268pub struct UseEntity<const V: i32> {
269 pub target: i32,
271 pub mouse: i32,
273 pub x: Option<f32>,
275 pub y: Option<f32>,
277 pub z: Option<f32>,
279 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#[derive(Debug, Clone, PartialEq)]
377pub struct KeepAlive<const V: i32> {
378 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#[derive(Debug, Clone, PartialEq)]
411pub struct VehicleMove<const V: i32> {
412 pub x: f64,
414 pub y: f64,
416 pub z: f64,
418 pub yaw: f32,
420 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#[derive(Debug, Clone, PartialEq)]
477pub struct SteerBoat<const V: i32> {
478 pub left_paddle: bool,
480 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#[derive(Debug, Clone, PartialEq)]
522pub struct CraftRecipeRequest<const V: i32> {
523 pub window_id: i8,
525 pub recipe: i32,
527 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#[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 pub const START_SNEAKING: Self = Self(0);
579 pub const STOP_SNEAKING: Self = Self(1);
581 pub const STOP_SLEEPING: Self = Self(2);
583 pub const START_SPRINTING: Self = Self(3);
585 pub const STOP_SPRINTING: Self = Self(4);
587 pub const START_RIDING_JUMP: Self = Self(5);
589 pub const STOP_RIDING_JUMP: Self = Self(6);
591 pub const OPEN_INVENTORY: Self = Self(7);
593 pub const START_FALL_FLYING: Self = Self(8);
595 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#[derive(Debug, Clone, PartialEq)]
624pub struct EntityAction<const V: i32> {
625 pub entity_id: i32,
627 pub action_id: crate::defs::p340::play::serverbound::EntityActionActionId,
629 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#[derive(Debug, Clone, PartialEq)]
681pub struct CraftingBookDataBodyCase0 {
682 pub displayed_recipe: i32,
684}
685
686#[cfg(feature = "v1_12_2")]
687#[derive(Debug, Clone, PartialEq)]
689pub struct CraftingBookDataBodyCase1 {
690 pub crafting_book_open: bool,
692 pub crafting_filter: bool,
694}
695
696#[cfg(feature = "v1_12_2")]
697#[derive(Debug, Clone, PartialEq)]
699pub enum CraftingBookDataBody {
700 Case0(crate::defs::p340::play::serverbound::CraftingBookDataBodyCase0),
702 Case1(crate::defs::p340::play::serverbound::CraftingBookDataBodyCase1),
704 Other,
706}
707
708#[cfg(feature = "v1_12_2")]
709#[derive(Debug, Clone, PartialEq)]
711pub struct CraftingBookData<const V: i32> {
712 pub r#type: i32,
714 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#[derive(Debug, Clone, PartialEq)]
817pub struct ResourcePackReceive<const V: i32> {
818 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#[derive(Debug, Clone, PartialEq)]
851pub struct AdvancementTab<const V: i32> {
852 pub action: i32,
854 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#[derive(Debug, Clone, PartialEq)]
910pub struct ArmAnimation<const V: i32> {
911 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#[derive(Debug, Clone, PartialEq)]
944pub struct BlockPlace<const V: i32> {
945 pub location: BlockPos,
947 pub direction: i32,
949 pub hand: i32,
951 pub cursor_x: f32,
953 pub cursor_y: f32,
955 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#[derive(Debug, Clone, PartialEq)]
1017pub struct UseItem<const V: i32> {
1018 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}