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_8", feature = "v1_12_2"))]
29#[derive(Debug, Clone, PartialEq)]
31pub struct KeepAlive<const V: i32> {
32 pub keep_alive_id: i32,
34}
35#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
36impl<const V: i32> Decode for KeepAlive<V> {
37 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
38 Ok({
39 let v1 = r.read_varint()?;
40 Self { keep_alive_id: v1 }
41 })
42 }
43}
44#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
45impl<const V: i32> Encode for KeepAlive<V> {
46 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
47 w.put_varint((*self).keep_alive_id);
48 Ok(())
49 }
50}
51#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
52#[cfg(feature = "testgen")]
53impl<const V: i32> Generate for KeepAlive<V> {
54 fn generate(g: &mut Gen) -> Self {
55 {
56 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
57 Self { keep_alive_id: v1 }
58 }
59 }
60}
61
62#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
63#[derive(Debug, Clone, PartialEq)]
65pub struct Chat<const V: i32> {
66 pub message: ByteString,
68}
69#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
70impl<const V: i32> Decode for Chat<V> {
71 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
72 Ok({
73 let v1 = r.read_string()?;
74 Self { message: v1 }
75 })
76 }
77}
78#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
79impl<const V: i32> Encode for Chat<V> {
80 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
81 w.put_string(&(*self).message)?;
82 Ok(())
83 }
84}
85#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
86#[cfg(feature = "testgen")]
87impl<const V: i32> Generate for Chat<V> {
88 fn generate(g: &mut Gen) -> Self {
89 {
90 let v1 = g.string();
91 Self { message: v1 }
92 }
93 }
94}
95
96#[cfg(feature = "v1_8")]
97#[derive(Debug, Clone, PartialEq)]
99pub struct UseEntity<const V: i32> {
100 pub target: i32,
102 pub mouse: i32,
104 pub x: Option<f32>,
106 pub y: Option<f32>,
108 pub z: Option<f32>,
110}
111#[cfg(feature = "v1_8")]
112impl<const V: i32> Decode for UseEntity<V> {
113 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
114 Ok({
115 let v1 = r.read_varint()?;
116 let v2 = r.read_varint()?;
117 let v3 = if (v2 == 2) { Some(r.read_f32()?) } else { None };
118 let v4 = if (v2 == 2) { Some(r.read_f32()?) } else { None };
119 let v5 = if (v2 == 2) { Some(r.read_f32()?) } else { None };
120 Self {
121 target: v1,
122 mouse: v2,
123 x: v3,
124 y: v4,
125 z: v5,
126 }
127 })
128 }
129}
130#[cfg(feature = "v1_8")]
131impl<const V: i32> Encode for UseEntity<V> {
132 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
133 w.put_varint((*self).target);
134 w.put_varint((*self).mouse);
135 match (&(*self).x, ((*self).mouse == 2)) {
136 (Some(v1), true) => {
137 w.put_f32((*v1));
138 }
139 (None, false) => {}
140 _ => return Err(EncodeError::SwitchMismatch("play.serverbound.use_entity.x")),
141 }
142 match (&(*self).y, ((*self).mouse == 2)) {
143 (Some(v2), true) => {
144 w.put_f32((*v2));
145 }
146 (None, false) => {}
147 _ => return Err(EncodeError::SwitchMismatch("play.serverbound.use_entity.y")),
148 }
149 match (&(*self).z, ((*self).mouse == 2)) {
150 (Some(v3), true) => {
151 w.put_f32((*v3));
152 }
153 (None, false) => {}
154 _ => return Err(EncodeError::SwitchMismatch("play.serverbound.use_entity.z")),
155 }
156 Ok(())
157 }
158}
159#[cfg(feature = "v1_8")]
160#[cfg(feature = "testgen")]
161impl<const V: i32> Generate for UseEntity<V> {
162 fn generate(g: &mut Gen) -> Self {
163 {
164 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
165 let v2 = (g.int_in(-2147483648, 2147483647, &[2, 2, 2]) as i32);
166 let v3 = if (v2 == 2) { Some(g.f32()) } else { None };
167 let v4 = if (v2 == 2) { Some(g.f32()) } else { None };
168 let v5 = if (v2 == 2) { Some(g.f32()) } else { None };
169 Self {
170 target: v1,
171 mouse: v2,
172 x: v3,
173 y: v4,
174 z: v5,
175 }
176 }
177 }
178}
179
180#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
181#[derive(Debug, Clone, PartialEq)]
183pub struct Flying<const V: i32> {
184 pub on_ground: bool,
186}
187#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
188impl<const V: i32> Decode for Flying<V> {
189 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
190 Ok({
191 let v1 = r.read_bool()?;
192 Self { on_ground: v1 }
193 })
194 }
195}
196#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
197impl<const V: i32> Encode for Flying<V> {
198 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
199 w.put_bool((*self).on_ground);
200 Ok(())
201 }
202}
203#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
204#[cfg(feature = "testgen")]
205impl<const V: i32> Generate for Flying<V> {
206 fn generate(g: &mut Gen) -> Self {
207 {
208 let v1 = g.bool();
209 Self { on_ground: v1 }
210 }
211 }
212}
213
214#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
215#[derive(Debug, Clone, PartialEq)]
217pub struct Position<const V: i32> {
218 pub x: f64,
220 pub y: f64,
222 pub z: f64,
224 pub on_ground: bool,
226}
227#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
228impl<const V: i32> Decode for Position<V> {
229 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
230 Ok({
231 let v1 = r.read_f64()?;
232 let v2 = r.read_f64()?;
233 let v3 = r.read_f64()?;
234 let v4 = r.read_bool()?;
235 Self {
236 x: v1,
237 y: v2,
238 z: v3,
239 on_ground: v4,
240 }
241 })
242 }
243}
244#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
245impl<const V: i32> Encode for Position<V> {
246 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
247 w.put_f64((*self).x);
248 w.put_f64((*self).y);
249 w.put_f64((*self).z);
250 w.put_bool((*self).on_ground);
251 Ok(())
252 }
253}
254#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
255#[cfg(feature = "testgen")]
256impl<const V: i32> Generate for Position<V> {
257 fn generate(g: &mut Gen) -> Self {
258 {
259 let v1 = g.f64();
260 let v2 = g.f64();
261 let v3 = g.f64();
262 let v4 = g.bool();
263 Self {
264 x: v1,
265 y: v2,
266 z: v3,
267 on_ground: v4,
268 }
269 }
270 }
271}
272
273#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
274#[derive(Debug, Clone, PartialEq)]
276pub struct Look<const V: i32> {
277 pub yaw: f32,
279 pub pitch: f32,
281 pub on_ground: bool,
283}
284#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
285impl<const V: i32> Decode for Look<V> {
286 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
287 Ok({
288 let v1 = r.read_f32()?;
289 let v2 = r.read_f32()?;
290 let v3 = r.read_bool()?;
291 Self {
292 yaw: v1,
293 pitch: v2,
294 on_ground: v3,
295 }
296 })
297 }
298}
299#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
300impl<const V: i32> Encode for Look<V> {
301 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
302 w.put_f32((*self).yaw);
303 w.put_f32((*self).pitch);
304 w.put_bool((*self).on_ground);
305 Ok(())
306 }
307}
308#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
309#[cfg(feature = "testgen")]
310impl<const V: i32> Generate for Look<V> {
311 fn generate(g: &mut Gen) -> Self {
312 {
313 let v1 = g.f32();
314 let v2 = g.f32();
315 let v3 = g.bool();
316 Self {
317 yaw: v1,
318 pitch: v2,
319 on_ground: v3,
320 }
321 }
322 }
323}
324
325#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
326#[derive(Debug, Clone, PartialEq)]
328pub struct PositionLook<const V: i32> {
329 pub x: f64,
331 pub y: f64,
333 pub z: f64,
335 pub yaw: f32,
337 pub pitch: f32,
339 pub on_ground: bool,
341}
342#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
343impl<const V: i32> Decode for PositionLook<V> {
344 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
345 Ok({
346 let v1 = r.read_f64()?;
347 let v2 = r.read_f64()?;
348 let v3 = r.read_f64()?;
349 let v4 = r.read_f32()?;
350 let v5 = r.read_f32()?;
351 let v6 = r.read_bool()?;
352 Self {
353 x: v1,
354 y: v2,
355 z: v3,
356 yaw: v4,
357 pitch: v5,
358 on_ground: v6,
359 }
360 })
361 }
362}
363#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
364impl<const V: i32> Encode for PositionLook<V> {
365 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
366 w.put_f64((*self).x);
367 w.put_f64((*self).y);
368 w.put_f64((*self).z);
369 w.put_f32((*self).yaw);
370 w.put_f32((*self).pitch);
371 w.put_bool((*self).on_ground);
372 Ok(())
373 }
374}
375#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
376#[cfg(feature = "testgen")]
377impl<const V: i32> Generate for PositionLook<V> {
378 fn generate(g: &mut Gen) -> Self {
379 {
380 let v1 = g.f64();
381 let v2 = g.f64();
382 let v3 = g.f64();
383 let v4 = g.f32();
384 let v5 = g.f32();
385 let v6 = g.bool();
386 Self {
387 x: v1,
388 y: v2,
389 z: v3,
390 yaw: v4,
391 pitch: v5,
392 on_ground: v6,
393 }
394 }
395 }
396}
397
398#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
399#[derive(Debug, Clone, PartialEq)]
401pub struct BlockDig<const V: i32> {
402 pub status: i32,
404 pub location: BlockPos,
406 pub face: i8,
408}
409#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
410impl<const V: i32> Decode for BlockDig<V> {
411 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
412 Ok({
413 let v1 = r.read_varint()?;
414 let v2 = BlockPos::read(r, PositionLayout::Xyz)?;
415 let v3 = r.read_i8()?;
416 Self {
417 status: v1,
418 location: v2,
419 face: v3,
420 }
421 })
422 }
423}
424#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
425impl<const V: i32> Encode for BlockDig<V> {
426 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
427 w.put_varint((*self).status);
428 (*self).location.write(w, PositionLayout::Xyz)?;
429 w.put_i8((*self).face);
430 Ok(())
431 }
432}
433#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
434#[cfg(feature = "testgen")]
435impl<const V: i32> Generate for BlockDig<V> {
436 fn generate(g: &mut Gen) -> Self {
437 {
438 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
439 let v2 = g.position();
440 let v3 = (g.int_in(-128, 127, &[]) as i8);
441 Self {
442 status: v1,
443 location: v2,
444 face: v3,
445 }
446 }
447 }
448}
449
450#[cfg(feature = "v1_8")]
451#[derive(Debug, Clone, PartialEq)]
453pub struct BlockPlace<const V: i32> {
454 pub location: BlockPos,
456 pub direction: i8,
458 pub held_item: crate::types::slot::legacy::Slot,
460 pub cursor_x: i8,
462 pub cursor_y: i8,
464 pub cursor_z: i8,
466}
467#[cfg(feature = "v1_8")]
468impl<const V: i32> Decode for BlockPlace<V> {
469 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
470 Ok({
471 let v1 = BlockPos::read(r, PositionLayout::Xyz)?;
472 let v2 = r.read_i8()?;
473 let v3 = <crate::types::slot::legacy::Slot as Decode>::decode(r)?;
474 let v4 = r.read_i8()?;
475 let v5 = r.read_i8()?;
476 let v6 = r.read_i8()?;
477 Self {
478 location: v1,
479 direction: v2,
480 held_item: v3,
481 cursor_x: v4,
482 cursor_y: v5,
483 cursor_z: v6,
484 }
485 })
486 }
487}
488#[cfg(feature = "v1_8")]
489impl<const V: i32> Encode for BlockPlace<V> {
490 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
491 (*self).location.write(w, PositionLayout::Xyz)?;
492 w.put_i8((*self).direction);
493 (*self).held_item.encode(w)?;
494 w.put_i8((*self).cursor_x);
495 w.put_i8((*self).cursor_y);
496 w.put_i8((*self).cursor_z);
497 Ok(())
498 }
499}
500#[cfg(feature = "v1_8")]
501#[cfg(feature = "testgen")]
502impl<const V: i32> Generate for BlockPlace<V> {
503 fn generate(g: &mut Gen) -> Self {
504 {
505 let v1 = g.position();
506 let v2 = (g.int_in(-128, 127, &[]) as i8);
507 let v3 = <crate::types::slot::legacy::Slot as Generate>::generate(g);
508 let v4 = (g.int_in(-128, 127, &[]) as i8);
509 let v5 = (g.int_in(-128, 127, &[]) as i8);
510 let v6 = (g.int_in(-128, 127, &[]) as i8);
511 Self {
512 location: v1,
513 direction: v2,
514 held_item: v3,
515 cursor_x: v4,
516 cursor_y: v5,
517 cursor_z: v6,
518 }
519 }
520 }
521}
522
523#[cfg(any(
524 feature = "v1_8",
525 feature = "v1_12_2",
526 feature = "v1_16_5",
527 feature = "v26_1",
528 feature = "v26_2",
529 feature = "v26_3"
530))]
531#[derive(Debug, Clone, PartialEq)]
533pub struct HeldItemSlot<const V: i32> {
534 pub slot_id: i16,
536}
537#[cfg(any(
538 feature = "v1_8",
539 feature = "v1_12_2",
540 feature = "v1_16_5",
541 feature = "v26_1",
542 feature = "v26_2",
543 feature = "v26_3"
544))]
545impl<const V: i32> Decode for HeldItemSlot<V> {
546 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
547 Ok({
548 let v1 = r.read_i16()?;
549 Self { slot_id: v1 }
550 })
551 }
552}
553#[cfg(any(
554 feature = "v1_8",
555 feature = "v1_12_2",
556 feature = "v1_16_5",
557 feature = "v26_1",
558 feature = "v26_2",
559 feature = "v26_3"
560))]
561impl<const V: i32> Encode for HeldItemSlot<V> {
562 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
563 w.put_i16((*self).slot_id);
564 Ok(())
565 }
566}
567#[cfg(any(
568 feature = "v1_8",
569 feature = "v1_12_2",
570 feature = "v1_16_5",
571 feature = "v26_1",
572 feature = "v26_2",
573 feature = "v26_3"
574))]
575#[cfg(feature = "testgen")]
576impl<const V: i32> Generate for HeldItemSlot<V> {
577 fn generate(g: &mut Gen) -> Self {
578 {
579 let v1 = (g.int_in(-32768, 32767, &[]) as i16);
580 Self { slot_id: v1 }
581 }
582 }
583}
584
585#[cfg(feature = "v1_8")]
586#[derive(Debug, Clone, PartialEq)]
588pub struct ArmAnimation<const V: i32> {}
589#[cfg(feature = "v1_8")]
590impl<const V: i32> Decode for ArmAnimation<V> {
591 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
592 Ok({ Self {} })
593 }
594}
595#[cfg(feature = "v1_8")]
596impl<const V: i32> Encode for ArmAnimation<V> {
597 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
598 Ok(())
599 }
600}
601#[cfg(feature = "v1_8")]
602#[cfg(feature = "testgen")]
603impl<const V: i32> Generate for ArmAnimation<V> {
604 fn generate(g: &mut Gen) -> Self {
605 { Self {} }
606 }
607}
608
609#[cfg(feature = "v1_8")]
610#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
612pub struct EntityActionActionId(pub i32);
613#[cfg(feature = "v1_8")]
614impl EntityActionActionId {
615 pub const START_SNEAKING: Self = Self(0);
617 pub const STOP_SNEAKING: Self = Self(1);
619 pub const STOP_SLEEPING: Self = Self(2);
621 pub const START_SPRINTING: Self = Self(3);
623 pub const STOP_SPRINTING: Self = Self(4);
625 pub const START_RIDING_JUMP: Self = Self(5);
627 pub const OPEN_INVENTORY: Self = Self(6);
629 pub const fn name(self) -> Option<&'static str> {
631 match self.0 {
632 0 => Some("start_sneaking"),
633 1 => Some("stop_sneaking"),
634 2 => Some("stop_sleeping"),
635 3 => Some("start_sprinting"),
636 4 => Some("stop_sprinting"),
637 5 => Some("start_riding_jump"),
638 6 => Some("open_inventory"),
639 _ => None,
640 }
641 }
642}
643#[cfg(feature = "v1_8")]
644impl std::fmt::Debug for EntityActionActionId {
645 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
646 match self.name() {
647 Some(n) => write!(f, "EntityActionActionId::{n}"),
648 None => write!(f, "EntityActionActionId({})", self.0),
649 }
650 }
651}
652
653#[cfg(feature = "v1_8")]
654#[derive(Debug, Clone, PartialEq)]
656pub struct EntityAction<const V: i32> {
657 pub entity_id: i32,
659 pub action_id: crate::defs::p47::play::serverbound::EntityActionActionId,
661 pub jump_boost: i32,
663}
664#[cfg(feature = "v1_8")]
665impl<const V: i32> Decode for EntityAction<V> {
666 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
667 Ok({
668 let v1 = r.read_varint()?;
669 let v2 = crate::defs::p47::play::serverbound::EntityActionActionId(r.read_varint()?);
670 let v3 = r.read_varint()?;
671 Self {
672 entity_id: v1,
673 action_id: v2,
674 jump_boost: v3,
675 }
676 })
677 }
678}
679#[cfg(feature = "v1_8")]
680impl<const V: i32> Encode for EntityAction<V> {
681 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
682 w.put_varint((*self).entity_id);
683 w.put_varint((*self).action_id.0);
684 w.put_varint((*self).jump_boost);
685 Ok(())
686 }
687}
688#[cfg(feature = "v1_8")]
689#[cfg(feature = "testgen")]
690impl<const V: i32> Generate for EntityAction<V> {
691 fn generate(g: &mut Gen) -> Self {
692 {
693 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
694 let v2 = crate::defs::p47::play::serverbound::EntityActionActionId(g.int_in(
695 -2147483648,
696 2147483647,
697 &[0, 1, 2, 3, 4, 5, 6],
698 )
699 as i32);
700 let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
701 Self {
702 entity_id: v1,
703 action_id: v2,
704 jump_boost: v3,
705 }
706 }
707 }
708}
709
710#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
711#[derive(Debug, Clone, PartialEq)]
713pub struct SteerVehicle<const V: i32> {
714 pub sideways: f32,
716 pub forward: f32,
718 pub jump: u8,
720}
721#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
722impl<const V: i32> Decode for SteerVehicle<V> {
723 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
724 Ok({
725 let v1 = r.read_f32()?;
726 let v2 = r.read_f32()?;
727 let v3 = r.read_u8()?;
728 Self {
729 sideways: v1,
730 forward: v2,
731 jump: v3,
732 }
733 })
734 }
735}
736#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
737impl<const V: i32> Encode for SteerVehicle<V> {
738 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
739 w.put_f32((*self).sideways);
740 w.put_f32((*self).forward);
741 w.put_u8((*self).jump);
742 Ok(())
743 }
744}
745#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
746#[cfg(feature = "testgen")]
747impl<const V: i32> Generate for SteerVehicle<V> {
748 fn generate(g: &mut Gen) -> Self {
749 {
750 let v1 = g.f32();
751 let v2 = g.f32();
752 let v3 = (g.int_in(0, 255, &[]) as u8);
753 Self {
754 sideways: v1,
755 forward: v2,
756 jump: v3,
757 }
758 }
759 }
760}
761
762#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
763#[derive(Debug, Clone, PartialEq)]
765pub struct CloseWindow<const V: i32> {
766 pub window_id: u8,
768}
769#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
770impl<const V: i32> Decode for CloseWindow<V> {
771 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
772 Ok({
773 let v1 = r.read_u8()?;
774 Self { window_id: v1 }
775 })
776 }
777}
778#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
779impl<const V: i32> Encode for CloseWindow<V> {
780 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
781 w.put_u8((*self).window_id);
782 Ok(())
783 }
784}
785#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
786#[cfg(feature = "testgen")]
787impl<const V: i32> Generate for CloseWindow<V> {
788 fn generate(g: &mut Gen) -> Self {
789 {
790 let v1 = (g.int_in(0, 255, &[]) as u8);
791 Self { window_id: v1 }
792 }
793 }
794}
795
796#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
797#[derive(Debug, Clone, PartialEq)]
799pub struct WindowClick<const V: i32> {
800 pub window_id: u8,
802 pub slot: i16,
804 pub mouse_button: i8,
806 pub action: i16,
808 pub mode: i8,
810 pub item: crate::types::slot::legacy::Slot,
812}
813#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
814impl<const V: i32> Decode for WindowClick<V> {
815 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
816 Ok({
817 let v1 = r.read_u8()?;
818 let v2 = r.read_i16()?;
819 let v3 = r.read_i8()?;
820 let v4 = r.read_i16()?;
821 let v5 = r.read_i8()?;
822 let v6 = <crate::types::slot::legacy::Slot as Decode>::decode(r)?;
823 Self {
824 window_id: v1,
825 slot: v2,
826 mouse_button: v3,
827 action: v4,
828 mode: v5,
829 item: v6,
830 }
831 })
832 }
833}
834#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
835impl<const V: i32> Encode for WindowClick<V> {
836 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
837 w.put_u8((*self).window_id);
838 w.put_i16((*self).slot);
839 w.put_i8((*self).mouse_button);
840 w.put_i16((*self).action);
841 w.put_i8((*self).mode);
842 (*self).item.encode(w)?;
843 Ok(())
844 }
845}
846#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
847#[cfg(feature = "testgen")]
848impl<const V: i32> Generate for WindowClick<V> {
849 fn generate(g: &mut Gen) -> Self {
850 {
851 let v1 = (g.int_in(0, 255, &[]) as u8);
852 let v2 = (g.int_in(-32768, 32767, &[]) as i16);
853 let v3 = (g.int_in(-128, 127, &[]) as i8);
854 let v4 = (g.int_in(-32768, 32767, &[]) as i16);
855 let v5 = (g.int_in(-128, 127, &[]) as i8);
856 let v6 = <crate::types::slot::legacy::Slot as Generate>::generate(g);
857 Self {
858 window_id: v1,
859 slot: v2,
860 mouse_button: v3,
861 action: v4,
862 mode: v5,
863 item: v6,
864 }
865 }
866 }
867}
868
869#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
870#[derive(Debug, Clone, PartialEq)]
872pub struct Transaction<const V: i32> {
873 pub window_id: i8,
875 pub action: i16,
877 pub accepted: bool,
879}
880#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
881impl<const V: i32> Decode for Transaction<V> {
882 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
883 Ok({
884 let v1 = r.read_i8()?;
885 let v2 = r.read_i16()?;
886 let v3 = r.read_bool()?;
887 Self {
888 window_id: v1,
889 action: v2,
890 accepted: v3,
891 }
892 })
893 }
894}
895#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
896impl<const V: i32> Encode for Transaction<V> {
897 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
898 w.put_i8((*self).window_id);
899 w.put_i16((*self).action);
900 w.put_bool((*self).accepted);
901 Ok(())
902 }
903}
904#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
905#[cfg(feature = "testgen")]
906impl<const V: i32> Generate for Transaction<V> {
907 fn generate(g: &mut Gen) -> Self {
908 {
909 let v1 = (g.int_in(-128, 127, &[]) as i8);
910 let v2 = (g.int_in(-32768, 32767, &[]) as i16);
911 let v3 = g.bool();
912 Self {
913 window_id: v1,
914 action: v2,
915 accepted: v3,
916 }
917 }
918 }
919}
920
921#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
922#[derive(Debug, Clone, PartialEq)]
924pub struct SetCreativeSlot<const V: i32> {
925 pub slot: i16,
927 pub item: crate::types::slot::legacy::Slot,
929}
930#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
931impl<const V: i32> Decode for SetCreativeSlot<V> {
932 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
933 Ok({
934 let v1 = r.read_i16()?;
935 let v2 = <crate::types::slot::legacy::Slot as Decode>::decode(r)?;
936 Self { slot: v1, item: v2 }
937 })
938 }
939}
940#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
941impl<const V: i32> Encode for SetCreativeSlot<V> {
942 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
943 w.put_i16((*self).slot);
944 (*self).item.encode(w)?;
945 Ok(())
946 }
947}
948#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
949#[cfg(feature = "testgen")]
950impl<const V: i32> Generate for SetCreativeSlot<V> {
951 fn generate(g: &mut Gen) -> Self {
952 {
953 let v1 = (g.int_in(-32768, 32767, &[]) as i16);
954 let v2 = <crate::types::slot::legacy::Slot as Generate>::generate(g);
955 Self { slot: v1, item: v2 }
956 }
957 }
958}
959
960#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
961#[derive(Debug, Clone, PartialEq)]
963pub struct EnchantItem<const V: i32> {
964 pub window_id: i8,
966 pub enchantment: i8,
968}
969#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
970impl<const V: i32> Decode for EnchantItem<V> {
971 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
972 Ok({
973 let v1 = r.read_i8()?;
974 let v2 = r.read_i8()?;
975 Self {
976 window_id: v1,
977 enchantment: v2,
978 }
979 })
980 }
981}
982#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
983impl<const V: i32> Encode for EnchantItem<V> {
984 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
985 w.put_i8((*self).window_id);
986 w.put_i8((*self).enchantment);
987 Ok(())
988 }
989}
990#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
991#[cfg(feature = "testgen")]
992impl<const V: i32> Generate for EnchantItem<V> {
993 fn generate(g: &mut Gen) -> Self {
994 {
995 let v1 = (g.int_in(-128, 127, &[]) as i8);
996 let v2 = (g.int_in(-128, 127, &[]) as i8);
997 Self {
998 window_id: v1,
999 enchantment: v2,
1000 }
1001 }
1002 }
1003}
1004
1005#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
1006#[derive(Debug, Clone, PartialEq)]
1008pub struct UpdateSign<const V: i32> {
1009 pub location: BlockPos,
1011 pub text1: ByteString,
1013 pub text2: ByteString,
1015 pub text3: ByteString,
1017 pub text4: ByteString,
1019}
1020#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
1021impl<const V: i32> Decode for UpdateSign<V> {
1022 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1023 Ok({
1024 let v1 = BlockPos::read(r, PositionLayout::Xyz)?;
1025 let v2 = r.read_string()?;
1026 let v3 = r.read_string()?;
1027 let v4 = r.read_string()?;
1028 let v5 = r.read_string()?;
1029 Self {
1030 location: v1,
1031 text1: v2,
1032 text2: v3,
1033 text3: v4,
1034 text4: v5,
1035 }
1036 })
1037 }
1038}
1039#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
1040impl<const V: i32> Encode for UpdateSign<V> {
1041 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1042 (*self).location.write(w, PositionLayout::Xyz)?;
1043 w.put_string(&(*self).text1)?;
1044 w.put_string(&(*self).text2)?;
1045 w.put_string(&(*self).text3)?;
1046 w.put_string(&(*self).text4)?;
1047 Ok(())
1048 }
1049}
1050#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
1051#[cfg(feature = "testgen")]
1052impl<const V: i32> Generate for UpdateSign<V> {
1053 fn generate(g: &mut Gen) -> Self {
1054 {
1055 let v1 = g.position();
1056 let v2 = g.string();
1057 let v3 = g.string();
1058 let v4 = g.string();
1059 let v5 = g.string();
1060 Self {
1061 location: v1,
1062 text1: v2,
1063 text2: v3,
1064 text3: v4,
1065 text4: v5,
1066 }
1067 }
1068 }
1069}
1070
1071#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
1072#[derive(Debug, Clone, PartialEq)]
1074pub struct Abilities<const V: i32> {
1075 pub flags: i8,
1077 pub flying_speed: f32,
1079 pub walking_speed: f32,
1081}
1082#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
1083impl<const V: i32> Decode for Abilities<V> {
1084 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1085 Ok({
1086 let v1 = r.read_i8()?;
1087 let v2 = r.read_f32()?;
1088 let v3 = r.read_f32()?;
1089 Self {
1090 flags: v1,
1091 flying_speed: v2,
1092 walking_speed: v3,
1093 }
1094 })
1095 }
1096}
1097#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
1098impl<const V: i32> Encode for Abilities<V> {
1099 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1100 w.put_i8((*self).flags);
1101 w.put_f32((*self).flying_speed);
1102 w.put_f32((*self).walking_speed);
1103 Ok(())
1104 }
1105}
1106#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
1107#[cfg(feature = "testgen")]
1108impl<const V: i32> Generate for Abilities<V> {
1109 fn generate(g: &mut Gen) -> Self {
1110 {
1111 let v1 = (g.int_in(-128, 127, &[]) as i8);
1112 let v2 = g.f32();
1113 let v3 = g.f32();
1114 Self {
1115 flags: v1,
1116 flying_speed: v2,
1117 walking_speed: v3,
1118 }
1119 }
1120 }
1121}
1122
1123#[cfg(feature = "v1_8")]
1124#[derive(Debug, Clone, PartialEq)]
1126pub struct TabComplete<const V: i32> {
1127 pub text: ByteString,
1129 pub block: Option<BlockPos>,
1131}
1132#[cfg(feature = "v1_8")]
1133impl<const V: i32> Decode for TabComplete<V> {
1134 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1135 Ok({
1136 let v1 = r.read_string()?;
1137 let v2 = if r.read_bool()? {
1138 Some(BlockPos::read(r, PositionLayout::Xyz)?)
1139 } else {
1140 None
1141 };
1142 Self {
1143 text: v1,
1144 block: v2,
1145 }
1146 })
1147 }
1148}
1149#[cfg(feature = "v1_8")]
1150impl<const V: i32> Encode for TabComplete<V> {
1151 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1152 w.put_string(&(*self).text)?;
1153 match &(*self).block {
1154 Some(v1) => {
1155 w.put_u8(1);
1156 (*v1).write(w, PositionLayout::Xyz)?;
1157 }
1158 None => w.put_u8(0),
1159 }
1160 Ok(())
1161 }
1162}
1163#[cfg(feature = "v1_8")]
1164#[cfg(feature = "testgen")]
1165impl<const V: i32> Generate for TabComplete<V> {
1166 fn generate(g: &mut Gen) -> Self {
1167 {
1168 let v1 = g.string();
1169 let v2 = if g.bool() { Some(g.position()) } else { None };
1170 Self {
1171 text: v1,
1172 block: v2,
1173 }
1174 }
1175 }
1176}
1177
1178#[cfg(feature = "v1_8")]
1179#[derive(Debug, Clone, PartialEq)]
1181pub struct Settings<const V: i32> {
1182 pub locale: ByteString,
1184 pub view_distance: i8,
1186 pub chat_flags: i8,
1188 pub chat_colors: bool,
1190 pub skin_parts: u8,
1192}
1193#[cfg(feature = "v1_8")]
1194impl<const V: i32> Decode for Settings<V> {
1195 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1196 Ok({
1197 let v1 = r.read_string()?;
1198 let v2 = r.read_i8()?;
1199 let v3 = r.read_i8()?;
1200 let v4 = r.read_bool()?;
1201 let v5 = r.read_u8()?;
1202 Self {
1203 locale: v1,
1204 view_distance: v2,
1205 chat_flags: v3,
1206 chat_colors: v4,
1207 skin_parts: v5,
1208 }
1209 })
1210 }
1211}
1212#[cfg(feature = "v1_8")]
1213impl<const V: i32> Encode for Settings<V> {
1214 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1215 w.put_string(&(*self).locale)?;
1216 w.put_i8((*self).view_distance);
1217 w.put_i8((*self).chat_flags);
1218 w.put_bool((*self).chat_colors);
1219 w.put_u8((*self).skin_parts);
1220 Ok(())
1221 }
1222}
1223#[cfg(feature = "v1_8")]
1224#[cfg(feature = "testgen")]
1225impl<const V: i32> Generate for Settings<V> {
1226 fn generate(g: &mut Gen) -> Self {
1227 {
1228 let v1 = g.string();
1229 let v2 = (g.int_in(-128, 127, &[]) as i8);
1230 let v3 = (g.int_in(-128, 127, &[]) as i8);
1231 let v4 = g.bool();
1232 let v5 = (g.int_in(0, 255, &[]) as u8);
1233 Self {
1234 locale: v1,
1235 view_distance: v2,
1236 chat_flags: v3,
1237 chat_colors: v4,
1238 skin_parts: v5,
1239 }
1240 }
1241 }
1242}
1243
1244#[cfg(feature = "v1_8")]
1245#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
1247pub struct ClientCommandPayload(pub i32);
1248#[cfg(feature = "v1_8")]
1249impl ClientCommandPayload {
1250 pub const PERFORM_RESPAWN: Self = Self(0);
1252 pub const REQUEST_STATS: Self = Self(1);
1254 pub const OPEN_INVENTORY_ACHIEVEMENT: Self = Self(2);
1256 pub const fn name(self) -> Option<&'static str> {
1258 match self.0 {
1259 0 => Some("perform_respawn"),
1260 1 => Some("request_stats"),
1261 2 => Some("open_inventory_achievement"),
1262 _ => None,
1263 }
1264 }
1265}
1266#[cfg(feature = "v1_8")]
1267impl std::fmt::Debug for ClientCommandPayload {
1268 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1269 match self.name() {
1270 Some(n) => write!(f, "ClientCommandPayload::{n}"),
1271 None => write!(f, "ClientCommandPayload({})", self.0),
1272 }
1273 }
1274}
1275
1276#[cfg(feature = "v1_8")]
1277#[derive(Debug, Clone, PartialEq)]
1279pub struct ClientCommand<const V: i32> {
1280 pub payload: crate::defs::p47::play::serverbound::ClientCommandPayload,
1282}
1283#[cfg(feature = "v1_8")]
1284impl<const V: i32> Decode for ClientCommand<V> {
1285 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1286 Ok({
1287 let v1 = crate::defs::p47::play::serverbound::ClientCommandPayload(r.read_varint()?);
1288 Self { payload: v1 }
1289 })
1290 }
1291}
1292#[cfg(feature = "v1_8")]
1293impl<const V: i32> Encode for ClientCommand<V> {
1294 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1295 w.put_varint((*self).payload.0);
1296 Ok(())
1297 }
1298}
1299#[cfg(feature = "v1_8")]
1300#[cfg(feature = "testgen")]
1301impl<const V: i32> Generate for ClientCommand<V> {
1302 fn generate(g: &mut Gen) -> Self {
1303 {
1304 let v1 = crate::defs::p47::play::serverbound::ClientCommandPayload(g.int_in(
1305 -2147483648,
1306 2147483647,
1307 &[0, 1, 2],
1308 )
1309 as i32);
1310 Self { payload: v1 }
1311 }
1312 }
1313}
1314
1315#[cfg(any(
1316 feature = "v1_8",
1317 feature = "v1_12_2",
1318 feature = "v1_16_5",
1319 feature = "v26_1",
1320 feature = "v26_2",
1321 feature = "v26_3"
1322))]
1323#[derive(Debug, Clone, PartialEq)]
1325pub struct CustomPayload<const V: i32> {
1326 pub channel: ByteString,
1328 pub data: Bytes,
1330}
1331#[cfg(any(
1332 feature = "v1_8",
1333 feature = "v1_12_2",
1334 feature = "v1_16_5",
1335 feature = "v26_1",
1336 feature = "v26_2",
1337 feature = "v26_3"
1338))]
1339impl<const V: i32> Decode for CustomPayload<V> {
1340 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1341 Ok({
1342 let v1 = r.read_string()?;
1343 let v2 = r.read_rest();
1344 Self {
1345 channel: v1,
1346 data: v2,
1347 }
1348 })
1349 }
1350}
1351#[cfg(any(
1352 feature = "v1_8",
1353 feature = "v1_12_2",
1354 feature = "v1_16_5",
1355 feature = "v26_1",
1356 feature = "v26_2",
1357 feature = "v26_3"
1358))]
1359impl<const V: i32> Encode for CustomPayload<V> {
1360 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1361 w.put_string(&(*self).channel)?;
1362 w.put_slice(&(*self).data);
1363 Ok(())
1364 }
1365}
1366#[cfg(any(
1367 feature = "v1_8",
1368 feature = "v1_12_2",
1369 feature = "v1_16_5",
1370 feature = "v26_1",
1371 feature = "v26_2",
1372 feature = "v26_3"
1373))]
1374#[cfg(feature = "testgen")]
1375impl<const V: i32> Generate for CustomPayload<V> {
1376 fn generate(g: &mut Gen) -> Self {
1377 {
1378 let v1 = g.string();
1379 let v2 = g.bytes();
1380 Self {
1381 channel: v1,
1382 data: v2,
1383 }
1384 }
1385 }
1386}
1387
1388#[cfg(any(
1389 feature = "v1_8",
1390 feature = "v1_12_2",
1391 feature = "v1_16_5",
1392 feature = "v26_1",
1393 feature = "v26_2",
1394 feature = "v26_3"
1395))]
1396#[derive(Debug, Clone, PartialEq)]
1398pub struct Spectate<const V: i32> {
1399 pub target: Uuid,
1401}
1402#[cfg(any(
1403 feature = "v1_8",
1404 feature = "v1_12_2",
1405 feature = "v1_16_5",
1406 feature = "v26_1",
1407 feature = "v26_2",
1408 feature = "v26_3"
1409))]
1410impl<const V: i32> Decode for Spectate<V> {
1411 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1412 Ok({
1413 let v1 = r.read_uuid()?;
1414 Self { target: v1 }
1415 })
1416 }
1417}
1418#[cfg(any(
1419 feature = "v1_8",
1420 feature = "v1_12_2",
1421 feature = "v1_16_5",
1422 feature = "v26_1",
1423 feature = "v26_2",
1424 feature = "v26_3"
1425))]
1426impl<const V: i32> Encode for Spectate<V> {
1427 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1428 w.put_uuid(&(*self).target);
1429 Ok(())
1430 }
1431}
1432#[cfg(any(
1433 feature = "v1_8",
1434 feature = "v1_12_2",
1435 feature = "v1_16_5",
1436 feature = "v26_1",
1437 feature = "v26_2",
1438 feature = "v26_3"
1439))]
1440#[cfg(feature = "testgen")]
1441impl<const V: i32> Generate for Spectate<V> {
1442 fn generate(g: &mut Gen) -> Self {
1443 {
1444 let v1 = g.uuid();
1445 Self { target: v1 }
1446 }
1447 }
1448}
1449
1450#[cfg(feature = "v1_8")]
1451#[derive(Debug, Clone, PartialEq)]
1453pub struct ResourcePackReceive<const V: i32> {
1454 pub hash: ByteString,
1456 pub result: i32,
1458}
1459#[cfg(feature = "v1_8")]
1460impl<const V: i32> Decode for ResourcePackReceive<V> {
1461 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1462 Ok({
1463 let v1 = r.read_string()?;
1464 let v2 = r.read_varint()?;
1465 Self {
1466 hash: v1,
1467 result: v2,
1468 }
1469 })
1470 }
1471}
1472#[cfg(feature = "v1_8")]
1473impl<const V: i32> Encode for ResourcePackReceive<V> {
1474 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1475 w.put_string(&(*self).hash)?;
1476 w.put_varint((*self).result);
1477 Ok(())
1478 }
1479}
1480#[cfg(feature = "v1_8")]
1481#[cfg(feature = "testgen")]
1482impl<const V: i32> Generate for ResourcePackReceive<V> {
1483 fn generate(g: &mut Gen) -> Self {
1484 {
1485 let v1 = g.string();
1486 let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1487 Self {
1488 hash: v1,
1489 result: v2,
1490 }
1491 }
1492 }
1493}