// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
// (data/pc/1.8/protocol.json). Do not edit; run `cargo run -p ghast-codegen-protocol`.
// minecraft-data is MIT licensed, Copyright (c) 2015 PrismarineJS; see the NOTICE file
// in crates/ghast-protocol/src/generated/.
//! Clientbound packets of the play state.
#![allow(
unused_imports,
unused_variables,
unused_mut,
unused_parens,
unused_braces,
clippy::all,
clippy::pedantic,
non_camel_case_types,
non_snake_case
)]
use crate::codec::{Decode, DecodeResult, Encode, EncodeResult, McWrite, Reader, decode_exact};
use crate::error::{DecodeError, EncodeError};
use crate::nbt::{AnonNbt, RawNbt};
use crate::packet::{Direction, PacketSet, RawPacket, State};
#[cfg(feature = "testgen")]
use crate::testgen::{Gen, Generate};
use crate::types::{BlockPos, ByteString, Holder, HolderSet, LpVec3, PositionLayout, Uuid};
use bytes::{BufMut, Bytes, BytesMut};
#[cfg(feature = "v1_8")]
/// `keep_alive` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct KeepAlive<const V: i32> {
/// `keepAliveId`
pub keep_alive_id: i32,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for KeepAlive<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
Self { keep_alive_id: v1 }
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for KeepAlive<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).keep_alive_id);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for KeepAlive<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
Self { keep_alive_id: v1 }
}
}
}
#[cfg(feature = "v1_8")]
/// `login` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Login<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `gameMode`
pub game_mode: u8,
/// `dimension`
pub dimension: i8,
/// `difficulty`
pub difficulty: u8,
/// `maxPlayers`
pub max_players: u8,
/// `levelType`
pub level_type: ByteString,
/// `reducedDebugInfo`
pub reduced_debug_info: bool,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for Login<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_i32()?;
let v2 = r.read_u8()?;
let v3 = r.read_i8()?;
let v4 = r.read_u8()?;
let v5 = r.read_u8()?;
let v6 = r.read_string()?;
let v7 = r.read_bool()?;
Self {
entity_id: v1,
game_mode: v2,
dimension: v3,
difficulty: v4,
max_players: v5,
level_type: v6,
reduced_debug_info: v7,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for Login<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_i32((*self).entity_id);
w.put_u8((*self).game_mode);
w.put_i8((*self).dimension);
w.put_u8((*self).difficulty);
w.put_u8((*self).max_players);
w.put_string(&(*self).level_type)?;
w.put_bool((*self).reduced_debug_info);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Login<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(0, 255, &[]) as u8);
let v3 = (g.int_in(-128, 127, &[]) as i8);
let v4 = (g.int_in(0, 255, &[]) as u8);
let v5 = (g.int_in(0, 255, &[]) as u8);
let v6 = g.string();
let v7 = g.bool();
Self {
entity_id: v1,
game_mode: v2,
dimension: v3,
difficulty: v4,
max_players: v5,
level_type: v6,
reduced_debug_info: v7,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `chat` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Chat<const V: i32> {
/// `message`
pub message: ByteString,
/// `position`
pub position: i8,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for Chat<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_string()?;
let v2 = r.read_i8()?;
Self {
message: v1,
position: v2,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for Chat<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_string(&(*self).message)?;
w.put_i8((*self).position);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Chat<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.string();
let v2 = (g.int_in(-128, 127, &[]) as i8);
Self {
message: v1,
position: v2,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `update_time` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct UpdateTime<const V: i32> {
/// `age`
pub age: i64,
/// `time`
pub time: i64,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for UpdateTime<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_i64()?;
let v2 = r.read_i64()?;
Self { age: v1, time: v2 }
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for UpdateTime<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_i64((*self).age);
w.put_i64((*self).time);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for UpdateTime<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.i64();
let v2 = g.i64();
Self { age: v1, time: v2 }
}
}
}
#[cfg(feature = "v1_8")]
/// `entity_equipment` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct EntityEquipment<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `slot`
pub slot: i16,
/// `item`
pub item: crate::types::slot::legacy::Slot,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for EntityEquipment<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_i16()?;
let v3 = <crate::types::slot::legacy::Slot as Decode>::decode(r)?;
Self {
entity_id: v1,
slot: v2,
item: v3,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for EntityEquipment<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_i16((*self).slot);
(*self).item.encode(w)?;
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for EntityEquipment<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-32768, 32767, &[]) as i16);
let v3 = <crate::types::slot::legacy::Slot as Generate>::generate(g);
Self {
entity_id: v1,
slot: v2,
item: v3,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `spawn_position` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct SpawnPosition<const V: i32> {
/// `location`
pub location: BlockPos,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for SpawnPosition<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = BlockPos::read(r, PositionLayout::Xyz)?;
Self { location: v1 }
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for SpawnPosition<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
(*self).location.write(w, PositionLayout::Xyz)?;
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for SpawnPosition<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.position();
Self { location: v1 }
}
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
/// `update_health` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct UpdateHealth<const V: i32> {
/// `health`
pub health: f32,
/// `food`
pub food: i32,
/// `foodSaturation`
pub food_saturation: f32,
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Decode for UpdateHealth<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_f32()?;
let v2 = r.read_varint()?;
let v3 = r.read_f32()?;
Self {
health: v1,
food: v2,
food_saturation: v3,
}
})
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Encode for UpdateHealth<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_f32((*self).health);
w.put_varint((*self).food);
w.put_f32((*self).food_saturation);
Ok(())
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for UpdateHealth<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.f32();
let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v3 = g.f32();
Self {
health: v1,
food: v2,
food_saturation: v3,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `respawn` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Respawn<const V: i32> {
/// `dimension`
pub dimension: i32,
/// `difficulty`
pub difficulty: u8,
/// `gamemode`
pub gamemode: u8,
/// `levelType`
pub level_type: ByteString,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for Respawn<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_i32()?;
let v2 = r.read_u8()?;
let v3 = r.read_u8()?;
let v4 = r.read_string()?;
Self {
dimension: v1,
difficulty: v2,
gamemode: v3,
level_type: v4,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for Respawn<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_i32((*self).dimension);
w.put_u8((*self).difficulty);
w.put_u8((*self).gamemode);
w.put_string(&(*self).level_type)?;
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Respawn<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(0, 255, &[]) as u8);
let v3 = (g.int_in(0, 255, &[]) as u8);
let v4 = g.string();
Self {
dimension: v1,
difficulty: v2,
gamemode: v3,
level_type: v4,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `position` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Position<const V: i32> {
/// `x`
pub x: f64,
/// `y`
pub y: f64,
/// `z`
pub z: f64,
/// `yaw`
pub yaw: f32,
/// `pitch`
pub pitch: f32,
/// `flags`
pub flags: i8,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for Position<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_f64()?;
let v2 = r.read_f64()?;
let v3 = r.read_f64()?;
let v4 = r.read_f32()?;
let v5 = r.read_f32()?;
let v6 = r.read_i8()?;
Self {
x: v1,
y: v2,
z: v3,
yaw: v4,
pitch: v5,
flags: v6,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for Position<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_f64((*self).x);
w.put_f64((*self).y);
w.put_f64((*self).z);
w.put_f32((*self).yaw);
w.put_f32((*self).pitch);
w.put_i8((*self).flags);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Position<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.f64();
let v2 = g.f64();
let v3 = g.f64();
let v4 = g.f32();
let v5 = g.f32();
let v6 = (g.int_in(-128, 127, &[]) as i8);
Self {
x: v1,
y: v2,
z: v3,
yaw: v4,
pitch: v5,
flags: v6,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `held_item_slot` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct HeldItemSlot<const V: i32> {
/// `slot`
pub slot: i8,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for HeldItemSlot<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_i8()?;
Self { slot: v1 }
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for HeldItemSlot<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_i8((*self).slot);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for HeldItemSlot<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-128, 127, &[]) as i8);
Self { slot: v1 }
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `bed` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Bed<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `location`
pub location: BlockPos,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for Bed<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = BlockPos::read(r, PositionLayout::Xyz)?;
Self {
entity_id: v1,
location: v2,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for Bed<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
(*self).location.write(w, PositionLayout::Xyz)?;
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Bed<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = g.position();
Self {
entity_id: v1,
location: v2,
}
}
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
/// `animation` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Animation<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `animation`
pub animation: u8,
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Decode for Animation<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_u8()?;
Self {
entity_id: v1,
animation: v2,
}
})
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Encode for Animation<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_u8((*self).animation);
Ok(())
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Animation<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(0, 255, &[]) as u8);
Self {
entity_id: v1,
animation: v2,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `named_entity_spawn` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct NamedEntitySpawn<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `playerUUID`
pub player_uuid: Uuid,
/// `x`
pub x: i32,
/// `y`
pub y: i32,
/// `z`
pub z: i32,
/// `yaw`
pub yaw: i8,
/// `pitch`
pub pitch: i8,
/// `currentItem`
pub current_item: i16,
/// `metadata`
pub metadata: Vec<crate::defs::p47::types::EntityMetadataEntry>,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for NamedEntitySpawn<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_uuid()?;
let v3 = r.read_i32()?;
let v4 = r.read_i32()?;
let v5 = r.read_i32()?;
let v6 = r.read_i8()?;
let v7 = r.read_i8()?;
let v8 = r.read_i16()?;
let v9 = {
let mut v10 = Vec::new();
loop {
if r.peek_u8()? == 127 {
r.skip(1)?;
break;
}
v10.push({
let v11 = u64::from(r.read_u8()?);
let v12 = (((v11 >> 5) & 0x7) as u8);
let v13 = (((v11 >> 0) & 0x1f) as u8);
let v14 = (if (v12 == 0) {
crate::defs::p47::types::EntityMetadataValue::Byte(r.read_i8()?)
} else if (v12 == 1) {
crate::defs::p47::types::EntityMetadataValue::Short(r.read_i16()?)
} else if (v12 == 2) {
crate::defs::p47::types::EntityMetadataValue::Int(r.read_i32()?)
} else if (v12 == 3) {
crate::defs::p47::types::EntityMetadataValue::Float(r.read_f32()?)
} else if (v12 == 4) {
crate::defs::p47::types::EntityMetadataValue::String(r.read_string()?)
} else if (v12 == 5) {
crate::defs::p47::types::EntityMetadataValue::Slot(
<crate::types::slot::legacy::Slot as Decode>::decode(r)?,
)
} else if (v12 == 6) {
crate::defs::p47::types::EntityMetadataValue::BlockPos({
let v15 = r.read_i32()?;
let v16 = r.read_i32()?;
let v17 = r.read_i32()?;
crate::defs::p47::types::EntityMetadataValueBlockPos {
x: v15,
y: v16,
z: v17,
}
})
} else if (v12 == 7) {
crate::defs::p47::types::EntityMetadataValue::Rotation({
let v18 = r.read_f32()?;
let v19 = r.read_f32()?;
let v20 = r.read_f32()?;
crate::defs::p47::types::EntityMetadataValueRotation {
pitch: v18,
yaw: v19,
roll: v20,
}
})
} else {
crate::defs::p47::types::EntityMetadataValue::Other
});
crate::defs::p47::types::EntityMetadataEntry {
r#type: v12,
key: v13,
value: v14,
}
});
}
v10
};
Self {
entity_id: v1,
player_uuid: v2,
x: v3,
y: v4,
z: v5,
yaw: v6,
pitch: v7,
current_item: v8,
metadata: v9,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for NamedEntitySpawn<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_uuid(&(*self).player_uuid);
w.put_i32((*self).x);
w.put_i32((*self).y);
w.put_i32((*self).z);
w.put_i8((*self).yaw);
w.put_i8((*self).pitch);
w.put_i16((*self).current_item);
for v1 in (*self).metadata.iter() {
let v2 = w.len();
{
let mut bits: u64 = 0;
{
let x = i128::from((*v1).r#type);
if x < 0 || x > 7 {
return Err(EncodeError::OutOfRange("type"));
}
bits = (bits << 3) | ((x as u64) & 0x7);
}
{
let x = i128::from((*v1).key);
if x < 0 || x > 31 {
return Err(EncodeError::OutOfRange("key"));
}
bits = (bits << 5) | ((x as u64) & 0x1f);
}
w.put_u8(bits as u8);
}
match &(*v1).value {
crate::defs::p47::types::EntityMetadataValue::Byte(v3) => {
if !((*v1).r#type == 0) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.named_entity_spawn.metadata.value",
));
}
w.put_i8((*v3));
}
crate::defs::p47::types::EntityMetadataValue::Short(v4) => {
if !((*v1).r#type == 1) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.named_entity_spawn.metadata.value",
));
}
w.put_i16((*v4));
}
crate::defs::p47::types::EntityMetadataValue::Int(v5) => {
if !((*v1).r#type == 2) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.named_entity_spawn.metadata.value",
));
}
w.put_i32((*v5));
}
crate::defs::p47::types::EntityMetadataValue::Float(v6) => {
if !((*v1).r#type == 3) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.named_entity_spawn.metadata.value",
));
}
w.put_f32((*v6));
}
crate::defs::p47::types::EntityMetadataValue::String(v7) => {
if !((*v1).r#type == 4) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.named_entity_spawn.metadata.value",
));
}
w.put_string(&(*v7))?;
}
crate::defs::p47::types::EntityMetadataValue::Slot(v8) => {
if !((*v1).r#type == 5) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.named_entity_spawn.metadata.value",
));
}
(*v8).encode(w)?;
}
crate::defs::p47::types::EntityMetadataValue::BlockPos(v9) => {
if !((*v1).r#type == 6) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.named_entity_spawn.metadata.value",
));
}
w.put_i32((*v9).x);
w.put_i32((*v9).y);
w.put_i32((*v9).z);
}
crate::defs::p47::types::EntityMetadataValue::Rotation(v10) => {
if !((*v1).r#type == 7) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.named_entity_spawn.metadata.value",
));
}
w.put_f32((*v10).pitch);
w.put_f32((*v10).yaw);
w.put_f32((*v10).roll);
}
crate::defs::p47::types::EntityMetadataValue::Other => {
if !(!(((*v1).r#type == 0)
|| ((*v1).r#type == 1)
|| ((*v1).r#type == 2)
|| ((*v1).r#type == 3)
|| ((*v1).r#type == 4)
|| ((*v1).r#type == 5)
|| ((*v1).r#type == 6)
|| ((*v1).r#type == 7)))
{
return Err(EncodeError::SwitchMismatch(
"play.clientbound.named_entity_spawn.metadata.value",
));
}
}
}
if w.get(v2) == Some(&127) {
return Err(EncodeError::OutOfRange(
"play.clientbound.named_entity_spawn.metadata",
));
}
}
w.put_u8(127);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for NamedEntitySpawn<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = g.uuid();
let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v5 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v6 = (g.int_in(-128, 127, &[]) as i8);
let v7 = (g.int_in(-128, 127, &[]) as i8);
let v8 = (g.int_in(-32768, 32767, &[]) as i16);
let v9 = {
let n = g.count();
let mut v10 = Vec::with_capacity(n);
for _ in 0..n {
v10.push(loop { let v11 = { let v13 = (g.int_in(0, 7, &[0, 1, 2, 3, 4, 5, 6, 7]) as u8);let v14 = (g.int_in(0, 31, &[]) as u8);let v15 = (if (v13 == 0) { crate::defs::p47::types::EntityMetadataValue::Byte((g.int_in(-128, 127, &[]) as i8)) } else if (v13 == 1) { crate::defs::p47::types::EntityMetadataValue::Short((g.int_in(-32768, 32767, &[]) as i16)) } else if (v13 == 2) { crate::defs::p47::types::EntityMetadataValue::Int((g.int_in(-2147483648, 2147483647, &[]) as i32)) } else if (v13 == 3) { crate::defs::p47::types::EntityMetadataValue::Float(g.f32()) } else if (v13 == 4) { crate::defs::p47::types::EntityMetadataValue::String(g.string()) } else if (v13 == 5) { crate::defs::p47::types::EntityMetadataValue::Slot(<crate::types::slot::legacy::Slot as Generate>::generate(g)) } else if (v13 == 6) { crate::defs::p47::types::EntityMetadataValue::BlockPos({ let v16 = (g.int_in(-2147483648, 2147483647, &[]) as i32);let v17 = (g.int_in(-2147483648, 2147483647, &[]) as i32);let v18 = (g.int_in(-2147483648, 2147483647, &[]) as i32); crate::defs::p47::types::EntityMetadataValueBlockPos { x: v16, y: v17, z: v18 } }) } else if (v13 == 7) { crate::defs::p47::types::EntityMetadataValue::Rotation({ let v19 = g.f32();let v20 = g.f32();let v21 = g.f32(); crate::defs::p47::types::EntityMetadataValueRotation { pitch: v19, yaw: v20, roll: v21 } }) } else { crate::defs::p47::types::EntityMetadataValue::Other }); crate::defs::p47::types::EntityMetadataEntry { r#type: v13, key: v14, value: v15 } }; if crate::testgen::first_byte_ok(|w: &mut BytesMut| -> EncodeResult { { let mut bits: u64 = 0;{ let x = i128::from(v11.r#type); if x < 0 || x > 7 { return Err(EncodeError::OutOfRange("type")); } bits = (bits << 3) | ((x as u64) & 0x7); }{ let x = i128::from(v11.key); if x < 0 || x > 31 { return Err(EncodeError::OutOfRange("key")); } bits = (bits << 5) | ((x as u64) & 0x1f); }w.put_u8(bits as u8); }match &v11.value { crate::defs::p47::types::EntityMetadataValue::Byte(v22) => { if !((v11.r#type == 0)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_i8((*v22)); }crate::defs::p47::types::EntityMetadataValue::Short(v23) => { if !((v11.r#type == 1)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_i16((*v23)); }crate::defs::p47::types::EntityMetadataValue::Int(v24) => { if !((v11.r#type == 2)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_i32((*v24)); }crate::defs::p47::types::EntityMetadataValue::Float(v25) => { if !((v11.r#type == 3)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_f32((*v25)); }crate::defs::p47::types::EntityMetadataValue::String(v26) => { if !((v11.r#type == 4)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_string(&(*v26))?; }crate::defs::p47::types::EntityMetadataValue::Slot(v27) => { if !((v11.r#type == 5)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } (*v27).encode(w)?; }crate::defs::p47::types::EntityMetadataValue::BlockPos(v28) => { if !((v11.r#type == 6)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_i32((*v28).x);w.put_i32((*v28).y);w.put_i32((*v28).z); }crate::defs::p47::types::EntityMetadataValue::Rotation(v29) => { if !((v11.r#type == 7)) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } w.put_f32((*v29).pitch);w.put_f32((*v29).yaw);w.put_f32((*v29).roll); }crate::defs::p47::types::EntityMetadataValue::Other => { if !(!((v11.r#type == 0) || (v11.r#type == 1) || (v11.r#type == 2) || (v11.r#type == 3) || (v11.r#type == 4) || (v11.r#type == 5) || (v11.r#type == 6) || (v11.r#type == 7))) { return Err(EncodeError::SwitchMismatch("play.clientbound.named_entity_spawn.metadata.value")); } } } Ok(()) }, |b| b != 127) { break v11; } });
}
v10
};
Self {
entity_id: v1,
player_uuid: v2,
x: v3,
y: v4,
z: v5,
yaw: v6,
pitch: v7,
current_item: v8,
metadata: v9,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `collect` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Collect<const V: i32> {
/// `collectedEntityId`
pub collected_entity_id: i32,
/// `collectorEntityId`
pub collector_entity_id: i32,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for Collect<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_varint()?;
Self {
collected_entity_id: v1,
collector_entity_id: v2,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for Collect<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).collected_entity_id);
w.put_varint((*self).collector_entity_id);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Collect<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
Self {
collected_entity_id: v1,
collector_entity_id: v2,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `spawn_entity` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct SpawnEntity<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `type`
pub r#type: i8,
/// `x`
pub x: i32,
/// `y`
pub y: i32,
/// `z`
pub z: i32,
/// `pitch`
pub pitch: i8,
/// `yaw`
pub yaw: i8,
/// `objectData`
pub object_data: i32,
/// `velocity` — present iff `objectData > 0`, as vanilla 1.8.9 reads it (minecraft-data says `!= 0`)
pub velocity: Option<crate::defs::p47::types::Vec3i16>,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for SpawnEntity<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_i8()?;
let v3 = r.read_i32()?;
let v4 = r.read_i32()?;
let v5 = r.read_i32()?;
let v6 = r.read_i8()?;
let v7 = r.read_i8()?;
let v8 = r.read_i32()?;
let v9 = if (v8 > 0) {
Some(<crate::defs::p47::types::Vec3i16 as Decode>::decode(r)?)
} else {
None
};
Self {
entity_id: v1,
r#type: v2,
x: v3,
y: v4,
z: v5,
pitch: v6,
yaw: v7,
object_data: v8,
velocity: v9,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for SpawnEntity<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_i8((*self).r#type);
w.put_i32((*self).x);
w.put_i32((*self).y);
w.put_i32((*self).z);
w.put_i8((*self).pitch);
w.put_i8((*self).yaw);
w.put_i32((*self).object_data);
match (&(*self).velocity, ((*self).object_data > 0)) {
(Some(v1), true) => {
(*v1).encode(w)?;
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.spawn_entity.velocity",
));
}
}
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for SpawnEntity<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-128, 127, &[]) as i8);
let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v5 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v6 = (g.int_in(-128, 127, &[]) as i8);
let v7 = (g.int_in(-128, 127, &[]) as i8);
let v8 = (g.int_in(-2147483648, 2147483647, &[0, 1, -1, 5, -2147483648]) as i32);
let v9 = if (v8 > 0) {
Some(<crate::defs::p47::types::Vec3i16 as Generate>::generate(g))
} else {
None
};
Self {
entity_id: v1,
r#type: v2,
x: v3,
y: v4,
z: v5,
pitch: v6,
yaw: v7,
object_data: v8,
velocity: v9,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `spawn_entity_living` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct SpawnEntityLiving<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `type`
pub r#type: u8,
/// `x`
pub x: i32,
/// `y`
pub y: i32,
/// `z`
pub z: i32,
/// `yaw`
pub yaw: i8,
/// `pitch`
pub pitch: i8,
/// `headPitch`
pub head_pitch: i8,
/// `velocity`
pub velocity: crate::defs::p47::types::Vec3i16,
/// `metadata`
pub metadata: Vec<crate::defs::p47::types::EntityMetadataEntry>,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for SpawnEntityLiving<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_u8()?;
let v3 = r.read_i32()?;
let v4 = r.read_i32()?;
let v5 = r.read_i32()?;
let v6 = r.read_i8()?;
let v7 = r.read_i8()?;
let v8 = r.read_i8()?;
let v9 = <crate::defs::p47::types::Vec3i16 as Decode>::decode(r)?;
let v10 = {
let mut v11 = Vec::new();
loop {
if r.peek_u8()? == 127 {
r.skip(1)?;
break;
}
v11.push({
let v12 = u64::from(r.read_u8()?);
let v13 = (((v12 >> 5) & 0x7) as u8);
let v14 = (((v12 >> 0) & 0x1f) as u8);
let v15 = (if (v13 == 0) {
crate::defs::p47::types::EntityMetadataValue::Byte(r.read_i8()?)
} else if (v13 == 1) {
crate::defs::p47::types::EntityMetadataValue::Short(r.read_i16()?)
} else if (v13 == 2) {
crate::defs::p47::types::EntityMetadataValue::Int(r.read_i32()?)
} else if (v13 == 3) {
crate::defs::p47::types::EntityMetadataValue::Float(r.read_f32()?)
} else if (v13 == 4) {
crate::defs::p47::types::EntityMetadataValue::String(r.read_string()?)
} else if (v13 == 5) {
crate::defs::p47::types::EntityMetadataValue::Slot(
<crate::types::slot::legacy::Slot as Decode>::decode(r)?,
)
} else if (v13 == 6) {
crate::defs::p47::types::EntityMetadataValue::BlockPos({
let v16 = r.read_i32()?;
let v17 = r.read_i32()?;
let v18 = r.read_i32()?;
crate::defs::p47::types::EntityMetadataValueBlockPos {
x: v16,
y: v17,
z: v18,
}
})
} else if (v13 == 7) {
crate::defs::p47::types::EntityMetadataValue::Rotation({
let v19 = r.read_f32()?;
let v20 = r.read_f32()?;
let v21 = r.read_f32()?;
crate::defs::p47::types::EntityMetadataValueRotation {
pitch: v19,
yaw: v20,
roll: v21,
}
})
} else {
crate::defs::p47::types::EntityMetadataValue::Other
});
crate::defs::p47::types::EntityMetadataEntry {
r#type: v13,
key: v14,
value: v15,
}
});
}
v11
};
Self {
entity_id: v1,
r#type: v2,
x: v3,
y: v4,
z: v5,
yaw: v6,
pitch: v7,
head_pitch: v8,
velocity: v9,
metadata: v10,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for SpawnEntityLiving<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_u8((*self).r#type);
w.put_i32((*self).x);
w.put_i32((*self).y);
w.put_i32((*self).z);
w.put_i8((*self).yaw);
w.put_i8((*self).pitch);
w.put_i8((*self).head_pitch);
(*self).velocity.encode(w)?;
for v1 in (*self).metadata.iter() {
let v2 = w.len();
{
let mut bits: u64 = 0;
{
let x = i128::from((*v1).r#type);
if x < 0 || x > 7 {
return Err(EncodeError::OutOfRange("type"));
}
bits = (bits << 3) | ((x as u64) & 0x7);
}
{
let x = i128::from((*v1).key);
if x < 0 || x > 31 {
return Err(EncodeError::OutOfRange("key"));
}
bits = (bits << 5) | ((x as u64) & 0x1f);
}
w.put_u8(bits as u8);
}
match &(*v1).value {
crate::defs::p47::types::EntityMetadataValue::Byte(v3) => {
if !((*v1).r#type == 0) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.spawn_entity_living.metadata.value",
));
}
w.put_i8((*v3));
}
crate::defs::p47::types::EntityMetadataValue::Short(v4) => {
if !((*v1).r#type == 1) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.spawn_entity_living.metadata.value",
));
}
w.put_i16((*v4));
}
crate::defs::p47::types::EntityMetadataValue::Int(v5) => {
if !((*v1).r#type == 2) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.spawn_entity_living.metadata.value",
));
}
w.put_i32((*v5));
}
crate::defs::p47::types::EntityMetadataValue::Float(v6) => {
if !((*v1).r#type == 3) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.spawn_entity_living.metadata.value",
));
}
w.put_f32((*v6));
}
crate::defs::p47::types::EntityMetadataValue::String(v7) => {
if !((*v1).r#type == 4) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.spawn_entity_living.metadata.value",
));
}
w.put_string(&(*v7))?;
}
crate::defs::p47::types::EntityMetadataValue::Slot(v8) => {
if !((*v1).r#type == 5) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.spawn_entity_living.metadata.value",
));
}
(*v8).encode(w)?;
}
crate::defs::p47::types::EntityMetadataValue::BlockPos(v9) => {
if !((*v1).r#type == 6) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.spawn_entity_living.metadata.value",
));
}
w.put_i32((*v9).x);
w.put_i32((*v9).y);
w.put_i32((*v9).z);
}
crate::defs::p47::types::EntityMetadataValue::Rotation(v10) => {
if !((*v1).r#type == 7) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.spawn_entity_living.metadata.value",
));
}
w.put_f32((*v10).pitch);
w.put_f32((*v10).yaw);
w.put_f32((*v10).roll);
}
crate::defs::p47::types::EntityMetadataValue::Other => {
if !(!(((*v1).r#type == 0)
|| ((*v1).r#type == 1)
|| ((*v1).r#type == 2)
|| ((*v1).r#type == 3)
|| ((*v1).r#type == 4)
|| ((*v1).r#type == 5)
|| ((*v1).r#type == 6)
|| ((*v1).r#type == 7)))
{
return Err(EncodeError::SwitchMismatch(
"play.clientbound.spawn_entity_living.metadata.value",
));
}
}
}
if w.get(v2) == Some(&127) {
return Err(EncodeError::OutOfRange(
"play.clientbound.spawn_entity_living.metadata",
));
}
}
w.put_u8(127);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for SpawnEntityLiving<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(0, 255, &[]) as u8);
let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v5 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v6 = (g.int_in(-128, 127, &[]) as i8);
let v7 = (g.int_in(-128, 127, &[]) as i8);
let v8 = (g.int_in(-128, 127, &[]) as i8);
let v9 = <crate::defs::p47::types::Vec3i16 as Generate>::generate(g);
let v10 = {
let n = g.count();
let mut v11 = Vec::with_capacity(n);
for _ in 0..n {
v11.push(loop { let v12 = { let v14 = (g.int_in(0, 7, &[0, 1, 2, 3, 4, 5, 6, 7]) as u8);let v15 = (g.int_in(0, 31, &[]) as u8);let v16 = (if (v14 == 0) { crate::defs::p47::types::EntityMetadataValue::Byte((g.int_in(-128, 127, &[]) as i8)) } else if (v14 == 1) { crate::defs::p47::types::EntityMetadataValue::Short((g.int_in(-32768, 32767, &[]) as i16)) } else if (v14 == 2) { crate::defs::p47::types::EntityMetadataValue::Int((g.int_in(-2147483648, 2147483647, &[]) as i32)) } else if (v14 == 3) { crate::defs::p47::types::EntityMetadataValue::Float(g.f32()) } else if (v14 == 4) { crate::defs::p47::types::EntityMetadataValue::String(g.string()) } else if (v14 == 5) { crate::defs::p47::types::EntityMetadataValue::Slot(<crate::types::slot::legacy::Slot as Generate>::generate(g)) } else if (v14 == 6) { crate::defs::p47::types::EntityMetadataValue::BlockPos({ let v17 = (g.int_in(-2147483648, 2147483647, &[]) as i32);let v18 = (g.int_in(-2147483648, 2147483647, &[]) as i32);let v19 = (g.int_in(-2147483648, 2147483647, &[]) as i32); crate::defs::p47::types::EntityMetadataValueBlockPos { x: v17, y: v18, z: v19 } }) } else if (v14 == 7) { crate::defs::p47::types::EntityMetadataValue::Rotation({ let v20 = g.f32();let v21 = g.f32();let v22 = g.f32(); crate::defs::p47::types::EntityMetadataValueRotation { pitch: v20, yaw: v21, roll: v22 } }) } else { crate::defs::p47::types::EntityMetadataValue::Other }); crate::defs::p47::types::EntityMetadataEntry { r#type: v14, key: v15, value: v16 } }; if crate::testgen::first_byte_ok(|w: &mut BytesMut| -> EncodeResult { { let mut bits: u64 = 0;{ let x = i128::from(v12.r#type); if x < 0 || x > 7 { return Err(EncodeError::OutOfRange("type")); } bits = (bits << 3) | ((x as u64) & 0x7); }{ let x = i128::from(v12.key); if x < 0 || x > 31 { return Err(EncodeError::OutOfRange("key")); } bits = (bits << 5) | ((x as u64) & 0x1f); }w.put_u8(bits as u8); }match &v12.value { crate::defs::p47::types::EntityMetadataValue::Byte(v23) => { if !((v12.r#type == 0)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_i8((*v23)); }crate::defs::p47::types::EntityMetadataValue::Short(v24) => { if !((v12.r#type == 1)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_i16((*v24)); }crate::defs::p47::types::EntityMetadataValue::Int(v25) => { if !((v12.r#type == 2)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_i32((*v25)); }crate::defs::p47::types::EntityMetadataValue::Float(v26) => { if !((v12.r#type == 3)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_f32((*v26)); }crate::defs::p47::types::EntityMetadataValue::String(v27) => { if !((v12.r#type == 4)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_string(&(*v27))?; }crate::defs::p47::types::EntityMetadataValue::Slot(v28) => { if !((v12.r#type == 5)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } (*v28).encode(w)?; }crate::defs::p47::types::EntityMetadataValue::BlockPos(v29) => { if !((v12.r#type == 6)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_i32((*v29).x);w.put_i32((*v29).y);w.put_i32((*v29).z); }crate::defs::p47::types::EntityMetadataValue::Rotation(v30) => { if !((v12.r#type == 7)) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } w.put_f32((*v30).pitch);w.put_f32((*v30).yaw);w.put_f32((*v30).roll); }crate::defs::p47::types::EntityMetadataValue::Other => { if !(!((v12.r#type == 0) || (v12.r#type == 1) || (v12.r#type == 2) || (v12.r#type == 3) || (v12.r#type == 4) || (v12.r#type == 5) || (v12.r#type == 6) || (v12.r#type == 7))) { return Err(EncodeError::SwitchMismatch("play.clientbound.spawn_entity_living.metadata.value")); } } } Ok(()) }, |b| b != 127) { break v12; } });
}
v11
};
Self {
entity_id: v1,
r#type: v2,
x: v3,
y: v4,
z: v5,
yaw: v6,
pitch: v7,
head_pitch: v8,
velocity: v9,
metadata: v10,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `spawn_entity_painting` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct SpawnEntityPainting<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `title`
pub title: ByteString,
/// `location`
pub location: BlockPos,
/// `direction`
pub direction: u8,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for SpawnEntityPainting<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_string()?;
let v3 = BlockPos::read(r, PositionLayout::Xyz)?;
let v4 = r.read_u8()?;
Self {
entity_id: v1,
title: v2,
location: v3,
direction: v4,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for SpawnEntityPainting<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_string(&(*self).title)?;
(*self).location.write(w, PositionLayout::Xyz)?;
w.put_u8((*self).direction);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for SpawnEntityPainting<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = g.string();
let v3 = g.position();
let v4 = (g.int_in(0, 255, &[]) as u8);
Self {
entity_id: v1,
title: v2,
location: v3,
direction: v4,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `spawn_entity_experience_orb` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct SpawnEntityExperienceOrb<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `x`
pub x: i32,
/// `y`
pub y: i32,
/// `z`
pub z: i32,
/// `count`
pub count: i16,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for SpawnEntityExperienceOrb<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_i32()?;
let v3 = r.read_i32()?;
let v4 = r.read_i32()?;
let v5 = r.read_i16()?;
Self {
entity_id: v1,
x: v2,
y: v3,
z: v4,
count: v5,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for SpawnEntityExperienceOrb<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_i32((*self).x);
w.put_i32((*self).y);
w.put_i32((*self).z);
w.put_i16((*self).count);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for SpawnEntityExperienceOrb<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v5 = (g.int_in(-32768, 32767, &[]) as i16);
Self {
entity_id: v1,
x: v2,
y: v3,
z: v4,
count: v5,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `entity_velocity` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct EntityVelocity<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `velocity`
pub velocity: crate::defs::p47::types::Vec3i16,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for EntityVelocity<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = <crate::defs::p47::types::Vec3i16 as Decode>::decode(r)?;
Self {
entity_id: v1,
velocity: v2,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for EntityVelocity<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
(*self).velocity.encode(w)?;
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for EntityVelocity<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = <crate::defs::p47::types::Vec3i16 as Generate>::generate(g);
Self {
entity_id: v1,
velocity: v2,
}
}
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
/// `entity_destroy` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct EntityDestroy<const V: i32> {
/// `entityIds`
pub entity_ids: Vec<i32>,
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Decode for EntityDestroy<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = {
let v2 = {
let c = r.read_varint()?;
r.check_count(i64::from(c), 1)?
};
let mut v3 = Vec::with_capacity(v2.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v2 {
v3.push(r.read_varint()?);
}
v3
};
Self { entity_ids: v1 }
})
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Encode for EntityDestroy<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_len_varint((*self).entity_ids.len())?;
for v1 in (*self).entity_ids.iter() {
w.put_varint((*v1));
}
Ok(())
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for EntityDestroy<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = {
let v2 = g.count();
let mut v3 = Vec::with_capacity(v2.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v2 {
v3.push((g.int_in(-2147483648, 2147483647, &[]) as i32));
}
v3
};
Self { entity_ids: v1 }
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `entity` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Entity<const V: i32> {
/// `entityId`
pub entity_id: i32,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for Entity<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
Self { entity_id: v1 }
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for Entity<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Entity<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
Self { entity_id: v1 }
}
}
}
#[cfg(feature = "v1_8")]
/// `rel_entity_move` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct RelEntityMove<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `dX`
pub d_x: i8,
/// `dY`
pub d_y: i8,
/// `dZ`
pub d_z: i8,
/// `onGround`
pub on_ground: bool,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for RelEntityMove<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_i8()?;
let v3 = r.read_i8()?;
let v4 = r.read_i8()?;
let v5 = r.read_bool()?;
Self {
entity_id: v1,
d_x: v2,
d_y: v3,
d_z: v4,
on_ground: v5,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for RelEntityMove<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_i8((*self).d_x);
w.put_i8((*self).d_y);
w.put_i8((*self).d_z);
w.put_bool((*self).on_ground);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for RelEntityMove<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-128, 127, &[]) as i8);
let v3 = (g.int_in(-128, 127, &[]) as i8);
let v4 = (g.int_in(-128, 127, &[]) as i8);
let v5 = g.bool();
Self {
entity_id: v1,
d_x: v2,
d_y: v3,
d_z: v4,
on_ground: v5,
}
}
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
/// `entity_look` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct EntityLook<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `yaw`
pub yaw: i8,
/// `pitch`
pub pitch: i8,
/// `onGround`
pub on_ground: bool,
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Decode for EntityLook<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_i8()?;
let v3 = r.read_i8()?;
let v4 = r.read_bool()?;
Self {
entity_id: v1,
yaw: v2,
pitch: v3,
on_ground: v4,
}
})
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Encode for EntityLook<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_i8((*self).yaw);
w.put_i8((*self).pitch);
w.put_bool((*self).on_ground);
Ok(())
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for EntityLook<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-128, 127, &[]) as i8);
let v3 = (g.int_in(-128, 127, &[]) as i8);
let v4 = g.bool();
Self {
entity_id: v1,
yaw: v2,
pitch: v3,
on_ground: v4,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `entity_move_look` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct EntityMoveLook<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `dX`
pub d_x: i8,
/// `dY`
pub d_y: i8,
/// `dZ`
pub d_z: i8,
/// `yaw`
pub yaw: i8,
/// `pitch`
pub pitch: i8,
/// `onGround`
pub on_ground: bool,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for EntityMoveLook<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_i8()?;
let v3 = r.read_i8()?;
let v4 = r.read_i8()?;
let v5 = r.read_i8()?;
let v6 = r.read_i8()?;
let v7 = r.read_bool()?;
Self {
entity_id: v1,
d_x: v2,
d_y: v3,
d_z: v4,
yaw: v5,
pitch: v6,
on_ground: v7,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for EntityMoveLook<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_i8((*self).d_x);
w.put_i8((*self).d_y);
w.put_i8((*self).d_z);
w.put_i8((*self).yaw);
w.put_i8((*self).pitch);
w.put_bool((*self).on_ground);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for EntityMoveLook<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-128, 127, &[]) as i8);
let v3 = (g.int_in(-128, 127, &[]) as i8);
let v4 = (g.int_in(-128, 127, &[]) as i8);
let v5 = (g.int_in(-128, 127, &[]) as i8);
let v6 = (g.int_in(-128, 127, &[]) as i8);
let v7 = g.bool();
Self {
entity_id: v1,
d_x: v2,
d_y: v3,
d_z: v4,
yaw: v5,
pitch: v6,
on_ground: v7,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `entity_teleport` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct EntityTeleport<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `x`
pub x: i32,
/// `y`
pub y: i32,
/// `z`
pub z: i32,
/// `yaw`
pub yaw: i8,
/// `pitch`
pub pitch: i8,
/// `onGround`
pub on_ground: bool,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for EntityTeleport<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_i32()?;
let v3 = r.read_i32()?;
let v4 = r.read_i32()?;
let v5 = r.read_i8()?;
let v6 = r.read_i8()?;
let v7 = r.read_bool()?;
Self {
entity_id: v1,
x: v2,
y: v3,
z: v4,
yaw: v5,
pitch: v6,
on_ground: v7,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for EntityTeleport<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_i32((*self).x);
w.put_i32((*self).y);
w.put_i32((*self).z);
w.put_i8((*self).yaw);
w.put_i8((*self).pitch);
w.put_bool((*self).on_ground);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for EntityTeleport<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v5 = (g.int_in(-128, 127, &[]) as i8);
let v6 = (g.int_in(-128, 127, &[]) as i8);
let v7 = g.bool();
Self {
entity_id: v1,
x: v2,
y: v3,
z: v4,
yaw: v5,
pitch: v6,
on_ground: v7,
}
}
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
/// `entity_head_rotation` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct EntityHeadRotation<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `headYaw`
pub head_yaw: i8,
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Decode for EntityHeadRotation<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_i8()?;
Self {
entity_id: v1,
head_yaw: v2,
}
})
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Encode for EntityHeadRotation<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_i8((*self).head_yaw);
Ok(())
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for EntityHeadRotation<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-128, 127, &[]) as i8);
Self {
entity_id: v1,
head_yaw: v2,
}
}
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
/// `entity_status` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct EntityStatus<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `entityStatus`
pub entity_status: i8,
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Decode for EntityStatus<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_i32()?;
let v2 = r.read_i8()?;
Self {
entity_id: v1,
entity_status: v2,
}
})
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Encode for EntityStatus<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_i32((*self).entity_id);
w.put_i8((*self).entity_status);
Ok(())
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for EntityStatus<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-128, 127, &[]) as i8);
Self {
entity_id: v1,
entity_status: v2,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `attach_entity` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct AttachEntity<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `vehicleId`
pub vehicle_id: i32,
/// `leash`
pub leash: bool,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for AttachEntity<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_i32()?;
let v2 = r.read_i32()?;
let v3 = r.read_bool()?;
Self {
entity_id: v1,
vehicle_id: v2,
leash: v3,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for AttachEntity<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_i32((*self).entity_id);
w.put_i32((*self).vehicle_id);
w.put_bool((*self).leash);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for AttachEntity<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v3 = g.bool();
Self {
entity_id: v1,
vehicle_id: v2,
leash: v3,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `entity_metadata` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct EntityMetadata<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `metadata`
pub metadata: Vec<crate::defs::p47::types::EntityMetadataEntry>,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for EntityMetadata<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = {
let mut v3 = Vec::new();
loop {
if r.peek_u8()? == 127 {
r.skip(1)?;
break;
}
v3.push({
let v4 = u64::from(r.read_u8()?);
let v5 = (((v4 >> 5) & 0x7) as u8);
let v6 = (((v4 >> 0) & 0x1f) as u8);
let v7 = (if (v5 == 0) {
crate::defs::p47::types::EntityMetadataValue::Byte(r.read_i8()?)
} else if (v5 == 1) {
crate::defs::p47::types::EntityMetadataValue::Short(r.read_i16()?)
} else if (v5 == 2) {
crate::defs::p47::types::EntityMetadataValue::Int(r.read_i32()?)
} else if (v5 == 3) {
crate::defs::p47::types::EntityMetadataValue::Float(r.read_f32()?)
} else if (v5 == 4) {
crate::defs::p47::types::EntityMetadataValue::String(r.read_string()?)
} else if (v5 == 5) {
crate::defs::p47::types::EntityMetadataValue::Slot(
<crate::types::slot::legacy::Slot as Decode>::decode(r)?,
)
} else if (v5 == 6) {
crate::defs::p47::types::EntityMetadataValue::BlockPos({
let v8 = r.read_i32()?;
let v9 = r.read_i32()?;
let v10 = r.read_i32()?;
crate::defs::p47::types::EntityMetadataValueBlockPos {
x: v8,
y: v9,
z: v10,
}
})
} else if (v5 == 7) {
crate::defs::p47::types::EntityMetadataValue::Rotation({
let v11 = r.read_f32()?;
let v12 = r.read_f32()?;
let v13 = r.read_f32()?;
crate::defs::p47::types::EntityMetadataValueRotation {
pitch: v11,
yaw: v12,
roll: v13,
}
})
} else {
crate::defs::p47::types::EntityMetadataValue::Other
});
crate::defs::p47::types::EntityMetadataEntry {
r#type: v5,
key: v6,
value: v7,
}
});
}
v3
};
Self {
entity_id: v1,
metadata: v2,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for EntityMetadata<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
for v1 in (*self).metadata.iter() {
let v2 = w.len();
{
let mut bits: u64 = 0;
{
let x = i128::from((*v1).r#type);
if x < 0 || x > 7 {
return Err(EncodeError::OutOfRange("type"));
}
bits = (bits << 3) | ((x as u64) & 0x7);
}
{
let x = i128::from((*v1).key);
if x < 0 || x > 31 {
return Err(EncodeError::OutOfRange("key"));
}
bits = (bits << 5) | ((x as u64) & 0x1f);
}
w.put_u8(bits as u8);
}
match &(*v1).value {
crate::defs::p47::types::EntityMetadataValue::Byte(v3) => {
if !((*v1).r#type == 0) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
w.put_i8((*v3));
}
crate::defs::p47::types::EntityMetadataValue::Short(v4) => {
if !((*v1).r#type == 1) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
w.put_i16((*v4));
}
crate::defs::p47::types::EntityMetadataValue::Int(v5) => {
if !((*v1).r#type == 2) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
w.put_i32((*v5));
}
crate::defs::p47::types::EntityMetadataValue::Float(v6) => {
if !((*v1).r#type == 3) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
w.put_f32((*v6));
}
crate::defs::p47::types::EntityMetadataValue::String(v7) => {
if !((*v1).r#type == 4) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
w.put_string(&(*v7))?;
}
crate::defs::p47::types::EntityMetadataValue::Slot(v8) => {
if !((*v1).r#type == 5) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
(*v8).encode(w)?;
}
crate::defs::p47::types::EntityMetadataValue::BlockPos(v9) => {
if !((*v1).r#type == 6) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
w.put_i32((*v9).x);
w.put_i32((*v9).y);
w.put_i32((*v9).z);
}
crate::defs::p47::types::EntityMetadataValue::Rotation(v10) => {
if !((*v1).r#type == 7) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
w.put_f32((*v10).pitch);
w.put_f32((*v10).yaw);
w.put_f32((*v10).roll);
}
crate::defs::p47::types::EntityMetadataValue::Other => {
if !(!(((*v1).r#type == 0)
|| ((*v1).r#type == 1)
|| ((*v1).r#type == 2)
|| ((*v1).r#type == 3)
|| ((*v1).r#type == 4)
|| ((*v1).r#type == 5)
|| ((*v1).r#type == 6)
|| ((*v1).r#type == 7)))
{
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
}
}
if w.get(v2) == Some(&127) {
return Err(EncodeError::OutOfRange(
"play.clientbound.entity_metadata.metadata",
));
}
}
w.put_u8(127);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for EntityMetadata<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = {
let n = g.count();
let mut v3 = Vec::with_capacity(n);
for _ in 0..n {
v3.push(loop {
let v4 = {
let v6 = (g.int_in(0, 7, &[0, 1, 2, 3, 4, 5, 6, 7]) as u8);
let v7 = (g.int_in(0, 31, &[]) as u8);
let v8 = (if (v6 == 0) {
crate::defs::p47::types::EntityMetadataValue::Byte(
(g.int_in(-128, 127, &[]) as i8),
)
} else if (v6 == 1) {
crate::defs::p47::types::EntityMetadataValue::Short(
(g.int_in(-32768, 32767, &[]) as i16),
)
} else if (v6 == 2) {
crate::defs::p47::types::EntityMetadataValue::Int(
(g.int_in(-2147483648, 2147483647, &[]) as i32),
)
} else if (v6 == 3) {
crate::defs::p47::types::EntityMetadataValue::Float(g.f32())
} else if (v6 == 4) {
crate::defs::p47::types::EntityMetadataValue::String(g.string())
} else if (v6 == 5) {
crate::defs::p47::types::EntityMetadataValue::Slot(
<crate::types::slot::legacy::Slot as Generate>::generate(g),
)
} else if (v6 == 6) {
crate::defs::p47::types::EntityMetadataValue::BlockPos({
let v9 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v10 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v11 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
crate::defs::p47::types::EntityMetadataValueBlockPos {
x: v9,
y: v10,
z: v11,
}
})
} else if (v6 == 7) {
crate::defs::p47::types::EntityMetadataValue::Rotation({
let v12 = g.f32();
let v13 = g.f32();
let v14 = g.f32();
crate::defs::p47::types::EntityMetadataValueRotation {
pitch: v12,
yaw: v13,
roll: v14,
}
})
} else {
crate::defs::p47::types::EntityMetadataValue::Other
});
crate::defs::p47::types::EntityMetadataEntry {
r#type: v6,
key: v7,
value: v8,
}
};
if crate::testgen::first_byte_ok(
|w: &mut BytesMut| -> EncodeResult {
{
let mut bits: u64 = 0;
{
let x = i128::from(v4.r#type);
if x < 0 || x > 7 {
return Err(EncodeError::OutOfRange("type"));
}
bits = (bits << 3) | ((x as u64) & 0x7);
}
{
let x = i128::from(v4.key);
if x < 0 || x > 31 {
return Err(EncodeError::OutOfRange("key"));
}
bits = (bits << 5) | ((x as u64) & 0x1f);
}
w.put_u8(bits as u8);
}
match &v4.value {
crate::defs::p47::types::EntityMetadataValue::Byte(v15) => {
if !(v4.r#type == 0) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
w.put_i8((*v15));
}
crate::defs::p47::types::EntityMetadataValue::Short(v16) => {
if !(v4.r#type == 1) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
w.put_i16((*v16));
}
crate::defs::p47::types::EntityMetadataValue::Int(v17) => {
if !(v4.r#type == 2) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
w.put_i32((*v17));
}
crate::defs::p47::types::EntityMetadataValue::Float(v18) => {
if !(v4.r#type == 3) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
w.put_f32((*v18));
}
crate::defs::p47::types::EntityMetadataValue::String(v19) => {
if !(v4.r#type == 4) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
w.put_string(&(*v19))?;
}
crate::defs::p47::types::EntityMetadataValue::Slot(v20) => {
if !(v4.r#type == 5) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
(*v20).encode(w)?;
}
crate::defs::p47::types::EntityMetadataValue::BlockPos(v21) => {
if !(v4.r#type == 6) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
w.put_i32((*v21).x);
w.put_i32((*v21).y);
w.put_i32((*v21).z);
}
crate::defs::p47::types::EntityMetadataValue::Rotation(v22) => {
if !(v4.r#type == 7) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
w.put_f32((*v22).pitch);
w.put_f32((*v22).yaw);
w.put_f32((*v22).roll);
}
crate::defs::p47::types::EntityMetadataValue::Other => {
if !(!((v4.r#type == 0)
|| (v4.r#type == 1)
|| (v4.r#type == 2)
|| (v4.r#type == 3)
|| (v4.r#type == 4)
|| (v4.r#type == 5)
|| (v4.r#type == 6)
|| (v4.r#type == 7)))
{
return Err(EncodeError::SwitchMismatch(
"play.clientbound.entity_metadata.metadata.value",
));
}
}
}
Ok(())
},
|b| b != 127,
) {
break v4;
}
});
}
v3
};
Self {
entity_id: v1,
metadata: v2,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `entity_effect` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct EntityEffect<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `effectId`
pub effect_id: i8,
/// `amplifier`
pub amplifier: i8,
/// `duration`
pub duration: i32,
/// `hideParticles`
pub hide_particles: bool,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for EntityEffect<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_i8()?;
let v3 = r.read_i8()?;
let v4 = r.read_varint()?;
let v5 = r.read_bool()?;
Self {
entity_id: v1,
effect_id: v2,
amplifier: v3,
duration: v4,
hide_particles: v5,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for EntityEffect<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_i8((*self).effect_id);
w.put_i8((*self).amplifier);
w.put_varint((*self).duration);
w.put_bool((*self).hide_particles);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for EntityEffect<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-128, 127, &[]) as i8);
let v3 = (g.int_in(-128, 127, &[]) as i8);
let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v5 = g.bool();
Self {
entity_id: v1,
effect_id: v2,
amplifier: v3,
duration: v4,
hide_particles: v5,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `remove_entity_effect` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct RemoveEntityEffect<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `effectId`
pub effect_id: i8,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for RemoveEntityEffect<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_i8()?;
Self {
entity_id: v1,
effect_id: v2,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for RemoveEntityEffect<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_i8((*self).effect_id);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for RemoveEntityEffect<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-128, 127, &[]) as i8);
Self {
entity_id: v1,
effect_id: v2,
}
}
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
/// `experience` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Experience<const V: i32> {
/// `experienceBar`
pub experience_bar: f32,
/// `level`
pub level: i32,
/// `totalExperience`
pub total_experience: i32,
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Decode for Experience<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_f32()?;
let v2 = r.read_varint()?;
let v3 = r.read_varint()?;
Self {
experience_bar: v1,
level: v2,
total_experience: v3,
}
})
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Encode for Experience<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_f32((*self).experience_bar);
w.put_varint((*self).level);
w.put_varint((*self).total_experience);
Ok(())
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Experience<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.f32();
let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
Self {
experience_bar: v1,
level: v2,
total_experience: v3,
}
}
}
}
#[cfg(feature = "v1_8")]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct UpdateAttributesPropertiesModifiers {
/// `uuid`
pub uuid: Uuid,
/// `amount`
pub amount: f64,
/// `operation`
pub operation: i8,
}
#[cfg(feature = "v1_8")]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct UpdateAttributesProperties {
/// `key`
pub key: ByteString,
/// `value`
pub value: f64,
/// `modifiers`
pub modifiers: Vec<crate::defs::p47::play::clientbound::UpdateAttributesPropertiesModifiers>,
}
#[cfg(feature = "v1_8")]
/// `update_attributes` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct UpdateAttributes<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `properties`
pub properties: Vec<crate::defs::p47::play::clientbound::UpdateAttributesProperties>,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for UpdateAttributes<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = {
let v3 = {
let c = r.read_i32()?;
r.check_count(i64::from(c), 10)?
};
let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v3 {
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::p47::play::clientbound::UpdateAttributesPropertiesModifiers { uuid: v10, amount: v11, operation: v12 } }); } v9 }; crate::defs::p47::play::clientbound::UpdateAttributesProperties { key: v5, value: v6, modifiers: v7 } });
}
v4
};
Self {
entity_id: v1,
properties: v2,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for UpdateAttributes<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_i32(crate::codec::count_i32((*self).properties.len())?);
for v1 in (*self).properties.iter() {
w.put_string(&(*v1).key)?;
w.put_f64((*v1).value);
w.put_len_varint((*v1).modifiers.len())?;
for v2 in (*v1).modifiers.iter() {
w.put_uuid(&(*v2).uuid);
w.put_f64((*v2).amount);
w.put_i8((*v2).operation);
}
}
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for UpdateAttributes<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = {
let v3 = g.count();
let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v3 {
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::p47::play::clientbound::UpdateAttributesPropertiesModifiers { uuid: v10, amount: v11, operation: v12 } }); } v9 }; crate::defs::p47::play::clientbound::UpdateAttributesProperties { key: v5, value: v6, modifiers: v7 } });
}
v4
};
Self {
entity_id: v1,
properties: v2,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `map_chunk` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct MapChunk<const V: i32> {
/// `x`
pub x: i32,
/// `z`
pub z: i32,
/// `groundUp`
pub ground_up: bool,
/// `bitMap`
pub bit_map: u16,
/// `chunkData`
pub chunk_data: Bytes,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for MapChunk<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_i32()?;
let v2 = r.read_i32()?;
let v3 = r.read_bool()?;
let v4 = r.read_u16()?;
let v5 = r.read_byte_array()?;
Self {
x: v1,
z: v2,
ground_up: v3,
bit_map: v4,
chunk_data: v5,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for MapChunk<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_i32((*self).x);
w.put_i32((*self).z);
w.put_bool((*self).ground_up);
w.put_u16((*self).bit_map);
w.put_byte_array(&(*self).chunk_data)?;
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for MapChunk<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v3 = g.bool();
let v4 = (g.int_in(0, 65535, &[]) as u16);
let v5 = g.bytes();
Self {
x: v1,
z: v2,
ground_up: v3,
bit_map: v4,
chunk_data: v5,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct MultiBlockChangeRecords {
/// `horizontalPos`
pub horizontal_pos: u8,
/// `y`
pub y: u8,
/// `blockId`
pub block_id: i32,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `multi_block_change` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct MultiBlockChange<const V: i32> {
/// `chunkX`
pub chunk_x: i32,
/// `chunkZ`
pub chunk_z: i32,
/// `records`
pub records: Vec<crate::defs::p47::play::clientbound::MultiBlockChangeRecords>,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for MultiBlockChange<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_i32()?;
let v2 = r.read_i32()?;
let v3 = {
let v4 = {
let c = r.read_varint()?;
r.check_count(i64::from(c), 3)?
};
let mut v5 = Vec::with_capacity(v4.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v4 {
v5.push({
let v6 = r.read_u8()?;
let v7 = r.read_u8()?;
let v8 = r.read_varint()?;
crate::defs::p47::play::clientbound::MultiBlockChangeRecords {
horizontal_pos: v6,
y: v7,
block_id: v8,
}
});
}
v5
};
Self {
chunk_x: v1,
chunk_z: v2,
records: v3,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for MultiBlockChange<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_i32((*self).chunk_x);
w.put_i32((*self).chunk_z);
w.put_len_varint((*self).records.len())?;
for v1 in (*self).records.iter() {
w.put_u8((*v1).horizontal_pos);
w.put_u8((*v1).y);
w.put_varint((*v1).block_id);
}
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for MultiBlockChange<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v3 = {
let v4 = g.count();
let mut v5 = Vec::with_capacity(v4.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v4 {
v5.push({
let v6 = (g.int_in(0, 255, &[]) as u8);
let v7 = (g.int_in(0, 255, &[]) as u8);
let v8 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
crate::defs::p47::play::clientbound::MultiBlockChangeRecords {
horizontal_pos: v6,
y: v7,
block_id: v8,
}
});
}
v5
};
Self {
chunk_x: v1,
chunk_z: v2,
records: v3,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `block_change` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct BlockChange<const V: i32> {
/// `location`
pub location: BlockPos,
/// `type`
pub r#type: i32,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for BlockChange<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = BlockPos::read(r, PositionLayout::Xyz)?;
let v2 = r.read_varint()?;
Self {
location: v1,
r#type: v2,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for BlockChange<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
(*self).location.write(w, PositionLayout::Xyz)?;
w.put_varint((*self).r#type);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for BlockChange<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.position();
let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
Self {
location: v1,
r#type: v2,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `block_action` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct BlockAction<const V: i32> {
/// `location`
pub location: BlockPos,
/// `byte1`
pub byte1: u8,
/// `byte2`
pub byte2: u8,
/// `blockId`
pub block_id: i32,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for BlockAction<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = BlockPos::read(r, PositionLayout::Xyz)?;
let v2 = r.read_u8()?;
let v3 = r.read_u8()?;
let v4 = r.read_varint()?;
Self {
location: v1,
byte1: v2,
byte2: v3,
block_id: v4,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for BlockAction<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
(*self).location.write(w, PositionLayout::Xyz)?;
w.put_u8((*self).byte1);
w.put_u8((*self).byte2);
w.put_varint((*self).block_id);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for BlockAction<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.position();
let v2 = (g.int_in(0, 255, &[]) as u8);
let v3 = (g.int_in(0, 255, &[]) as u8);
let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
Self {
location: v1,
byte1: v2,
byte2: v3,
block_id: v4,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `block_break_animation` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct BlockBreakAnimation<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `location`
pub location: BlockPos,
/// `destroyStage`
pub destroy_stage: i8,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for BlockBreakAnimation<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = BlockPos::read(r, PositionLayout::Xyz)?;
let v3 = r.read_i8()?;
Self {
entity_id: v1,
location: v2,
destroy_stage: v3,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for BlockBreakAnimation<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
(*self).location.write(w, PositionLayout::Xyz)?;
w.put_i8((*self).destroy_stage);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for BlockBreakAnimation<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = g.position();
let v3 = (g.int_in(-128, 127, &[]) as i8);
Self {
entity_id: v1,
location: v2,
destroy_stage: v3,
}
}
}
}
#[cfg(feature = "v1_8")]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct MapChunkBulkMeta {
/// `x`
pub x: i32,
/// `z`
pub z: i32,
/// `bitMap`
pub bit_map: u16,
}
#[cfg(feature = "v1_8")]
/// `map_chunk_bulk` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct MapChunkBulk<const V: i32> {
/// `skyLightSent`
pub sky_light_sent: bool,
/// `meta`
pub meta: Vec<crate::defs::p47::play::clientbound::MapChunkBulkMeta>,
/// `data`
pub data: Bytes,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for MapChunkBulk<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_bool()?;
let v2 = {
let v3 = {
let c = r.read_varint()?;
r.check_count(i64::from(c), 10)?
};
let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v3 {
v4.push({
let v5 = r.read_i32()?;
let v6 = r.read_i32()?;
let v7 = r.read_u16()?;
crate::defs::p47::play::clientbound::MapChunkBulkMeta {
x: v5,
z: v6,
bit_map: v7,
}
});
}
v4
};
let v8 = r.read_rest();
Self {
sky_light_sent: v1,
meta: v2,
data: v8,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for MapChunkBulk<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_bool((*self).sky_light_sent);
w.put_len_varint((*self).meta.len())?;
for v1 in (*self).meta.iter() {
w.put_i32((*v1).x);
w.put_i32((*v1).z);
w.put_u16((*v1).bit_map);
}
w.put_slice(&(*self).data);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for MapChunkBulk<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.bool();
let v2 = {
let v3 = g.count();
let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v3 {
v4.push({
let v5 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v6 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v7 = (g.int_in(0, 65535, &[]) as u16);
crate::defs::p47::play::clientbound::MapChunkBulkMeta {
x: v5,
z: v6,
bit_map: v7,
}
});
}
v4
};
let v8 = g.bytes();
Self {
sky_light_sent: v1,
meta: v2,
data: v8,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct ExplosionAffectedBlockOffsets {
/// `x`
pub x: i8,
/// `y`
pub y: i8,
/// `z`
pub z: i8,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `explosion` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Explosion<const V: i32> {
/// `x`
pub x: f32,
/// `y`
pub y: f32,
/// `z`
pub z: f32,
/// `radius`
pub radius: f32,
/// `affectedBlockOffsets`
pub affected_block_offsets:
Vec<crate::defs::p47::play::clientbound::ExplosionAffectedBlockOffsets>,
/// `playerMotionX`
pub player_motion_x: f32,
/// `playerMotionY`
pub player_motion_y: f32,
/// `playerMotionZ`
pub player_motion_z: f32,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for Explosion<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_f32()?;
let v2 = r.read_f32()?;
let v3 = r.read_f32()?;
let v4 = r.read_f32()?;
let v5 = {
let v6 = {
let c = r.read_i32()?;
r.check_count(i64::from(c), 3)?
};
let mut v7 = Vec::with_capacity(v6.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v6 {
v7.push({
let v8 = r.read_i8()?;
let v9 = r.read_i8()?;
let v10 = r.read_i8()?;
crate::defs::p47::play::clientbound::ExplosionAffectedBlockOffsets {
x: v8,
y: v9,
z: v10,
}
});
}
v7
};
let v11 = r.read_f32()?;
let v12 = r.read_f32()?;
let v13 = r.read_f32()?;
Self {
x: v1,
y: v2,
z: v3,
radius: v4,
affected_block_offsets: v5,
player_motion_x: v11,
player_motion_y: v12,
player_motion_z: v13,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for Explosion<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_f32((*self).x);
w.put_f32((*self).y);
w.put_f32((*self).z);
w.put_f32((*self).radius);
w.put_i32(crate::codec::count_i32(
(*self).affected_block_offsets.len(),
)?);
for v1 in (*self).affected_block_offsets.iter() {
w.put_i8((*v1).x);
w.put_i8((*v1).y);
w.put_i8((*v1).z);
}
w.put_f32((*self).player_motion_x);
w.put_f32((*self).player_motion_y);
w.put_f32((*self).player_motion_z);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Explosion<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.f32();
let v2 = g.f32();
let v3 = g.f32();
let v4 = g.f32();
let v5 = {
let v6 = g.count();
let mut v7 = Vec::with_capacity(v6.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v6 {
v7.push({
let v8 = (g.int_in(-128, 127, &[]) as i8);
let v9 = (g.int_in(-128, 127, &[]) as i8);
let v10 = (g.int_in(-128, 127, &[]) as i8);
crate::defs::p47::play::clientbound::ExplosionAffectedBlockOffsets {
x: v8,
y: v9,
z: v10,
}
});
}
v7
};
let v11 = g.f32();
let v12 = g.f32();
let v13 = g.f32();
Self {
x: v1,
y: v2,
z: v3,
radius: v4,
affected_block_offsets: v5,
player_motion_x: v11,
player_motion_y: v12,
player_motion_z: v13,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `world_event` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct WorldEvent<const V: i32> {
/// `effectId`
pub effect_id: i32,
/// `location`
pub location: BlockPos,
/// `data`
pub data: i32,
/// `global`
pub global: bool,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for WorldEvent<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_i32()?;
let v2 = BlockPos::read(r, PositionLayout::Xyz)?;
let v3 = r.read_i32()?;
let v4 = r.read_bool()?;
Self {
effect_id: v1,
location: v2,
data: v3,
global: v4,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for WorldEvent<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_i32((*self).effect_id);
(*self).location.write(w, PositionLayout::Xyz)?;
w.put_i32((*self).data);
w.put_bool((*self).global);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for WorldEvent<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = g.position();
let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v4 = g.bool();
Self {
effect_id: v1,
location: v2,
data: v3,
global: v4,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `named_sound_effect` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct NamedSoundEffect<const V: i32> {
/// `soundName`
pub sound_name: ByteString,
/// `x`
pub x: i32,
/// `y`
pub y: i32,
/// `z`
pub z: i32,
/// `volume`
pub volume: f32,
/// `pitch`
pub pitch: u8,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for NamedSoundEffect<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_string()?;
let v2 = r.read_i32()?;
let v3 = r.read_i32()?;
let v4 = r.read_i32()?;
let v5 = r.read_f32()?;
let v6 = r.read_u8()?;
Self {
sound_name: v1,
x: v2,
y: v3,
z: v4,
volume: v5,
pitch: v6,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for NamedSoundEffect<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_string(&(*self).sound_name)?;
w.put_i32((*self).x);
w.put_i32((*self).y);
w.put_i32((*self).z);
w.put_f32((*self).volume);
w.put_u8((*self).pitch);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for NamedSoundEffect<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.string();
let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v5 = g.f32();
let v6 = (g.int_in(0, 255, &[]) as u8);
Self {
sound_name: v1,
x: v2,
y: v3,
z: v4,
volume: v5,
pitch: v6,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// Switch on `particleId`.
#[derive(Debug, Clone, PartialEq)]
pub enum WorldParticlesData {
/// Case(s) `36`.
Case36(Vec<i32>),
/// Case(s) `37`.
Case37(Vec<i32>),
/// Case(s) `38`.
Case38(Vec<i32>),
/// Any other value.
Other,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `world_particles` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct WorldParticles<const V: i32> {
/// `particleId`
pub particle_id: i32,
/// `longDistance`
pub long_distance: bool,
/// `x`
pub x: f32,
/// `y`
pub y: f32,
/// `z`
pub z: f32,
/// `offsetX`
pub offset_x: f32,
/// `offsetY`
pub offset_y: f32,
/// `offsetZ`
pub offset_z: f32,
/// `particleData`
pub particle_data: f32,
/// `particles`
pub particles: i32,
/// `data`
pub data: crate::defs::p47::play::clientbound::WorldParticlesData,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for WorldParticles<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_i32()?;
let v2 = r.read_bool()?;
let v3 = r.read_f32()?;
let v4 = r.read_f32()?;
let v5 = r.read_f32()?;
let v6 = r.read_f32()?;
let v7 = r.read_f32()?;
let v8 = r.read_f32()?;
let v9 = r.read_f32()?;
let v10 = r.read_i32()?;
let v11 = (if (v1 == 36) {
crate::defs::p47::play::clientbound::WorldParticlesData::Case36({
let v12 = 2;
let mut v13 = Vec::with_capacity(v12.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v12 {
v13.push(r.read_varint()?);
}
v13
})
} else if (v1 == 37) {
crate::defs::p47::play::clientbound::WorldParticlesData::Case37({
let v14 = 1;
let mut v15 = Vec::with_capacity(v14.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v14 {
v15.push(r.read_varint()?);
}
v15
})
} else if (v1 == 38) {
crate::defs::p47::play::clientbound::WorldParticlesData::Case38({
let v16 = 1;
let mut v17 = Vec::with_capacity(v16.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v16 {
v17.push(r.read_varint()?);
}
v17
})
} else {
crate::defs::p47::play::clientbound::WorldParticlesData::Other
});
Self {
particle_id: v1,
long_distance: v2,
x: v3,
y: v4,
z: v5,
offset_x: v6,
offset_y: v7,
offset_z: v8,
particle_data: v9,
particles: v10,
data: v11,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for WorldParticles<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_i32((*self).particle_id);
w.put_bool((*self).long_distance);
w.put_f32((*self).x);
w.put_f32((*self).y);
w.put_f32((*self).z);
w.put_f32((*self).offset_x);
w.put_f32((*self).offset_y);
w.put_f32((*self).offset_z);
w.put_f32((*self).particle_data);
w.put_i32((*self).particles);
match &(*self).data {
crate::defs::p47::play::clientbound::WorldParticlesData::Case36(v1) => {
if !((*self).particle_id == 36) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.world_particles.data",
));
}
if (*v1).len() != 2 {
return Err(EncodeError::CountMismatch {
field: "play.clientbound.world_particles.data",
expected: 2,
actual: (*v1).len(),
});
}
for v2 in (*v1).iter() {
w.put_varint((*v2));
}
}
crate::defs::p47::play::clientbound::WorldParticlesData::Case37(v3) => {
if !((*self).particle_id == 37) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.world_particles.data",
));
}
if (*v3).len() != 1 {
return Err(EncodeError::CountMismatch {
field: "play.clientbound.world_particles.data",
expected: 1,
actual: (*v3).len(),
});
}
for v4 in (*v3).iter() {
w.put_varint((*v4));
}
}
crate::defs::p47::play::clientbound::WorldParticlesData::Case38(v5) => {
if !((*self).particle_id == 38) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.world_particles.data",
));
}
if (*v5).len() != 1 {
return Err(EncodeError::CountMismatch {
field: "play.clientbound.world_particles.data",
expected: 1,
actual: (*v5).len(),
});
}
for v6 in (*v5).iter() {
w.put_varint((*v6));
}
}
crate::defs::p47::play::clientbound::WorldParticlesData::Other => {
if !(!(((*self).particle_id == 36)
|| ((*self).particle_id == 37)
|| ((*self).particle_id == 38)))
{
return Err(EncodeError::SwitchMismatch(
"play.clientbound.world_particles.data",
));
}
}
}
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for WorldParticles<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[36, 37, 38]) as i32);
let v2 = g.bool();
let v3 = g.f32();
let v4 = g.f32();
let v5 = g.f32();
let v6 = g.f32();
let v7 = g.f32();
let v8 = g.f32();
let v9 = g.f32();
let v10 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v11 = (if (v1 == 36) {
crate::defs::p47::play::clientbound::WorldParticlesData::Case36({
let v12 = 2;
let mut v13 = Vec::with_capacity(v12.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v12 {
v13.push((g.int_in(-2147483648, 2147483647, &[]) as i32));
}
v13
})
} else if (v1 == 37) {
crate::defs::p47::play::clientbound::WorldParticlesData::Case37({
let v14 = 1;
let mut v15 = Vec::with_capacity(v14.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v14 {
v15.push((g.int_in(-2147483648, 2147483647, &[]) as i32));
}
v15
})
} else if (v1 == 38) {
crate::defs::p47::play::clientbound::WorldParticlesData::Case38({
let v16 = 1;
let mut v17 = Vec::with_capacity(v16.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v16 {
v17.push((g.int_in(-2147483648, 2147483647, &[]) as i32));
}
v17
})
} else {
crate::defs::p47::play::clientbound::WorldParticlesData::Other
});
Self {
particle_id: v1,
long_distance: v2,
x: v3,
y: v4,
z: v5,
offset_x: v6,
offset_y: v7,
offset_z: v8,
particle_data: v9,
particles: v10,
data: v11,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// Mapped `u8` value; unknown values are kept as-is.
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
pub struct GameStateChangeReason(pub u8);
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl GameStateChangeReason {
/// `no_respawn_block_available`
pub const NO_RESPAWN_BLOCK_AVAILABLE: Self = Self(0);
/// `start_raining`
pub const START_RAINING: Self = Self(1);
/// `stop_raining`
pub const STOP_RAINING: Self = Self(2);
/// `change_game_mode`
pub const CHANGE_GAME_MODE: Self = Self(3);
/// `win_game`
pub const WIN_GAME: Self = Self(4);
/// `demo_event`
pub const DEMO_EVENT: Self = Self(5);
/// `play_arrow_hit_sound`
pub const PLAY_ARROW_HIT_SOUND: Self = Self(6);
/// `rain_level_change`
pub const RAIN_LEVEL_CHANGE: Self = Self(7);
/// `thunder_level_change`
pub const THUNDER_LEVEL_CHANGE: Self = Self(8);
/// `guardian_elder_effect`
pub const GUARDIAN_ELDER_EFFECT: Self = Self(10);
/// minecraft-data name of the value, if known.
pub const fn name(self) -> Option<&'static str> {
match self.0 {
0 => Some("no_respawn_block_available"),
1 => Some("start_raining"),
2 => Some("stop_raining"),
3 => Some("change_game_mode"),
4 => Some("win_game"),
5 => Some("demo_event"),
6 => Some("play_arrow_hit_sound"),
7 => Some("rain_level_change"),
8 => Some("thunder_level_change"),
10 => Some("guardian_elder_effect"),
_ => None,
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl std::fmt::Debug for GameStateChangeReason {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.name() {
Some(n) => write!(f, "GameStateChangeReason::{n}"),
None => write!(f, "GameStateChangeReason({})", self.0),
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `game_state_change` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct GameStateChange<const V: i32> {
/// `reason`
pub reason: crate::defs::p47::play::clientbound::GameStateChangeReason,
/// `gameMode`
pub game_mode: f32,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for GameStateChange<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = crate::defs::p47::play::clientbound::GameStateChangeReason(r.read_u8()?);
let v2 = r.read_f32()?;
Self {
reason: v1,
game_mode: v2,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for GameStateChange<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_u8((*self).reason.0);
w.put_f32((*self).game_mode);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for GameStateChange<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = crate::defs::p47::play::clientbound::GameStateChangeReason(g.int_in(
0,
255,
&[0, 1, 2, 3, 4, 5, 6, 7, 8, 10],
)
as u8);
let v2 = g.f32();
Self {
reason: v1,
game_mode: v2,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `spawn_entity_weather` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct SpawnEntityWeather<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `type`
pub r#type: i8,
/// `x`
pub x: i32,
/// `y`
pub y: i32,
/// `z`
pub z: i32,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for SpawnEntityWeather<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_i8()?;
let v3 = r.read_i32()?;
let v4 = r.read_i32()?;
let v5 = r.read_i32()?;
Self {
entity_id: v1,
r#type: v2,
x: v3,
y: v4,
z: v5,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for SpawnEntityWeather<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
w.put_i8((*self).r#type);
w.put_i32((*self).x);
w.put_i32((*self).y);
w.put_i32((*self).z);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for SpawnEntityWeather<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-128, 127, &[]) as i8);
let v3 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v4 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v5 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
Self {
entity_id: v1,
r#type: v2,
x: v3,
y: v4,
z: v5,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `open_window` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct OpenWindow<const V: i32> {
/// `windowId`
pub window_id: u8,
/// `inventoryType`
pub inventory_type: ByteString,
/// `windowTitle`
pub window_title: ByteString,
/// `slotCount`
pub slot_count: u8,
/// `entityId`
pub entity_id: Option<i32>,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for OpenWindow<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_u8()?;
let v2 = r.read_string()?;
let v3 = r.read_string()?;
let v4 = r.read_u8()?;
let v5 = if (&*v2 == "EntityHorse") {
Some(r.read_i32()?)
} else {
None
};
Self {
window_id: v1,
inventory_type: v2,
window_title: v3,
slot_count: v4,
entity_id: v5,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for OpenWindow<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_u8((*self).window_id);
w.put_string(&(*self).inventory_type)?;
w.put_string(&(*self).window_title)?;
w.put_u8((*self).slot_count);
match (
&(*self).entity_id,
(&*(*self).inventory_type == "EntityHorse"),
) {
(Some(v1), true) => {
w.put_i32((*v1));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.open_window.entityId",
));
}
}
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for OpenWindow<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(0, 255, &[]) as u8);
let v2 = g.string_in(&["EntityHorse"]);
let v3 = g.string();
let v4 = (g.int_in(0, 255, &[]) as u8);
let v5 = if (&*v2 == "EntityHorse") {
Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
} else {
None
};
Self {
window_id: v1,
inventory_type: v2,
window_title: v3,
slot_count: v4,
entity_id: v5,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `close_window` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct CloseWindow<const V: i32> {
/// `windowId`
pub window_id: u8,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for CloseWindow<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_u8()?;
Self { window_id: v1 }
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for CloseWindow<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_u8((*self).window_id);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for CloseWindow<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(0, 255, &[]) as u8);
Self { window_id: v1 }
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `set_slot` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct SetSlot<const V: i32> {
/// `windowId`
pub window_id: i8,
/// `slot`
pub slot: i16,
/// `item`
pub item: crate::types::slot::legacy::Slot,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for SetSlot<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_i8()?;
let v2 = r.read_i16()?;
let v3 = <crate::types::slot::legacy::Slot as Decode>::decode(r)?;
Self {
window_id: v1,
slot: v2,
item: v3,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for SetSlot<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_i8((*self).window_id);
w.put_i16((*self).slot);
(*self).item.encode(w)?;
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for SetSlot<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-128, 127, &[]) as i8);
let v2 = (g.int_in(-32768, 32767, &[]) as i16);
let v3 = <crate::types::slot::legacy::Slot as Generate>::generate(g);
Self {
window_id: v1,
slot: v2,
item: v3,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `window_items` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct WindowItems<const V: i32> {
/// `windowId`
pub window_id: u8,
/// `items`
pub items: Vec<crate::types::slot::legacy::Slot>,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for WindowItems<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_u8()?;
let v2 = {
let v3 = {
let c = r.read_i16()?;
r.check_count(i64::from(c), 1)?
};
let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v3 {
v4.push(<crate::types::slot::legacy::Slot as Decode>::decode(r)?);
}
v4
};
Self {
window_id: v1,
items: v2,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for WindowItems<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_u8((*self).window_id);
w.put_i16(crate::codec::count_i16((*self).items.len())?);
for v1 in (*self).items.iter() {
(*v1).encode(w)?;
}
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for WindowItems<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(0, 255, &[]) as u8);
let v2 = {
let v3 = g.count();
let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v3 {
v4.push(<crate::types::slot::legacy::Slot as Generate>::generate(g));
}
v4
};
Self {
window_id: v1,
items: v2,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `craft_progress_bar` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct CraftProgressBar<const V: i32> {
/// `windowId`
pub window_id: u8,
/// `property`
pub property: i16,
/// `value`
pub value: i16,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for CraftProgressBar<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_u8()?;
let v2 = r.read_i16()?;
let v3 = r.read_i16()?;
Self {
window_id: v1,
property: v2,
value: v3,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for CraftProgressBar<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_u8((*self).window_id);
w.put_i16((*self).property);
w.put_i16((*self).value);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for CraftProgressBar<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(0, 255, &[]) as u8);
let v2 = (g.int_in(-32768, 32767, &[]) as i16);
let v3 = (g.int_in(-32768, 32767, &[]) as i16);
Self {
window_id: v1,
property: v2,
value: v3,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `transaction` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Transaction<const V: i32> {
/// `windowId`
pub window_id: i8,
/// `action`
pub action: i16,
/// `accepted`
pub accepted: bool,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for Transaction<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_i8()?;
let v2 = r.read_i16()?;
let v3 = r.read_bool()?;
Self {
window_id: v1,
action: v2,
accepted: v3,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for Transaction<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_i8((*self).window_id);
w.put_i16((*self).action);
w.put_bool((*self).accepted);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Transaction<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-128, 127, &[]) as i8);
let v2 = (g.int_in(-32768, 32767, &[]) as i16);
let v3 = g.bool();
Self {
window_id: v1,
action: v2,
accepted: v3,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `update_sign` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct UpdateSign<const V: i32> {
/// `location`
pub location: BlockPos,
/// `text1`
pub text1: ByteString,
/// `text2`
pub text2: ByteString,
/// `text3`
pub text3: ByteString,
/// `text4`
pub text4: ByteString,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for UpdateSign<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = BlockPos::read(r, PositionLayout::Xyz)?;
let v2 = r.read_string()?;
let v3 = r.read_string()?;
let v4 = r.read_string()?;
let v5 = r.read_string()?;
Self {
location: v1,
text1: v2,
text2: v3,
text3: v4,
text4: v5,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for UpdateSign<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
(*self).location.write(w, PositionLayout::Xyz)?;
w.put_string(&(*self).text1)?;
w.put_string(&(*self).text2)?;
w.put_string(&(*self).text3)?;
w.put_string(&(*self).text4)?;
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for UpdateSign<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.position();
let v2 = g.string();
let v3 = g.string();
let v4 = g.string();
let v5 = g.string();
Self {
location: v1,
text1: v2,
text2: v3,
text3: v4,
text4: v5,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct MapIcons {
/// `directionAndType`
pub direction_and_type: i8,
/// `x`
pub x: i8,
/// `z`
pub z: i8,
}
#[cfg(feature = "v1_8")]
/// `map` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Map<const V: i32> {
/// `itemDamage`
pub item_damage: i32,
/// `scale`
pub scale: i8,
/// `icons`
pub icons: Vec<crate::defs::p47::play::clientbound::MapIcons>,
/// `columns`
pub columns: i8,
/// `rows`
pub rows: Option<i8>,
/// `x`
pub x: Option<i8>,
/// `y`
pub y: Option<i8>,
/// `data`
pub data: Option<Bytes>,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for Map<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = r.read_i8()?;
let v3 = {
let v4 = {
let c = r.read_varint()?;
r.check_count(i64::from(c), 3)?
};
let mut v5 = Vec::with_capacity(v4.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v4 {
v5.push({
let v6 = r.read_i8()?;
let v7 = r.read_i8()?;
let v8 = r.read_i8()?;
crate::defs::p47::play::clientbound::MapIcons {
direction_and_type: v6,
x: v7,
z: v8,
}
});
}
v5
};
let v9 = r.read_i8()?;
let v10 = if !(v9 == 0) { Some(r.read_i8()?) } else { None };
let v11 = if !(v9 == 0) { Some(r.read_i8()?) } else { None };
let v12 = if !(v9 == 0) { Some(r.read_i8()?) } else { None };
let v13 = if !(v9 == 0) {
Some(r.read_byte_array()?)
} else {
None
};
Self {
item_damage: v1,
scale: v2,
icons: v3,
columns: v9,
rows: v10,
x: v11,
y: v12,
data: v13,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for Map<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).item_damage);
w.put_i8((*self).scale);
w.put_len_varint((*self).icons.len())?;
for v1 in (*self).icons.iter() {
w.put_i8((*v1).direction_and_type);
w.put_i8((*v1).x);
w.put_i8((*v1).z);
}
w.put_i8((*self).columns);
match (&(*self).rows, !((*self).columns == 0)) {
(Some(v2), true) => {
w.put_i8((*v2));
}
(None, false) => {}
_ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.rows")),
}
match (&(*self).x, !((*self).columns == 0)) {
(Some(v3), true) => {
w.put_i8((*v3));
}
(None, false) => {}
_ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.x")),
}
match (&(*self).y, !((*self).columns == 0)) {
(Some(v4), true) => {
w.put_i8((*v4));
}
(None, false) => {}
_ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.y")),
}
match (&(*self).data, !((*self).columns == 0)) {
(Some(v5), true) => {
w.put_byte_array(&(*v5))?;
}
(None, false) => {}
_ => return Err(EncodeError::SwitchMismatch("play.clientbound.map.data")),
}
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Map<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = (g.int_in(-128, 127, &[]) as i8);
let v3 = {
let v4 = g.count();
let mut v5 = Vec::with_capacity(v4.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v4 {
v5.push({
let v6 = (g.int_in(-128, 127, &[]) as i8);
let v7 = (g.int_in(-128, 127, &[]) as i8);
let v8 = (g.int_in(-128, 127, &[]) as i8);
crate::defs::p47::play::clientbound::MapIcons {
direction_and_type: v6,
x: v7,
z: v8,
}
});
}
v5
};
let v9 = (g.int_in(-128, 127, &[0, 0, 0, 0]) as i8);
let v10 = if !(v9 == 0) {
Some((g.int_in(-128, 127, &[]) as i8))
} else {
None
};
let v11 = if !(v9 == 0) {
Some((g.int_in(-128, 127, &[]) as i8))
} else {
None
};
let v12 = if !(v9 == 0) {
Some((g.int_in(-128, 127, &[]) as i8))
} else {
None
};
let v13 = if !(v9 == 0) { Some(g.bytes()) } else { None };
Self {
item_damage: v1,
scale: v2,
icons: v3,
columns: v9,
rows: v10,
x: v11,
y: v12,
data: v13,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `tile_entity_data` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct TileEntityData<const V: i32> {
/// `location`
pub location: BlockPos,
/// `action`
pub action: u8,
/// `nbtData`
pub nbt_data: Option<RawNbt>,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for TileEntityData<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = BlockPos::read(r, PositionLayout::Xyz)?;
let v2 = r.read_u8()?;
let v3 = RawNbt::read_optional(r)?;
Self {
location: v1,
action: v2,
nbt_data: v3,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for TileEntityData<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
(*self).location.write(w, PositionLayout::Xyz)?;
w.put_u8((*self).action);
RawNbt::write_optional(&(*self).nbt_data, w);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for TileEntityData<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.position();
let v2 = (g.int_in(0, 255, &[]) as u8);
let v3 = g.opt_nbt();
Self {
location: v1,
action: v2,
nbt_data: v3,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `open_sign_entity` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct OpenSignEntity<const V: i32> {
/// `location`
pub location: BlockPos,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for OpenSignEntity<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = BlockPos::read(r, PositionLayout::Xyz)?;
Self { location: v1 }
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for OpenSignEntity<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
(*self).location.write(w, PositionLayout::Xyz)?;
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for OpenSignEntity<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.position();
Self { location: v1 }
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct StatisticsEntries {
/// `name`
pub name: ByteString,
/// `value`
pub value: i32,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `statistics` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Statistics<const V: i32> {
/// `entries`
pub entries: Vec<crate::defs::p47::play::clientbound::StatisticsEntries>,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for Statistics<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = {
let v2 = {
let c = r.read_varint()?;
r.check_count(i64::from(c), 2)?
};
let mut v3 = Vec::with_capacity(v2.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v2 {
v3.push({
let v4 = r.read_string()?;
let v5 = r.read_varint()?;
crate::defs::p47::play::clientbound::StatisticsEntries {
name: v4,
value: v5,
}
});
}
v3
};
Self { entries: v1 }
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for Statistics<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_len_varint((*self).entries.len())?;
for v1 in (*self).entries.iter() {
w.put_string(&(*v1).name)?;
w.put_varint((*v1).value);
}
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Statistics<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = {
let v2 = g.count();
let mut v3 = Vec::with_capacity(v2.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v2 {
v3.push({
let v4 = g.string();
let v5 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
crate::defs::p47::play::clientbound::StatisticsEntries {
name: v4,
value: v5,
}
});
}
v3
};
Self { entries: v1 }
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// Mapped `i32` value; unknown values are kept as-is.
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
pub struct PlayerInfoAction(pub i32);
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl PlayerInfoAction {
/// `add_player`
pub const ADD_PLAYER: Self = Self(0);
/// `update_game_mode`
pub const UPDATE_GAME_MODE: Self = Self(1);
/// `update_latency`
pub const UPDATE_LATENCY: Self = Self(2);
/// `update_display_name`
pub const UPDATE_DISPLAY_NAME: Self = Self(3);
/// `remove_player`
pub const REMOVE_PLAYER: Self = Self(4);
/// minecraft-data name of the value, if known.
pub const fn name(self) -> Option<&'static str> {
match self.0 {
0 => Some("add_player"),
1 => Some("update_game_mode"),
2 => Some("update_latency"),
3 => Some("update_display_name"),
4 => Some("remove_player"),
_ => None,
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl std::fmt::Debug for PlayerInfoAction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.name() {
Some(n) => write!(f, "PlayerInfoAction::{n}"),
None => write!(f, "PlayerInfoAction({})", self.0),
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct PlayerInfoDataBodyAddPlayerProperties {
/// `name`
pub name: ByteString,
/// `value`
pub value: ByteString,
/// `signature`
pub signature: Option<ByteString>,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct PlayerInfoDataBodyAddPlayer {
/// `name`
pub name: ByteString,
/// `properties`
pub properties: Vec<crate::defs::p47::play::clientbound::PlayerInfoDataBodyAddPlayerProperties>,
/// `gamemode`
pub gamemode: i32,
/// `ping`
pub ping: i32,
/// `displayName`
pub display_name: Option<ByteString>,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct PlayerInfoDataBodyUpdateGameMode {
/// `gamemode`
pub gamemode: i32,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct PlayerInfoDataBodyUpdateLatency {
/// `ping`
pub ping: i32,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct PlayerInfoDataBodyUpdateDisplayName {
/// `displayName`
pub display_name: Option<ByteString>,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// Switch on `../action`.
#[derive(Debug, Clone, PartialEq)]
pub enum PlayerInfoDataBody {
/// Case(s) `add_player`.
AddPlayer(crate::defs::p47::play::clientbound::PlayerInfoDataBodyAddPlayer),
/// Case(s) `update_game_mode`.
UpdateGameMode(crate::defs::p47::play::clientbound::PlayerInfoDataBodyUpdateGameMode),
/// Case(s) `update_latency`.
UpdateLatency(crate::defs::p47::play::clientbound::PlayerInfoDataBodyUpdateLatency),
/// Case(s) `update_display_name`.
UpdateDisplayName(crate::defs::p47::play::clientbound::PlayerInfoDataBodyUpdateDisplayName),
/// Case(s) `remove_player`.
RemovePlayer,
/// Any other value.
Other,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct PlayerInfoData {
/// `uuid`
pub uuid: Uuid,
/// Anonymous switch
pub body: crate::defs::p47::play::clientbound::PlayerInfoDataBody,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `player_info` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct PlayerInfo<const V: i32> {
/// `action`
pub action: crate::defs::p47::play::clientbound::PlayerInfoAction,
/// `data`
pub data: Vec<crate::defs::p47::play::clientbound::PlayerInfoData>,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for PlayerInfo<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = crate::defs::p47::play::clientbound::PlayerInfoAction(r.read_varint()?);
let v2 = {
let v3 = {
let c = r.read_varint()?;
r.check_count(i64::from(c), 16)?
};
let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v3 {
v4.push({ let v5 = r.read_uuid()?;let v6 = (if (v1.0 == 0) { crate::defs::p47::play::clientbound::PlayerInfoDataBody::AddPlayer({ let v7 = r.read_string()?;let v8 = { let v9 = { let c = r.read_varint()?; r.check_count(i64::from(c), 3)? }; let mut v10 = Vec::with_capacity(v9.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v9 { v10.push({ let v11 = r.read_string()?;let v12 = r.read_string()?;let v13 = if r.read_bool()? { Some(r.read_string()?) } else { None }; crate::defs::p47::play::clientbound::PlayerInfoDataBodyAddPlayerProperties { name: v11, value: v12, signature: v13 } }); } v10 };let v14 = r.read_varint()?;let v15 = r.read_varint()?;let v16 = if r.read_bool()? { Some(r.read_string()?) } else { None }; crate::defs::p47::play::clientbound::PlayerInfoDataBodyAddPlayer { name: v7, properties: v8, gamemode: v14, ping: v15, display_name: v16 } }) } else if (v1.0 == 1) { crate::defs::p47::play::clientbound::PlayerInfoDataBody::UpdateGameMode({ let v17 = r.read_varint()?; crate::defs::p47::play::clientbound::PlayerInfoDataBodyUpdateGameMode { gamemode: v17 } }) } else if (v1.0 == 2) { crate::defs::p47::play::clientbound::PlayerInfoDataBody::UpdateLatency({ let v18 = r.read_varint()?; crate::defs::p47::play::clientbound::PlayerInfoDataBodyUpdateLatency { ping: v18 } }) } else if (v1.0 == 3) { crate::defs::p47::play::clientbound::PlayerInfoDataBody::UpdateDisplayName({ let v19 = if r.read_bool()? { Some(r.read_string()?) } else { None }; crate::defs::p47::play::clientbound::PlayerInfoDataBodyUpdateDisplayName { display_name: v19 } }) } else if (v1.0 == 4) { crate::defs::p47::play::clientbound::PlayerInfoDataBody::RemovePlayer } else { crate::defs::p47::play::clientbound::PlayerInfoDataBody::Other }); crate::defs::p47::play::clientbound::PlayerInfoData { uuid: v5, body: v6 } });
}
v4
};
Self {
action: v1,
data: v2,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for PlayerInfo<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).action.0);
w.put_len_varint((*self).data.len())?;
for v1 in (*self).data.iter() {
w.put_uuid(&(*v1).uuid);
match &(*v1).body {
crate::defs::p47::play::clientbound::PlayerInfoDataBody::AddPlayer(v2) => {
if !((*self).action.0 == 0) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.player_info.data.body",
));
}
w.put_string(&(*v2).name)?;
w.put_len_varint((*v2).properties.len())?;
for v3 in (*v2).properties.iter() {
w.put_string(&(*v3).name)?;
w.put_string(&(*v3).value)?;
match &(*v3).signature {
Some(v4) => {
w.put_u8(1);
w.put_string(&(*v4))?;
}
None => w.put_u8(0),
}
}
w.put_varint((*v2).gamemode);
w.put_varint((*v2).ping);
match &(*v2).display_name {
Some(v5) => {
w.put_u8(1);
w.put_string(&(*v5))?;
}
None => w.put_u8(0),
}
}
crate::defs::p47::play::clientbound::PlayerInfoDataBody::UpdateGameMode(v6) => {
if !((*self).action.0 == 1) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.player_info.data.body",
));
}
w.put_varint((*v6).gamemode);
}
crate::defs::p47::play::clientbound::PlayerInfoDataBody::UpdateLatency(v7) => {
if !((*self).action.0 == 2) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.player_info.data.body",
));
}
w.put_varint((*v7).ping);
}
crate::defs::p47::play::clientbound::PlayerInfoDataBody::UpdateDisplayName(v8) => {
if !((*self).action.0 == 3) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.player_info.data.body",
));
}
match &(*v8).display_name {
Some(v9) => {
w.put_u8(1);
w.put_string(&(*v9))?;
}
None => w.put_u8(0),
}
}
crate::defs::p47::play::clientbound::PlayerInfoDataBody::RemovePlayer => {
if !((*self).action.0 == 4) {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.player_info.data.body",
));
}
}
crate::defs::p47::play::clientbound::PlayerInfoDataBody::Other => {
if !(!(((*self).action.0 == 0)
|| ((*self).action.0 == 1)
|| ((*self).action.0 == 2)
|| ((*self).action.0 == 3)
|| ((*self).action.0 == 4)))
{
return Err(EncodeError::SwitchMismatch(
"play.clientbound.player_info.data.body",
));
}
}
}
}
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for PlayerInfo<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = crate::defs::p47::play::clientbound::PlayerInfoAction(g.int_in(
-2147483648,
2147483647,
&[0, 1, 2, 3, 4],
) as i32);
let v2 = {
let v3 = g.count();
let mut v4 = Vec::with_capacity(v3.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v3 {
v4.push({ let v5 = g.uuid();let v6 = (if (v1.0 == 0) { crate::defs::p47::play::clientbound::PlayerInfoDataBody::AddPlayer({ let v7 = g.string();let v8 = { let v9 = g.count(); let mut v10 = Vec::with_capacity(v9.min(crate::codec::PREALLOC_LIMIT)); for _ in 0..v9 { v10.push({ let v11 = g.string();let v12 = g.string();let v13 = if g.bool() { Some(g.string()) } else { None }; crate::defs::p47::play::clientbound::PlayerInfoDataBodyAddPlayerProperties { name: v11, value: v12, signature: v13 } }); } v10 };let v14 = (g.int_in(-2147483648, 2147483647, &[]) as i32);let v15 = (g.int_in(-2147483648, 2147483647, &[]) as i32);let v16 = if g.bool() { Some(g.string()) } else { None }; crate::defs::p47::play::clientbound::PlayerInfoDataBodyAddPlayer { name: v7, properties: v8, gamemode: v14, ping: v15, display_name: v16 } }) } else if (v1.0 == 1) { crate::defs::p47::play::clientbound::PlayerInfoDataBody::UpdateGameMode({ let v17 = (g.int_in(-2147483648, 2147483647, &[]) as i32); crate::defs::p47::play::clientbound::PlayerInfoDataBodyUpdateGameMode { gamemode: v17 } }) } else if (v1.0 == 2) { crate::defs::p47::play::clientbound::PlayerInfoDataBody::UpdateLatency({ let v18 = (g.int_in(-2147483648, 2147483647, &[]) as i32); crate::defs::p47::play::clientbound::PlayerInfoDataBodyUpdateLatency { ping: v18 } }) } else if (v1.0 == 3) { crate::defs::p47::play::clientbound::PlayerInfoDataBody::UpdateDisplayName({ let v19 = if g.bool() { Some(g.string()) } else { None }; crate::defs::p47::play::clientbound::PlayerInfoDataBodyUpdateDisplayName { display_name: v19 } }) } else if (v1.0 == 4) { crate::defs::p47::play::clientbound::PlayerInfoDataBody::RemovePlayer } else { crate::defs::p47::play::clientbound::PlayerInfoDataBody::Other }); crate::defs::p47::play::clientbound::PlayerInfoData { uuid: v5, body: v6 } });
}
v4
};
Self {
action: v1,
data: v2,
}
}
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
/// `abilities` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Abilities<const V: i32> {
/// `flags`
pub flags: i8,
/// `flyingSpeed`
pub flying_speed: f32,
/// `walkingSpeed`
pub walking_speed: f32,
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Decode for Abilities<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_i8()?;
let v2 = r.read_f32()?;
let v3 = r.read_f32()?;
Self {
flags: v1,
flying_speed: v2,
walking_speed: v3,
}
})
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Encode for Abilities<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_i8((*self).flags);
w.put_f32((*self).flying_speed);
w.put_f32((*self).walking_speed);
Ok(())
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Abilities<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-128, 127, &[]) as i8);
let v2 = g.f32();
let v3 = g.f32();
Self {
flags: v1,
flying_speed: v2,
walking_speed: v3,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `tab_complete` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct TabComplete<const V: i32> {
/// `matches`
pub matches: Vec<ByteString>,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for TabComplete<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = {
let v2 = {
let c = r.read_varint()?;
r.check_count(i64::from(c), 1)?
};
let mut v3 = Vec::with_capacity(v2.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v2 {
v3.push(r.read_string()?);
}
v3
};
Self { matches: v1 }
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for TabComplete<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_len_varint((*self).matches.len())?;
for v1 in (*self).matches.iter() {
w.put_string(&(*v1))?;
}
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for TabComplete<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = {
let v2 = g.count();
let mut v3 = Vec::with_capacity(v2.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v2 {
v3.push(g.string());
}
v3
};
Self { matches: v1 }
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `scoreboard_objective` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct ScoreboardObjective<const V: i32> {
/// `name`
pub name: ByteString,
/// `action`
pub action: i8,
/// `displayText`
pub display_text: Option<ByteString>,
/// `type`
pub r#type: Option<ByteString>,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for ScoreboardObjective<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_string()?;
let v2 = r.read_i8()?;
let v3 = if (v2 == 0) || (v2 == 2) {
Some(r.read_string()?)
} else {
None
};
let v4 = if (v2 == 0) || (v2 == 2) {
Some(r.read_string()?)
} else {
None
};
Self {
name: v1,
action: v2,
display_text: v3,
r#type: v4,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for ScoreboardObjective<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_string(&(*self).name)?;
w.put_i8((*self).action);
match (
&(*self).display_text,
((*self).action == 0) || ((*self).action == 2),
) {
(Some(v1), true) => {
w.put_string(&(*v1))?;
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.scoreboard_objective.displayText",
));
}
}
match (
&(*self).r#type,
((*self).action == 0) || ((*self).action == 2),
) {
(Some(v2), true) => {
w.put_string(&(*v2))?;
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.scoreboard_objective.type",
));
}
}
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for ScoreboardObjective<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.string();
let v2 = (g.int_in(-128, 127, &[0, 2, 0, 2]) as i8);
let v3 = if (v2 == 0) || (v2 == 2) {
Some(g.string())
} else {
None
};
let v4 = if (v2 == 0) || (v2 == 2) {
Some(g.string())
} else {
None
};
Self {
name: v1,
action: v2,
display_text: v3,
r#type: v4,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `scoreboard_score` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct ScoreboardScore<const V: i32> {
/// `itemName`
pub item_name: ByteString,
/// `action`
pub action: i32,
/// `scoreName`
pub score_name: ByteString,
/// `value`
pub value: Option<i32>,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for ScoreboardScore<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_string()?;
let v2 = r.read_varint()?;
let v3 = r.read_string()?;
let v4 = if !(v2 == 1) {
Some(r.read_varint()?)
} else {
None
};
Self {
item_name: v1,
action: v2,
score_name: v3,
value: v4,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for ScoreboardScore<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_string(&(*self).item_name)?;
w.put_varint((*self).action);
w.put_string(&(*self).score_name)?;
match (&(*self).value, !((*self).action == 1)) {
(Some(v1), true) => {
w.put_varint((*v1));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.scoreboard_score.value",
));
}
}
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for ScoreboardScore<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.string();
let v2 = (g.int_in(-2147483648, 2147483647, &[1]) as i32);
let v3 = g.string();
let v4 = if !(v2 == 1) {
Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
} else {
None
};
Self {
item_name: v1,
action: v2,
score_name: v3,
value: v4,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `scoreboard_display_objective` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct ScoreboardDisplayObjective<const V: i32> {
/// `position`
pub position: i8,
/// `name`
pub name: ByteString,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for ScoreboardDisplayObjective<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_i8()?;
let v2 = r.read_string()?;
Self {
position: v1,
name: v2,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for ScoreboardDisplayObjective<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_i8((*self).position);
w.put_string(&(*self).name)?;
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for ScoreboardDisplayObjective<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-128, 127, &[]) as i8);
let v2 = g.string();
Self {
position: v1,
name: v2,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `scoreboard_team` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct ScoreboardTeam<const V: i32> {
/// `team`
pub team: ByteString,
/// `mode`
pub mode: i8,
/// `name`
pub name: Option<ByteString>,
/// `prefix`
pub prefix: Option<ByteString>,
/// `suffix`
pub suffix: Option<ByteString>,
/// `friendlyFire`
pub friendly_fire: Option<i8>,
/// `nameTagVisibility`
pub name_tag_visibility: Option<ByteString>,
/// `color`
pub color: Option<i8>,
/// `players`
pub players: Option<Vec<ByteString>>,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for ScoreboardTeam<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_string()?;
let v2 = r.read_i8()?;
let v3 = if (v2 == 0) || (v2 == 2) {
Some(r.read_string()?)
} else {
None
};
let v4 = if (v2 == 0) || (v2 == 2) {
Some(r.read_string()?)
} else {
None
};
let v5 = if (v2 == 0) || (v2 == 2) {
Some(r.read_string()?)
} else {
None
};
let v6 = if (v2 == 0) || (v2 == 2) {
Some(r.read_i8()?)
} else {
None
};
let v7 = if (v2 == 0) || (v2 == 2) {
Some(r.read_string()?)
} else {
None
};
let v8 = if (v2 == 0) || (v2 == 2) {
Some(r.read_i8()?)
} else {
None
};
let v9 = if (v2 == 0) || (v2 == 3) || (v2 == 4) {
Some({
let v10 = {
let c = r.read_varint()?;
r.check_count(i64::from(c), 1)?
};
let mut v11 = Vec::with_capacity(v10.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v10 {
v11.push(r.read_string()?);
}
v11
})
} else {
None
};
Self {
team: v1,
mode: v2,
name: v3,
prefix: v4,
suffix: v5,
friendly_fire: v6,
name_tag_visibility: v7,
color: v8,
players: v9,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for ScoreboardTeam<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_string(&(*self).team)?;
w.put_i8((*self).mode);
match (&(*self).name, ((*self).mode == 0) || ((*self).mode == 2)) {
(Some(v1), true) => {
w.put_string(&(*v1))?;
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.scoreboard_team.name",
));
}
}
match (&(*self).prefix, ((*self).mode == 0) || ((*self).mode == 2)) {
(Some(v2), true) => {
w.put_string(&(*v2))?;
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.scoreboard_team.prefix",
));
}
}
match (&(*self).suffix, ((*self).mode == 0) || ((*self).mode == 2)) {
(Some(v3), true) => {
w.put_string(&(*v3))?;
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.scoreboard_team.suffix",
));
}
}
match (
&(*self).friendly_fire,
((*self).mode == 0) || ((*self).mode == 2),
) {
(Some(v4), true) => {
w.put_i8((*v4));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.scoreboard_team.friendlyFire",
));
}
}
match (
&(*self).name_tag_visibility,
((*self).mode == 0) || ((*self).mode == 2),
) {
(Some(v5), true) => {
w.put_string(&(*v5))?;
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.scoreboard_team.nameTagVisibility",
));
}
}
match (&(*self).color, ((*self).mode == 0) || ((*self).mode == 2)) {
(Some(v6), true) => {
w.put_i8((*v6));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.scoreboard_team.color",
));
}
}
match (
&(*self).players,
((*self).mode == 0) || ((*self).mode == 3) || ((*self).mode == 4),
) {
(Some(v7), true) => {
w.put_len_varint((*v7).len())?;
for v8 in (*v7).iter() {
w.put_string(&(*v8))?;
}
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.scoreboard_team.players",
));
}
}
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for ScoreboardTeam<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.string();
let v2 = (g.int_in(-128, 127, &[0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 3, 4]) as i8);
let v3 = if (v2 == 0) || (v2 == 2) {
Some(g.string())
} else {
None
};
let v4 = if (v2 == 0) || (v2 == 2) {
Some(g.string())
} else {
None
};
let v5 = if (v2 == 0) || (v2 == 2) {
Some(g.string())
} else {
None
};
let v6 = if (v2 == 0) || (v2 == 2) {
Some((g.int_in(-128, 127, &[]) as i8))
} else {
None
};
let v7 = if (v2 == 0) || (v2 == 2) {
Some(g.string())
} else {
None
};
let v8 = if (v2 == 0) || (v2 == 2) {
Some((g.int_in(-128, 127, &[]) as i8))
} else {
None
};
let v9 = if (v2 == 0) || (v2 == 3) || (v2 == 4) {
Some({
let v10 = g.count();
let mut v11 = Vec::with_capacity(v10.min(crate::codec::PREALLOC_LIMIT));
for _ in 0..v10 {
v11.push(g.string());
}
v11
})
} else {
None
};
Self {
team: v1,
mode: v2,
name: v3,
prefix: v4,
suffix: v5,
friendly_fire: v6,
name_tag_visibility: v7,
color: v8,
players: v9,
}
}
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
/// `custom_payload` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct CustomPayload<const V: i32> {
/// `channel`
pub channel: ByteString,
/// `data`
pub data: Bytes,
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Decode for CustomPayload<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_string()?;
let v2 = r.read_rest();
Self {
channel: v1,
data: v2,
}
})
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Encode for CustomPayload<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_string(&(*self).channel)?;
w.put_slice(&(*self).data);
Ok(())
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for CustomPayload<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.string();
let v2 = g.bytes();
Self {
channel: v1,
data: v2,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `kick_disconnect` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct KickDisconnect<const V: i32> {
/// `reason`
pub reason: ByteString,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for KickDisconnect<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_string()?;
Self { reason: v1 }
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for KickDisconnect<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_string(&(*self).reason)?;
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for KickDisconnect<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.string();
Self { reason: v1 }
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// Mapped `u8` value; unknown values are kept as-is.
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
pub struct DifficultyDifficulty(pub u8);
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl DifficultyDifficulty {
/// `peaceful`
pub const PEACEFUL: Self = Self(0);
/// `easy`
pub const EASY: Self = Self(1);
/// `normal`
pub const NORMAL: Self = Self(2);
/// `hard`
pub const HARD: Self = Self(3);
/// minecraft-data name of the value, if known.
pub const fn name(self) -> Option<&'static str> {
match self.0 {
0 => Some("peaceful"),
1 => Some("easy"),
2 => Some("normal"),
3 => Some("hard"),
_ => None,
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl std::fmt::Debug for DifficultyDifficulty {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.name() {
Some(n) => write!(f, "DifficultyDifficulty::{n}"),
None => write!(f, "DifficultyDifficulty({})", self.0),
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
/// `difficulty` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Difficulty<const V: i32> {
/// `difficulty`
pub difficulty: crate::defs::p47::play::clientbound::DifficultyDifficulty,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Decode for Difficulty<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = crate::defs::p47::play::clientbound::DifficultyDifficulty(r.read_u8()?);
Self { difficulty: v1 }
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
impl<const V: i32> Encode for Difficulty<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_u8((*self).difficulty.0);
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Difficulty<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = crate::defs::p47::play::clientbound::DifficultyDifficulty(g.int_in(
0,
255,
&[0, 1, 2, 3],
) as u8);
Self { difficulty: v1 }
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `combat_event` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct CombatEvent<const V: i32> {
/// `event`
pub event: i32,
/// `duration`
pub duration: Option<i32>,
/// `playerId`
pub player_id: Option<i32>,
/// `entityId`
pub entity_id: Option<i32>,
/// `message`
pub message: Option<ByteString>,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for CombatEvent<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = if (v1 == 1) {
Some(r.read_varint()?)
} else {
None
};
let v3 = if (v1 == 2) {
Some(r.read_varint()?)
} else {
None
};
let v4 = if (v1 == 1) || (v1 == 2) {
Some(r.read_i32()?)
} else {
None
};
let v5 = if (v1 == 2) {
Some(r.read_string()?)
} else {
None
};
Self {
event: v1,
duration: v2,
player_id: v3,
entity_id: v4,
message: v5,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for CombatEvent<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).event);
match (&(*self).duration, ((*self).event == 1)) {
(Some(v1), true) => {
w.put_varint((*v1));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.combat_event.duration",
));
}
}
match (&(*self).player_id, ((*self).event == 2)) {
(Some(v2), true) => {
w.put_varint((*v2));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.combat_event.playerId",
));
}
}
match (
&(*self).entity_id,
((*self).event == 1) || ((*self).event == 2),
) {
(Some(v3), true) => {
w.put_i32((*v3));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.combat_event.entityId",
));
}
}
match (&(*self).message, ((*self).event == 2)) {
(Some(v4), true) => {
w.put_string(&(*v4))?;
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.combat_event.message",
));
}
}
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for CombatEvent<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[1, 2, 1, 2, 2]) as i32);
let v2 = if (v1 == 1) {
Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
} else {
None
};
let v3 = if (v1 == 2) {
Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
} else {
None
};
let v4 = if (v1 == 1) || (v1 == 2) {
Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
} else {
None
};
let v5 = if (v1 == 2) { Some(g.string()) } else { None };
Self {
event: v1,
duration: v2,
player_id: v3,
entity_id: v4,
message: v5,
}
}
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
/// `camera` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Camera<const V: i32> {
/// `cameraId`
pub camera_id: i32,
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Decode for Camera<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
Self { camera_id: v1 }
})
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
impl<const V: i32> Encode for Camera<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).camera_id);
Ok(())
}
}
#[cfg(any(
feature = "v1_8",
feature = "v1_12_2",
feature = "v1_16_5",
feature = "v26_1"
))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Camera<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
Self { camera_id: v1 }
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `world_border` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct WorldBorder<const V: i32> {
/// `action`
pub action: i32,
/// `radius`
pub radius: Option<f64>,
/// `x`
pub x: Option<f64>,
/// `z`
pub z: Option<f64>,
/// `old_radius`
pub old_radius: Option<f64>,
/// `new_radius`
pub new_radius: Option<f64>,
/// `speed`
pub speed: Option<i64>,
/// `portalBoundary`
pub portal_boundary: Option<i32>,
/// `warning_time`
pub warning_time: Option<i32>,
/// `warning_blocks`
pub warning_blocks: Option<i32>,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for WorldBorder<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = if (v1 == 0) { Some(r.read_f64()?) } else { None };
let v3 = if (v1 == 2) || (v1 == 3) {
Some(r.read_f64()?)
} else {
None
};
let v4 = if (v1 == 2) || (v1 == 3) {
Some(r.read_f64()?)
} else {
None
};
let v5 = if (v1 == 1) || (v1 == 3) {
Some(r.read_f64()?)
} else {
None
};
let v6 = if (v1 == 1) || (v1 == 3) {
Some(r.read_f64()?)
} else {
None
};
let v7 = if (v1 == 1) || (v1 == 3) {
Some(r.read_varlong()?)
} else {
None
};
let v8 = if (v1 == 3) {
Some(r.read_varint()?)
} else {
None
};
let v9 = if (v1 == 3) || (v1 == 4) {
Some(r.read_varint()?)
} else {
None
};
let v10 = if (v1 == 3) || (v1 == 5) {
Some(r.read_varint()?)
} else {
None
};
Self {
action: v1,
radius: v2,
x: v3,
z: v4,
old_radius: v5,
new_radius: v6,
speed: v7,
portal_boundary: v8,
warning_time: v9,
warning_blocks: v10,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for WorldBorder<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).action);
match (&(*self).radius, ((*self).action == 0)) {
(Some(v1), true) => {
w.put_f64((*v1));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.world_border.radius",
));
}
}
match (&(*self).x, ((*self).action == 2) || ((*self).action == 3)) {
(Some(v2), true) => {
w.put_f64((*v2));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.world_border.x",
));
}
}
match (&(*self).z, ((*self).action == 2) || ((*self).action == 3)) {
(Some(v3), true) => {
w.put_f64((*v3));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.world_border.z",
));
}
}
match (
&(*self).old_radius,
((*self).action == 1) || ((*self).action == 3),
) {
(Some(v4), true) => {
w.put_f64((*v4));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.world_border.old_radius",
));
}
}
match (
&(*self).new_radius,
((*self).action == 1) || ((*self).action == 3),
) {
(Some(v5), true) => {
w.put_f64((*v5));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.world_border.new_radius",
));
}
}
match (
&(*self).speed,
((*self).action == 1) || ((*self).action == 3),
) {
(Some(v6), true) => {
w.put_varlong((*v6));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.world_border.speed",
));
}
}
match (&(*self).portal_boundary, ((*self).action == 3)) {
(Some(v7), true) => {
w.put_varint((*v7));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.world_border.portalBoundary",
));
}
}
match (
&(*self).warning_time,
((*self).action == 3) || ((*self).action == 4),
) {
(Some(v8), true) => {
w.put_varint((*v8));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.world_border.warning_time",
));
}
}
match (
&(*self).warning_blocks,
((*self).action == 3) || ((*self).action == 5),
) {
(Some(v9), true) => {
w.put_varint((*v9));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.world_border.warning_blocks",
));
}
}
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for WorldBorder<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(
-2147483648,
2147483647,
&[0, 2, 3, 2, 3, 1, 3, 1, 3, 1, 3, 3, 3, 4, 3, 5],
) as i32);
let v2 = if (v1 == 0) { Some(g.f64()) } else { None };
let v3 = if (v1 == 2) || (v1 == 3) {
Some(g.f64())
} else {
None
};
let v4 = if (v1 == 2) || (v1 == 3) {
Some(g.f64())
} else {
None
};
let v5 = if (v1 == 1) || (v1 == 3) {
Some(g.f64())
} else {
None
};
let v6 = if (v1 == 1) || (v1 == 3) {
Some(g.f64())
} else {
None
};
let v7 = if (v1 == 1) || (v1 == 3) {
Some(g.varlong())
} else {
None
};
let v8 = if (v1 == 3) {
Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
} else {
None
};
let v9 = if (v1 == 3) || (v1 == 4) {
Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
} else {
None
};
let v10 = if (v1 == 3) || (v1 == 5) {
Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
} else {
None
};
Self {
action: v1,
radius: v2,
x: v3,
z: v4,
old_radius: v5,
new_radius: v6,
speed: v7,
portal_boundary: v8,
warning_time: v9,
warning_blocks: v10,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `title` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct Title<const V: i32> {
/// `action`
pub action: i32,
/// `text`
pub text: Option<ByteString>,
/// `fadeIn`
pub fade_in: Option<i32>,
/// `stay`
pub stay: Option<i32>,
/// `fadeOut`
pub fade_out: Option<i32>,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for Title<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = if (v1 == 0) || (v1 == 1) {
Some(r.read_string()?)
} else {
None
};
let v3 = if (v1 == 2) { Some(r.read_i32()?) } else { None };
let v4 = if (v1 == 2) { Some(r.read_i32()?) } else { None };
let v5 = if (v1 == 2) { Some(r.read_i32()?) } else { None };
Self {
action: v1,
text: v2,
fade_in: v3,
stay: v4,
fade_out: v5,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for Title<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).action);
match (
&(*self).text,
((*self).action == 0) || ((*self).action == 1),
) {
(Some(v1), true) => {
w.put_string(&(*v1))?;
}
(None, false) => {}
_ => return Err(EncodeError::SwitchMismatch("play.clientbound.title.text")),
}
match (&(*self).fade_in, ((*self).action == 2)) {
(Some(v2), true) => {
w.put_i32((*v2));
}
(None, false) => {}
_ => return Err(EncodeError::SwitchMismatch("play.clientbound.title.fadeIn")),
}
match (&(*self).stay, ((*self).action == 2)) {
(Some(v3), true) => {
w.put_i32((*v3));
}
(None, false) => {}
_ => return Err(EncodeError::SwitchMismatch("play.clientbound.title.stay")),
}
match (&(*self).fade_out, ((*self).action == 2)) {
(Some(v4), true) => {
w.put_i32((*v4));
}
(None, false) => {}
_ => {
return Err(EncodeError::SwitchMismatch(
"play.clientbound.title.fadeOut",
));
}
}
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for Title<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[0, 1, 2, 2, 2]) as i32);
let v2 = if (v1 == 0) || (v1 == 1) {
Some(g.string())
} else {
None
};
let v3 = if (v1 == 2) {
Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
} else {
None
};
let v4 = if (v1 == 2) {
Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
} else {
None
};
let v5 = if (v1 == 2) {
Some((g.int_in(-2147483648, 2147483647, &[]) as i32))
} else {
None
};
Self {
action: v1,
text: v2,
fade_in: v3,
stay: v4,
fade_out: v5,
}
}
}
}
#[cfg(feature = "v1_8")]
/// `set_compression` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct SetCompression<const V: i32> {
/// `threshold`
pub threshold: i32,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for SetCompression<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
Self { threshold: v1 }
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for SetCompression<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).threshold);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for SetCompression<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
Self { threshold: v1 }
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `playerlist_header` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct PlayerlistHeader<const V: i32> {
/// `header`
pub header: ByteString,
/// `footer`
pub footer: ByteString,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for PlayerlistHeader<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_string()?;
let v2 = r.read_string()?;
Self {
header: v1,
footer: v2,
}
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for PlayerlistHeader<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_string(&(*self).header)?;
w.put_string(&(*self).footer)?;
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for PlayerlistHeader<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.string();
let v2 = g.string();
Self {
header: v1,
footer: v2,
}
}
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
/// `resource_pack_send` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct ResourcePackSend<const V: i32> {
/// `url`
pub url: ByteString,
/// `hash`
pub hash: ByteString,
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Decode for ResourcePackSend<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_string()?;
let v2 = r.read_string()?;
Self { url: v1, hash: v2 }
})
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
impl<const V: i32> Encode for ResourcePackSend<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_string(&(*self).url)?;
w.put_string(&(*self).hash)?;
Ok(())
}
}
#[cfg(any(feature = "v1_8", feature = "v1_12_2", feature = "v1_16_5"))]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for ResourcePackSend<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = g.string();
let v2 = g.string();
Self { url: v1, hash: v2 }
}
}
}
#[cfg(feature = "v1_8")]
/// `update_entity_nbt` (clientbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct UpdateEntityNbt<const V: i32> {
/// `entityId`
pub entity_id: i32,
/// `tag`
pub tag: RawNbt,
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Decode for UpdateEntityNbt<V> {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v1 = r.read_varint()?;
let v2 = RawNbt::read(r)?;
Self {
entity_id: v1,
tag: v2,
}
})
}
}
#[cfg(feature = "v1_8")]
impl<const V: i32> Encode for UpdateEntityNbt<V> {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).entity_id);
(*self).tag.write(w);
Ok(())
}
}
#[cfg(feature = "v1_8")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for UpdateEntityNbt<V> {
fn generate(g: &mut Gen) -> Self {
{
let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
let v2 = g.nbt();
Self {
entity_id: v1,
tag: v2,
}
}
}
}