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_12_2")]
29#[derive(Debug, Clone, PartialEq)]
31pub struct SpawnEntity<const V: i32> {
32 pub entity_id: i32,
34 pub object_uuid: Uuid,
36 pub r#type: i8,
38 pub x: f64,
40 pub y: f64,
42 pub z: f64,
44 pub pitch: i8,
46 pub yaw: i8,
48 pub object_data: i32,
50 pub velocity: crate::defs::p47::types::Vec3i16,
52}
53#[cfg(feature = "v1_12_2")]
54impl<const V: i32> Decode for SpawnEntity<V> {
55 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
56 Ok({
57 let v1 = r.read_varint()?;
58 let v2 = r.read_uuid()?;
59 let v3 = r.read_i8()?;
60 let v4 = r.read_f64()?;
61 let v5 = r.read_f64()?;
62 let v6 = r.read_f64()?;
63 let v7 = r.read_i8()?;
64 let v8 = r.read_i8()?;
65 let v9 = r.read_i32()?;
66 let v10 = <crate::defs::p47::types::Vec3i16 as Decode>::decode(r)?;
67 Self {
68 entity_id: v1,
69 object_uuid: v2,
70 r#type: v3,
71 x: v4,
72 y: v5,
73 z: v6,
74 pitch: v7,
75 yaw: v8,
76 object_data: v9,
77 velocity: v10,
78 }
79 })
80 }
81}
82#[cfg(feature = "v1_12_2")]
83impl<const V: i32> Encode for SpawnEntity<V> {
84 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
85 w.put_varint((*self).entity_id);
86 w.put_uuid(&(*self).object_uuid);
87 w.put_i8((*self).r#type);
88 w.put_f64((*self).x);
89 w.put_f64((*self).y);
90 w.put_f64((*self).z);
91 w.put_i8((*self).pitch);
92 w.put_i8((*self).yaw);
93 w.put_i32((*self).object_data);
94 (*self).velocity.encode(w)?;
95 Ok(())
96 }
97}
98#[cfg(feature = "v1_12_2")]
99#[cfg(feature = "testgen")]
100impl<const V: i32> Generate for SpawnEntity<V> {
101 fn generate(g: &mut Gen) -> Self {
102 {
103 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
104 let v2 = g.uuid();
105 let v3 = (g.int_in(-128, 127, &[]) as i8);
106 let v4 = g.f64();
107 let v5 = g.f64();
108 let v6 = g.f64();
109 let v7 = (g.int_in(-128, 127, &[]) as i8);
110 let v8 = (g.int_in(-128, 127, &[]) as i8);
111 let v9 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
112 let v10 = <crate::defs::p47::types::Vec3i16 as Generate>::generate(g);
113 Self {
114 entity_id: v1,
115 object_uuid: v2,
116 r#type: v3,
117 x: v4,
118 y: v5,
119 z: v6,
120 pitch: v7,
121 yaw: v8,
122 object_data: v9,
123 velocity: v10,
124 }
125 }
126 }
127}
128
129#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
130#[derive(Debug, Clone, PartialEq)]
132pub struct SpawnEntityExperienceOrb<const V: i32> {
133 pub entity_id: i32,
135 pub x: f64,
137 pub y: f64,
139 pub z: f64,
141 pub count: i16,
143}
144#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
145impl<const V: i32> Decode for SpawnEntityExperienceOrb<V> {
146 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
147 Ok({
148 let v1 = r.read_varint()?;
149 let v2 = r.read_f64()?;
150 let v3 = r.read_f64()?;
151 let v4 = r.read_f64()?;
152 let v5 = r.read_i16()?;
153 Self {
154 entity_id: v1,
155 x: v2,
156 y: v3,
157 z: v4,
158 count: v5,
159 }
160 })
161 }
162}
163#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
164impl<const V: i32> Encode for SpawnEntityExperienceOrb<V> {
165 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
166 w.put_varint((*self).entity_id);
167 w.put_f64((*self).x);
168 w.put_f64((*self).y);
169 w.put_f64((*self).z);
170 w.put_i16((*self).count);
171 Ok(())
172 }
173}
174#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
175#[cfg(feature = "testgen")]
176impl<const V: i32> Generate for SpawnEntityExperienceOrb<V> {
177 fn generate(g: &mut Gen) -> Self {
178 {
179 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
180 let v2 = g.f64();
181 let v3 = g.f64();
182 let v4 = g.f64();
183 let v5 = (g.int_in(-32768, 32767, &[]) as i16);
184 Self {
185 entity_id: v1,
186 x: v2,
187 y: v3,
188 z: v4,
189 count: v5,
190 }
191 }
192 }
193}
194
195#[cfg(feature = "v1_12_2")]
196#[derive(Debug, Clone, PartialEq)]
198pub struct SpawnEntityWeather<const V: i32> {
199 pub entity_id: i32,
201 pub r#type: i8,
203 pub x: f64,
205 pub y: f64,
207 pub z: f64,
209}
210#[cfg(feature = "v1_12_2")]
211impl<const V: i32> Decode for SpawnEntityWeather<V> {
212 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
213 Ok({
214 let v1 = r.read_varint()?;
215 let v2 = r.read_i8()?;
216 let v3 = r.read_f64()?;
217 let v4 = r.read_f64()?;
218 let v5 = r.read_f64()?;
219 Self {
220 entity_id: v1,
221 r#type: v2,
222 x: v3,
223 y: v4,
224 z: v5,
225 }
226 })
227 }
228}
229#[cfg(feature = "v1_12_2")]
230impl<const V: i32> Encode for SpawnEntityWeather<V> {
231 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
232 w.put_varint((*self).entity_id);
233 w.put_i8((*self).r#type);
234 w.put_f64((*self).x);
235 w.put_f64((*self).y);
236 w.put_f64((*self).z);
237 Ok(())
238 }
239}
240#[cfg(feature = "v1_12_2")]
241#[cfg(feature = "testgen")]
242impl<const V: i32> Generate for SpawnEntityWeather<V> {
243 fn generate(g: &mut Gen) -> Self {
244 {
245 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
246 let v2 = (g.int_in(-128, 127, &[]) as i8);
247 let v3 = g.f64();
248 let v4 = g.f64();
249 let v5 = g.f64();
250 Self {
251 entity_id: v1,
252 r#type: v2,
253 x: v3,
254 y: v4,
255 z: v5,
256 }
257 }
258 }
259}
260
261#[cfg(feature = "v1_12_2")]
262#[derive(Debug, Clone, PartialEq)]
264pub struct SpawnEntityLiving<const V: i32> {
265 pub entity_id: i32,
267 pub entity_uuid: Uuid,
269 pub r#type: i32,
271 pub x: f64,
273 pub y: f64,
275 pub z: f64,
277 pub yaw: i8,
279 pub pitch: i8,
281 pub head_pitch: i8,
283 pub velocity: crate::defs::p47::types::Vec3i16,
285 pub metadata: Vec<crate::defs::p340::types::EntityMetadataEntry>,
287}
288#[cfg(feature = "v1_12_2")]
289impl<const V: i32> Decode for SpawnEntityLiving<V> {
290 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
291 Ok({
292 let v1 = r.read_varint()?;
293 let v2 = r.read_uuid()?;
294 let v3 = r.read_varint()?;
295 let v4 = r.read_f64()?;
296 let v5 = r.read_f64()?;
297 let v6 = r.read_f64()?;
298 let v7 = r.read_i8()?;
299 let v8 = r.read_i8()?;
300 let v9 = r.read_i8()?;
301 let v10 = <crate::defs::p47::types::Vec3i16 as Decode>::decode(r)?;
302 let v11 = {
303 let mut v12 = Vec::new();
304 loop {
305 if r.peek_u8()? == 255 {
306 r.skip(1)?;
307 break;
308 }
309 v12.push({
310 let v13 = r.read_u8()?;
311 let v14 = r.read_i8()?;
312 let v15 = (if (v14 == 0) {
313 crate::defs::p340::types::EntityMetadataValue::Byte(r.read_i8()?)
314 } else if (v14 == 1) {
315 crate::defs::p340::types::EntityMetadataValue::VarInt(r.read_varint()?)
316 } else if (v14 == 2) {
317 crate::defs::p340::types::EntityMetadataValue::Float(r.read_f32()?)
318 } else if (v14 == 3) {
319 crate::defs::p340::types::EntityMetadataValue::String(r.read_string()?)
320 } else if (v14 == 4) {
321 crate::defs::p340::types::EntityMetadataValue::Chat(r.read_string()?)
322 } else if (v14 == 5) {
323 crate::defs::p340::types::EntityMetadataValue::Slot(
324 <crate::types::slot::legacy::Slot as Decode>::decode(r)?,
325 )
326 } else if (v14 == 6) {
327 crate::defs::p340::types::EntityMetadataValue::Boolean(r.read_bool()?)
328 } else if (v14 == 7) {
329 crate::defs::p340::types::EntityMetadataValue::Rotation({
330 let v16 = r.read_f32()?;
331 let v17 = r.read_f32()?;
332 let v18 = r.read_f32()?;
333 crate::defs::p47::types::EntityMetadataValueRotation {
334 pitch: v16,
335 yaw: v17,
336 roll: v18,
337 }
338 })
339 } else if (v14 == 8) {
340 crate::defs::p340::types::EntityMetadataValue::Position(BlockPos::read(
341 r,
342 PositionLayout::Xyz,
343 )?)
344 } else if (v14 == 9) {
345 crate::defs::p340::types::EntityMetadataValue::OptPosition(
346 if r.read_bool()? {
347 Some(BlockPos::read(r, PositionLayout::Xyz)?)
348 } else {
349 None
350 },
351 )
352 } else if (v14 == 10) {
353 crate::defs::p340::types::EntityMetadataValue::Direction(
354 r.read_varint()?,
355 )
356 } else if (v14 == 11) {
357 crate::defs::p340::types::EntityMetadataValue::OptUuid(
358 if r.read_bool()? {
359 Some(r.read_uuid()?)
360 } else {
361 None
362 },
363 )
364 } else if (v14 == 12) {
365 crate::defs::p340::types::EntityMetadataValue::BlockState(
366 r.read_varint()?,
367 )
368 } else if (v14 == 13) {
369 crate::defs::p340::types::EntityMetadataValue::Nbt(RawNbt::read(r)?)
370 } else {
371 crate::defs::p340::types::EntityMetadataValue::Other
372 });
373 crate::defs::p340::types::EntityMetadataEntry {
374 key: v13,
375 r#type: v14,
376 value: v15,
377 }
378 });
379 }
380 v12
381 };
382 Self {
383 entity_id: v1,
384 entity_uuid: v2,
385 r#type: v3,
386 x: v4,
387 y: v5,
388 z: v6,
389 yaw: v7,
390 pitch: v8,
391 head_pitch: v9,
392 velocity: v10,
393 metadata: v11,
394 }
395 })
396 }
397}
398#[cfg(feature = "v1_12_2")]
399impl<const V: i32> Encode for SpawnEntityLiving<V> {
400 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
401 w.put_varint((*self).entity_id);
402 w.put_uuid(&(*self).entity_uuid);
403 w.put_varint((*self).r#type);
404 w.put_f64((*self).x);
405 w.put_f64((*self).y);
406 w.put_f64((*self).z);
407 w.put_i8((*self).yaw);
408 w.put_i8((*self).pitch);
409 w.put_i8((*self).head_pitch);
410 (*self).velocity.encode(w)?;
411 for v1 in (*self).metadata.iter() {
412 let v2 = w.len();
413 w.put_u8((*v1).key);
414 w.put_i8((*v1).r#type);
415 match &(*v1).value {
416 crate::defs::p340::types::EntityMetadataValue::Byte(v3) => {
417 if !((*v1).r#type == 0) {
418 return Err(EncodeError::SwitchMismatch(
419 "play.clientbound.spawn_entity_living.metadata.value",
420 ));
421 }
422 w.put_i8((*v3));
423 }
424 crate::defs::p340::types::EntityMetadataValue::VarInt(v4) => {
425 if !((*v1).r#type == 1) {
426 return Err(EncodeError::SwitchMismatch(
427 "play.clientbound.spawn_entity_living.metadata.value",
428 ));
429 }
430 w.put_varint((*v4));
431 }
432 crate::defs::p340::types::EntityMetadataValue::Float(v5) => {
433 if !((*v1).r#type == 2) {
434 return Err(EncodeError::SwitchMismatch(
435 "play.clientbound.spawn_entity_living.metadata.value",
436 ));
437 }
438 w.put_f32((*v5));
439 }
440 crate::defs::p340::types::EntityMetadataValue::String(v6) => {
441 if !((*v1).r#type == 3) {
442 return Err(EncodeError::SwitchMismatch(
443 "play.clientbound.spawn_entity_living.metadata.value",
444 ));
445 }
446 w.put_string(&(*v6))?;
447 }
448 crate::defs::p340::types::EntityMetadataValue::Chat(v7) => {
449 if !((*v1).r#type == 4) {
450 return Err(EncodeError::SwitchMismatch(
451 "play.clientbound.spawn_entity_living.metadata.value",
452 ));
453 }
454 w.put_string(&(*v7))?;
455 }
456 crate::defs::p340::types::EntityMetadataValue::Slot(v8) => {
457 if !((*v1).r#type == 5) {
458 return Err(EncodeError::SwitchMismatch(
459 "play.clientbound.spawn_entity_living.metadata.value",
460 ));
461 }
462 (*v8).encode(w)?;
463 }
464 crate::defs::p340::types::EntityMetadataValue::Boolean(v9) => {
465 if !((*v1).r#type == 6) {
466 return Err(EncodeError::SwitchMismatch(
467 "play.clientbound.spawn_entity_living.metadata.value",
468 ));
469 }
470 w.put_bool((*v9));
471 }
472 crate::defs::p340::types::EntityMetadataValue::Rotation(v10) => {
473 if !((*v1).r#type == 7) {
474 return Err(EncodeError::SwitchMismatch(
475 "play.clientbound.spawn_entity_living.metadata.value",
476 ));
477 }
478 w.put_f32((*v10).pitch);
479 w.put_f32((*v10).yaw);
480 w.put_f32((*v10).roll);
481 }
482 crate::defs::p340::types::EntityMetadataValue::Position(v11) => {
483 if !((*v1).r#type == 8) {
484 return Err(EncodeError::SwitchMismatch(
485 "play.clientbound.spawn_entity_living.metadata.value",
486 ));
487 }
488 (*v11).write(w, PositionLayout::Xyz)?;
489 }
490 crate::defs::p340::types::EntityMetadataValue::OptPosition(v12) => {
491 if !((*v1).r#type == 9) {
492 return Err(EncodeError::SwitchMismatch(
493 "play.clientbound.spawn_entity_living.metadata.value",
494 ));
495 }
496 match &(*v12) {
497 Some(v13) => {
498 w.put_u8(1);
499 (*v13).write(w, PositionLayout::Xyz)?;
500 }
501 None => w.put_u8(0),
502 }
503 }
504 crate::defs::p340::types::EntityMetadataValue::Direction(v14) => {
505 if !((*v1).r#type == 10) {
506 return Err(EncodeError::SwitchMismatch(
507 "play.clientbound.spawn_entity_living.metadata.value",
508 ));
509 }
510 w.put_varint((*v14));
511 }
512 crate::defs::p340::types::EntityMetadataValue::OptUuid(v15) => {
513 if !((*v1).r#type == 11) {
514 return Err(EncodeError::SwitchMismatch(
515 "play.clientbound.spawn_entity_living.metadata.value",
516 ));
517 }
518 match &(*v15) {
519 Some(v16) => {
520 w.put_u8(1);
521 w.put_uuid(&(*v16));
522 }
523 None => w.put_u8(0),
524 }
525 }
526 crate::defs::p340::types::EntityMetadataValue::BlockState(v17) => {
527 if !((*v1).r#type == 12) {
528 return Err(EncodeError::SwitchMismatch(
529 "play.clientbound.spawn_entity_living.metadata.value",
530 ));
531 }
532 w.put_varint((*v17));
533 }
534 crate::defs::p340::types::EntityMetadataValue::Nbt(v18) => {
535 if !((*v1).r#type == 13) {
536 return Err(EncodeError::SwitchMismatch(
537 "play.clientbound.spawn_entity_living.metadata.value",
538 ));
539 }
540 (*v18).write(w);
541 }
542 crate::defs::p340::types::EntityMetadataValue::Other => {
543 if !(!(((*v1).r#type == 0)
544 || ((*v1).r#type == 1)
545 || ((*v1).r#type == 2)
546 || ((*v1).r#type == 3)
547 || ((*v1).r#type == 4)
548 || ((*v1).r#type == 5)
549 || ((*v1).r#type == 6)
550 || ((*v1).r#type == 7)
551 || ((*v1).r#type == 8)
552 || ((*v1).r#type == 9)
553 || ((*v1).r#type == 10)
554 || ((*v1).r#type == 11)
555 || ((*v1).r#type == 12)
556 || ((*v1).r#type == 13)))
557 {
558 return Err(EncodeError::SwitchMismatch(
559 "play.clientbound.spawn_entity_living.metadata.value",
560 ));
561 }
562 }
563 }
564 if w.get(v2) == Some(&255) {
565 return Err(EncodeError::OutOfRange(
566 "play.clientbound.spawn_entity_living.metadata",
567 ));
568 }
569 }
570 w.put_u8(255);
571 Ok(())
572 }
573}
574#[cfg(feature = "v1_12_2")]
575#[cfg(feature = "testgen")]
576impl<const V: i32> Generate for SpawnEntityLiving<V> {
577 fn generate(g: &mut Gen) -> Self {
578 {
579 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
580 let v2 = g.uuid();
581 let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
582 let v4 = g.f64();
583 let v5 = g.f64();
584 let v6 = g.f64();
585 let v7 = (g.int_in(-128, 127, &[]) as i8);
586 let v8 = (g.int_in(-128, 127, &[]) as i8);
587 let v9 = (g.int_in(-128, 127, &[]) as i8);
588 let v10 = <crate::defs::p47::types::Vec3i16 as Generate>::generate(g);
589 let v11 = {
590 let n = g.count();
591 let mut v12 = Vec::with_capacity(n);
592 for _ in 0..n {
593 v12.push(loop { let v13 = { let v14 = (g.int_in(0, 255, &[]) as u8);let v15 = (g.int_in(-128, 127, &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) as i8);let v16 = (if (v15 == 0) { crate::defs::p340::types::EntityMetadataValue::Byte((g.int_in(-128, 127, &[]) as i8)) } else if (v15 == 1) { crate::defs::p340::types::EntityMetadataValue::VarInt((g.int_in(-2147483648, 2147483647, &[]) as i32)) } else if (v15 == 2) { crate::defs::p340::types::EntityMetadataValue::Float(g.f32()) } else if (v15 == 3) { crate::defs::p340::types::EntityMetadataValue::String(g.string()) } else if (v15 == 4) { crate::defs::p340::types::EntityMetadataValue::Chat(g.string()) } else if (v15 == 5) { crate::defs::p340::types::EntityMetadataValue::Slot(<crate::types::slot::legacy::Slot as Generate>::generate(g)) } else if (v15 == 6) { crate::defs::p340::types::EntityMetadataValue::Boolean(g.bool()) } else if (v15 == 7) { crate::defs::p340::types::EntityMetadataValue::Rotation({ let v17 = g.f32();let v18 = g.f32();let v19 = g.f32(); crate::defs::p47::types::EntityMetadataValueRotation { pitch: v17, yaw: v18, roll: v19 } }) } else if (v15 == 8) { crate::defs::p340::types::EntityMetadataValue::Position(g.position()) } else if (v15 == 9) { crate::defs::p340::types::EntityMetadataValue::OptPosition(if g.bool() { Some(g.position()) } else { None }) } else if (v15 == 10) { crate::defs::p340::types::EntityMetadataValue::Direction((g.int_in(-2147483648, 2147483647, &[]) as i32)) } else if (v15 == 11) { crate::defs::p340::types::EntityMetadataValue::OptUuid(if g.bool() { Some(g.uuid()) } else { None }) } else if (v15 == 12) { crate::defs::p340::types::EntityMetadataValue::BlockState((g.int_in(-2147483648, 2147483647, &[]) as i32)) } else if (v15 == 13) { crate::defs::p340::types::EntityMetadataValue::Nbt(g.nbt()) } else { crate::defs::p340::types::EntityMetadataValue::Other }); crate::defs::p340::types::EntityMetadataEntry { key: v14, r#type: v15, value: v16 } }; if crate::testgen::first_byte_ok(|w: &mut BytesMut| -> EncodeResult { w.put_u8(v13.key);w.put_i8(v13.r#type);match &v13.value { crate::defs::p340::types::EntityMetadataValue::Byte(v20) => { if !((v13.r#type == 0)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_i8((*v20)); }crate::defs::p340::types::EntityMetadataValue::VarInt(v21) => { if !((v13.r#type == 1)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_varint((*v21)); }crate::defs::p340::types::EntityMetadataValue::Float(v22) => { if !((v13.r#type == 2)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_f32((*v22)); }crate::defs::p340::types::EntityMetadataValue::String(v23) => { if !((v13.r#type == 3)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_string(&(*v23))?; }crate::defs::p340::types::EntityMetadataValue::Chat(v24) => { if !((v13.r#type == 4)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_string(&(*v24))?; }crate::defs::p340::types::EntityMetadataValue::Slot(v25) => { if !((v13.r#type == 5)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } (*v25).encode(w)?; }crate::defs::p340::types::EntityMetadataValue::Boolean(v26) => { if !((v13.r#type == 6)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_bool((*v26)); }crate::defs::p340::types::EntityMetadataValue::Rotation(v27) => { if !((v13.r#type == 7)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_f32((*v27).pitch);w.put_f32((*v27).yaw);w.put_f32((*v27).roll); }crate::defs::p340::types::EntityMetadataValue::Position(v28) => { if !((v13.r#type == 8)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } (*v28).write(w, PositionLayout::Xyz)?; }crate::defs::p340::types::EntityMetadataValue::OptPosition(v29) => { if !((v13.r#type == 9)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } match &(*v29) { Some(v30) => { w.put_u8(1); (*v30).write(w, PositionLayout::Xyz)?; } None => w.put_u8(0), } }crate::defs::p340::types::EntityMetadataValue::Direction(v31) => { if !((v13.r#type == 10)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_varint((*v31)); }crate::defs::p340::types::EntityMetadataValue::OptUuid(v32) => { if !((v13.r#type == 11)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } match &(*v32) { Some(v33) => { w.put_u8(1); w.put_uuid(&(*v33)); } None => w.put_u8(0), } }crate::defs::p340::types::EntityMetadataValue::BlockState(v34) => { if !((v13.r#type == 12)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_varint((*v34)); }crate::defs::p340::types::EntityMetadataValue::Nbt(v35) => { if !((v13.r#type == 13)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } (*v35).write(w); }crate::defs::p340::types::EntityMetadataValue::Other => { if !(!((v13.r#type == 0) || (v13.r#type == 1) || (v13.r#type == 2) || (v13.r#type == 3) || (v13.r#type == 4) || (v13.r#type == 5) || (v13.r#type == 6) || (v13.r#type == 7) || (v13.r#type == 8) || (v13.r#type == 9) || (v13.r#type == 10) || (v13.r#type == 11) || (v13.r#type == 12) || (v13.r#type == 13))) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } } } Ok(()) }, |b| b != 255) { break v13; } });
594 }
595 v12
596 };
597 Self {
598 entity_id: v1,
599 entity_uuid: v2,
600 r#type: v3,
601 x: v4,
602 y: v5,
603 z: v6,
604 yaw: v7,
605 pitch: v8,
606 head_pitch: v9,
607 velocity: v10,
608 metadata: v11,
609 }
610 }
611 }
612}
613
614#[cfg(feature = "v1_12_2")]
615#[derive(Debug, Clone, PartialEq)]
617pub struct SpawnEntityPainting<const V: i32> {
618 pub entity_id: i32,
620 pub entity_uuid: Uuid,
622 pub title: ByteString,
624 pub location: BlockPos,
626 pub direction: u8,
628}
629#[cfg(feature = "v1_12_2")]
630impl<const V: i32> Decode for SpawnEntityPainting<V> {
631 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
632 Ok({
633 let v1 = r.read_varint()?;
634 let v2 = r.read_uuid()?;
635 let v3 = r.read_string()?;
636 let v4 = BlockPos::read(r, PositionLayout::Xyz)?;
637 let v5 = r.read_u8()?;
638 Self {
639 entity_id: v1,
640 entity_uuid: v2,
641 title: v3,
642 location: v4,
643 direction: v5,
644 }
645 })
646 }
647}
648#[cfg(feature = "v1_12_2")]
649impl<const V: i32> Encode for SpawnEntityPainting<V> {
650 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
651 w.put_varint((*self).entity_id);
652 w.put_uuid(&(*self).entity_uuid);
653 w.put_string(&(*self).title)?;
654 (*self).location.write(w, PositionLayout::Xyz)?;
655 w.put_u8((*self).direction);
656 Ok(())
657 }
658}
659#[cfg(feature = "v1_12_2")]
660#[cfg(feature = "testgen")]
661impl<const V: i32> Generate for SpawnEntityPainting<V> {
662 fn generate(g: &mut Gen) -> Self {
663 {
664 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
665 let v2 = g.uuid();
666 let v3 = g.string();
667 let v4 = g.position();
668 let v5 = (g.int_in(0, 255, &[]) as u8);
669 Self {
670 entity_id: v1,
671 entity_uuid: v2,
672 title: v3,
673 location: v4,
674 direction: v5,
675 }
676 }
677 }
678}
679
680#[cfg(feature = "v1_12_2")]
681#[derive(Debug, Clone, PartialEq)]
683pub struct NamedEntitySpawn<const V: i32> {
684 pub entity_id: i32,
686 pub player_uuid: Uuid,
688 pub x: f64,
690 pub y: f64,
692 pub z: f64,
694 pub yaw: i8,
696 pub pitch: i8,
698 pub metadata: Vec<crate::defs::p340::types::EntityMetadataEntry>,
700}
701#[cfg(feature = "v1_12_2")]
702impl<const V: i32> Decode for NamedEntitySpawn<V> {
703 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
704 Ok({
705 let v1 = r.read_varint()?;
706 let v2 = r.read_uuid()?;
707 let v3 = r.read_f64()?;
708 let v4 = r.read_f64()?;
709 let v5 = r.read_f64()?;
710 let v6 = r.read_i8()?;
711 let v7 = r.read_i8()?;
712 let v8 = {
713 let mut v9 = Vec::new();
714 loop {
715 if r.peek_u8()? == 255 {
716 r.skip(1)?;
717 break;
718 }
719 v9.push({
720 let v10 = r.read_u8()?;
721 let v11 = r.read_i8()?;
722 let v12 = (if (v11 == 0) {
723 crate::defs::p340::types::EntityMetadataValue::Byte(r.read_i8()?)
724 } else if (v11 == 1) {
725 crate::defs::p340::types::EntityMetadataValue::VarInt(r.read_varint()?)
726 } else if (v11 == 2) {
727 crate::defs::p340::types::EntityMetadataValue::Float(r.read_f32()?)
728 } else if (v11 == 3) {
729 crate::defs::p340::types::EntityMetadataValue::String(r.read_string()?)
730 } else if (v11 == 4) {
731 crate::defs::p340::types::EntityMetadataValue::Chat(r.read_string()?)
732 } else if (v11 == 5) {
733 crate::defs::p340::types::EntityMetadataValue::Slot(
734 <crate::types::slot::legacy::Slot as Decode>::decode(r)?,
735 )
736 } else if (v11 == 6) {
737 crate::defs::p340::types::EntityMetadataValue::Boolean(r.read_bool()?)
738 } else if (v11 == 7) {
739 crate::defs::p340::types::EntityMetadataValue::Rotation({
740 let v13 = r.read_f32()?;
741 let v14 = r.read_f32()?;
742 let v15 = r.read_f32()?;
743 crate::defs::p47::types::EntityMetadataValueRotation {
744 pitch: v13,
745 yaw: v14,
746 roll: v15,
747 }
748 })
749 } else if (v11 == 8) {
750 crate::defs::p340::types::EntityMetadataValue::Position(BlockPos::read(
751 r,
752 PositionLayout::Xyz,
753 )?)
754 } else if (v11 == 9) {
755 crate::defs::p340::types::EntityMetadataValue::OptPosition(
756 if r.read_bool()? {
757 Some(BlockPos::read(r, PositionLayout::Xyz)?)
758 } else {
759 None
760 },
761 )
762 } else if (v11 == 10) {
763 crate::defs::p340::types::EntityMetadataValue::Direction(
764 r.read_varint()?,
765 )
766 } else if (v11 == 11) {
767 crate::defs::p340::types::EntityMetadataValue::OptUuid(
768 if r.read_bool()? {
769 Some(r.read_uuid()?)
770 } else {
771 None
772 },
773 )
774 } else if (v11 == 12) {
775 crate::defs::p340::types::EntityMetadataValue::BlockState(
776 r.read_varint()?,
777 )
778 } else if (v11 == 13) {
779 crate::defs::p340::types::EntityMetadataValue::Nbt(RawNbt::read(r)?)
780 } else {
781 crate::defs::p340::types::EntityMetadataValue::Other
782 });
783 crate::defs::p340::types::EntityMetadataEntry {
784 key: v10,
785 r#type: v11,
786 value: v12,
787 }
788 });
789 }
790 v9
791 };
792 Self {
793 entity_id: v1,
794 player_uuid: v2,
795 x: v3,
796 y: v4,
797 z: v5,
798 yaw: v6,
799 pitch: v7,
800 metadata: v8,
801 }
802 })
803 }
804}
805#[cfg(feature = "v1_12_2")]
806impl<const V: i32> Encode for NamedEntitySpawn<V> {
807 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
808 w.put_varint((*self).entity_id);
809 w.put_uuid(&(*self).player_uuid);
810 w.put_f64((*self).x);
811 w.put_f64((*self).y);
812 w.put_f64((*self).z);
813 w.put_i8((*self).yaw);
814 w.put_i8((*self).pitch);
815 for v1 in (*self).metadata.iter() {
816 let v2 = w.len();
817 w.put_u8((*v1).key);
818 w.put_i8((*v1).r#type);
819 match &(*v1).value {
820 crate::defs::p340::types::EntityMetadataValue::Byte(v3) => {
821 if !((*v1).r#type == 0) {
822 return Err(EncodeError::SwitchMismatch(
823 "play.clientbound.named_entity_spawn.metadata.value",
824 ));
825 }
826 w.put_i8((*v3));
827 }
828 crate::defs::p340::types::EntityMetadataValue::VarInt(v4) => {
829 if !((*v1).r#type == 1) {
830 return Err(EncodeError::SwitchMismatch(
831 "play.clientbound.named_entity_spawn.metadata.value",
832 ));
833 }
834 w.put_varint((*v4));
835 }
836 crate::defs::p340::types::EntityMetadataValue::Float(v5) => {
837 if !((*v1).r#type == 2) {
838 return Err(EncodeError::SwitchMismatch(
839 "play.clientbound.named_entity_spawn.metadata.value",
840 ));
841 }
842 w.put_f32((*v5));
843 }
844 crate::defs::p340::types::EntityMetadataValue::String(v6) => {
845 if !((*v1).r#type == 3) {
846 return Err(EncodeError::SwitchMismatch(
847 "play.clientbound.named_entity_spawn.metadata.value",
848 ));
849 }
850 w.put_string(&(*v6))?;
851 }
852 crate::defs::p340::types::EntityMetadataValue::Chat(v7) => {
853 if !((*v1).r#type == 4) {
854 return Err(EncodeError::SwitchMismatch(
855 "play.clientbound.named_entity_spawn.metadata.value",
856 ));
857 }
858 w.put_string(&(*v7))?;
859 }
860 crate::defs::p340::types::EntityMetadataValue::Slot(v8) => {
861 if !((*v1).r#type == 5) {
862 return Err(EncodeError::SwitchMismatch(
863 "play.clientbound.named_entity_spawn.metadata.value",
864 ));
865 }
866 (*v8).encode(w)?;
867 }
868 crate::defs::p340::types::EntityMetadataValue::Boolean(v9) => {
869 if !((*v1).r#type == 6) {
870 return Err(EncodeError::SwitchMismatch(
871 "play.clientbound.named_entity_spawn.metadata.value",
872 ));
873 }
874 w.put_bool((*v9));
875 }
876 crate::defs::p340::types::EntityMetadataValue::Rotation(v10) => {
877 if !((*v1).r#type == 7) {
878 return Err(EncodeError::SwitchMismatch(
879 "play.clientbound.named_entity_spawn.metadata.value",
880 ));
881 }
882 w.put_f32((*v10).pitch);
883 w.put_f32((*v10).yaw);
884 w.put_f32((*v10).roll);
885 }
886 crate::defs::p340::types::EntityMetadataValue::Position(v11) => {
887 if !((*v1).r#type == 8) {
888 return Err(EncodeError::SwitchMismatch(
889 "play.clientbound.named_entity_spawn.metadata.value",
890 ));
891 }
892 (*v11).write(w, PositionLayout::Xyz)?;
893 }
894 crate::defs::p340::types::EntityMetadataValue::OptPosition(v12) => {
895 if !((*v1).r#type == 9) {
896 return Err(EncodeError::SwitchMismatch(
897 "play.clientbound.named_entity_spawn.metadata.value",
898 ));
899 }
900 match &(*v12) {
901 Some(v13) => {
902 w.put_u8(1);
903 (*v13).write(w, PositionLayout::Xyz)?;
904 }
905 None => w.put_u8(0),
906 }
907 }
908 crate::defs::p340::types::EntityMetadataValue::Direction(v14) => {
909 if !((*v1).r#type == 10) {
910 return Err(EncodeError::SwitchMismatch(
911 "play.clientbound.named_entity_spawn.metadata.value",
912 ));
913 }
914 w.put_varint((*v14));
915 }
916 crate::defs::p340::types::EntityMetadataValue::OptUuid(v15) => {
917 if !((*v1).r#type == 11) {
918 return Err(EncodeError::SwitchMismatch(
919 "play.clientbound.named_entity_spawn.metadata.value",
920 ));
921 }
922 match &(*v15) {
923 Some(v16) => {
924 w.put_u8(1);
925 w.put_uuid(&(*v16));
926 }
927 None => w.put_u8(0),
928 }
929 }
930 crate::defs::p340::types::EntityMetadataValue::BlockState(v17) => {
931 if !((*v1).r#type == 12) {
932 return Err(EncodeError::SwitchMismatch(
933 "play.clientbound.named_entity_spawn.metadata.value",
934 ));
935 }
936 w.put_varint((*v17));
937 }
938 crate::defs::p340::types::EntityMetadataValue::Nbt(v18) => {
939 if !((*v1).r#type == 13) {
940 return Err(EncodeError::SwitchMismatch(
941 "play.clientbound.named_entity_spawn.metadata.value",
942 ));
943 }
944 (*v18).write(w);
945 }
946 crate::defs::p340::types::EntityMetadataValue::Other => {
947 if !(!(((*v1).r#type == 0)
948 || ((*v1).r#type == 1)
949 || ((*v1).r#type == 2)
950 || ((*v1).r#type == 3)
951 || ((*v1).r#type == 4)
952 || ((*v1).r#type == 5)
953 || ((*v1).r#type == 6)
954 || ((*v1).r#type == 7)
955 || ((*v1).r#type == 8)
956 || ((*v1).r#type == 9)
957 || ((*v1).r#type == 10)
958 || ((*v1).r#type == 11)
959 || ((*v1).r#type == 12)
960 || ((*v1).r#type == 13)))
961 {
962 return Err(EncodeError::SwitchMismatch(
963 "play.clientbound.named_entity_spawn.metadata.value",
964 ));
965 }
966 }
967 }
968 if w.get(v2) == Some(&255) {
969 return Err(EncodeError::OutOfRange(
970 "play.clientbound.named_entity_spawn.metadata",
971 ));
972 }
973 }
974 w.put_u8(255);
975 Ok(())
976 }
977}
978#[cfg(feature = "v1_12_2")]
979#[cfg(feature = "testgen")]
980impl<const V: i32> Generate for NamedEntitySpawn<V> {
981 fn generate(g: &mut Gen) -> Self {
982 {
983 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
984 let v2 = g.uuid();
985 let v3 = g.f64();
986 let v4 = g.f64();
987 let v5 = g.f64();
988 let v6 = (g.int_in(-128, 127, &[]) as i8);
989 let v7 = (g.int_in(-128, 127, &[]) as i8);
990 let v8 = {
991 let n = g.count();
992 let mut v9 = Vec::with_capacity(n);
993 for _ in 0..n {
994 v9.push(loop { let v10 = { let v11 = (g.int_in(0, 255, &[]) as u8);let v12 = (g.int_in(-128, 127, &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) as i8);let v13 = (if (v12 == 0) { crate::defs::p340::types::EntityMetadataValue::Byte((g.int_in(-128, 127, &[]) as i8)) } else if (v12 == 1) { crate::defs::p340::types::EntityMetadataValue::VarInt((g.int_in(-2147483648, 2147483647, &[]) as i32)) } else if (v12 == 2) { crate::defs::p340::types::EntityMetadataValue::Float(g.f32()) } else if (v12 == 3) { crate::defs::p340::types::EntityMetadataValue::String(g.string()) } else if (v12 == 4) { crate::defs::p340::types::EntityMetadataValue::Chat(g.string()) } else if (v12 == 5) { crate::defs::p340::types::EntityMetadataValue::Slot(<crate::types::slot::legacy::Slot as Generate>::generate(g)) } else if (v12 == 6) { crate::defs::p340::types::EntityMetadataValue::Boolean(g.bool()) } else if (v12 == 7) { crate::defs::p340::types::EntityMetadataValue::Rotation({ let v14 = g.f32();let v15 = g.f32();let v16 = g.f32(); crate::defs::p47::types::EntityMetadataValueRotation { pitch: v14, yaw: v15, roll: v16 } }) } else if (v12 == 8) { crate::defs::p340::types::EntityMetadataValue::Position(g.position()) } else if (v12 == 9) { crate::defs::p340::types::EntityMetadataValue::OptPosition(if g.bool() { Some(g.position()) } else { None }) } else if (v12 == 10) { crate::defs::p340::types::EntityMetadataValue::Direction((g.int_in(-2147483648, 2147483647, &[]) as i32)) } else if (v12 == 11) { crate::defs::p340::types::EntityMetadataValue::OptUuid(if g.bool() { Some(g.uuid()) } else { None }) } else if (v12 == 12) { crate::defs::p340::types::EntityMetadataValue::BlockState((g.int_in(-2147483648, 2147483647, &[]) as i32)) } else if (v12 == 13) { crate::defs::p340::types::EntityMetadataValue::Nbt(g.nbt()) } else { crate::defs::p340::types::EntityMetadataValue::Other }); crate::defs::p340::types::EntityMetadataEntry { key: v11, r#type: v12, value: v13 } }; if crate::testgen::first_byte_ok(|w: &mut BytesMut| -> EncodeResult { w.put_u8(v10.key);w.put_i8(v10.r#type);match &v10.value { crate::defs::p340::types::EntityMetadataValue::Byte(v17) => { if !((v10.r#type == 0)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_i8((*v17)); }crate::defs::p340::types::EntityMetadataValue::VarInt(v18) => { if !((v10.r#type == 1)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_varint((*v18)); }crate::defs::p340::types::EntityMetadataValue::Float(v19) => { if !((v10.r#type == 2)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_f32((*v19)); }crate::defs::p340::types::EntityMetadataValue::String(v20) => { if !((v10.r#type == 3)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_string(&(*v20))?; }crate::defs::p340::types::EntityMetadataValue::Chat(v21) => { if !((v10.r#type == 4)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_string(&(*v21))?; }crate::defs::p340::types::EntityMetadataValue::Slot(v22) => { if !((v10.r#type == 5)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } (*v22).encode(w)?; }crate::defs::p340::types::EntityMetadataValue::Boolean(v23) => { if !((v10.r#type == 6)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_bool((*v23)); }crate::defs::p340::types::EntityMetadataValue::Rotation(v24) => { if !((v10.r#type == 7)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_f32((*v24).pitch);w.put_f32((*v24).yaw);w.put_f32((*v24).roll); }crate::defs::p340::types::EntityMetadataValue::Position(v25) => { if !((v10.r#type == 8)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } (*v25).write(w, PositionLayout::Xyz)?; }crate::defs::p340::types::EntityMetadataValue::OptPosition(v26) => { if !((v10.r#type == 9)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } match &(*v26) { Some(v27) => { w.put_u8(1); (*v27).write(w, PositionLayout::Xyz)?; } None => w.put_u8(0), } }crate::defs::p340::types::EntityMetadataValue::Direction(v28) => { if !((v10.r#type == 10)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_varint((*v28)); }crate::defs::p340::types::EntityMetadataValue::OptUuid(v29) => { if !((v10.r#type == 11)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } match &(*v29) { Some(v30) => { w.put_u8(1); w.put_uuid(&(*v30)); } None => w.put_u8(0), } }crate::defs::p340::types::EntityMetadataValue::BlockState(v31) => { if !((v10.r#type == 12)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_varint((*v31)); }crate::defs::p340::types::EntityMetadataValue::Nbt(v32) => { if !((v10.r#type == 13)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } (*v32).write(w); }crate::defs::p340::types::EntityMetadataValue::Other => { if !(!((v10.r#type == 0) || (v10.r#type == 1) || (v10.r#type == 2) || (v10.r#type == 3) || (v10.r#type == 4) || (v10.r#type == 5) || (v10.r#type == 6) || (v10.r#type == 7) || (v10.r#type == 8) || (v10.r#type == 9) || (v10.r#type == 10) || (v10.r#type == 11) || (v10.r#type == 12) || (v10.r#type == 13))) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } } } Ok(()) }, |b| b != 255) { break v10; } });
995 }
996 v9
997 };
998 Self {
999 entity_id: v1,
1000 player_uuid: v2,
1001 x: v3,
1002 y: v4,
1003 z: v5,
1004 yaw: v6,
1005 pitch: v7,
1006 metadata: v8,
1007 }
1008 }
1009 }
1010}
1011
1012#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1013#[derive(Debug, Clone, PartialEq)]
1015pub struct BossBar<const V: i32> {
1016 pub entity_uuid: Uuid,
1018 pub action: i32,
1020 pub title: Option<ByteString>,
1022 pub health: Option<f32>,
1024 pub color: Option<i32>,
1026 pub dividers: Option<i32>,
1028 pub flags: Option<u8>,
1030}
1031#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1032impl<const V: i32> Decode for BossBar<V> {
1033 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1034 Ok({
1035 let v1 = r.read_uuid()?;
1036 let v2 = r.read_varint()?;
1037 let v3 = if (v2 == 0) || (v2 == 3) {
1038 Some(r.read_string()?)
1039 } else {
1040 None
1041 };
1042 let v4 = if (v2 == 0) || (v2 == 2) {
1043 Some(r.read_f32()?)
1044 } else {
1045 None
1046 };
1047 let v5 = if (v2 == 0) || (v2 == 4) {
1048 Some(r.read_varint()?)
1049 } else {
1050 None
1051 };
1052 let v6 = if (v2 == 0) || (v2 == 4) {
1053 Some(r.read_varint()?)
1054 } else {
1055 None
1056 };
1057 let v7 = if (v2 == 0) || (v2 == 5) {
1058 Some(r.read_u8()?)
1059 } else {
1060 None
1061 };
1062 Self {
1063 entity_uuid: v1,
1064 action: v2,
1065 title: v3,
1066 health: v4,
1067 color: v5,
1068 dividers: v6,
1069 flags: v7,
1070 }
1071 })
1072 }
1073}
1074#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1075impl<const V: i32> Encode for BossBar<V> {
1076 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1077 w.put_uuid(&(*self).entity_uuid);
1078 w.put_varint((*self).action);
1079 match (
1080 &(*self).title,
1081 ((*self).action == 0) || ((*self).action == 3),
1082 ) {
1083 (Some(v1), true) => {
1084 w.put_string(&(*v1))?;
1085 }
1086 (None, false) => {}
1087 _ => {
1088 return Err(EncodeError::SwitchMismatch(
1089 "play.clientbound.boss_bar.title",
1090 ));
1091 }
1092 }
1093 match (
1094 &(*self).health,
1095 ((*self).action == 0) || ((*self).action == 2),
1096 ) {
1097 (Some(v2), true) => {
1098 w.put_f32((*v2));
1099 }
1100 (None, false) => {}
1101 _ => {
1102 return Err(EncodeError::SwitchMismatch(
1103 "play.clientbound.boss_bar.health",
1104 ));
1105 }
1106 }
1107 match (
1108 &(*self).color,
1109 ((*self).action == 0) || ((*self).action == 4),
1110 ) {
1111 (Some(v3), true) => {
1112 w.put_varint((*v3));
1113 }
1114 (None, false) => {}
1115 _ => {
1116 return Err(EncodeError::SwitchMismatch(
1117 "play.clientbound.boss_bar.color",
1118 ));
1119 }
1120 }
1121 match (
1122 &(*self).dividers,
1123 ((*self).action == 0) || ((*self).action == 4),
1124 ) {
1125 (Some(v4), true) => {
1126 w.put_varint((*v4));
1127 }
1128 (None, false) => {}
1129 _ => {
1130 return Err(EncodeError::SwitchMismatch(
1131 "play.clientbound.boss_bar.dividers",
1132 ));
1133 }
1134 }
1135 match (
1136 &(*self).flags,
1137 ((*self).action == 0) || ((*self).action == 5),
1138 ) {
1139 (Some(v5), true) => {
1140 w.put_u8((*v5));
1141 }
1142 (None, false) => {}
1143 _ => {
1144 return Err(EncodeError::SwitchMismatch(
1145 "play.clientbound.boss_bar.flags",
1146 ));
1147 }
1148 }
1149 Ok(())
1150 }
1151}
1152#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1153#[cfg(feature = "testgen")]
1154impl<const V: i32> Generate for BossBar<V> {
1155 fn generate(g: &mut Gen) -> Self {
1156 {
1157 let v1 = g.uuid();
1158 let v2 = (g.int_in(-2147483648, 2147483647, &[0, 3, 0, 2, 0, 4, 0, 4, 0, 5]) as i32);
1159 let v3 = if (v2 == 0) || (v2 == 3) {
1160 Some(g.string())
1161 } else {
1162 None
1163 };
1164 let v4 = if (v2 == 0) || (v2 == 2) {
1165 Some(g.f32())
1166 } else {
1167 None
1168 };
1169 let v5 = if (v2 == 0) || (v2 == 4) {
1170 Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
1171 } else {
1172 None
1173 };
1174 let v6 = if (v2 == 0) || (v2 == 4) {
1175 Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
1176 } else {
1177 None
1178 };
1179 let v7 = if (v2 == 0) || (v2 == 5) {
1180 Some((g.int_in(0, 255, &[]) as u8))
1181 } else {
1182 None
1183 };
1184 Self {
1185 entity_uuid: v1,
1186 action: v2,
1187 title: v3,
1188 health: v4,
1189 color: v5,
1190 dividers: v6,
1191 flags: v7,
1192 }
1193 }
1194 }
1195}
1196
1197#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1198#[derive(Debug, Clone, PartialEq)]
1200pub struct SetCooldown<const V: i32> {
1201 pub item_id: i32,
1203 pub cooldown_ticks: i32,
1205}
1206#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1207impl<const V: i32> Decode for SetCooldown<V> {
1208 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1209 Ok({
1210 let v1 = r.read_varint()?;
1211 let v2 = r.read_varint()?;
1212 Self {
1213 item_id: v1,
1214 cooldown_ticks: v2,
1215 }
1216 })
1217 }
1218}
1219#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1220impl<const V: i32> Encode for SetCooldown<V> {
1221 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1222 w.put_varint((*self).item_id);
1223 w.put_varint((*self).cooldown_ticks);
1224 Ok(())
1225 }
1226}
1227#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1228#[cfg(feature = "testgen")]
1229impl<const V: i32> Generate for SetCooldown<V> {
1230 fn generate(g: &mut Gen) -> Self {
1231 {
1232 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1233 let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1234 Self {
1235 item_id: v1,
1236 cooldown_ticks: v2,
1237 }
1238 }
1239 }
1240}
1241
1242#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1243#[derive(Debug, Clone, PartialEq)]
1245pub struct NamedSoundEffect<const V: i32> {
1246 pub sound_name: ByteString,
1248 pub sound_category: i32,
1250 pub x: i32,
1252 pub y: i32,
1254 pub z: i32,
1256 pub volume: f32,
1258 pub pitch: f32,
1260}
1261#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1262impl<const V: i32> Decode for NamedSoundEffect<V> {
1263 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1264 Ok({
1265 let v1 = r.read_string()?;
1266 let v2 = r.read_varint()?;
1267 let v3 = r.read_i32()?;
1268 let v4 = r.read_i32()?;
1269 let v5 = r.read_i32()?;
1270 let v6 = r.read_f32()?;
1271 let v7 = r.read_f32()?;
1272 Self {
1273 sound_name: v1,
1274 sound_category: v2,
1275 x: v3,
1276 y: v4,
1277 z: v5,
1278 volume: v6,
1279 pitch: v7,
1280 }
1281 })
1282 }
1283}
1284#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1285impl<const V: i32> Encode for NamedSoundEffect<V> {
1286 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1287 w.put_string(&(*self).sound_name)?;
1288 w.put_varint((*self).sound_category);
1289 w.put_i32((*self).x);
1290 w.put_i32((*self).y);
1291 w.put_i32((*self).z);
1292 w.put_f32((*self).volume);
1293 w.put_f32((*self).pitch);
1294 Ok(())
1295 }
1296}
1297#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1298#[cfg(feature = "testgen")]
1299impl<const V: i32> Generate for NamedSoundEffect<V> {
1300 fn generate(g: &mut Gen) -> Self {
1301 {
1302 let v1 = g.string();
1303 let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1304 let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1305 let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1306 let v5 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1307 let v6 = g.f32();
1308 let v7 = g.f32();
1309 Self {
1310 sound_name: v1,
1311 sound_category: v2,
1312 x: v3,
1313 y: v4,
1314 z: v5,
1315 volume: v6,
1316 pitch: v7,
1317 }
1318 }
1319 }
1320}
1321
1322#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1323#[derive(Debug, Clone, PartialEq)]
1325pub struct UnloadChunk<const V: i32> {
1326 pub chunk_x: i32,
1328 pub chunk_z: i32,
1330}
1331#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1332impl<const V: i32> Decode for UnloadChunk<V> {
1333 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1334 Ok({
1335 let v1 = r.read_i32()?;
1336 let v2 = r.read_i32()?;
1337 Self {
1338 chunk_x: v1,
1339 chunk_z: v2,
1340 }
1341 })
1342 }
1343}
1344#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1345impl<const V: i32> Encode for UnloadChunk<V> {
1346 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1347 w.put_i32((*self).chunk_x);
1348 w.put_i32((*self).chunk_z);
1349 Ok(())
1350 }
1351}
1352#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
1353#[cfg(feature = "testgen")]
1354impl<const V: i32> Generate for UnloadChunk<V> {
1355 fn generate(g: &mut Gen) -> Self {
1356 {
1357 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1358 let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1359 Self {
1360 chunk_x: v1,
1361 chunk_z: v2,
1362 }
1363 }
1364 }
1365}
1366
1367#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1368#[derive(Debug, Clone, PartialEq)]
1370pub struct KeepAlive<const V: i32> {
1371 pub keep_alive_id: i64,
1373}
1374#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1375impl<const V: i32> Decode for KeepAlive<V> {
1376 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1377 Ok({
1378 let v1 = r.read_i64()?;
1379 Self { keep_alive_id: v1 }
1380 })
1381 }
1382}
1383#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1384impl<const V: i32> Encode for KeepAlive<V> {
1385 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1386 w.put_i64((*self).keep_alive_id);
1387 Ok(())
1388 }
1389}
1390#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1391#[cfg(feature = "testgen")]
1392impl<const V: i32> Generate for KeepAlive<V> {
1393 fn generate(g: &mut Gen) -> Self {
1394 {
1395 let v1 = g.i64();
1396 Self { keep_alive_id: v1 }
1397 }
1398 }
1399}
1400
1401#[cfg(feature = "v1_12_2")]
1402#[derive(Debug, Clone, PartialEq)]
1404pub struct MapChunk<const V: i32> {
1405 pub x: i32,
1407 pub z: i32,
1409 pub ground_up: bool,
1411 pub bit_map: i32,
1413 pub chunk_data: Bytes,
1415 pub block_entities: Vec<RawNbt>,
1417}
1418#[cfg(feature = "v1_12_2")]
1419impl<const V: i32> Decode for MapChunk<V> {
1420 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1421 Ok({
1422 let v1 = r.read_i32()?;
1423 let v2 = r.read_i32()?;
1424 let v3 = r.read_bool()?;
1425 let v4 = r.read_varint()?;
1426 let v5 = r.read_byte_array()?;
1427 let v6 = {
1428 let v7 = {
1429 let c = r.read_varint()?;
1430 r.check_count(i64::from(c), 1)?
1431 };
1432 let mut v8 = Vec::with_capacity(v7.min(crate::codec::PREALLOC_LIMIT));
1433 for _ in 0..v7 {
1434 v8.push(RawNbt::read(r)?);
1435 }
1436 v8
1437 };
1438 Self {
1439 x: v1,
1440 z: v2,
1441 ground_up: v3,
1442 bit_map: v4,
1443 chunk_data: v5,
1444 block_entities: v6,
1445 }
1446 })
1447 }
1448}
1449#[cfg(feature = "v1_12_2")]
1450impl<const V: i32> Encode for MapChunk<V> {
1451 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1452 w.put_i32((*self).x);
1453 w.put_i32((*self).z);
1454 w.put_bool((*self).ground_up);
1455 w.put_varint((*self).bit_map);
1456 w.put_byte_array(&(*self).chunk_data)?;
1457 w.put_len_varint((*self).block_entities.len())?;
1458 for v1 in (*self).block_entities.iter() {
1459 (*v1).write(w);
1460 }
1461 Ok(())
1462 }
1463}
1464#[cfg(feature = "v1_12_2")]
1465#[cfg(feature = "testgen")]
1466impl<const V: i32> Generate for MapChunk<V> {
1467 fn generate(g: &mut Gen) -> Self {
1468 {
1469 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1470 let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1471 let v3 = g.bool();
1472 let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1473 let v5 = g.bytes();
1474 let v6 = {
1475 let v7 = g.count();
1476 let mut v8 = Vec::with_capacity(v7.min(crate::codec::PREALLOC_LIMIT));
1477 for _ in 0..v7 {
1478 v8.push(g.nbt());
1479 }
1480 v8
1481 };
1482 Self {
1483 x: v1,
1484 z: v2,
1485 ground_up: v3,
1486 bit_map: v4,
1487 chunk_data: v5,
1488 block_entities: v6,
1489 }
1490 }
1491 }
1492}
1493
1494#[cfg(feature = "v1_12_2")]
1495#[derive(Debug, Clone, PartialEq)]
1497pub struct Login<const V: i32> {
1498 pub entity_id: i32,
1500 pub game_mode: u8,
1502 pub dimension: i32,
1504 pub difficulty: u8,
1506 pub max_players: u8,
1508 pub level_type: ByteString,
1510 pub reduced_debug_info: bool,
1512}
1513#[cfg(feature = "v1_12_2")]
1514impl<const V: i32> Decode for Login<V> {
1515 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1516 Ok({
1517 let v1 = r.read_i32()?;
1518 let v2 = r.read_u8()?;
1519 let v3 = r.read_i32()?;
1520 let v4 = r.read_u8()?;
1521 let v5 = r.read_u8()?;
1522 let v6 = r.read_string()?;
1523 let v7 = r.read_bool()?;
1524 Self {
1525 entity_id: v1,
1526 game_mode: v2,
1527 dimension: v3,
1528 difficulty: v4,
1529 max_players: v5,
1530 level_type: v6,
1531 reduced_debug_info: v7,
1532 }
1533 })
1534 }
1535}
1536#[cfg(feature = "v1_12_2")]
1537impl<const V: i32> Encode for Login<V> {
1538 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1539 w.put_i32((*self).entity_id);
1540 w.put_u8((*self).game_mode);
1541 w.put_i32((*self).dimension);
1542 w.put_u8((*self).difficulty);
1543 w.put_u8((*self).max_players);
1544 w.put_string(&(*self).level_type)?;
1545 w.put_bool((*self).reduced_debug_info);
1546 Ok(())
1547 }
1548}
1549#[cfg(feature = "v1_12_2")]
1550#[cfg(feature = "testgen")]
1551impl<const V: i32> Generate for Login<V> {
1552 fn generate(g: &mut Gen) -> Self {
1553 {
1554 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1555 let v2 = (g.int_in(0, 255, &[]) as u8);
1556 let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1557 let v4 = (g.int_in(0, 255, &[]) as u8);
1558 let v5 = (g.int_in(0, 255, &[]) as u8);
1559 let v6 = g.string();
1560 let v7 = g.bool();
1561 Self {
1562 entity_id: v1,
1563 game_mode: v2,
1564 dimension: v3,
1565 difficulty: v4,
1566 max_players: v5,
1567 level_type: v6,
1568 reduced_debug_info: v7,
1569 }
1570 }
1571 }
1572}
1573
1574#[cfg(feature = "v1_12_2")]
1575#[derive(Debug, Clone, PartialEq)]
1577pub struct Map<const V: i32> {
1578 pub item_damage: i32,
1580 pub scale: i8,
1582 pub tracking_position: bool,
1584 pub icons: Vec<crate::defs::p47::play::clientbound::MapIcons>,
1586 pub columns: i8,
1588 pub rows: Option<i8>,
1590 pub x: Option<i8>,
1592 pub y: Option<i8>,
1594 pub data: Option<Bytes>,
1596}
1597#[cfg(feature = "v1_12_2")]
1598impl<const V: i32> Decode for Map<V> {
1599 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1600 Ok({
1601 let v1 = r.read_varint()?;
1602 let v2 = r.read_i8()?;
1603 let v3 = r.read_bool()?;
1604 let v4 = {
1605 let v5 = {
1606 let c = r.read_varint()?;
1607 r.check_count(i64::from(c), 3)?
1608 };
1609 let mut v6 = Vec::with_capacity(v5.min(crate::codec::PREALLOC_LIMIT));
1610 for _ in 0..v5 {
1611 v6.push({
1612 let v7 = r.read_i8()?;
1613 let v8 = r.read_i8()?;
1614 let v9 = r.read_i8()?;
1615 crate::defs::p47::play::clientbound::MapIcons {
1616 direction_and_type: v7,
1617 x: v8,
1618 z: v9,
1619 }
1620 });
1621 }
1622 v6
1623 };
1624 let v10 = r.read_i8()?;
1625 let v11 = if !(v10 == 0) {
1626 Some(r.read_i8()?)
1627 } else {
1628 None
1629 };
1630 let v12 = if !(v10 == 0) {
1631 Some(r.read_i8()?)
1632 } else {
1633 None
1634 };
1635 let v13 = if !(v10 == 0) {
1636 Some(r.read_i8()?)
1637 } else {
1638 None
1639 };
1640 let v14 = if !(v10 == 0) {
1641 Some(r.read_byte_array()?)
1642 } else {
1643 None
1644 };
1645 Self {
1646 item_damage: v1,
1647 scale: v2,
1648 tracking_position: v3,
1649 icons: v4,
1650 columns: v10,
1651 rows: v11,
1652 x: v12,
1653 y: v13,
1654 data: v14,
1655 }
1656 })
1657 }
1658}
1659#[cfg(feature = "v1_12_2")]
1660impl<const V: i32> Encode for Map<V> {
1661 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1662 w.put_varint((*self).item_damage);
1663 w.put_i8((*self).scale);
1664 w.put_bool((*self).tracking_position);
1665 w.put_len_varint((*self).icons.len())?;
1666 for v1 in (*self).icons.iter() {
1667 w.put_i8((*v1).direction_and_type);
1668 w.put_i8((*v1).x);
1669 w.put_i8((*v1).z);
1670 }
1671 w.put_i8((*self).columns);
1672 match (&(*self).rows, !((*self).columns == 0)) {
1673 (Some(v2), true) => {
1674 w.put_i8((*v2));
1675 }
1676 (None, false) => {}
1677 _ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.rows")),
1678 }
1679 match (&(*self).x, !((*self).columns == 0)) {
1680 (Some(v3), true) => {
1681 w.put_i8((*v3));
1682 }
1683 (None, false) => {}
1684 _ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.x")),
1685 }
1686 match (&(*self).y, !((*self).columns == 0)) {
1687 (Some(v4), true) => {
1688 w.put_i8((*v4));
1689 }
1690 (None, false) => {}
1691 _ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.y")),
1692 }
1693 match (&(*self).data, !((*self).columns == 0)) {
1694 (Some(v5), true) => {
1695 w.put_byte_array(&(*v5))?;
1696 }
1697 (None, false) => {}
1698 _ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.data")),
1699 }
1700 Ok(())
1701 }
1702}
1703#[cfg(feature = "v1_12_2")]
1704#[cfg(feature = "testgen")]
1705impl<const V: i32> Generate for Map<V> {
1706 fn generate(g: &mut Gen) -> Self {
1707 {
1708 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1709 let v2 = (g.int_in(-128, 127, &[]) as i8);
1710 let v3 = g.bool();
1711 let v4 = {
1712 let v5 = g.count();
1713 let mut v6 = Vec::with_capacity(v5.min(crate::codec::PREALLOC_LIMIT));
1714 for _ in 0..v5 {
1715 v6.push({
1716 let v7 = (g.int_in(-128, 127, &[]) as i8);
1717 let v8 = (g.int_in(-128, 127, &[]) as i8);
1718 let v9 = (g.int_in(-128, 127, &[]) as i8);
1719 crate::defs::p47::play::clientbound::MapIcons {
1720 direction_and_type: v7,
1721 x: v8,
1722 z: v9,
1723 }
1724 });
1725 }
1726 v6
1727 };
1728 let v10 = (g.int_in(-128, 127, &[0, 0, 0, 0]) as i8);
1729 let v11 = if !(v10 == 0) {
1730 Some((g.int_in(-128, 127, &[]) as i8))
1731 } else {
1732 None
1733 };
1734 let v12 = if !(v10 == 0) {
1735 Some((g.int_in(-128, 127, &[]) as i8))
1736 } else {
1737 None
1738 };
1739 let v13 = if !(v10 == 0) {
1740 Some((g.int_in(-128, 127, &[]) as i8))
1741 } else {
1742 None
1743 };
1744 let v14 = if !(v10 == 0) { Some(g.bytes()) } else { None };
1745 Self {
1746 item_damage: v1,
1747 scale: v2,
1748 tracking_position: v3,
1749 icons: v4,
1750 columns: v10,
1751 rows: v11,
1752 x: v12,
1753 y: v13,
1754 data: v14,
1755 }
1756 }
1757 }
1758}
1759
1760#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1761#[derive(Debug, Clone, PartialEq)]
1763pub struct RelEntityMove<const V: i32> {
1764 pub entity_id: i32,
1766 pub d_x: i16,
1768 pub d_y: i16,
1770 pub d_z: i16,
1772 pub on_ground: bool,
1774}
1775#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1776impl<const V: i32> Decode for RelEntityMove<V> {
1777 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1778 Ok({
1779 let v1 = r.read_varint()?;
1780 let v2 = r.read_i16()?;
1781 let v3 = r.read_i16()?;
1782 let v4 = r.read_i16()?;
1783 let v5 = r.read_bool()?;
1784 Self {
1785 entity_id: v1,
1786 d_x: v2,
1787 d_y: v3,
1788 d_z: v4,
1789 on_ground: v5,
1790 }
1791 })
1792 }
1793}
1794#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1795impl<const V: i32> Encode for RelEntityMove<V> {
1796 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1797 w.put_varint((*self).entity_id);
1798 w.put_i16((*self).d_x);
1799 w.put_i16((*self).d_y);
1800 w.put_i16((*self).d_z);
1801 w.put_bool((*self).on_ground);
1802 Ok(())
1803 }
1804}
1805#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1806#[cfg(feature = "testgen")]
1807impl<const V: i32> Generate for RelEntityMove<V> {
1808 fn generate(g: &mut Gen) -> Self {
1809 {
1810 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1811 let v2 = (g.int_in(-32768, 32767, &[]) as i16);
1812 let v3 = (g.int_in(-32768, 32767, &[]) as i16);
1813 let v4 = (g.int_in(-32768, 32767, &[]) as i16);
1814 let v5 = g.bool();
1815 Self {
1816 entity_id: v1,
1817 d_x: v2,
1818 d_y: v3,
1819 d_z: v4,
1820 on_ground: v5,
1821 }
1822 }
1823 }
1824}
1825
1826#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1827#[derive(Debug, Clone, PartialEq)]
1829pub struct EntityMoveLook<const V: i32> {
1830 pub entity_id: i32,
1832 pub d_x: i16,
1834 pub d_y: i16,
1836 pub d_z: i16,
1838 pub yaw: i8,
1840 pub pitch: i8,
1842 pub on_ground: bool,
1844}
1845#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1846impl<const V: i32> Decode for EntityMoveLook<V> {
1847 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1848 Ok({
1849 let v1 = r.read_varint()?;
1850 let v2 = r.read_i16()?;
1851 let v3 = r.read_i16()?;
1852 let v4 = r.read_i16()?;
1853 let v5 = r.read_i8()?;
1854 let v6 = r.read_i8()?;
1855 let v7 = r.read_bool()?;
1856 Self {
1857 entity_id: v1,
1858 d_x: v2,
1859 d_y: v3,
1860 d_z: v4,
1861 yaw: v5,
1862 pitch: v6,
1863 on_ground: v7,
1864 }
1865 })
1866 }
1867}
1868#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1869impl<const V: i32> Encode for EntityMoveLook<V> {
1870 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1871 w.put_varint((*self).entity_id);
1872 w.put_i16((*self).d_x);
1873 w.put_i16((*self).d_y);
1874 w.put_i16((*self).d_z);
1875 w.put_i8((*self).yaw);
1876 w.put_i8((*self).pitch);
1877 w.put_bool((*self).on_ground);
1878 Ok(())
1879 }
1880}
1881#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1882#[cfg(feature = "testgen")]
1883impl<const V: i32> Generate for EntityMoveLook<V> {
1884 fn generate(g: &mut Gen) -> Self {
1885 {
1886 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
1887 let v2 = (g.int_in(-32768, 32767, &[]) as i16);
1888 let v3 = (g.int_in(-32768, 32767, &[]) as i16);
1889 let v4 = (g.int_in(-32768, 32767, &[]) as i16);
1890 let v5 = (g.int_in(-128, 127, &[]) as i8);
1891 let v6 = (g.int_in(-128, 127, &[]) as i8);
1892 let v7 = g.bool();
1893 Self {
1894 entity_id: v1,
1895 d_x: v2,
1896 d_y: v3,
1897 d_z: v4,
1898 yaw: v5,
1899 pitch: v6,
1900 on_ground: v7,
1901 }
1902 }
1903 }
1904}
1905
1906#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1907#[derive(Debug, Clone, PartialEq)]
1909pub struct VehicleMove<const V: i32> {
1910 pub x: f64,
1912 pub y: f64,
1914 pub z: f64,
1916 pub yaw: f32,
1918 pub pitch: f32,
1920}
1921#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1922impl<const V: i32> Decode for VehicleMove<V> {
1923 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1924 Ok({
1925 let v1 = r.read_f64()?;
1926 let v2 = r.read_f64()?;
1927 let v3 = r.read_f64()?;
1928 let v4 = r.read_f32()?;
1929 let v5 = r.read_f32()?;
1930 Self {
1931 x: v1,
1932 y: v2,
1933 z: v3,
1934 yaw: v4,
1935 pitch: v5,
1936 }
1937 })
1938 }
1939}
1940#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1941impl<const V: i32> Encode for VehicleMove<V> {
1942 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1943 w.put_f64((*self).x);
1944 w.put_f64((*self).y);
1945 w.put_f64((*self).z);
1946 w.put_f32((*self).yaw);
1947 w.put_f32((*self).pitch);
1948 Ok(())
1949 }
1950}
1951#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
1952#[cfg(feature = "testgen")]
1953impl<const V: i32> Generate for VehicleMove<V> {
1954 fn generate(g: &mut Gen) -> Self {
1955 {
1956 let v1 = g.f64();
1957 let v2 = g.f64();
1958 let v3 = g.f64();
1959 let v4 = g.f32();
1960 let v5 = g.f32();
1961 Self {
1962 x: v1,
1963 y: v2,
1964 z: v3,
1965 yaw: v4,
1966 pitch: v5,
1967 }
1968 }
1969 }
1970}
1971
1972#[cfg(feature = "v1_12_2")]
1973#[derive(Debug, Clone, PartialEq)]
1975pub struct CraftRecipeResponse<const V: i32> {
1976 pub window_id: i8,
1978 pub recipe: i32,
1980}
1981#[cfg(feature = "v1_12_2")]
1982impl<const V: i32> Decode for CraftRecipeResponse<V> {
1983 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
1984 Ok({
1985 let v1 = r.read_i8()?;
1986 let v2 = r.read_varint()?;
1987 Self {
1988 window_id: v1,
1989 recipe: v2,
1990 }
1991 })
1992 }
1993}
1994#[cfg(feature = "v1_12_2")]
1995impl<const V: i32> Encode for CraftRecipeResponse<V> {
1996 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
1997 w.put_i8((*self).window_id);
1998 w.put_varint((*self).recipe);
1999 Ok(())
2000 }
2001}
2002#[cfg(feature = "v1_12_2")]
2003#[cfg(feature = "testgen")]
2004impl<const V: i32> Generate for CraftRecipeResponse<V> {
2005 fn generate(g: &mut Gen) -> Self {
2006 {
2007 let v1 = (g.int_in(-128, 127, &[]) as i8);
2008 let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2009 Self {
2010 window_id: v1,
2011 recipe: v2,
2012 }
2013 }
2014 }
2015}
2016
2017#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
2018#[derive(Debug, Clone, PartialEq)]
2020pub struct Position<const V: i32> {
2021 pub x: f64,
2023 pub y: f64,
2025 pub z: f64,
2027 pub yaw: f32,
2029 pub pitch: f32,
2031 pub flags: i8,
2033 pub teleport_id: i32,
2035}
2036#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
2037impl<const V: i32> Decode for Position<V> {
2038 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2039 Ok({
2040 let v1 = r.read_f64()?;
2041 let v2 = r.read_f64()?;
2042 let v3 = r.read_f64()?;
2043 let v4 = r.read_f32()?;
2044 let v5 = r.read_f32()?;
2045 let v6 = r.read_i8()?;
2046 let v7 = r.read_varint()?;
2047 Self {
2048 x: v1,
2049 y: v2,
2050 z: v3,
2051 yaw: v4,
2052 pitch: v5,
2053 flags: v6,
2054 teleport_id: v7,
2055 }
2056 })
2057 }
2058}
2059#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
2060impl<const V: i32> Encode for Position<V> {
2061 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2062 w.put_f64((*self).x);
2063 w.put_f64((*self).y);
2064 w.put_f64((*self).z);
2065 w.put_f32((*self).yaw);
2066 w.put_f32((*self).pitch);
2067 w.put_i8((*self).flags);
2068 w.put_varint((*self).teleport_id);
2069 Ok(())
2070 }
2071}
2072#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
2073#[cfg(feature = "testgen")]
2074impl<const V: i32> Generate for Position<V> {
2075 fn generate(g: &mut Gen) -> Self {
2076 {
2077 let v1 = g.f64();
2078 let v2 = g.f64();
2079 let v3 = g.f64();
2080 let v4 = g.f32();
2081 let v5 = g.f32();
2082 let v6 = (g.int_in(-128, 127, &[]) as i8);
2083 let v7 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2084 Self {
2085 x: v1,
2086 y: v2,
2087 z: v3,
2088 yaw: v4,
2089 pitch: v5,
2090 flags: v6,
2091 teleport_id: v7,
2092 }
2093 }
2094 }
2095}
2096
2097#[cfg(feature = "v1_12_2")]
2098#[derive(Debug, Clone, PartialEq)]
2100pub struct UnlockRecipes<const V: i32> {
2101 pub action: i32,
2103 pub crafting_book_open: bool,
2105 pub filtering_craftable: bool,
2107 pub recipes1: Vec<i32>,
2109 pub recipes2: Option<Vec<i32>>,
2111}
2112#[cfg(feature = "v1_12_2")]
2113impl<const V: i32> Decode for UnlockRecipes<V> {
2114 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2115 Ok({
2116 let v1 = r.read_varint()?;
2117 let v2 = r.read_bool()?;
2118 let v3 = r.read_bool()?;
2119 let v4 = {
2120 let v5 = {
2121 let c = r.read_varint()?;
2122 r.check_count(i64::from(c), 1)?
2123 };
2124 let mut v6 = Vec::with_capacity(v5.min(crate::codec::PREALLOC_LIMIT));
2125 for _ in 0..v5 {
2126 v6.push(r.read_varint()?);
2127 }
2128 v6
2129 };
2130 let v7 = if (v1 == 0) {
2131 Some({
2132 let v8 = {
2133 let c = r.read_varint()?;
2134 r.check_count(i64::from(c), 1)?
2135 };
2136 let mut v9 = Vec::with_capacity(v8.min(crate::codec::PREALLOC_LIMIT));
2137 for _ in 0..v8 {
2138 v9.push(r.read_varint()?);
2139 }
2140 v9
2141 })
2142 } else {
2143 None
2144 };
2145 Self {
2146 action: v1,
2147 crafting_book_open: v2,
2148 filtering_craftable: v3,
2149 recipes1: v4,
2150 recipes2: v7,
2151 }
2152 })
2153 }
2154}
2155#[cfg(feature = "v1_12_2")]
2156impl<const V: i32> Encode for UnlockRecipes<V> {
2157 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2158 w.put_varint((*self).action);
2159 w.put_bool((*self).crafting_book_open);
2160 w.put_bool((*self).filtering_craftable);
2161 w.put_len_varint((*self).recipes1.len())?;
2162 for v1 in (*self).recipes1.iter() {
2163 w.put_varint((*v1));
2164 }
2165 match (&(*self).recipes2, ((*self).action == 0)) {
2166 (Some(v2), true) => {
2167 w.put_len_varint((*v2).len())?;
2168 for v3 in (*v2).iter() {
2169 w.put_varint((*v3));
2170 }
2171 }
2172 (None, false) => {}
2173 _ => {
2174 return Err(EncodeError::SwitchMismatch(
2175 "play.clientbound.unlock_recipes.recipes2",
2176 ));
2177 }
2178 }
2179 Ok(())
2180 }
2181}
2182#[cfg(feature = "v1_12_2")]
2183#[cfg(feature = "testgen")]
2184impl<const V: i32> Generate for UnlockRecipes<V> {
2185 fn generate(g: &mut Gen) -> Self {
2186 {
2187 let v1 = (g.int_in(-2147483648, 2147483647, &[0]) as i32);
2188 let v2 = g.bool();
2189 let v3 = g.bool();
2190 let v4 = {
2191 let v5 = g.count();
2192 let mut v6 = Vec::with_capacity(v5.min(crate::codec::PREALLOC_LIMIT));
2193 for _ in 0..v5 {
2194 v6.push((g.int_in(-2147483648, 2147483647, &[]) as i32));
2195 }
2196 v6
2197 };
2198 let v7 = if (v1 == 0) {
2199 Some({
2200 let v8 = g.count();
2201 let mut v9 = Vec::with_capacity(v8.min(crate::codec::PREALLOC_LIMIT));
2202 for _ in 0..v8 {
2203 v9.push((g.int_in(-2147483648, 2147483647, &[]) as i32));
2204 }
2205 v9
2206 })
2207 } else {
2208 None
2209 };
2210 Self {
2211 action: v1,
2212 crafting_book_open: v2,
2213 filtering_craftable: v3,
2214 recipes1: v4,
2215 recipes2: v7,
2216 }
2217 }
2218 }
2219}
2220
2221#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
2222#[derive(Debug, Clone, PartialEq)]
2224pub struct SelectAdvancementTab<const V: i32> {
2225 pub id: Option<ByteString>,
2227}
2228#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
2229impl<const V: i32> Decode for SelectAdvancementTab<V> {
2230 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2231 Ok({
2232 let v1 = if r.read_bool()? {
2233 Some(r.read_string()?)
2234 } else {
2235 None
2236 };
2237 Self { id: v1 }
2238 })
2239 }
2240}
2241#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
2242impl<const V: i32> Encode for SelectAdvancementTab<V> {
2243 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2244 match &(*self).id {
2245 Some(v1) => {
2246 w.put_u8(1);
2247 w.put_string(&(*v1))?;
2248 }
2249 None => w.put_u8(0),
2250 }
2251 Ok(())
2252 }
2253}
2254#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
2255#[cfg(feature = "testgen")]
2256impl<const V: i32> Generate for SelectAdvancementTab<V> {
2257 fn generate(g: &mut Gen) -> Self {
2258 {
2259 let v1 = if g.bool() { Some(g.string()) } else { None };
2260 Self { id: v1 }
2261 }
2262 }
2263}
2264
2265#[cfg(feature = "v1_12_2")]
2266#[derive(Debug, Clone, PartialEq)]
2268pub struct EntityMetadata<const V: i32> {
2269 pub entity_id: i32,
2271 pub metadata: Vec<crate::defs::p340::types::EntityMetadataEntry>,
2273}
2274#[cfg(feature = "v1_12_2")]
2275impl<const V: i32> Decode for EntityMetadata<V> {
2276 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2277 Ok({
2278 let v1 = r.read_varint()?;
2279 let v2 = {
2280 let mut v3 = Vec::new();
2281 loop {
2282 if r.peek_u8()? == 255 {
2283 r.skip(1)?;
2284 break;
2285 }
2286 v3.push({
2287 let v4 = r.read_u8()?;
2288 let v5 = r.read_i8()?;
2289 let v6 = (if (v5 == 0) {
2290 crate::defs::p340::types::EntityMetadataValue::Byte(r.read_i8()?)
2291 } else if (v5 == 1) {
2292 crate::defs::p340::types::EntityMetadataValue::VarInt(r.read_varint()?)
2293 } else if (v5 == 2) {
2294 crate::defs::p340::types::EntityMetadataValue::Float(r.read_f32()?)
2295 } else if (v5 == 3) {
2296 crate::defs::p340::types::EntityMetadataValue::String(r.read_string()?)
2297 } else if (v5 == 4) {
2298 crate::defs::p340::types::EntityMetadataValue::Chat(r.read_string()?)
2299 } else if (v5 == 5) {
2300 crate::defs::p340::types::EntityMetadataValue::Slot(
2301 <crate::types::slot::legacy::Slot as Decode>::decode(r)?,
2302 )
2303 } else if (v5 == 6) {
2304 crate::defs::p340::types::EntityMetadataValue::Boolean(r.read_bool()?)
2305 } else if (v5 == 7) {
2306 crate::defs::p340::types::EntityMetadataValue::Rotation({
2307 let v7 = r.read_f32()?;
2308 let v8 = r.read_f32()?;
2309 let v9 = r.read_f32()?;
2310 crate::defs::p47::types::EntityMetadataValueRotation {
2311 pitch: v7,
2312 yaw: v8,
2313 roll: v9,
2314 }
2315 })
2316 } else if (v5 == 8) {
2317 crate::defs::p340::types::EntityMetadataValue::Position(BlockPos::read(
2318 r,
2319 PositionLayout::Xyz,
2320 )?)
2321 } else if (v5 == 9) {
2322 crate::defs::p340::types::EntityMetadataValue::OptPosition(
2323 if r.read_bool()? {
2324 Some(BlockPos::read(r, PositionLayout::Xyz)?)
2325 } else {
2326 None
2327 },
2328 )
2329 } else if (v5 == 10) {
2330 crate::defs::p340::types::EntityMetadataValue::Direction(
2331 r.read_varint()?,
2332 )
2333 } else if (v5 == 11) {
2334 crate::defs::p340::types::EntityMetadataValue::OptUuid(
2335 if r.read_bool()? {
2336 Some(r.read_uuid()?)
2337 } else {
2338 None
2339 },
2340 )
2341 } else if (v5 == 12) {
2342 crate::defs::p340::types::EntityMetadataValue::BlockState(
2343 r.read_varint()?,
2344 )
2345 } else if (v5 == 13) {
2346 crate::defs::p340::types::EntityMetadataValue::Nbt(RawNbt::read(r)?)
2347 } else {
2348 crate::defs::p340::types::EntityMetadataValue::Other
2349 });
2350 crate::defs::p340::types::EntityMetadataEntry {
2351 key: v4,
2352 r#type: v5,
2353 value: v6,
2354 }
2355 });
2356 }
2357 v3
2358 };
2359 Self {
2360 entity_id: v1,
2361 metadata: v2,
2362 }
2363 })
2364 }
2365}
2366#[cfg(feature = "v1_12_2")]
2367impl<const V: i32> Encode for EntityMetadata<V> {
2368 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2369 w.put_varint((*self).entity_id);
2370 for v1 in (*self).metadata.iter() {
2371 let v2 = w.len();
2372 w.put_u8((*v1).key);
2373 w.put_i8((*v1).r#type);
2374 match &(*v1).value {
2375 crate::defs::p340::types::EntityMetadataValue::Byte(v3) => {
2376 if !((*v1).r#type == 0) {
2377 return Err(EncodeError::SwitchMismatch(
2378 "play.clientbound.entity_metadata.metadata.value",
2379 ));
2380 }
2381 w.put_i8((*v3));
2382 }
2383 crate::defs::p340::types::EntityMetadataValue::VarInt(v4) => {
2384 if !((*v1).r#type == 1) {
2385 return Err(EncodeError::SwitchMismatch(
2386 "play.clientbound.entity_metadata.metadata.value",
2387 ));
2388 }
2389 w.put_varint((*v4));
2390 }
2391 crate::defs::p340::types::EntityMetadataValue::Float(v5) => {
2392 if !((*v1).r#type == 2) {
2393 return Err(EncodeError::SwitchMismatch(
2394 "play.clientbound.entity_metadata.metadata.value",
2395 ));
2396 }
2397 w.put_f32((*v5));
2398 }
2399 crate::defs::p340::types::EntityMetadataValue::String(v6) => {
2400 if !((*v1).r#type == 3) {
2401 return Err(EncodeError::SwitchMismatch(
2402 "play.clientbound.entity_metadata.metadata.value",
2403 ));
2404 }
2405 w.put_string(&(*v6))?;
2406 }
2407 crate::defs::p340::types::EntityMetadataValue::Chat(v7) => {
2408 if !((*v1).r#type == 4) {
2409 return Err(EncodeError::SwitchMismatch(
2410 "play.clientbound.entity_metadata.metadata.value",
2411 ));
2412 }
2413 w.put_string(&(*v7))?;
2414 }
2415 crate::defs::p340::types::EntityMetadataValue::Slot(v8) => {
2416 if !((*v1).r#type == 5) {
2417 return Err(EncodeError::SwitchMismatch(
2418 "play.clientbound.entity_metadata.metadata.value",
2419 ));
2420 }
2421 (*v8).encode(w)?;
2422 }
2423 crate::defs::p340::types::EntityMetadataValue::Boolean(v9) => {
2424 if !((*v1).r#type == 6) {
2425 return Err(EncodeError::SwitchMismatch(
2426 "play.clientbound.entity_metadata.metadata.value",
2427 ));
2428 }
2429 w.put_bool((*v9));
2430 }
2431 crate::defs::p340::types::EntityMetadataValue::Rotation(v10) => {
2432 if !((*v1).r#type == 7) {
2433 return Err(EncodeError::SwitchMismatch(
2434 "play.clientbound.entity_metadata.metadata.value",
2435 ));
2436 }
2437 w.put_f32((*v10).pitch);
2438 w.put_f32((*v10).yaw);
2439 w.put_f32((*v10).roll);
2440 }
2441 crate::defs::p340::types::EntityMetadataValue::Position(v11) => {
2442 if !((*v1).r#type == 8) {
2443 return Err(EncodeError::SwitchMismatch(
2444 "play.clientbound.entity_metadata.metadata.value",
2445 ));
2446 }
2447 (*v11).write(w, PositionLayout::Xyz)?;
2448 }
2449 crate::defs::p340::types::EntityMetadataValue::OptPosition(v12) => {
2450 if !((*v1).r#type == 9) {
2451 return Err(EncodeError::SwitchMismatch(
2452 "play.clientbound.entity_metadata.metadata.value",
2453 ));
2454 }
2455 match &(*v12) {
2456 Some(v13) => {
2457 w.put_u8(1);
2458 (*v13).write(w, PositionLayout::Xyz)?;
2459 }
2460 None => w.put_u8(0),
2461 }
2462 }
2463 crate::defs::p340::types::EntityMetadataValue::Direction(v14) => {
2464 if !((*v1).r#type == 10) {
2465 return Err(EncodeError::SwitchMismatch(
2466 "play.clientbound.entity_metadata.metadata.value",
2467 ));
2468 }
2469 w.put_varint((*v14));
2470 }
2471 crate::defs::p340::types::EntityMetadataValue::OptUuid(v15) => {
2472 if !((*v1).r#type == 11) {
2473 return Err(EncodeError::SwitchMismatch(
2474 "play.clientbound.entity_metadata.metadata.value",
2475 ));
2476 }
2477 match &(*v15) {
2478 Some(v16) => {
2479 w.put_u8(1);
2480 w.put_uuid(&(*v16));
2481 }
2482 None => w.put_u8(0),
2483 }
2484 }
2485 crate::defs::p340::types::EntityMetadataValue::BlockState(v17) => {
2486 if !((*v1).r#type == 12) {
2487 return Err(EncodeError::SwitchMismatch(
2488 "play.clientbound.entity_metadata.metadata.value",
2489 ));
2490 }
2491 w.put_varint((*v17));
2492 }
2493 crate::defs::p340::types::EntityMetadataValue::Nbt(v18) => {
2494 if !((*v1).r#type == 13) {
2495 return Err(EncodeError::SwitchMismatch(
2496 "play.clientbound.entity_metadata.metadata.value",
2497 ));
2498 }
2499 (*v18).write(w);
2500 }
2501 crate::defs::p340::types::EntityMetadataValue::Other => {
2502 if !(!(((*v1).r#type == 0)
2503 || ((*v1).r#type == 1)
2504 || ((*v1).r#type == 2)
2505 || ((*v1).r#type == 3)
2506 || ((*v1).r#type == 4)
2507 || ((*v1).r#type == 5)
2508 || ((*v1).r#type == 6)
2509 || ((*v1).r#type == 7)
2510 || ((*v1).r#type == 8)
2511 || ((*v1).r#type == 9)
2512 || ((*v1).r#type == 10)
2513 || ((*v1).r#type == 11)
2514 || ((*v1).r#type == 12)
2515 || ((*v1).r#type == 13)))
2516 {
2517 return Err(EncodeError::SwitchMismatch(
2518 "play.clientbound.entity_metadata.metadata.value",
2519 ));
2520 }
2521 }
2522 }
2523 if w.get(v2) == Some(&255) {
2524 return Err(EncodeError::OutOfRange(
2525 "play.clientbound.entity_metadata.metadata",
2526 ));
2527 }
2528 }
2529 w.put_u8(255);
2530 Ok(())
2531 }
2532}
2533#[cfg(feature = "v1_12_2")]
2534#[cfg(feature = "testgen")]
2535impl<const V: i32> Generate for EntityMetadata<V> {
2536 fn generate(g: &mut Gen) -> Self {
2537 {
2538 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2539 let v2 = {
2540 let n = g.count();
2541 let mut v3 = Vec::with_capacity(n);
2542 for _ in 0..n {
2543 v3.push(loop {
2544 let v4 = {
2545 let v5 = (g.int_in(0, 255, &[]) as u8);
2546 let v6 = (g.int_in(
2547 -128,
2548 127,
2549 &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
2550 ) as i8);
2551 let v7 = (if (v6 == 0) {
2552 crate::defs::p340::types::EntityMetadataValue::Byte(
2553 (g.int_in(-128, 127, &[]) as i8),
2554 )
2555 } else if (v6 == 1) {
2556 crate::defs::p340::types::EntityMetadataValue::VarInt(
2557 (g.int_in(-2147483648, 2147483647, &[]) as i32),
2558 )
2559 } else if (v6 == 2) {
2560 crate::defs::p340::types::EntityMetadataValue::Float(g.f32())
2561 } else if (v6 == 3) {
2562 crate::defs::p340::types::EntityMetadataValue::String(g.string())
2563 } else if (v6 == 4) {
2564 crate::defs::p340::types::EntityMetadataValue::Chat(g.string())
2565 } else if (v6 == 5) {
2566 crate::defs::p340::types::EntityMetadataValue::Slot(
2567 <crate::types::slot::legacy::Slot as Generate>::generate(g),
2568 )
2569 } else if (v6 == 6) {
2570 crate::defs::p340::types::EntityMetadataValue::Boolean(g.bool())
2571 } else if (v6 == 7) {
2572 crate::defs::p340::types::EntityMetadataValue::Rotation({
2573 let v8 = g.f32();
2574 let v9 = g.f32();
2575 let v10 = g.f32();
2576 crate::defs::p47::types::EntityMetadataValueRotation {
2577 pitch: v8,
2578 yaw: v9,
2579 roll: v10,
2580 }
2581 })
2582 } else if (v6 == 8) {
2583 crate::defs::p340::types::EntityMetadataValue::Position(
2584 g.position(),
2585 )
2586 } else if (v6 == 9) {
2587 crate::defs::p340::types::EntityMetadataValue::OptPosition(
2588 if g.bool() { Some(g.position()) } else { None },
2589 )
2590 } else if (v6 == 10) {
2591 crate::defs::p340::types::EntityMetadataValue::Direction(
2592 (g.int_in(-2147483648, 2147483647, &[]) as i32),
2593 )
2594 } else if (v6 == 11) {
2595 crate::defs::p340::types::EntityMetadataValue::OptUuid(
2596 if g.bool() { Some(g.uuid()) } else { None },
2597 )
2598 } else if (v6 == 12) {
2599 crate::defs::p340::types::EntityMetadataValue::BlockState(
2600 (g.int_in(-2147483648, 2147483647, &[]) as i32),
2601 )
2602 } else if (v6 == 13) {
2603 crate::defs::p340::types::EntityMetadataValue::Nbt(g.nbt())
2604 } else {
2605 crate::defs::p340::types::EntityMetadataValue::Other
2606 });
2607 crate::defs::p340::types::EntityMetadataEntry {
2608 key: v5,
2609 r#type: v6,
2610 value: v7,
2611 }
2612 };
2613 if crate::testgen::first_byte_ok(
2614 |w: &mut BytesMut| -> EncodeResult {
2615 w.put_u8(v4.key);
2616 w.put_i8(v4.r#type);
2617 match &v4.value {
2618 crate::defs::p340::types::EntityMetadataValue::Byte(v11) => {
2619 if !(v4.r#type == 0) {
2620 return Err(EncodeError::SwitchMismatch(
2621 "play.clientbound.entity_metadata.metadata.value",
2622 ));
2623 }
2624 w.put_i8((*v11));
2625 }
2626 crate::defs::p340::types::EntityMetadataValue::VarInt(v12) => {
2627 if !(v4.r#type == 1) {
2628 return Err(EncodeError::SwitchMismatch(
2629 "play.clientbound.entity_metadata.metadata.value",
2630 ));
2631 }
2632 w.put_varint((*v12));
2633 }
2634 crate::defs::p340::types::EntityMetadataValue::Float(v13) => {
2635 if !(v4.r#type == 2) {
2636 return Err(EncodeError::SwitchMismatch(
2637 "play.clientbound.entity_metadata.metadata.value",
2638 ));
2639 }
2640 w.put_f32((*v13));
2641 }
2642 crate::defs::p340::types::EntityMetadataValue::String(v14) => {
2643 if !(v4.r#type == 3) {
2644 return Err(EncodeError::SwitchMismatch(
2645 "play.clientbound.entity_metadata.metadata.value",
2646 ));
2647 }
2648 w.put_string(&(*v14))?;
2649 }
2650 crate::defs::p340::types::EntityMetadataValue::Chat(v15) => {
2651 if !(v4.r#type == 4) {
2652 return Err(EncodeError::SwitchMismatch(
2653 "play.clientbound.entity_metadata.metadata.value",
2654 ));
2655 }
2656 w.put_string(&(*v15))?;
2657 }
2658 crate::defs::p340::types::EntityMetadataValue::Slot(v16) => {
2659 if !(v4.r#type == 5) {
2660 return Err(EncodeError::SwitchMismatch(
2661 "play.clientbound.entity_metadata.metadata.value",
2662 ));
2663 }
2664 (*v16).encode(w)?;
2665 }
2666 crate::defs::p340::types::EntityMetadataValue::Boolean(v17) => {
2667 if !(v4.r#type == 6) {
2668 return Err(EncodeError::SwitchMismatch(
2669 "play.clientbound.entity_metadata.metadata.value",
2670 ));
2671 }
2672 w.put_bool((*v17));
2673 }
2674 crate::defs::p340::types::EntityMetadataValue::Rotation(
2675 v18,
2676 ) => {
2677 if !(v4.r#type == 7) {
2678 return Err(EncodeError::SwitchMismatch(
2679 "play.clientbound.entity_metadata.metadata.value",
2680 ));
2681 }
2682 w.put_f32((*v18).pitch);
2683 w.put_f32((*v18).yaw);
2684 w.put_f32((*v18).roll);
2685 }
2686 crate::defs::p340::types::EntityMetadataValue::Position(
2687 v19,
2688 ) => {
2689 if !(v4.r#type == 8) {
2690 return Err(EncodeError::SwitchMismatch(
2691 "play.clientbound.entity_metadata.metadata.value",
2692 ));
2693 }
2694 (*v19).write(w, PositionLayout::Xyz)?;
2695 }
2696 crate::defs::p340::types::EntityMetadataValue::OptPosition(
2697 v20,
2698 ) => {
2699 if !(v4.r#type == 9) {
2700 return Err(EncodeError::SwitchMismatch(
2701 "play.clientbound.entity_metadata.metadata.value",
2702 ));
2703 }
2704 match &(*v20) {
2705 Some(v21) => {
2706 w.put_u8(1);
2707 (*v21).write(w, PositionLayout::Xyz)?;
2708 }
2709 None => w.put_u8(0),
2710 }
2711 }
2712 crate::defs::p340::types::EntityMetadataValue::Direction(
2713 v22,
2714 ) => {
2715 if !(v4.r#type == 10) {
2716 return Err(EncodeError::SwitchMismatch(
2717 "play.clientbound.entity_metadata.metadata.value",
2718 ));
2719 }
2720 w.put_varint((*v22));
2721 }
2722 crate::defs::p340::types::EntityMetadataValue::OptUuid(v23) => {
2723 if !(v4.r#type == 11) {
2724 return Err(EncodeError::SwitchMismatch(
2725 "play.clientbound.entity_metadata.metadata.value",
2726 ));
2727 }
2728 match &(*v23) {
2729 Some(v24) => {
2730 w.put_u8(1);
2731 w.put_uuid(&(*v24));
2732 }
2733 None => w.put_u8(0),
2734 }
2735 }
2736 crate::defs::p340::types::EntityMetadataValue::BlockState(
2737 v25,
2738 ) => {
2739 if !(v4.r#type == 12) {
2740 return Err(EncodeError::SwitchMismatch(
2741 "play.clientbound.entity_metadata.metadata.value",
2742 ));
2743 }
2744 w.put_varint((*v25));
2745 }
2746 crate::defs::p340::types::EntityMetadataValue::Nbt(v26) => {
2747 if !(v4.r#type == 13) {
2748 return Err(EncodeError::SwitchMismatch(
2749 "play.clientbound.entity_metadata.metadata.value",
2750 ));
2751 }
2752 (*v26).write(w);
2753 }
2754 crate::defs::p340::types::EntityMetadataValue::Other => {
2755 if !(!((v4.r#type == 0)
2756 || (v4.r#type == 1)
2757 || (v4.r#type == 2)
2758 || (v4.r#type == 3)
2759 || (v4.r#type == 4)
2760 || (v4.r#type == 5)
2761 || (v4.r#type == 6)
2762 || (v4.r#type == 7)
2763 || (v4.r#type == 8)
2764 || (v4.r#type == 9)
2765 || (v4.r#type == 10)
2766 || (v4.r#type == 11)
2767 || (v4.r#type == 12)
2768 || (v4.r#type == 13)))
2769 {
2770 return Err(EncodeError::SwitchMismatch(
2771 "play.clientbound.entity_metadata.metadata.value",
2772 ));
2773 }
2774 }
2775 }
2776 Ok(())
2777 },
2778 |b| b != 255,
2779 ) {
2780 break v4;
2781 }
2782 });
2783 }
2784 v3
2785 };
2786 Self {
2787 entity_id: v1,
2788 metadata: v2,
2789 }
2790 }
2791 }
2792}
2793
2794#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
2795#[derive(Debug, Clone, PartialEq)]
2797pub struct AttachEntity<const V: i32> {
2798 pub entity_id: i32,
2800 pub vehicle_id: i32,
2802}
2803#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
2804impl<const V: i32> Decode for AttachEntity<V> {
2805 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2806 Ok({
2807 let v1 = r.read_i32()?;
2808 let v2 = r.read_i32()?;
2809 Self {
2810 entity_id: v1,
2811 vehicle_id: v2,
2812 }
2813 })
2814 }
2815}
2816#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
2817impl<const V: i32> Encode for AttachEntity<V> {
2818 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2819 w.put_i32((*self).entity_id);
2820 w.put_i32((*self).vehicle_id);
2821 Ok(())
2822 }
2823}
2824#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
2825#[cfg(feature = "testgen")]
2826impl<const V: i32> Generate for AttachEntity<V> {
2827 fn generate(g: &mut Gen) -> Self {
2828 {
2829 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2830 let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2831 Self {
2832 entity_id: v1,
2833 vehicle_id: v2,
2834 }
2835 }
2836 }
2837}
2838
2839#[cfg(feature = "v1_12_2")]
2840#[derive(Debug, Clone, PartialEq)]
2842pub struct EntityEquipment<const V: i32> {
2843 pub entity_id: i32,
2845 pub slot: i32,
2847 pub item: crate::types::slot::legacy::Slot,
2849}
2850#[cfg(feature = "v1_12_2")]
2851impl<const V: i32> Decode for EntityEquipment<V> {
2852 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2853 Ok({
2854 let v1 = r.read_varint()?;
2855 let v2 = r.read_varint()?;
2856 let v3 = <crate::types::slot::legacy::Slot as Decode>::decode(r)?;
2857 Self {
2858 entity_id: v1,
2859 slot: v2,
2860 item: v3,
2861 }
2862 })
2863 }
2864}
2865#[cfg(feature = "v1_12_2")]
2866impl<const V: i32> Encode for EntityEquipment<V> {
2867 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2868 w.put_varint((*self).entity_id);
2869 w.put_varint((*self).slot);
2870 (*self).item.encode(w)?;
2871 Ok(())
2872 }
2873}
2874#[cfg(feature = "v1_12_2")]
2875#[cfg(feature = "testgen")]
2876impl<const V: i32> Generate for EntityEquipment<V> {
2877 fn generate(g: &mut Gen) -> Self {
2878 {
2879 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2880 let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2881 let v3 = <crate::types::slot::legacy::Slot as Generate>::generate(g);
2882 Self {
2883 entity_id: v1,
2884 slot: v2,
2885 item: v3,
2886 }
2887 }
2888 }
2889}
2890
2891#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
2892#[derive(Debug, Clone, PartialEq)]
2894pub struct SetPassengers<const V: i32> {
2895 pub entity_id: i32,
2897 pub passengers: Vec<i32>,
2899}
2900#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
2901impl<const V: i32> Decode for SetPassengers<V> {
2902 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2903 Ok({
2904 let v1 = r.read_varint()?;
2905 let v2 = {
2906 let v3 = {
2907 let c = r.read_varint()?;
2908 r.check_count(i64::from(c), 1)?
2909 };
2910 let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
2911 for _ in 0..v3 {
2912 v4.push(r.read_varint()?);
2913 }
2914 v4
2915 };
2916 Self {
2917 entity_id: v1,
2918 passengers: v2,
2919 }
2920 })
2921 }
2922}
2923#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
2924impl<const V: i32> Encode for SetPassengers<V> {
2925 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
2926 w.put_varint((*self).entity_id);
2927 w.put_len_varint((*self).passengers.len())?;
2928 for v1 in (*self).passengers.iter() {
2929 w.put_varint((*v1));
2930 }
2931 Ok(())
2932 }
2933}
2934#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
2935#[cfg(feature = "testgen")]
2936impl<const V: i32> Generate for SetPassengers<V> {
2937 fn generate(g: &mut Gen) -> Self {
2938 {
2939 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
2940 let v2 = {
2941 let v3 = g.count();
2942 let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
2943 for _ in 0..v3 {
2944 v4.push((g.int_in(-2147483648, 2147483647, &[]) as i32));
2945 }
2946 v4
2947 };
2948 Self {
2949 entity_id: v1,
2950 passengers: v2,
2951 }
2952 }
2953 }
2954}
2955
2956#[cfg(feature = "v1_12_2")]
2957#[derive(Debug, Clone, PartialEq)]
2959pub struct Teams<const V: i32> {
2960 pub team: ByteString,
2962 pub mode: i8,
2964 pub name: Option<ByteString>,
2966 pub prefix: Option<ByteString>,
2968 pub suffix: Option<ByteString>,
2970 pub friendly_fire: Option<i8>,
2972 pub name_tag_visibility: Option<ByteString>,
2974 pub collision_rule: Option<ByteString>,
2976 pub color: Option<i8>,
2978 pub players: Option<Vec<ByteString>>,
2980}
2981#[cfg(feature = "v1_12_2")]
2982impl<const V: i32> Decode for Teams<V> {
2983 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
2984 Ok({
2985 let v1 = r.read_string()?;
2986 let v2 = r.read_i8()?;
2987 let v3 = if (v2 == 0) || (v2 == 2) {
2988 Some(r.read_string()?)
2989 } else {
2990 None
2991 };
2992 let v4 = if (v2 == 0) || (v2 == 2) {
2993 Some(r.read_string()?)
2994 } else {
2995 None
2996 };
2997 let v5 = if (v2 == 0) || (v2 == 2) {
2998 Some(r.read_string()?)
2999 } else {
3000 None
3001 };
3002 let v6 = if (v2 == 0) || (v2 == 2) {
3003 Some(r.read_i8()?)
3004 } else {
3005 None
3006 };
3007 let v7 = if (v2 == 0) || (v2 == 2) {
3008 Some(r.read_string()?)
3009 } else {
3010 None
3011 };
3012 let v8 = if (v2 == 0) || (v2 == 2) {
3013 Some(r.read_string()?)
3014 } else {
3015 None
3016 };
3017 let v9 = if (v2 == 0) || (v2 == 2) {
3018 Some(r.read_i8()?)
3019 } else {
3020 None
3021 };
3022 let v10 = if (v2 == 0) || (v2 == 3) || (v2 == 4) {
3023 Some({
3024 let v11 = {
3025 let c = r.read_varint()?;
3026 r.check_count(i64::from(c), 1)?
3027 };
3028 let mut v12 = Vec::with_capacity(v11.min(crate::codec::PREALLOC_LIMIT));
3029 for _ in 0..v11 {
3030 v12.push(r.read_string()?);
3031 }
3032 v12
3033 })
3034 } else {
3035 None
3036 };
3037 Self {
3038 team: v1,
3039 mode: v2,
3040 name: v3,
3041 prefix: v4,
3042 suffix: v5,
3043 friendly_fire: v6,
3044 name_tag_visibility: v7,
3045 collision_rule: v8,
3046 color: v9,
3047 players: v10,
3048 }
3049 })
3050 }
3051}
3052#[cfg(feature = "v1_12_2")]
3053impl<const V: i32> Encode for Teams<V> {
3054 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3055 w.put_string(&(*self).team)?;
3056 w.put_i8((*self).mode);
3057 match (&(*self).name, ((*self).mode == 0) || ((*self).mode == 2)) {
3058 (Some(v1), true) => {
3059 w.put_string(&(*v1))?;
3060 }
3061 (None, false) => {}
3062 _ => return Err(EncodeError::SwitchMismatch("play.clientbound.teams.name")),
3063 }
3064 match (&(*self).prefix, ((*self).mode == 0) || ((*self).mode == 2)) {
3065 (Some(v2), true) => {
3066 w.put_string(&(*v2))?;
3067 }
3068 (None, false) => {}
3069 _ => return Err(EncodeError::SwitchMismatch("play.clientbound.teams.prefix")),
3070 }
3071 match (&(*self).suffix, ((*self).mode == 0) || ((*self).mode == 2)) {
3072 (Some(v3), true) => {
3073 w.put_string(&(*v3))?;
3074 }
3075 (None, false) => {}
3076 _ => return Err(EncodeError::SwitchMismatch("play.clientbound.teams.suffix")),
3077 }
3078 match (
3079 &(*self).friendly_fire,
3080 ((*self).mode == 0) || ((*self).mode == 2),
3081 ) {
3082 (Some(v4), true) => {
3083 w.put_i8((*v4));
3084 }
3085 (None, false) => {}
3086 _ => {
3087 return Err(EncodeError::SwitchMismatch(
3088 "play.clientbound.teams.friendlyFire",
3089 ));
3090 }
3091 }
3092 match (
3093 &(*self).name_tag_visibility,
3094 ((*self).mode == 0) || ((*self).mode == 2),
3095 ) {
3096 (Some(v5), true) => {
3097 w.put_string(&(*v5))?;
3098 }
3099 (None, false) => {}
3100 _ => {
3101 return Err(EncodeError::SwitchMismatch(
3102 "play.clientbound.teams.nameTagVisibility",
3103 ));
3104 }
3105 }
3106 match (
3107 &(*self).collision_rule,
3108 ((*self).mode == 0) || ((*self).mode == 2),
3109 ) {
3110 (Some(v6), true) => {
3111 w.put_string(&(*v6))?;
3112 }
3113 (None, false) => {}
3114 _ => {
3115 return Err(EncodeError::SwitchMismatch(
3116 "play.clientbound.teams.collisionRule",
3117 ));
3118 }
3119 }
3120 match (&(*self).color, ((*self).mode == 0) || ((*self).mode == 2)) {
3121 (Some(v7), true) => {
3122 w.put_i8((*v7));
3123 }
3124 (None, false) => {}
3125 _ => return Err(EncodeError::SwitchMismatch("play.clientbound.teams.color")),
3126 }
3127 match (
3128 &(*self).players,
3129 ((*self).mode == 0) || ((*self).mode == 3) || ((*self).mode == 4),
3130 ) {
3131 (Some(v8), true) => {
3132 w.put_len_varint((*v8).len())?;
3133 for v9 in (*v8).iter() {
3134 w.put_string(&(*v9))?;
3135 }
3136 }
3137 (None, false) => {}
3138 _ => {
3139 return Err(EncodeError::SwitchMismatch(
3140 "play.clientbound.teams.players",
3141 ));
3142 }
3143 }
3144 Ok(())
3145 }
3146}
3147#[cfg(feature = "v1_12_2")]
3148#[cfg(feature = "testgen")]
3149impl<const V: i32> Generate for Teams<V> {
3150 fn generate(g: &mut Gen) -> Self {
3151 {
3152 let v1 = g.string();
3153 let v2 = (g.int_in(
3154 -128,
3155 127,
3156 &[0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 3, 4],
3157 ) as i8);
3158 let v3 = if (v2 == 0) || (v2 == 2) {
3159 Some(g.string())
3160 } else {
3161 None
3162 };
3163 let v4 = if (v2 == 0) || (v2 == 2) {
3164 Some(g.string())
3165 } else {
3166 None
3167 };
3168 let v5 = if (v2 == 0) || (v2 == 2) {
3169 Some(g.string())
3170 } else {
3171 None
3172 };
3173 let v6 = if (v2 == 0) || (v2 == 2) {
3174 Some((g.int_in(-128, 127, &[]) as i8))
3175 } else {
3176 None
3177 };
3178 let v7 = if (v2 == 0) || (v2 == 2) {
3179 Some(g.string())
3180 } else {
3181 None
3182 };
3183 let v8 = if (v2 == 0) || (v2 == 2) {
3184 Some(g.string())
3185 } else {
3186 None
3187 };
3188 let v9 = if (v2 == 0) || (v2 == 2) {
3189 Some((g.int_in(-128, 127, &[]) as i8))
3190 } else {
3191 None
3192 };
3193 let v10 = if (v2 == 0) || (v2 == 3) || (v2 == 4) {
3194 Some({
3195 let v11 = g.count();
3196 let mut v12 = Vec::with_capacity(v11.min(crate::codec::PREALLOC_LIMIT));
3197 for _ in 0..v11 {
3198 v12.push(g.string());
3199 }
3200 v12
3201 })
3202 } else {
3203 None
3204 };
3205 Self {
3206 team: v1,
3207 mode: v2,
3208 name: v3,
3209 prefix: v4,
3210 suffix: v5,
3211 friendly_fire: v6,
3212 name_tag_visibility: v7,
3213 collision_rule: v8,
3214 color: v9,
3215 players: v10,
3216 }
3217 }
3218 }
3219}
3220
3221#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3222#[derive(Debug, Clone, PartialEq)]
3224pub struct Title<const V: i32> {
3225 pub action: i32,
3227 pub text: Option<ByteString>,
3229 pub fade_in: Option<i32>,
3231 pub stay: Option<i32>,
3233 pub fade_out: Option<i32>,
3235}
3236#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3237impl<const V: i32> Decode for Title<V> {
3238 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3239 Ok({
3240 let v1 = r.read_varint()?;
3241 let v2 = if (v1 == 0) || (v1 == 1) || (v1 == 2) {
3242 Some(r.read_string()?)
3243 } else {
3244 None
3245 };
3246 let v3 = if (v1 == 3) { Some(r.read_i32()?) } else { None };
3247 let v4 = if (v1 == 3) { Some(r.read_i32()?) } else { None };
3248 let v5 = if (v1 == 3) { Some(r.read_i32()?) } else { None };
3249 Self {
3250 action: v1,
3251 text: v2,
3252 fade_in: v3,
3253 stay: v4,
3254 fade_out: v5,
3255 }
3256 })
3257 }
3258}
3259#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3260impl<const V: i32> Encode for Title<V> {
3261 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3262 w.put_varint((*self).action);
3263 match (
3264 &(*self).text,
3265 ((*self).action == 0) || ((*self).action == 1) || ((*self).action == 2),
3266 ) {
3267 (Some(v1), true) => {
3268 w.put_string(&(*v1))?;
3269 }
3270 (None, false) => {}
3271 _ => return Err(EncodeError::SwitchMismatch("play.clientbound.title.text")),
3272 }
3273 match (&(*self).fade_in, ((*self).action == 3)) {
3274 (Some(v2), true) => {
3275 w.put_i32((*v2));
3276 }
3277 (None, false) => {}
3278 _ => return Err(EncodeError::SwitchMismatch("play.clientbound.title.fadeIn")),
3279 }
3280 match (&(*self).stay, ((*self).action == 3)) {
3281 (Some(v3), true) => {
3282 w.put_i32((*v3));
3283 }
3284 (None, false) => {}
3285 _ => return Err(EncodeError::SwitchMismatch("play.clientbound.title.stay")),
3286 }
3287 match (&(*self).fade_out, ((*self).action == 3)) {
3288 (Some(v4), true) => {
3289 w.put_i32((*v4));
3290 }
3291 (None, false) => {}
3292 _ => {
3293 return Err(EncodeError::SwitchMismatch(
3294 "play.clientbound.title.fadeOut",
3295 ));
3296 }
3297 }
3298 Ok(())
3299 }
3300}
3301#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3302#[cfg(feature = "testgen")]
3303impl<const V: i32> Generate for Title<V> {
3304 fn generate(g: &mut Gen) -> Self {
3305 {
3306 let v1 = (g.int_in(-2147483648, 2147483647, &[0, 1, 2, 3, 3, 3]) as i32);
3307 let v2 = if (v1 == 0) || (v1 == 1) || (v1 == 2) {
3308 Some(g.string())
3309 } else {
3310 None
3311 };
3312 let v3 = if (v1 == 3) {
3313 Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
3314 } else {
3315 None
3316 };
3317 let v4 = if (v1 == 3) {
3318 Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
3319 } else {
3320 None
3321 };
3322 let v5 = if (v1 == 3) {
3323 Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
3324 } else {
3325 None
3326 };
3327 Self {
3328 action: v1,
3329 text: v2,
3330 fade_in: v3,
3331 stay: v4,
3332 fade_out: v5,
3333 }
3334 }
3335 }
3336}
3337
3338#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3339#[derive(Debug, Clone, PartialEq)]
3341pub struct SoundEffect<const V: i32> {
3342 pub sound_id: i32,
3344 pub sound_category: i32,
3346 pub x: i32,
3348 pub y: i32,
3350 pub z: i32,
3352 pub volume: f32,
3354 pub pitch: f32,
3356}
3357#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3358impl<const V: i32> Decode for SoundEffect<V> {
3359 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3360 Ok({
3361 let v1 = r.read_varint()?;
3362 let v2 = r.read_varint()?;
3363 let v3 = r.read_i32()?;
3364 let v4 = r.read_i32()?;
3365 let v5 = r.read_i32()?;
3366 let v6 = r.read_f32()?;
3367 let v7 = r.read_f32()?;
3368 Self {
3369 sound_id: v1,
3370 sound_category: v2,
3371 x: v3,
3372 y: v4,
3373 z: v5,
3374 volume: v6,
3375 pitch: v7,
3376 }
3377 })
3378 }
3379}
3380#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3381impl<const V: i32> Encode for SoundEffect<V> {
3382 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3383 w.put_varint((*self).sound_id);
3384 w.put_varint((*self).sound_category);
3385 w.put_i32((*self).x);
3386 w.put_i32((*self).y);
3387 w.put_i32((*self).z);
3388 w.put_f32((*self).volume);
3389 w.put_f32((*self).pitch);
3390 Ok(())
3391 }
3392}
3393#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3394#[cfg(feature = "testgen")]
3395impl<const V: i32> Generate for SoundEffect<V> {
3396 fn generate(g: &mut Gen) -> Self {
3397 {
3398 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3399 let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3400 let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3401 let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3402 let v5 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3403 let v6 = g.f32();
3404 let v7 = g.f32();
3405 Self {
3406 sound_id: v1,
3407 sound_category: v2,
3408 x: v3,
3409 y: v4,
3410 z: v5,
3411 volume: v6,
3412 pitch: v7,
3413 }
3414 }
3415 }
3416}
3417
3418#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
3419#[derive(Debug, Clone, PartialEq)]
3421pub struct Collect<const V: i32> {
3422 pub collected_entity_id: i32,
3424 pub collector_entity_id: i32,
3426 pub pickup_item_count: i32,
3428}
3429#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
3430impl<const V: i32> Decode for Collect<V> {
3431 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3432 Ok({
3433 let v1 = r.read_varint()?;
3434 let v2 = r.read_varint()?;
3435 let v3 = r.read_varint()?;
3436 Self {
3437 collected_entity_id: v1,
3438 collector_entity_id: v2,
3439 pickup_item_count: v3,
3440 }
3441 })
3442 }
3443}
3444#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
3445impl<const V: i32> Encode for Collect<V> {
3446 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3447 w.put_varint((*self).collected_entity_id);
3448 w.put_varint((*self).collector_entity_id);
3449 w.put_varint((*self).pickup_item_count);
3450 Ok(())
3451 }
3452}
3453#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
3454#[cfg(feature = "testgen")]
3455impl<const V: i32> Generate for Collect<V> {
3456 fn generate(g: &mut Gen) -> Self {
3457 {
3458 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3459 let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3460 let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3461 Self {
3462 collected_entity_id: v1,
3463 collector_entity_id: v2,
3464 pickup_item_count: v3,
3465 }
3466 }
3467 }
3468}
3469
3470#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3471#[derive(Debug, Clone, PartialEq)]
3473pub struct EntityTeleport<const V: i32> {
3474 pub entity_id: i32,
3476 pub x: f64,
3478 pub y: f64,
3480 pub z: f64,
3482 pub yaw: i8,
3484 pub pitch: i8,
3486 pub on_ground: bool,
3488}
3489#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3490impl<const V: i32> Decode for EntityTeleport<V> {
3491 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3492 Ok({
3493 let v1 = r.read_varint()?;
3494 let v2 = r.read_f64()?;
3495 let v3 = r.read_f64()?;
3496 let v4 = r.read_f64()?;
3497 let v5 = r.read_i8()?;
3498 let v6 = r.read_i8()?;
3499 let v7 = r.read_bool()?;
3500 Self {
3501 entity_id: v1,
3502 x: v2,
3503 y: v3,
3504 z: v4,
3505 yaw: v5,
3506 pitch: v6,
3507 on_ground: v7,
3508 }
3509 })
3510 }
3511}
3512#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3513impl<const V: i32> Encode for EntityTeleport<V> {
3514 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3515 w.put_varint((*self).entity_id);
3516 w.put_f64((*self).x);
3517 w.put_f64((*self).y);
3518 w.put_f64((*self).z);
3519 w.put_i8((*self).yaw);
3520 w.put_i8((*self).pitch);
3521 w.put_bool((*self).on_ground);
3522 Ok(())
3523 }
3524}
3525#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3526#[cfg(feature = "testgen")]
3527impl<const V: i32> Generate for EntityTeleport<V> {
3528 fn generate(g: &mut Gen) -> Self {
3529 {
3530 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3531 let v2 = g.f64();
3532 let v3 = g.f64();
3533 let v4 = g.f64();
3534 let v5 = (g.int_in(-128, 127, &[]) as i8);
3535 let v6 = (g.int_in(-128, 127, &[]) as i8);
3536 let v7 = g.bool();
3537 Self {
3538 entity_id: v1,
3539 x: v2,
3540 y: v3,
3541 z: v4,
3542 yaw: v5,
3543 pitch: v6,
3544 on_ground: v7,
3545 }
3546 }
3547 }
3548}
3549
3550#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3551#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
3553pub struct AdvancementsAdvancementMappingValueDisplayDataFlags {
3554 pub _unused: u32,
3556 pub hidden: u8,
3558 pub show_toast: u8,
3560 pub has_background_texture: u8,
3562}
3563
3564#[cfg(feature = "v1_12_2")]
3565#[derive(Debug, Clone, PartialEq)]
3567pub struct AdvancementsAdvancementMappingValueDisplayData {
3568 pub title: ByteString,
3570 pub description: ByteString,
3572 pub icon: crate::types::slot::legacy::Slot,
3574 pub frame_type: i32,
3576 pub flags:
3578 crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueDisplayDataFlags,
3579 pub background_texture: Option<ByteString>,
3581 pub x_cord: f32,
3583 pub y_cord: f32,
3585}
3586
3587#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3588#[derive(Debug, Clone, PartialEq)]
3590pub struct AdvancementsAdvancementMappingValueCriteria {
3591 pub key: ByteString,
3593}
3594
3595#[cfg(feature = "v1_12_2")]
3596#[derive(Debug, Clone, PartialEq)]
3598pub struct AdvancementsAdvancementMappingValue {
3599 pub parent_id: Option<ByteString>,
3601 pub display_data: Option<
3603 crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueDisplayData,
3604 >,
3605 pub criteria:
3607 Vec<crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueCriteria>,
3608 pub requirements: Vec<Vec<ByteString>>,
3610}
3611
3612#[cfg(feature = "v1_12_2")]
3613#[derive(Debug, Clone, PartialEq)]
3615pub struct AdvancementsAdvancementMapping {
3616 pub key: ByteString,
3618 pub value: crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValue,
3620}
3621
3622#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
3623#[derive(Debug, Clone, PartialEq)]
3625pub struct AdvancementsProgressMappingValue {
3626 pub criterion_identifier: ByteString,
3628 pub criterion_progress: Option<i64>,
3630}
3631
3632#[cfg(any(feature = "v1_12_2", feature = "v1_16_5", feature = "v26_1"))]
3633#[derive(Debug, Clone, PartialEq)]
3635pub struct AdvancementsProgressMapping {
3636 pub key: ByteString,
3638 pub value: Vec<crate::defs::p340::play::clientbound::AdvancementsProgressMappingValue>,
3640}
3641
3642#[cfg(feature = "v1_12_2")]
3643#[derive(Debug, Clone, PartialEq)]
3645pub struct Advancements<const V: i32> {
3646 pub reset: bool,
3648 pub advancement_mapping:
3650 Vec<crate::defs::p340::play::clientbound::AdvancementsAdvancementMapping>,
3651 pub identifiers: Vec<ByteString>,
3653 pub progress_mapping: Vec<crate::defs::p340::play::clientbound::AdvancementsProgressMapping>,
3655}
3656#[cfg(feature = "v1_12_2")]
3657impl<const V: i32> Decode for Advancements<V> {
3658 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3659 Ok({
3660 let v1 = r.read_bool()?;
3661 let v2 = {
3662 let v3 = {
3663 let c = r.read_varint()?;
3664 r.check_count(i64::from(c), 5)?
3665 };
3666 let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
3667 for _ in 0..v3 {
3668 v4.push({ let v5 = r.read_string()?;let v6 = { let v7 = if r.read_bool()? { Some(r.read_string()?) } else { None };let v8 = if r.read_bool()? { Some({ let v9 = r.read_string()?;let v10 = r.read_string()?;let v11 = <crate::types::slot::legacy::Slot as Decode>::decode(r)?;let v12 = r.read_varint()?;let v13 = { let v14 = u64::from(r.read_i32()? as u32); crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueDisplayDataFlags { _unused: (((v14 >> 3) & 0x1fffffff) as u32), hidden: (((v14 >> 2) & 0x1) as u8), show_toast: (((v14 >> 1) & 0x1) as u8), has_background_texture: (((v14 >> 0) & 0x1) as u8) } };let v15 = if (v13.has_background_texture == 1) { Some(r.read_string()?) } else { None };let v16 = r.read_f32()?;let v17 = r.read_f32()?; crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueDisplayData { title: v9, description: v10, icon: v11, frame_type: v12, flags: v13, background_texture: v15, x_cord: v16, y_cord: v17 } }) } else { None };let v18 = { let v19 = { let c = r.read_varint()?; r.check_count(i64::from(c), 1)? }; let mut v20 = Vec::with_capacity(v19.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v19 { v20.push({ let v21 = r.read_string()?; crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueCriteria { key: v21 } }); } v20 };let v23 = { let v24 = { let c = r.read_varint()?; r.check_count(i64::from(c), 1)? }; let mut v25 = Vec::with_capacity(v24.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v24 { v25.push({ let v26 = { let c = r.read_varint()?; r.check_count(i64::from(c), 1)? }; let mut v27 = Vec::with_capacity(v26.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v26 { v27.push(r.read_string()?); } v27 }); } v25 }; crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValue { parent_id: v7, display_data: v8, criteria: v18, requirements: v23 } }; crate::defs::p340::play::clientbound::AdvancementsAdvancementMapping { key: v5, value: v6 } });
3669 }
3670 v4
3671 };
3672 let v28 = {
3673 let v29 = {
3674 let c = r.read_varint()?;
3675 r.check_count(i64::from(c), 1)?
3676 };
3677 let mut v30 = Vec::with_capacity(v29.min(crate::codec::PREALLOC_LIMIT));
3678 for _ in 0..v29 {
3679 v30.push(r.read_string()?);
3680 }
3681 v30
3682 };
3683 let v31 = {
3684 let v32 = {
3685 let c = r.read_varint()?;
3686 r.check_count(i64::from(c), 2)?
3687 };
3688 let mut v33 = Vec::with_capacity(v32.min(crate::codec::PREALLOC_LIMIT));
3689 for _ in 0..v32 {
3690 v33.push({ let v34 = r.read_string()?;let v35 = { let v36 = { let c = r.read_varint()?; r.check_count(i64::from(c), 2)? }; let mut v37 = Vec::with_capacity(v36.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v36 { v37.push({ let v38 = r.read_string()?;let v39 = if r.read_bool()? { Some(r.read_i64()?) } else { None }; crate::defs::p340::play::clientbound::AdvancementsProgressMappingValue { criterion_identifier: v38, criterion_progress: v39 } }); } v37 }; crate::defs::p340::play::clientbound::AdvancementsProgressMapping { key: v34, value: v35 } });
3691 }
3692 v33
3693 };
3694 Self {
3695 reset: v1,
3696 advancement_mapping: v2,
3697 identifiers: v28,
3698 progress_mapping: v31,
3699 }
3700 })
3701 }
3702}
3703#[cfg(feature = "v1_12_2")]
3704impl<const V: i32> Encode for Advancements<V> {
3705 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3706 w.put_bool((*self).reset);
3707 w.put_len_varint((*self).advancement_mapping.len())?;
3708 for v1 in (*self).advancement_mapping.iter() {
3709 w.put_string(&(*v1).key)?;
3710 match &(*v1).value.parent_id {
3711 Some(v2) => {
3712 w.put_u8(1);
3713 w.put_string(&(*v2))?;
3714 }
3715 None => w.put_u8(0),
3716 }
3717 match &(*v1).value.display_data {
3718 Some(v3) => {
3719 w.put_u8(1);
3720 w.put_string(&(*v3).title)?;
3721 w.put_string(&(*v3).description)?;
3722 (*v3).icon.encode(w)?;
3723 w.put_varint((*v3).frame_type);
3724 {
3725 let mut bits: u64 = 0;
3726 {
3727 let x = i128::from((*v3).flags._unused);
3728 if x < 0 || x > 536870911 {
3729 return Err(EncodeError::OutOfRange("_unused"));
3730 }
3731 bits = (bits << 29) | ((x as u64) & 0x1fffffff);
3732 }
3733 {
3734 let x = i128::from((*v3).flags.hidden);
3735 if x < 0 || x > 1 {
3736 return Err(EncodeError::OutOfRange("hidden"));
3737 }
3738 bits = (bits << 1) | ((x as u64) & 0x1);
3739 }
3740 {
3741 let x = i128::from((*v3).flags.show_toast);
3742 if x < 0 || x > 1 {
3743 return Err(EncodeError::OutOfRange("show_toast"));
3744 }
3745 bits = (bits << 1) | ((x as u64) & 0x1);
3746 }
3747 {
3748 let x = i128::from((*v3).flags.has_background_texture);
3749 if x < 0 || x > 1 {
3750 return Err(EncodeError::OutOfRange("has_background_texture"));
3751 }
3752 bits = (bits << 1) | ((x as u64) & 0x1);
3753 }
3754 w.put_u32(bits as u32);
3755 }
3756 match (
3757 &(*v3).background_texture,
3758 ((*v3).flags.has_background_texture == 1),
3759 ) {
3760 (Some(v4), true) => {
3761 w.put_string(&(*v4))?;
3762 }
3763 (None, false) => {}
3764 _ => {
3765 return Err(EncodeError::SwitchMismatch(
3766 "play.clientbound.advancements.advancementMapping.value.displayData.backgroundTexture",
3767 ));
3768 }
3769 }
3770 w.put_f32((*v3).x_cord);
3771 w.put_f32((*v3).y_cord);
3772 }
3773 None => w.put_u8(0),
3774 }
3775 w.put_len_varint((*v1).value.criteria.len())?;
3776 for v5 in (*v1).value.criteria.iter() {
3777 w.put_string(&(*v5).key)?;
3778 }
3779 w.put_len_varint((*v1).value.requirements.len())?;
3780 for v6 in (*v1).value.requirements.iter() {
3781 w.put_len_varint((*v6).len())?;
3782 for v7 in (*v6).iter() {
3783 w.put_string(&(*v7))?;
3784 }
3785 }
3786 }
3787 w.put_len_varint((*self).identifiers.len())?;
3788 for v8 in (*self).identifiers.iter() {
3789 w.put_string(&(*v8))?;
3790 }
3791 w.put_len_varint((*self).progress_mapping.len())?;
3792 for v9 in (*self).progress_mapping.iter() {
3793 w.put_string(&(*v9).key)?;
3794 w.put_len_varint((*v9).value.len())?;
3795 for v10 in (*v9).value.iter() {
3796 w.put_string(&(*v10).criterion_identifier)?;
3797 match &(*v10).criterion_progress {
3798 Some(v11) => {
3799 w.put_u8(1);
3800 w.put_i64((*v11));
3801 }
3802 None => w.put_u8(0),
3803 }
3804 }
3805 }
3806 Ok(())
3807 }
3808}
3809#[cfg(feature = "v1_12_2")]
3810#[cfg(feature = "testgen")]
3811impl<const V: i32> Generate for Advancements<V> {
3812 fn generate(g: &mut Gen) -> Self {
3813 {
3814 let v1 = g.bool();
3815 let v2 = {
3816 let v3 = g.count();
3817 let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
3818 for _ in 0..v3 {
3819 v4.push({ let v5 = g.string();let v6 = { let v7 = if g.bool() { Some(g.string()) } else { None };let v8 = if g.bool() { Some({ let v9 = g.string();let v10 = g.string();let v11 = <crate::types::slot::legacy::Slot as Generate>::generate(g);let v12 = (g.int_in(-2147483648, 2147483647, &[]) as i32);let v13 = { crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueDisplayDataFlags { _unused: (g.int_in(0, 536870911, &[]) as u32), hidden: (g.int_in(0, 1, &[]) as u8), show_toast: (g.int_in(0, 1, &[]) as u8), has_background_texture: (g.int_in(0, 1, &[1]) as u8) } };let v15 = if (v13.has_background_texture == 1) { Some(g.string()) } else { None };let v16 = g.f32();let v17 = g.f32(); crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueDisplayData { title: v9, description: v10, icon: v11, frame_type: v12, flags: v13, background_texture: v15, x_cord: v16, y_cord: v17 } }) } else { None };let v18 = { let v19 = g.count(); let mut v20 = Vec::with_capacity(v19.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v19 { v20.push({ let v21 = g.string(); crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValueCriteria { key: v21 } }); } v20 };let v23 = { let v24 = g.count(); let mut v25 = Vec::with_capacity(v24.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v24 { v25.push({ let v26 = g.count(); let mut v27 = Vec::with_capacity(v26.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v26 { v27.push(g.string()); } v27 }); } v25 }; crate::defs::p340::play::clientbound::AdvancementsAdvancementMappingValue { parent_id: v7, display_data: v8, criteria: v18, requirements: v23 } }; crate::defs::p340::play::clientbound::AdvancementsAdvancementMapping { key: v5, value: v6 } });
3820 }
3821 v4
3822 };
3823 let v28 = {
3824 let v29 = g.count();
3825 let mut v30 = Vec::with_capacity(v29.min(crate::codec::PREALLOC_LIMIT));
3826 for _ in 0..v29 {
3827 v30.push(g.string());
3828 }
3829 v30
3830 };
3831 let v31 = {
3832 let v32 = g.count();
3833 let mut v33 = Vec::with_capacity(v32.min(crate::codec::PREALLOC_LIMIT));
3834 for _ in 0..v32 {
3835 v33.push({ let v34 = g.string();let v35 = { let v36 = g.count(); let mut v37 = Vec::with_capacity(v36.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v36 { v37.push({ let v38 = g.string();let v39 = if g.bool() { Some(g.i64()) } else { None }; crate::defs::p340::play::clientbound::AdvancementsProgressMappingValue { criterion_identifier: v38, criterion_progress: v39 } }); } v37 }; crate::defs::p340::play::clientbound::AdvancementsProgressMapping { key: v34, value: v35 } });
3836 }
3837 v33
3838 };
3839 Self {
3840 reset: v1,
3841 advancement_mapping: v2,
3842 identifiers: v28,
3843 progress_mapping: v31,
3844 }
3845 }
3846 }
3847}
3848
3849#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3850#[derive(Debug, Clone, PartialEq)]
3852pub struct EntityUpdateAttributesPropertiesModifiers {
3853 pub uuid: Uuid,
3855 pub amount: f64,
3857 pub operation: i8,
3859}
3860
3861#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3862#[derive(Debug, Clone, PartialEq)]
3864pub struct EntityUpdateAttributesProperties {
3865 pub key: ByteString,
3867 pub value: f64,
3869 pub modifiers:
3871 Vec<crate::defs::p340::play::clientbound::EntityUpdateAttributesPropertiesModifiers>,
3872}
3873
3874#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3875#[derive(Debug, Clone, PartialEq)]
3877pub struct EntityUpdateAttributes<const V: i32> {
3878 pub entity_id: i32,
3880 pub properties: Vec<crate::defs::p340::play::clientbound::EntityUpdateAttributesProperties>,
3882}
3883#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3884impl<const V: i32> Decode for EntityUpdateAttributes<V> {
3885 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3886 Ok({
3887 let v1 = r.read_varint()?;
3888 let v2 = {
3889 let v3 = {
3890 let c = r.read_i32()?;
3891 r.check_count(i64::from(c), 10)?
3892 };
3893 let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
3894 for _ in 0..v3 {
3895 v4.push({ let v5 = r.read_string()?;let v6 = r.read_f64()?;let v7 = { let v8 = { let c = r.read_varint()?; r.check_count(i64::from(c), 25)? }; let mut v9 = Vec::with_capacity(v8.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v8 { v9.push({ let v10 = r.read_uuid()?;let v11 = r.read_f64()?;let v12 = r.read_i8()?; crate::defs::p340::play::clientbound::EntityUpdateAttributesPropertiesModifiers { uuid: v10, amount: v11, operation: v12 } }); } v9 }; crate::defs::p340::play::clientbound::EntityUpdateAttributesProperties { key: v5, value: v6, modifiers: v7 } });
3896 }
3897 v4
3898 };
3899 Self {
3900 entity_id: v1,
3901 properties: v2,
3902 }
3903 })
3904 }
3905}
3906#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3907impl<const V: i32> Encode for EntityUpdateAttributes<V> {
3908 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3909 w.put_varint((*self).entity_id);
3910 w.put_i32(crate::codec::count_i32((*self).properties.len())?);
3911 for v1 in (*self).properties.iter() {
3912 w.put_string(&(*v1).key)?;
3913 w.put_f64((*v1).value);
3914 w.put_len_varint((*v1).modifiers.len())?;
3915 for v2 in (*v1).modifiers.iter() {
3916 w.put_uuid(&(*v2).uuid);
3917 w.put_f64((*v2).amount);
3918 w.put_i8((*v2).operation);
3919 }
3920 }
3921 Ok(())
3922 }
3923}
3924#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3925#[cfg(feature = "testgen")]
3926impl<const V: i32> Generate for EntityUpdateAttributes<V> {
3927 fn generate(g: &mut Gen) -> Self {
3928 {
3929 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3930 let v2 = {
3931 let v3 = g.count();
3932 let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
3933 for _ in 0..v3 {
3934 v4.push({ let v5 = g.string();let v6 = g.f64();let v7 = { let v8 = g.count(); let mut v9 = Vec::with_capacity(v8.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v8 { v9.push({ let v10 = g.uuid();let v11 = g.f64();let v12 = (g.int_in(-128, 127, &[]) as i8); crate::defs::p340::play::clientbound::EntityUpdateAttributesPropertiesModifiers { uuid: v10, amount: v11, operation: v12 } }); } v9 }; crate::defs::p340::play::clientbound::EntityUpdateAttributesProperties { key: v5, value: v6, modifiers: v7 } });
3935 }
3936 v4
3937 };
3938 Self {
3939 entity_id: v1,
3940 properties: v2,
3941 }
3942 }
3943 }
3944}
3945
3946#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3947#[derive(Debug, Clone, PartialEq)]
3949pub struct EntityEffect<const V: i32> {
3950 pub entity_id: i32,
3952 pub effect_id: i8,
3954 pub amplifier: i8,
3956 pub duration: i32,
3958 pub hide_particles: i8,
3960}
3961#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3962impl<const V: i32> Decode for EntityEffect<V> {
3963 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
3964 Ok({
3965 let v1 = r.read_varint()?;
3966 let v2 = r.read_i8()?;
3967 let v3 = r.read_i8()?;
3968 let v4 = r.read_varint()?;
3969 let v5 = r.read_i8()?;
3970 Self {
3971 entity_id: v1,
3972 effect_id: v2,
3973 amplifier: v3,
3974 duration: v4,
3975 hide_particles: v5,
3976 }
3977 })
3978 }
3979}
3980#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3981impl<const V: i32> Encode for EntityEffect<V> {
3982 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
3983 w.put_varint((*self).entity_id);
3984 w.put_i8((*self).effect_id);
3985 w.put_i8((*self).amplifier);
3986 w.put_varint((*self).duration);
3987 w.put_i8((*self).hide_particles);
3988 Ok(())
3989 }
3990}
3991#[cfg(any(feature = "v1_12_2", feature = "v1_16_5"))]
3992#[cfg(feature = "testgen")]
3993impl<const V: i32> Generate for EntityEffect<V> {
3994 fn generate(g: &mut Gen) -> Self {
3995 {
3996 let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
3997 let v2 = (g.int_in(-128, 127, &[]) as i8);
3998 let v3 = (g.int_in(-128, 127, &[]) as i8);
3999 let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
4000 let v5 = (g.int_in(-128, 127, &[]) as i8);
4001 Self {
4002 entity_id: v1,
4003 effect_id: v2,
4004 amplifier: v3,
4005 duration: v4,
4006 hide_particles: v5,
4007 }
4008 }
4009 }
4010}