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(feature = "v1_8")]
29#[derive(Debug, Clone, PartialEq)]
31pub struct KeepAlive<const V: i32> {
32 pub keep_alive_id: i32,
34}
35#[cfg(feature = "v1_8")]
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(feature = "v1_8")]
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(feature = "v1_8")]
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))]
529#[derive(Debug, Clone, PartialEq)]
531pub struct HeldItemSlot<const V: i32> {
532 pub slot_id: i16,
534}
535#[cfg(any(
536 feature = "v1_8",
537 feature = "v1_12_2",
538 feature = "v1_16_5",
539 feature = "v26_1"
540))]
541impl<const V: i32> Decode for HeldItemSlot<V> {
542 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
543 Ok({
544 let v1 = r.read_i16()?;
545 Self { slot_id: v1 }
546 })
547 }
548}
549#[cfg(any(
550 feature = "v1_8",
551 feature = "v1_12_2",
552 feature = "v1_16_5",
553 feature = "v26_1"
554))]
555impl<const V: i32> Encode for HeldItemSlot<V> {
556 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
557 w.put_i16((*self).slot_id);
558 Ok(())
559 }
560}
561#[cfg(any(
562 feature = "v1_8",
563 feature = "v1_12_2",
564 feature = "v1_16_5",
565 feature = "v26_1"
566))]
567#[cfg(feature = "testgen")]
568impl<const V: i32> Generate for HeldItemSlot<V> {
569 fn generate(g: &mut Gen) -> Self {
570 {
571 let v1 = (g.int_in(-32768, 32767, &[]) as i16);
572 Self { slot_id: v1 }
573 }
574 }
575}
576
577#[cfg(feature = "v1_8")]
578#[derive(Debug, Clone, PartialEq)]
580pub struct ArmAnimation<const V: i32> {}
581#[cfg(feature = "v1_8")]
582impl<const V: i32> Decode for ArmAnimation<V> {
583 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
584 Ok({ Self {} })
585 }
586}
587#[cfg(feature = "v1_8")]
588impl<const V: i32> Encode for ArmAnimation<V> {
589 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
590 Ok(())
591 }
592}
593#[cfg(feature = "v1_8")]
594#[cfg(feature = "testgen")]
595impl<const V: i32> Generate for ArmAnimation<V> {
596 fn generate(g: &mut Gen) -> Self {
597 { Self {} }
598 }
599}
600
601#[cfg(feature = "v1_8")]
602#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
604pub struct EntityActionActionId(pub i32);
605#[cfg(feature = "v1_8")]
606impl EntityActionActionId {
607 pub const START_SNEAKING: Self = Self(0);
609 pub const STOP_SNEAKING: Self = Self(1);
611 pub const STOP_SLEEPING: Self = Self(2);
613 pub const START_SPRINTING: Self = Self(3);
615 pub const STOP_SPRINTING: Self = Self(4);
617 pub const START_RIDING_JUMP: Self = Self(5);
619 pub const OPEN_INVENTORY: Self = Self(6);
621 pub const fn name(self) -> Option<&'static str> {
623 match self.0 {
624 0 => Some("start_sneaking"),
625 1 => Some("stop_sneaking"),
626 2 => Some("stop_sleeping"),
627 3 => Some("start_sprinting"),
628 4 => Some("stop_sprinting"),
629 5 => Some("start_riding_jump"),
630 6 => Some("open_inventory"),
631 _ => None,
632 }
633 }
634}
635#[cfg(feature = "v1_8")]
636impl std::fmt::Debug for EntityActionActionId {
637 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
638 match self.name() {
639 Some(n) => write!(f, "EntityActionActionId::{n}"),
640 None => write!(f, "EntityActionActionId({})", self.0),
641 }
642 }
643}
644
645#[cfg(feature = "v1_8")]
646#[derive(Debug, Clone, PartialEq)]
648pub struct EntityAction<const V: i32> {
649 pub entity_id: i32,
651 pub action_id: crate::defs::p47::play::serverbound::EntityActionActionId,
653 pub jump_boost: i32,
655}
656#[cfg(feature = "v1_8")]
657impl<const V: i32> Decode for EntityAction<V> {
658 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
659 Ok({
660 let v1 = r.read_varint()?;
661 let v2 = crate::defs::p47::play::serverbound::EntityActionActionId(r.read_varint()?);
662 let v3 = r.read_varint()?;
663 Self {
664 entity_id: v1,
665 action_id: v2,
666 jump_boost: v3,
667 }
668 })
669 }
670}
671#[cfg(feature = "v1_8")]
672impl<const V: i32> Encode for EntityAction<V> {
673 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
674 w.put_varint((*self).entity_id);
675 w.put_varint((*self).action_id.0);
676 w.put_varint((*self).jump_boost);
677 Ok(())
678 }
679}
680#[cfg(feature = "v1_8")]
681#[cfg(feature = "testgen")]
682impl<const V: i32> Generate for EntityAction<V> {
683 fn generate(g: &mut Gen) -> Self {
684 {
685 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
686 let v2 = crate::defs::p47::play::serverbound::EntityActionActionId(g.int_in(
687 -2147483648,
688 2147483647,
689 &[0, 1, 2, 3, 4, 5, 6],
690 )
691 as i32);
692 let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
693 Self {
694 entity_id: v1,
695 action_id: v2,
696 jump_boost: v3,
697 }
698 }
699 }
700}
701
702#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
703#[derive(Debug, Clone, PartialEq)]
705pub struct SteerVehicle<const V: i32> {
706 pub sideways: f32,
708 pub forward: f32,
710 pub jump: u8,
712}
713#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
714impl<const V: i32> Decode for SteerVehicle<V> {
715 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
716 Ok({
717 let v1 = r.read_f32()?;
718 let v2 = r.read_f32()?;
719 let v3 = r.read_u8()?;
720 Self {
721 sideways: v1,
722 forward: v2,
723 jump: v3,
724 }
725 })
726 }
727}
728#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
729impl<const V: i32> Encode for SteerVehicle<V> {
730 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
731 w.put_f32((*self).sideways);
732 w.put_f32((*self).forward);
733 w.put_u8((*self).jump);
734 Ok(())
735 }
736}
737#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
738#[cfg(feature = "testgen")]
739impl<const V: i32> Generate for SteerVehicle<V> {
740 fn generate(g: &mut Gen) -> Self {
741 {
742 let v1 = g.f32();
743 let v2 = g.f32();
744 let v3 = (g.int_in(0, 255, &[]) as u8);
745 Self {
746 sideways: v1,
747 forward: v2,
748 jump: v3,
749 }
750 }
751 }
752}
753
754#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
755#[derive(Debug, Clone, PartialEq)]
757pub struct CloseWindow<const V: i32> {
758 pub window_id: u8,
760}
761#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
762impl<const V: i32> Decode for CloseWindow<V> {
763 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
764 Ok({
765 let v1 = r.read_u8()?;
766 Self { window_id: v1 }
767 })
768 }
769}
770#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
771impl<const V: i32> Encode for CloseWindow<V> {
772 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
773 w.put_u8((*self).window_id);
774 Ok(())
775 }
776}
777#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
778#[cfg(feature = "testgen")]
779impl<const V: i32> Generate for CloseWindow<V> {
780 fn generate(g: &mut Gen) -> Self {
781 {
782 let v1 = (g.int_in(0, 255, &[]) as u8);
783 Self { window_id: v1 }
784 }
785 }
786}
787
788#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
789#[derive(Debug, Clone, PartialEq)]
791pub struct WindowClick<const V: i32> {
792 pub window_id: u8,
794 pub slot: i16,
796 pub mouse_button: i8,
798 pub action: i16,
800 pub mode: i8,
802 pub item: crate::types::slot::legacy::Slot,
804}
805#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
806impl<const V: i32> Decode for WindowClick<V> {
807 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
808 Ok({
809 let v1 = r.read_u8()?;
810 let v2 = r.read_i16()?;
811 let v3 = r.read_i8()?;
812 let v4 = r.read_i16()?;
813 let v5 = r.read_i8()?;
814 let v6 = <crate::types::slot::legacy::Slot as Decode>::decode(r)?;
815 Self {
816 window_id: v1,
817 slot: v2,
818 mouse_button: v3,
819 action: v4,
820 mode: v5,
821 item: v6,
822 }
823 })
824 }
825}
826#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
827impl<const V: i32> Encode for WindowClick<V> {
828 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
829 w.put_u8((*self).window_id);
830 w.put_i16((*self).slot);
831 w.put_i8((*self).mouse_button);
832 w.put_i16((*self).action);
833 w.put_i8((*self).mode);
834 (*self).item.encode(w)?;
835 Ok(())
836 }
837}
838#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
839#[cfg(feature = "testgen")]
840impl<const V: i32> Generate for WindowClick<V> {
841 fn generate(g: &mut Gen) -> Self {
842 {
843 let v1 = (g.int_in(0, 255, &[]) as u8);
844 let v2 = (g.int_in(-32768, 32767, &[]) as i16);
845 let v3 = (g.int_in(-128, 127, &[]) as i8);
846 let v4 = (g.int_in(-32768, 32767, &[]) as i16);
847 let v5 = (g.int_in(-128, 127, &[]) as i8);
848 let v6 = <crate::types::slot::legacy::Slot as Generate>::generate(g);
849 Self {
850 window_id: v1,
851 slot: v2,
852 mouse_button: v3,
853 action: v4,
854 mode: v5,
855 item: v6,
856 }
857 }
858 }
859}
860
861#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
862#[derive(Debug, Clone, PartialEq)]
864pub struct Transaction<const V: i32> {
865 pub window_id: i8,
867 pub action: i16,
869 pub accepted: bool,
871}
872#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
873impl<const V: i32> Decode for Transaction<V> {
874 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
875 Ok({
876 let v1 = r.read_i8()?;
877 let v2 = r.read_i16()?;
878 let v3 = r.read_bool()?;
879 Self {
880 window_id: v1,
881 action: v2,
882 accepted: v3,
883 }
884 })
885 }
886}
887#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
888impl<const V: i32> Encode for Transaction<V> {
889 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
890 w.put_i8((*self).window_id);
891 w.put_i16((*self).action);
892 w.put_bool((*self).accepted);
893 Ok(())
894 }
895}
896#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
897#[cfg(feature = "testgen")]
898impl<const V: i32> Generate for Transaction<V> {
899 fn generate(g: &mut Gen) -> Self {
900 {
901 let v1 = (g.int_in(-128, 127, &[]) as i8);
902 let v2 = (g.int_in(-32768, 32767, &[]) as i16);
903 let v3 = g.bool();
904 Self {
905 window_id: v1,
906 action: v2,
907 accepted: v3,
908 }
909 }
910 }
911}
912
913#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
914#[derive(Debug, Clone, PartialEq)]
916pub struct SetCreativeSlot<const V: i32> {
917 pub slot: i16,
919 pub item: crate::types::slot::legacy::Slot,
921}
922#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
923impl<const V: i32> Decode for SetCreativeSlot<V> {
924 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
925 Ok({
926 let v1 = r.read_i16()?;
927 let v2 = <crate::types::slot::legacy::Slot as Decode>::decode(r)?;
928 Self { slot: v1, item: v2 }
929 })
930 }
931}
932#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
933impl<const V: i32> Encode for SetCreativeSlot<V> {
934 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
935 w.put_i16((*self).slot);
936 (*self).item.encode(w)?;
937 Ok(())
938 }
939}
940#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
941#[cfg(feature = "testgen")]
942impl<const V: i32> Generate for SetCreativeSlot<V> {
943 fn generate(g: &mut Gen) -> Self {
944 {
945 let v1 = (g.int_in(-32768, 32767, &[]) as i16);
946 let v2 = <crate::types::slot::legacy::Slot as Generate>::generate(g);
947 Self { slot: v1, item: v2 }
948 }
949 }
950}
951
952#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
953#[derive(Debug, Clone, PartialEq)]
955pub struct EnchantItem<const V: i32> {
956 pub window_id: i8,
958 pub enchantment: i8,
960}
961#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
962impl<const V: i32> Decode for EnchantItem<V> {
963 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
964 Ok({
965 let v1 = r.read_i8()?;
966 let v2 = r.read_i8()?;
967 Self {
968 window_id: v1,
969 enchantment: v2,
970 }
971 })
972 }
973}
974#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
975impl<const V: i32> Encode for EnchantItem<V> {
976 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
977 w.put_i8((*self).window_id);
978 w.put_i8((*self).enchantment);
979 Ok(())
980 }
981}
982#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
983#[cfg(feature = "testgen")]
984impl<const V: i32> Generate for EnchantItem<V> {
985 fn generate(g: &mut Gen) -> Self {
986 {
987 let v1 = (g.int_in(-128, 127, &[]) as i8);
988 let v2 = (g.int_in(-128, 127, &[]) as i8);
989 Self {
990 window_id: v1,
991 enchantment: v2,
992 }
993 }
994 }
995}
996
997#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
998#[derive(Debug, Clone, PartialEq)]
1000pub struct UpdateSign<const V: i32> {
1001 pub location: BlockPos,
1003 pub text1: ByteString,
1005 pub text2: ByteString,
1007 pub text3: ByteString,
1009 pub text4: ByteString,
1011}
1012#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
1013impl<const V: i32> Decode for UpdateSign<V> {
1014 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1015 Ok({
1016 let v1 = BlockPos::read(r, PositionLayout::Xyz)?;
1017 let v2 = r.read_string()?;
1018 let v3 = r.read_string()?;
1019 let v4 = r.read_string()?;
1020 let v5 = r.read_string()?;
1021 Self {
1022 location: v1,
1023 text1: v2,
1024 text2: v3,
1025 text3: v4,
1026 text4: v5,
1027 }
1028 })
1029 }
1030}
1031#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
1032impl<const V: i32> Encode for UpdateSign<V> {
1033 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1034 (*self).location.write(w, PositionLayout::Xyz)?;
1035 w.put_string(&(*self).text1)?;
1036 w.put_string(&(*self).text2)?;
1037 w.put_string(&(*self).text3)?;
1038 w.put_string(&(*self).text4)?;
1039 Ok(())
1040 }
1041}
1042#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
1043#[cfg(feature = "testgen")]
1044impl<const V: i32> Generate for UpdateSign<V> {
1045 fn generate(g: &mut Gen) -> Self {
1046 {
1047 let v1 = g.position();
1048 let v2 = g.string();
1049 let v3 = g.string();
1050 let v4 = g.string();
1051 let v5 = g.string();
1052 Self {
1053 location: v1,
1054 text1: v2,
1055 text2: v3,
1056 text3: v4,
1057 text4: v5,
1058 }
1059 }
1060 }
1061}
1062
1063#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
1064#[derive(Debug, Clone, PartialEq)]
1066pub struct Abilities<const V: i32> {
1067 pub flags: i8,
1069 pub flying_speed: f32,
1071 pub walking_speed: f32,
1073}
1074#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
1075impl<const V: i32> Decode for Abilities<V> {
1076 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1077 Ok({
1078 let v1 = r.read_i8()?;
1079 let v2 = r.read_f32()?;
1080 let v3 = r.read_f32()?;
1081 Self {
1082 flags: v1,
1083 flying_speed: v2,
1084 walking_speed: v3,
1085 }
1086 })
1087 }
1088}
1089#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
1090impl<const V: i32> Encode for Abilities<V> {
1091 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1092 w.put_i8((*self).flags);
1093 w.put_f32((*self).flying_speed);
1094 w.put_f32((*self).walking_speed);
1095 Ok(())
1096 }
1097}
1098#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
1099#[cfg(feature = "testgen")]
1100impl<const V: i32> Generate for Abilities<V> {
1101 fn generate(g: &mut Gen) -> Self {
1102 {
1103 let v1 = (g.int_in(-128, 127, &[]) as i8);
1104 let v2 = g.f32();
1105 let v3 = g.f32();
1106 Self {
1107 flags: v1,
1108 flying_speed: v2,
1109 walking_speed: v3,
1110 }
1111 }
1112 }
1113}
1114
1115#[cfg(feature = "v1_8")]
1116#[derive(Debug, Clone, PartialEq)]
1118pub struct TabComplete<const V: i32> {
1119 pub text: ByteString,
1121 pub block: Option<BlockPos>,
1123}
1124#[cfg(feature = "v1_8")]
1125impl<const V: i32> Decode for TabComplete<V> {
1126 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1127 Ok({
1128 let v1 = r.read_string()?;
1129 let v2 = if r.read_bool()? {
1130 Some(BlockPos::read(r, PositionLayout::Xyz)?)
1131 } else {
1132 None
1133 };
1134 Self {
1135 text: v1,
1136 block: v2,
1137 }
1138 })
1139 }
1140}
1141#[cfg(feature = "v1_8")]
1142impl<const V: i32> Encode for TabComplete<V> {
1143 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1144 w.put_string(&(*self).text)?;
1145 match &(*self).block {
1146 Some(v1) => {
1147 w.put_u8(1);
1148 (*v1).write(w, PositionLayout::Xyz)?;
1149 }
1150 None => w.put_u8(0),
1151 }
1152 Ok(())
1153 }
1154}
1155#[cfg(feature = "v1_8")]
1156#[cfg(feature = "testgen")]
1157impl<const V: i32> Generate for TabComplete<V> {
1158 fn generate(g: &mut Gen) -> Self {
1159 {
1160 let v1 = g.string();
1161 let v2 = if g.bool() { Some(g.position()) } else { None };
1162 Self {
1163 text: v1,
1164 block: v2,
1165 }
1166 }
1167 }
1168}
1169
1170#[cfg(feature = "v1_8")]
1171#[derive(Debug, Clone, PartialEq)]
1173pub struct Settings<const V: i32> {
1174 pub locale: ByteString,
1176 pub view_distance: i8,
1178 pub chat_flags: i8,
1180 pub chat_colors: bool,
1182 pub skin_parts: u8,
1184}
1185#[cfg(feature = "v1_8")]
1186impl<const V: i32> Decode for Settings<V> {
1187 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1188 Ok({
1189 let v1 = r.read_string()?;
1190 let v2 = r.read_i8()?;
1191 let v3 = r.read_i8()?;
1192 let v4 = r.read_bool()?;
1193 let v5 = r.read_u8()?;
1194 Self {
1195 locale: v1,
1196 view_distance: v2,
1197 chat_flags: v3,
1198 chat_colors: v4,
1199 skin_parts: v5,
1200 }
1201 })
1202 }
1203}
1204#[cfg(feature = "v1_8")]
1205impl<const V: i32> Encode for Settings<V> {
1206 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1207 w.put_string(&(*self).locale)?;
1208 w.put_i8((*self).view_distance);
1209 w.put_i8((*self).chat_flags);
1210 w.put_bool((*self).chat_colors);
1211 w.put_u8((*self).skin_parts);
1212 Ok(())
1213 }
1214}
1215#[cfg(feature = "v1_8")]
1216#[cfg(feature = "testgen")]
1217impl<const V: i32> Generate for Settings<V> {
1218 fn generate(g: &mut Gen) -> Self {
1219 {
1220 let v1 = g.string();
1221 let v2 = (g.int_in(-128, 127, &[]) as i8);
1222 let v3 = (g.int_in(-128, 127, &[]) as i8);
1223 let v4 = g.bool();
1224 let v5 = (g.int_in(0, 255, &[]) as u8);
1225 Self {
1226 locale: v1,
1227 view_distance: v2,
1228 chat_flags: v3,
1229 chat_colors: v4,
1230 skin_parts: v5,
1231 }
1232 }
1233 }
1234}
1235
1236#[cfg(feature = "v1_8")]
1237#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
1239pub struct ClientCommandPayload(pub i32);
1240#[cfg(feature = "v1_8")]
1241impl ClientCommandPayload {
1242 pub const PERFORM_RESPAWN: Self = Self(0);
1244 pub const REQUEST_STATS: Self = Self(1);
1246 pub const OPEN_INVENTORY_ACHIEVEMENT: Self = Self(2);
1248 pub const fn name(self) -> Option<&'static str> {
1250 match self.0 {
1251 0 => Some("perform_respawn"),
1252 1 => Some("request_stats"),
1253 2 => Some("open_inventory_achievement"),
1254 _ => None,
1255 }
1256 }
1257}
1258#[cfg(feature = "v1_8")]
1259impl std::fmt::Debug for ClientCommandPayload {
1260 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1261 match self.name() {
1262 Some(n) => write!(f, "ClientCommandPayload::{n}"),
1263 None => write!(f, "ClientCommandPayload({})", self.0),
1264 }
1265 }
1266}
1267
1268#[cfg(feature = "v1_8")]
1269#[derive(Debug, Clone, PartialEq)]
1271pub struct ClientCommand<const V: i32> {
1272 pub payload: crate::defs::p47::play::serverbound::ClientCommandPayload,
1274}
1275#[cfg(feature = "v1_8")]
1276impl<const V: i32> Decode for ClientCommand<V> {
1277 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1278 Ok({
1279 let v1 = crate::defs::p47::play::serverbound::ClientCommandPayload(r.read_varint()?);
1280 Self { payload: v1 }
1281 })
1282 }
1283}
1284#[cfg(feature = "v1_8")]
1285impl<const V: i32> Encode for ClientCommand<V> {
1286 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1287 w.put_varint((*self).payload.0);
1288 Ok(())
1289 }
1290}
1291#[cfg(feature = "v1_8")]
1292#[cfg(feature = "testgen")]
1293impl<const V: i32> Generate for ClientCommand<V> {
1294 fn generate(g: &mut Gen) -> Self {
1295 {
1296 let v1 = crate::defs::p47::play::serverbound::ClientCommandPayload(g.int_in(
1297 -2147483648,
1298 2147483647,
1299 &[0, 1, 2],
1300 )
1301 as i32);
1302 Self { payload: v1 }
1303 }
1304 }
1305}
1306
1307#[cfg(any(
1308 feature = "v1_8",
1309 feature = "v1_12_2",
1310 feature = "v1_16_5",
1311 feature = "v26_1"
1312))]
1313#[derive(Debug, Clone, PartialEq)]
1315pub struct CustomPayload<const V: i32> {
1316 pub channel: ByteString,
1318 pub data: Bytes,
1320}
1321#[cfg(any(
1322 feature = "v1_8",
1323 feature = "v1_12_2",
1324 feature = "v1_16_5",
1325 feature = "v26_1"
1326))]
1327impl<const V: i32> Decode for CustomPayload<V> {
1328 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1329 Ok({
1330 let v1 = r.read_string()?;
1331 let v2 = r.read_rest();
1332 Self {
1333 channel: v1,
1334 data: v2,
1335 }
1336 })
1337 }
1338}
1339#[cfg(any(
1340 feature = "v1_8",
1341 feature = "v1_12_2",
1342 feature = "v1_16_5",
1343 feature = "v26_1"
1344))]
1345impl<const V: i32> Encode for CustomPayload<V> {
1346 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1347 w.put_string(&(*self).channel)?;
1348 w.put_slice(&(*self).data);
1349 Ok(())
1350 }
1351}
1352#[cfg(any(
1353 feature = "v1_8",
1354 feature = "v1_12_2",
1355 feature = "v1_16_5",
1356 feature = "v26_1"
1357))]
1358#[cfg(feature = "testgen")]
1359impl<const V: i32> Generate for CustomPayload<V> {
1360 fn generate(g: &mut Gen) -> Self {
1361 {
1362 let v1 = g.string();
1363 let v2 = g.bytes();
1364 Self {
1365 channel: v1,
1366 data: v2,
1367 }
1368 }
1369 }
1370}
1371
1372#[cfg(any(
1373 feature = "v1_8",
1374 feature = "v1_12_2",
1375 feature = "v1_16_5",
1376 feature = "v26_1"
1377))]
1378#[derive(Debug, Clone, PartialEq)]
1380pub struct Spectate<const V: i32> {
1381 pub target: Uuid,
1383}
1384#[cfg(any(
1385 feature = "v1_8",
1386 feature = "v1_12_2",
1387 feature = "v1_16_5",
1388 feature = "v26_1"
1389))]
1390impl<const V: i32> Decode for Spectate<V> {
1391 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1392 Ok({
1393 let v1 = r.read_uuid()?;
1394 Self { target: v1 }
1395 })
1396 }
1397}
1398#[cfg(any(
1399 feature = "v1_8",
1400 feature = "v1_12_2",
1401 feature = "v1_16_5",
1402 feature = "v26_1"
1403))]
1404impl<const V: i32> Encode for Spectate<V> {
1405 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1406 w.put_uuid(&(*self).target);
1407 Ok(())
1408 }
1409}
1410#[cfg(any(
1411 feature = "v1_8",
1412 feature = "v1_12_2",
1413 feature = "v1_16_5",
1414 feature = "v26_1"
1415))]
1416#[cfg(feature = "testgen")]
1417impl<const V: i32> Generate for Spectate<V> {
1418 fn generate(g: &mut Gen) -> Self {
1419 {
1420 let v1 = g.uuid();
1421 Self { target: v1 }
1422 }
1423 }
1424}
1425
1426#[cfg(feature = "v1_8")]
1427#[derive(Debug, Clone, PartialEq)]
1429pub struct ResourcePackReceive<const V: i32> {
1430 pub hash: ByteString,
1432 pub result: i32,
1434}
1435#[cfg(feature = "v1_8")]
1436impl<const V: i32> Decode for ResourcePackReceive<V> {
1437 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1438 Ok({
1439 let v1 = r.read_string()?;
1440 let v2 = r.read_varint()?;
1441 Self {
1442 hash: v1,
1443 result: v2,
1444 }
1445 })
1446 }
1447}
1448#[cfg(feature = "v1_8")]
1449impl<const V: i32> Encode for ResourcePackReceive<V> {
1450 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1451 w.put_string(&(*self).hash)?;
1452 w.put_varint((*self).result);
1453 Ok(())
1454 }
1455}
1456#[cfg(feature = "v1_8")]
1457#[cfg(feature = "testgen")]
1458impl<const V: i32> Generate for ResourcePackReceive<V> {
1459 fn generate(g: &mut Gen) -> Self {
1460 {
1461 let v1 = g.string();
1462 let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1463 Self {
1464 hash: v1,
1465 result: v2,
1466 }
1467 }
1468 }
1469}