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(
29 feature = "v1_12_2",
30 feature = "v1_16_5",
31 feature = "v26_1",
32 feature = "v26_2"
33))]
34#[derive(Debug, Clone, PartialEq)]
36pub struct TeleportConfirm<const V: i32> {
37 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#[derive(Debug, Clone, PartialEq)]
85pub struct TabComplete<const V: i32> {
86 pub text: ByteString,
88 pub assume_command: bool,
90 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#[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 pub const PERFORM_RESPAWN: Self = Self(0);
152 pub const REQUEST_STATS: Self = Self(1);
154 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#[derive(Debug, Clone, PartialEq)]
176pub struct ClientCommand<const V: i32> {
177 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#[derive(Debug, Clone, PartialEq)]
215pub struct Settings<const V: i32> {
216 pub locale: ByteString,
218 pub view_distance: i8,
220 pub chat_flags: i32,
222 pub chat_colors: bool,
224 pub skin_parts: u8,
226 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#[derive(Debug, Clone, PartialEq)]
288pub struct UseEntity<const V: i32> {
289 pub target: i32,
291 pub mouse: i32,
293 pub x: Option<f32>,
295 pub y: Option<f32>,
297 pub z: Option<f32>,
299 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 feature = "v26_3"
400))]
401#[derive(Debug, Clone, PartialEq)]
403pub struct KeepAlive<const V: i32> {
404 pub keep_alive_id: i64,
406}
407#[cfg(any(
408 feature = "v1_12_2",
409 feature = "v1_16_5",
410 feature = "v26_1",
411 feature = "v26_2",
412 feature = "v26_3"
413))]
414impl<const V: i32> Decode for KeepAlive<V> {
415 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
416 Ok({
417 let v1 = r.read_i64()?;
418 Self { keep_alive_id: v1 }
419 })
420 }
421}
422#[cfg(any(
423 feature = "v1_12_2",
424 feature = "v1_16_5",
425 feature = "v26_1",
426 feature = "v26_2",
427 feature = "v26_3"
428))]
429impl<const V: i32> Encode for KeepAlive<V> {
430 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
431 w.put_i64((*self).keep_alive_id);
432 Ok(())
433 }
434}
435#[cfg(any(
436 feature = "v1_12_2",
437 feature = "v1_16_5",
438 feature = "v26_1",
439 feature = "v26_2",
440 feature = "v26_3"
441))]
442#[cfg(feature = "testgen")]
443impl<const V: i32> Generate for KeepAlive<V> {
444 fn generate(g: &mut Gen) -> Self {
445 {
446 let v1 = g.i64();
447 Self { keep_alive_id: v1 }
448 }
449 }
450}
451
452#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
453#[derive(Debug, Clone, PartialEq)]
455pub struct VehicleMove<const V: i32> {
456 pub x: f64,
458 pub y: f64,
460 pub z: f64,
462 pub yaw: f32,
464 pub pitch: f32,
466}
467#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
468impl<const V: i32> Decode for VehicleMove<V> {
469 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
470 Ok({
471 let v1 = r.read_f64()?;
472 let v2 = r.read_f64()?;
473 let v3 = r.read_f64()?;
474 let v4 = r.read_f32()?;
475 let v5 = r.read_f32()?;
476 Self {
477 x: v1,
478 y: v2,
479 z: v3,
480 yaw: v4,
481 pitch: v5,
482 }
483 })
484 }
485}
486#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
487impl<const V: i32> Encode for VehicleMove<V> {
488 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
489 w.put_f64((*self).x);
490 w.put_f64((*self).y);
491 w.put_f64((*self).z);
492 w.put_f32((*self).yaw);
493 w.put_f32((*self).pitch);
494 Ok(())
495 }
496}
497#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
498#[cfg(feature = "testgen")]
499impl<const V: i32> Generate for VehicleMove<V> {
500 fn generate(g: &mut Gen) -> Self {
501 {
502 let v1 = g.f64();
503 let v2 = g.f64();
504 let v3 = g.f64();
505 let v4 = g.f32();
506 let v5 = g.f32();
507 Self {
508 x: v1,
509 y: v2,
510 z: v3,
511 yaw: v4,
512 pitch: v5,
513 }
514 }
515 }
516}
517
518#[cfg(any(
519 feature = "v1_12_2",
520 feature = "v1_16_5",
521 feature = "v26_1",
522 feature = "v26_2",
523 feature = "v26_3"
524))]
525#[derive(Debug, Clone, PartialEq)]
527pub struct SteerBoat<const V: i32> {
528 pub left_paddle: bool,
530 pub right_paddle: bool,
532}
533#[cfg(any(
534 feature = "v1_12_2",
535 feature = "v1_16_5",
536 feature = "v26_1",
537 feature = "v26_2",
538 feature = "v26_3"
539))]
540impl<const V: i32> Decode for SteerBoat<V> {
541 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
542 Ok({
543 let v1 = r.read_bool()?;
544 let v2 = r.read_bool()?;
545 Self {
546 left_paddle: v1,
547 right_paddle: v2,
548 }
549 })
550 }
551}
552#[cfg(any(
553 feature = "v1_12_2",
554 feature = "v1_16_5",
555 feature = "v26_1",
556 feature = "v26_2",
557 feature = "v26_3"
558))]
559impl<const V: i32> Encode for SteerBoat<V> {
560 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
561 w.put_bool((*self).left_paddle);
562 w.put_bool((*self).right_paddle);
563 Ok(())
564 }
565}
566#[cfg(any(
567 feature = "v1_12_2",
568 feature = "v1_16_5",
569 feature = "v26_1",
570 feature = "v26_2",
571 feature = "v26_3"
572))]
573#[cfg(feature = "testgen")]
574impl<const V: i32> Generate for SteerBoat<V> {
575 fn generate(g: &mut Gen) -> Self {
576 {
577 let v1 = g.bool();
578 let v2 = g.bool();
579 Self {
580 left_paddle: v1,
581 right_paddle: v2,
582 }
583 }
584 }
585}
586
587#[cfg(feature = "v1_12_2")]
588#[derive(Debug, Clone, PartialEq)]
590pub struct CraftRecipeRequest<const V: i32> {
591 pub window_id: i8,
593 pub recipe: i32,
595 pub make_all: bool,
597}
598#[cfg(feature = "v1_12_2")]
599impl<const V: i32> Decode for CraftRecipeRequest<V> {
600 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
601 Ok({
602 let v1 = r.read_i8()?;
603 let v2 = r.read_varint()?;
604 let v3 = r.read_bool()?;
605 Self {
606 window_id: v1,
607 recipe: v2,
608 make_all: v3,
609 }
610 })
611 }
612}
613#[cfg(feature = "v1_12_2")]
614impl<const V: i32> Encode for CraftRecipeRequest<V> {
615 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
616 w.put_i8((*self).window_id);
617 w.put_varint((*self).recipe);
618 w.put_bool((*self).make_all);
619 Ok(())
620 }
621}
622#[cfg(feature = "v1_12_2")]
623#[cfg(feature = "testgen")]
624impl<const V: i32> Generate for CraftRecipeRequest<V> {
625 fn generate(g: &mut Gen) -> Self {
626 {
627 let v1 = (g.int_in(-128, 127, &[]) as i8);
628 let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
629 let v3 = g.bool();
630 Self {
631 window_id: v1,
632 recipe: v2,
633 make_all: v3,
634 }
635 }
636 }
637}
638
639#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
640#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
642pub struct EntityActionActionId(pub i32);
643#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
644impl EntityActionActionId {
645 pub const START_SNEAKING: Self = Self(0);
647 pub const STOP_SNEAKING: Self = Self(1);
649 pub const STOP_SLEEPING: Self = Self(2);
651 pub const START_SPRINTING: Self = Self(3);
653 pub const STOP_SPRINTING: Self = Self(4);
655 pub const START_RIDING_JUMP: Self = Self(5);
657 pub const STOP_RIDING_JUMP: Self = Self(6);
659 pub const OPEN_INVENTORY: Self = Self(7);
661 pub const START_FALL_FLYING: Self = Self(8);
663 pub const fn name(self) -> Option<&'static str> {
665 match self.0 {
666 0 => Some("start_sneaking"),
667 1 => Some("stop_sneaking"),
668 2 => Some("stop_sleeping"),
669 3 => Some("start_sprinting"),
670 4 => Some("stop_sprinting"),
671 5 => Some("start_riding_jump"),
672 6 => Some("stop_riding_jump"),
673 7 => Some("open_inventory"),
674 8 => Some("start_fall_flying"),
675 _ => None,
676 }
677 }
678}
679#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
680impl std::fmt::Debug for EntityActionActionId {
681 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
682 match self.name() {
683 Some(n) => write!(f, "EntityActionActionId::{n}"),
684 None => write!(f, "EntityActionActionId({})", self.0),
685 }
686 }
687}
688
689#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
690#[derive(Debug, Clone, PartialEq)]
692pub struct EntityAction<const V: i32> {
693 pub entity_id: i32,
695 pub action_id: crate::defs::p340::play::serverbound::EntityActionActionId,
697 pub jump_boost: i32,
699}
700#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
701impl<const V: i32> Decode for EntityAction<V> {
702 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
703 Ok({
704 let v1 = r.read_varint()?;
705 let v2 = crate::defs::p340::play::serverbound::EntityActionActionId(r.read_varint()?);
706 let v3 = r.read_varint()?;
707 Self {
708 entity_id: v1,
709 action_id: v2,
710 jump_boost: v3,
711 }
712 })
713 }
714}
715#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
716impl<const V: i32> Encode for EntityAction<V> {
717 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
718 w.put_varint((*self).entity_id);
719 w.put_varint((*self).action_id.0);
720 w.put_varint((*self).jump_boost);
721 Ok(())
722 }
723}
724#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
725#[cfg(feature = "testgen")]
726impl<const V: i32> Generate for EntityAction<V> {
727 fn generate(g: &mut Gen) -> Self {
728 {
729 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
730 let v2 = crate::defs::p340::play::serverbound::EntityActionActionId(g.int_in(
731 -2147483648,
732 2147483647,
733 &[0, 1, 2, 3, 4, 5, 6, 7, 8],
734 )
735 as i32);
736 let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
737 Self {
738 entity_id: v1,
739 action_id: v2,
740 jump_boost: v3,
741 }
742 }
743 }
744}
745
746#[cfg(feature = "v1_12_2")]
747#[derive(Debug, Clone, PartialEq)]
749pub struct CraftingBookDataBodyCase0 {
750 pub displayed_recipe: i32,
752}
753
754#[cfg(feature = "v1_12_2")]
755#[derive(Debug, Clone, PartialEq)]
757pub struct CraftingBookDataBodyCase1 {
758 pub crafting_book_open: bool,
760 pub crafting_filter: bool,
762}
763
764#[cfg(feature = "v1_12_2")]
765#[derive(Debug, Clone, PartialEq)]
767pub enum CraftingBookDataBody {
768 Case0(crate::defs::p340::play::serverbound::CraftingBookDataBodyCase0),
770 Case1(crate::defs::p340::play::serverbound::CraftingBookDataBodyCase1),
772 Other,
774}
775
776#[cfg(feature = "v1_12_2")]
777#[derive(Debug, Clone, PartialEq)]
779pub struct CraftingBookData<const V: i32> {
780 pub r#type: i32,
782 pub body: crate::defs::p340::play::serverbound::CraftingBookDataBody,
784}
785#[cfg(feature = "v1_12_2")]
786impl<const V: i32> Decode for CraftingBookData<V> {
787 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
788 Ok({
789 let v1 = r.read_varint()?;
790 let v2 = (if (v1 == 0) {
791 crate::defs::p340::play::serverbound::CraftingBookDataBody::Case0({
792 let v3 = r.read_i32()?;
793 crate::defs::p340::play::serverbound::CraftingBookDataBodyCase0 {
794 displayed_recipe: v3,
795 }
796 })
797 } else if (v1 == 1) {
798 crate::defs::p340::play::serverbound::CraftingBookDataBody::Case1({
799 let v4 = r.read_bool()?;
800 let v5 = r.read_bool()?;
801 crate::defs::p340::play::serverbound::CraftingBookDataBodyCase1 {
802 crafting_book_open: v4,
803 crafting_filter: v5,
804 }
805 })
806 } else {
807 crate::defs::p340::play::serverbound::CraftingBookDataBody::Other
808 });
809 Self {
810 r#type: v1,
811 body: v2,
812 }
813 })
814 }
815}
816#[cfg(feature = "v1_12_2")]
817impl<const V: i32> Encode for CraftingBookData<V> {
818 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
819 w.put_varint((*self).r#type);
820 match &(*self).body {
821 crate::defs::p340::play::serverbound::CraftingBookDataBody::Case0(v1) => {
822 if !((*self).r#type == 0) {
823 return Err(EncodeError::SwitchMismatch(
824 "play.serverbound.crafting_book_data.body",
825 ));
826 }
827 w.put_i32((*v1).displayed_recipe);
828 }
829 crate::defs::p340::play::serverbound::CraftingBookDataBody::Case1(v2) => {
830 if !((*self).r#type == 1) {
831 return Err(EncodeError::SwitchMismatch(
832 "play.serverbound.crafting_book_data.body",
833 ));
834 }
835 w.put_bool((*v2).crafting_book_open);
836 w.put_bool((*v2).crafting_filter);
837 }
838 crate::defs::p340::play::serverbound::CraftingBookDataBody::Other => {
839 if !(!(((*self).r#type == 0) || ((*self).r#type == 1))) {
840 return Err(EncodeError::SwitchMismatch(
841 "play.serverbound.crafting_book_data.body",
842 ));
843 }
844 }
845 }
846 Ok(())
847 }
848}
849#[cfg(feature = "v1_12_2")]
850#[cfg(feature = "testgen")]
851impl<const V: i32> Generate for CraftingBookData<V> {
852 fn generate(g: &mut Gen) -> Self {
853 {
854 let v1 = (g.int_in(-2147483648, 2147483647, &[0, 1]) as i32);
855 let v2 = (if (v1 == 0) {
856 crate::defs::p340::play::serverbound::CraftingBookDataBody::Case0({
857 let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
858 crate::defs::p340::play::serverbound::CraftingBookDataBodyCase0 {
859 displayed_recipe: v3,
860 }
861 })
862 } else if (v1 == 1) {
863 crate::defs::p340::play::serverbound::CraftingBookDataBody::Case1({
864 let v4 = g.bool();
865 let v5 = g.bool();
866 crate::defs::p340::play::serverbound::CraftingBookDataBodyCase1 {
867 crafting_book_open: v4,
868 crafting_filter: v5,
869 }
870 })
871 } else {
872 crate::defs::p340::play::serverbound::CraftingBookDataBody::Other
873 });
874 Self {
875 r#type: v1,
876 body: v2,
877 }
878 }
879 }
880}
881
882#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
883#[derive(Debug, Clone, PartialEq)]
885pub struct ResourcePackReceive<const V: i32> {
886 pub result: i32,
888}
889#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
890impl<const V: i32> Decode for ResourcePackReceive<V> {
891 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
892 Ok({
893 let v1 = r.read_varint()?;
894 Self { result: v1 }
895 })
896 }
897}
898#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
899impl<const V: i32> Encode for ResourcePackReceive<V> {
900 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
901 w.put_varint((*self).result);
902 Ok(())
903 }
904}
905#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
906#[cfg(feature = "testgen")]
907impl<const V: i32> Generate for ResourcePackReceive<V> {
908 fn generate(g: &mut Gen) -> Self {
909 {
910 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
911 Self { result: v1 }
912 }
913 }
914}
915
916#[cfg(any(
917 feature = "v1_12_2",
918 feature = "v1_16_5",
919 feature = "v26_1",
920 feature = "v26_2",
921 feature = "v26_3"
922))]
923#[derive(Debug, Clone, PartialEq)]
925pub struct AdvancementTab<const V: i32> {
926 pub action: i32,
928 pub tab_id: Option<ByteString>,
930}
931#[cfg(any(
932 feature = "v1_12_2",
933 feature = "v1_16_5",
934 feature = "v26_1",
935 feature = "v26_2",
936 feature = "v26_3"
937))]
938impl<const V: i32> Decode for AdvancementTab<V> {
939 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
940 Ok({
941 let v1 = r.read_varint()?;
942 let v2 = if (v1 == 0) {
943 Some(r.read_string()?)
944 } else {
945 None
946 };
947 Self {
948 action: v1,
949 tab_id: v2,
950 }
951 })
952 }
953}
954#[cfg(any(
955 feature = "v1_12_2",
956 feature = "v1_16_5",
957 feature = "v26_1",
958 feature = "v26_2",
959 feature = "v26_3"
960))]
961impl<const V: i32> Encode for AdvancementTab<V> {
962 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
963 w.put_varint((*self).action);
964 match (&(*self).tab_id, ((*self).action == 0)) {
965 (Some(v1), true) => {
966 w.put_string(&(*v1))?;
967 }
968 (None, false) => {}
969 _ => {
970 return Err(EncodeError::SwitchMismatch(
971 "play.serverbound.advancement_tab.tabId",
972 ));
973 }
974 }
975 Ok(())
976 }
977}
978#[cfg(any(
979 feature = "v1_12_2",
980 feature = "v1_16_5",
981 feature = "v26_1",
982 feature = "v26_2",
983 feature = "v26_3"
984))]
985#[cfg(feature = "testgen")]
986impl<const V: i32> Generate for AdvancementTab<V> {
987 fn generate(g: &mut Gen) -> Self {
988 {
989 let v1 = (g.int_in(-2147483648, 2147483647, &[0, 1]) as i32);
990 let v2 = if (v1 == 0) { Some(g.string()) } else { None };
991 Self {
992 action: v1,
993 tab_id: v2,
994 }
995 }
996 }
997}
998
999#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1000#[derive(Debug, Clone, PartialEq)]
1002pub struct ArmAnimation<const V: i32> {
1003 pub hand: i32,
1005}
1006#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1007impl<const V: i32> Decode for ArmAnimation<V> {
1008 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1009 Ok({
1010 let v1 = r.read_varint()?;
1011 Self { hand: v1 }
1012 })
1013 }
1014}
1015#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1016impl<const V: i32> Encode for ArmAnimation<V> {
1017 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1018 w.put_varint((*self).hand);
1019 Ok(())
1020 }
1021}
1022#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1023#[cfg(feature = "testgen")]
1024impl<const V: i32> Generate for ArmAnimation<V> {
1025 fn generate(g: &mut Gen) -> Self {
1026 {
1027 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1028 Self { hand: v1 }
1029 }
1030 }
1031}
1032
1033#[cfg(feature = "v1_12_2")]
1034#[derive(Debug, Clone, PartialEq)]
1036pub struct BlockPlace<const V: i32> {
1037 pub location: BlockPos,
1039 pub direction: i32,
1041 pub hand: i32,
1043 pub cursor_x: f32,
1045 pub cursor_y: f32,
1047 pub cursor_z: f32,
1049}
1050#[cfg(feature = "v1_12_2")]
1051impl<const V: i32> Decode for BlockPlace<V> {
1052 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1053 Ok({
1054 let v1 = BlockPos::read(r, PositionLayout::Xyz)?;
1055 let v2 = r.read_varint()?;
1056 let v3 = r.read_varint()?;
1057 let v4 = r.read_f32()?;
1058 let v5 = r.read_f32()?;
1059 let v6 = r.read_f32()?;
1060 Self {
1061 location: v1,
1062 direction: v2,
1063 hand: v3,
1064 cursor_x: v4,
1065 cursor_y: v5,
1066 cursor_z: v6,
1067 }
1068 })
1069 }
1070}
1071#[cfg(feature = "v1_12_2")]
1072impl<const V: i32> Encode for BlockPlace<V> {
1073 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1074 (*self).location.write(w, PositionLayout::Xyz)?;
1075 w.put_varint((*self).direction);
1076 w.put_varint((*self).hand);
1077 w.put_f32((*self).cursor_x);
1078 w.put_f32((*self).cursor_y);
1079 w.put_f32((*self).cursor_z);
1080 Ok(())
1081 }
1082}
1083#[cfg(feature = "v1_12_2")]
1084#[cfg(feature = "testgen")]
1085impl<const V: i32> Generate for BlockPlace<V> {
1086 fn generate(g: &mut Gen) -> Self {
1087 {
1088 let v1 = g.position();
1089 let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1090 let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1091 let v4 = g.f32();
1092 let v5 = g.f32();
1093 let v6 = g.f32();
1094 Self {
1095 location: v1,
1096 direction: v2,
1097 hand: v3,
1098 cursor_x: v4,
1099 cursor_y: v5,
1100 cursor_z: v6,
1101 }
1102 }
1103 }
1104}
1105
1106#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1107#[derive(Debug, Clone, PartialEq)]
1109pub struct UseItem<const V: i32> {
1110 pub hand: i32,
1112}
1113#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1114impl<const V: i32> Decode for UseItem<V> {
1115 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1116 Ok({
1117 let v1 = r.read_varint()?;
1118 Self { hand: v1 }
1119 })
1120 }
1121}
1122#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1123impl<const V: i32> Encode for UseItem<V> {
1124 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1125 w.put_varint((*self).hand);
1126 Ok(())
1127 }
1128}
1129#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1130#[cfg(feature = "testgen")]
1131impl<const V: i32> Generate for UseItem<V> {
1132 fn generate(g: &mut Gen) -> Self {
1133 {
1134 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1135 Self { hand: v1 }
1136 }
1137 }
1138}