// Generated by pumpkin-codegen. Do not edit.
#![allow(clippy::all)]
#![allow(clippy::pedantic)]
#![allow(unused_imports)]
#![allow(unused_variables)]
use crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::{
    ClientboundPacket, ServerboundPacket,
};
use bytes::Bytes;
use pumpkin_protocol::codec::var_int::VarInt;
use pumpkin_protocol::codec::var_uint::VarUInt;
use pumpkin_protocol::packet::MultiVersionJavaPacket;
use pumpkin_protocol::packet::Packet;
use pumpkin_util::version::JavaMinecraftVersion;
use std::any::Any;
use std::io::Cursor;

#[must_use]
pub fn serialize_java_packet(
    packet: &ClientboundPacket,
    version: JavaMinecraftVersion,
) -> Option<Bytes> {
    match packet {
        ClientboundPacket::ConfigCConfigDisconnect(data) => {
            let p = pumpkin_protocol::java::client::config::CConfigDisconnect {
                reason: &data.reason,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::ConfigCPluginMessage(data) => {
            let p = pumpkin_protocol::java::client::config::CPluginMessage {
                channel: &data.channel,
                data: &data.data,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::ConfigCTransfer(data) => {
            let var_int_port = VarInt(data.port);
            let p = pumpkin_protocol::java::client::config::CTransfer {
                host: &data.host,
                port: &var_int_port,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::LoginCEncryptionRequest(data) => {
            let p = pumpkin_protocol::java::client::login::CEncryptionRequest {
                server_id: &data.server_id,
                public_key: &data.public_key,
                verify_token: &data.verify_token,
                should_authenticate: data.should_authenticate.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::LoginCLoginDisconnect(data) => {
            let p = pumpkin_protocol::java::client::login::CLoginDisconnect {
                json_reason: data.json_reason.clone(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::LoginCLoginPluginRequest(data) => {
            let p = pumpkin_protocol::java::client::login::CLoginPluginRequest {
                message_id: VarInt(data.message_id),
                channel: &data.channel,
                data: &data.data,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::LoginCSetCompression(data) => {
            let p = pumpkin_protocol::java::client::login::CSetCompression {
                threshold: VarInt(data.threshold),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CAcknowledgeBlockChange(data) => {
            let p = pumpkin_protocol::java::client::play::CAcknowledgeBlockChange {
                sequence_id: VarInt(data.sequence_id),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CActionBar(data) => {
            let component_action_bar =
                pumpkin_util::text::TextComponent::text(data.action_bar.clone());
            let p = pumpkin_protocol::java::client::play::CActionBar {
                action_bar: &component_action_bar,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CSetBlockDestroyStage(data) => {
            let p = pumpkin_protocol::java::client::play::CSetBlockDestroyStage {
                entity_id: VarInt(data.entity_id),
                location: pumpkin_util::math::position::BlockPos::new(
                    data.location.0,
                    data.location.1,
                    data.location.2,
                ),
                destroy_stage: data.destroy_stage.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CBlockEvent(data) => {
            let p = pumpkin_protocol::java::client::play::CBlockEvent {
                location: pumpkin_util::math::position::BlockPos::new(
                    data.location.0,
                    data.location.1,
                    data.location.2,
                ),
                action_id: data.action_id.try_into().unwrap_or_default(),
                action_parameter: data.action_parameter.try_into().unwrap_or_default(),
                block_type: VarInt(data.block_type),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CBlockUpdate(data) => {
            let p = pumpkin_protocol::java::client::play::CBlockUpdate {
                location: pumpkin_util::math::position::BlockPos::new(
                    data.location.0,
                    data.location.1,
                    data.location.2,
                ),
                state_id: VarInt(data.state_id),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CCenterChunk(data) => {
            let p = pumpkin_protocol::java::client::play::CCenterChunk {
                chunk_x: VarInt(data.chunk_x),
                chunk_z: VarInt(data.chunk_z),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CChangeDifficulty(data) => {
            let p = pumpkin_protocol::java::client::play::CChangeDifficulty {
                difficulty: data.difficulty.try_into().unwrap_or_default(),
                locked: data.locked.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CChunkBatchEnd(data) => {
            let p = pumpkin_protocol::java::client::play::CChunkBatchEnd {
                batch_size: VarInt(data.batch_size),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CClearTitle(data) => {
            let p = pumpkin_protocol::java::client::play::CClearTitle {
                reset: data.reset.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CCloseContainer(data) => {
            let p = pumpkin_protocol::java::client::play::CCloseContainer {
                sync_id: VarInt(data.sync_id),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CCombatDeath(data) => {
            let component_message = pumpkin_util::text::TextComponent::text(data.message.clone());
            let p = pumpkin_protocol::java::client::play::CCombatDeath {
                player_id: VarInt(data.player_id),
                message: &component_message,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CCustomPayload(data) => {
            let p = pumpkin_protocol::java::client::play::CCustomPayload {
                channel: &data.channel,
                data: &data.data,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CDebugSample(data) => {
            let vec_sample: Vec<_> = data.sample.iter().map(|v| *v as _).collect();
            let p = pumpkin_protocol::java::client::play::CDebugSample {
                sample: &vec_sample,
                sample_type: VarInt(data.sample_type),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CPlayDisconnect(data) => {
            let component_reason = pumpkin_util::text::TextComponent::text(data.reason.clone());
            let p = pumpkin_protocol::java::client::play::CPlayDisconnect {
                reason: &component_reason,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CDisplayObjective(data) => {
            let p = pumpkin_protocol::java::client::play::CDisplayObjective {
                position: VarInt(data.position),
                score_name: data.score_name.clone(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CEntityAnimation(data) => {
            let p = pumpkin_protocol::java::client::play::CEntityAnimation {
                entity_id: VarInt(data.entity_id),
                animation: data.animation.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CEntityPositionSync(data) => {
            let p = pumpkin_protocol::java::client::play::CEntityPositionSync {
                entity_id: VarInt(data.entity_id),
                position: pumpkin_util::math::vector3::Vector3::new(
                    data.position.0 as _,
                    data.position.1 as _,
                    data.position.2 as _,
                ),
                delta: pumpkin_util::math::vector3::Vector3::new(
                    data.delta.0 as _,
                    data.delta.1 as _,
                    data.delta.2 as _,
                ),
                yaw: data.yaw.try_into().unwrap_or_default(),
                pitch: data.pitch.try_into().unwrap_or_default(),
                on_ground: data.on_ground.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CEntityStatus(data) => {
            let p = pumpkin_protocol::java::client::play::CEntityStatus {
                entity_id: data.entity_id.try_into().unwrap_or_default(),
                entity_status: data.entity_status.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CGameEvent(data) => {
            let p = pumpkin_protocol::java::client::play::CGameEvent {
                event: data.event.try_into().unwrap_or_default(),
                value: data.value.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CHeadRot(data) => {
            let p = pumpkin_protocol::java::client::play::CHeadRot {
                entity_id: VarInt(data.entity_id),
                head_yaw: data.head_yaw.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CHurtAnimation(data) => {
            let p = pumpkin_protocol::java::client::play::CHurtAnimation {
                entity_id: VarInt(data.entity_id),
                yaw: data.yaw.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CInitializeWorldBorder(data) => {
            let p = pumpkin_protocol::java::client::play::CInitializeWorldBorder {
                x: data.x.try_into().unwrap_or_default(),
                z: data.z.try_into().unwrap_or_default(),
                old_diameter: data.old_diameter.try_into().unwrap_or_default(),
                new_diameter: data.new_diameter.try_into().unwrap_or_default(),
                speed: pumpkin_protocol::codec::var_long::VarLong(
                    data.speed.try_into().unwrap_or_default(),
                ),
                portal_teleport_boundary: VarInt(data.portal_teleport_boundary),
                warning_blocks: VarInt(data.warning_blocks),
                warning_time: VarInt(data.warning_time),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CItemCooldown(data) => {
            let p = pumpkin_protocol::java::client::play::CItemCooldown {
                group: data.group.clone(),
                cooldown: VarInt(data.cooldown),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CKeepAlive(data) => {
            let p = pumpkin_protocol::java::client::play::CKeepAlive {
                keep_alive_id: data.keep_alive_id.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CLevelEvent(data) => {
            let p = pumpkin_protocol::java::client::play::CLevelEvent {
                event: data.event.try_into().unwrap_or_default(),
                location: pumpkin_util::math::position::BlockPos::new(
                    data.location.0,
                    data.location.1,
                    data.location.2,
                ),
                data: data.data.try_into().unwrap_or_default(),
                disable_relative_volume: data
                    .disable_relative_volume
                    .try_into()
                    .unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::COpenScreen(data) => {
            let component_window_title =
                pumpkin_util::text::TextComponent::text(data.window_title.clone());
            let p = pumpkin_protocol::java::client::play::COpenScreen {
                sync_id: VarInt(data.sync_id),
                window_type: VarInt(data.window_type),
                window_title: &component_window_title,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::COpenSignEditor(data) => {
            let p = pumpkin_protocol::java::client::play::COpenSignEditor {
                location: pumpkin_util::math::position::BlockPos::new(
                    data.location.0,
                    data.location.1,
                    data.location.2,
                ),
                is_front_text: data.is_front_text.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CParticle(data) => {
            let p = pumpkin_protocol::java::client::play::CParticle {
                force_spawn: data.force_spawn.try_into().unwrap_or_default(),
                important: data.important.try_into().unwrap_or_default(),
                position: pumpkin_util::math::vector3::Vector3::new(
                    data.position.0 as _,
                    data.position.1 as _,
                    data.position.2 as _,
                ),
                offset: pumpkin_util::math::vector3::Vector3::new(
                    data.offset.0 as _,
                    data.offset.1 as _,
                    data.offset.2 as _,
                ),
                max_speed: data.max_speed.try_into().unwrap_or_default(),
                particle_count: data.particle_count.try_into().unwrap_or_default(),
                particle_id: VarInt(data.particle_id),
                data: &data.data,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CPingResponse(data) => {
            let p = pumpkin_protocol::java::client::play::CPingResponse {
                payload: data.payload.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CPlayerAbilities(data) => {
            let p = pumpkin_protocol::java::client::play::CPlayerAbilities {
                flags: data.flags.try_into().unwrap_or_default(),
                flying_speed: data.flying_speed.try_into().unwrap_or_default(),
                field_of_view: data.field_of_view.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CRemovePlayerInfo(data) => {
            let vec_players = data
                .players
                .iter()
                .map(|u| uuid::Uuid::from_u64_pair(u.high, u.low))
                .collect::<Vec<_>>();
            let p = pumpkin_protocol::java::client::play::CRemovePlayerInfo {
                players: &vec_players,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CPlayerSpawnPosition(data) => {
            let p = pumpkin_protocol::java::client::play::CPlayerSpawnPosition {
                dimension_name: data.dimension_name.clone(),
                location: pumpkin_util::math::position::BlockPos::new(
                    data.location.0,
                    data.location.1,
                    data.location.2,
                ),
                yaw: data.yaw.try_into().unwrap_or_default(),
                pitch: data.pitch.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CRecipeBookAdd(data) => {
            let p = pumpkin_protocol::java::client::play::CRecipeBookAdd {
                replace: data.replace.try_into().unwrap_or_default(),
                dynamic_recipes: &[],
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CRecipeBookSettings(data) => {
            let p = pumpkin_protocol::java::client::play::CRecipeBookSettings {
                crafting_open: data.crafting_open.try_into().unwrap_or_default(),
                crafting_filtering: data.crafting_filtering.try_into().unwrap_or_default(),
                furnace_open: data.furnace_open.try_into().unwrap_or_default(),
                furnace_filtering: data.furnace_filtering.try_into().unwrap_or_default(),
                blast_furnace_open: data.blast_furnace_open.try_into().unwrap_or_default(),
                blast_furnace_filtering: data
                    .blast_furnace_filtering
                    .try_into()
                    .unwrap_or_default(),
                smoker_open: data.smoker_open.try_into().unwrap_or_default(),
                smoker_filtering: data.smoker_filtering.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CRemoveEntities(data) => {
            let vec_entity_ids: Vec<VarInt> = data.entity_ids.iter().map(|v| VarInt(*v)).collect();
            let p = pumpkin_protocol::java::client::play::CRemoveEntities {
                entity_ids: &vec_entity_ids,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CRemoveMobEffect(data) => {
            let p = pumpkin_protocol::java::client::play::CRemoveMobEffect {
                entity_id: VarInt(data.entity_id),
                effect_id: VarInt(data.effect_id),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CSetBorderCenter(data) => {
            let p = pumpkin_protocol::java::client::play::CSetBorderCenter {
                x: data.x.try_into().unwrap_or_default(),
                z: data.z.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CSetBorderLerpSize(data) => {
            let p = pumpkin_protocol::java::client::play::CSetBorderLerpSize {
                old_diameter: data.old_diameter.try_into().unwrap_or_default(),
                new_diameter: data.new_diameter.try_into().unwrap_or_default(),
                speed: pumpkin_protocol::codec::var_long::VarLong(
                    data.speed.try_into().unwrap_or_default(),
                ),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CSetBorderSize(data) => {
            let p = pumpkin_protocol::java::client::play::CSetBorderSize {
                diameter: data.diameter.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CSetBorderWarningDelay(data) => {
            let p = pumpkin_protocol::java::client::play::CSetBorderWarningDelay {
                warning_time: VarInt(data.warning_time),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CSetBorderWarningDistance(data) => {
            let p = pumpkin_protocol::java::client::play::CSetBorderWarningDistance {
                warning_blocks: VarInt(data.warning_blocks),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CSetContainerProperty(data) => {
            let p = pumpkin_protocol::java::client::play::CSetContainerProperty {
                window_id: VarInt(data.window_id),
                property: data.property.try_into().unwrap_or_default(),
                value: data.value.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CSetEntityLink(data) => {
            let p = pumpkin_protocol::java::client::play::CSetEntityLink {
                attached_entity_id: data.attached_entity_id.try_into().unwrap_or_default(),
                holding_entity_id: data.holding_entity_id.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CSetExperience(data) => {
            let p = pumpkin_protocol::java::client::play::CSetExperience {
                progress: data.progress.try_into().unwrap_or_default(),
                level: VarInt(data.level),
                total_experience: VarInt(data.total_experience),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CSetHealth(data) => {
            let p = pumpkin_protocol::java::client::play::CSetHealth {
                health: data.health.try_into().unwrap_or_default(),
                food: VarInt(data.food),
                food_saturation: data.food_saturation.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CSetPassengers(data) => {
            let vec_passengers: Vec<VarInt> = data.passengers.iter().map(|v| VarInt(*v)).collect();
            let p = pumpkin_protocol::java::client::play::CSetPassengers {
                entity_id: VarInt(data.entity_id),
                passengers: &vec_passengers,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CTitleText(data) => {
            let component_title = pumpkin_util::text::TextComponent::text(data.title.clone());
            let p = pumpkin_protocol::java::client::play::CTitleText {
                title: &component_title,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CTitleAnimation(data) => {
            let p = pumpkin_protocol::java::client::play::CTitleAnimation {
                fade_in_ticks: data.fade_in_ticks.try_into().unwrap_or_default(),
                stay_ticks: data.stay_ticks.try_into().unwrap_or_default(),
                fade_out_ticks: data.fade_out_ticks.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CSubtitle(data) => {
            let component_subtitle = pumpkin_util::text::TextComponent::text(data.subtitle.clone());
            let p = pumpkin_protocol::java::client::play::CSubtitle {
                subtitle: &component_subtitle,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CSystemChatMessage(data) => {
            let component_content = pumpkin_util::text::TextComponent::text(data.content.clone());
            let p = pumpkin_protocol::java::client::play::CSystemChatMessage {
                content: &component_content,
                overlay: data.overlay.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CTabList(data) => {
            let component_header = pumpkin_util::text::TextComponent::text(data.header.clone());
            let component_footer = pumpkin_util::text::TextComponent::text(data.footer.clone());
            let p = pumpkin_protocol::java::client::play::CTabList {
                header: &component_header,
                footer: &component_footer,
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CTakeItemEntity(data) => {
            let p = pumpkin_protocol::java::client::play::CTakeItemEntity {
                entity_id: VarInt(data.entity_id),
                collector_entity_id: VarInt(data.collector_entity_id),
                stack_amount: VarInt(data.stack_amount),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CTickingState(data) => {
            let p = pumpkin_protocol::java::client::play::CTickingState {
                tick_rate: data.tick_rate.try_into().unwrap_or_default(),
                is_frozen: data.is_frozen.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CTickingStep(data) => {
            let p = pumpkin_protocol::java::client::play::CTickingStep {
                tick_steps: VarInt(data.tick_steps),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CTransfer(data) => {
            let p = pumpkin_protocol::java::client::play::CTransfer {
                host: &data.host,
                port: VarInt(data.port),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CUnloadChunk(data) => {
            let p = pumpkin_protocol::java::client::play::CUnloadChunk {
                z: data.z.try_into().unwrap_or_default(),
                x: data.x.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CUpdateEntityPos(data) => {
            let p = pumpkin_protocol::java::client::play::CUpdateEntityPos {
                entity_id: VarInt(data.entity_id),
                delta: pumpkin_util::math::vector3::Vector3::new(
                    data.delta.0 as _,
                    data.delta.1 as _,
                    data.delta.2 as _,
                ),
                on_ground: data.on_ground.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CUpdateEntityPosRot(data) => {
            let p = pumpkin_protocol::java::client::play::CUpdateEntityPosRot {
                entity_id: VarInt(data.entity_id),
                delta: pumpkin_util::math::vector3::Vector3::new(
                    data.delta.0 as _,
                    data.delta.1 as _,
                    data.delta.2 as _,
                ),
                yaw: data.yaw.try_into().unwrap_or_default(),
                pitch: data.pitch.try_into().unwrap_or_default(),
                on_ground: data.on_ground.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CUpdateEntityRot(data) => {
            let p = pumpkin_protocol::java::client::play::CUpdateEntityRot {
                entity_id: VarInt(data.entity_id),
                yaw: data.yaw.try_into().unwrap_or_default(),
                pitch: data.pitch.try_into().unwrap_or_default(),
                on_ground: data.on_ground.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CUpdateMobEffect(data) => {
            let p = pumpkin_protocol::java::client::play::CUpdateMobEffect {
                entity_id: VarInt(data.entity_id),
                effect_id: VarInt(data.effect_id),
                amplifier: VarInt(data.amplifier),
                duration: VarInt(data.duration),
                flags: data.flags.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::CWorldEvent(data) => {
            let p = pumpkin_protocol::java::client::play::CWorldEvent {
                event: data.event.try_into().unwrap_or_default(),
                location: pumpkin_util::math::position::BlockPos::new(
                    data.location.0,
                    data.location.1,
                    data.location.2,
                ),
                data: data.data.try_into().unwrap_or_default(),
                disable_relative_volume: data
                    .disable_relative_volume
                    .try_into()
                    .unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::StatusCPingResponse(data) => {
            let p = pumpkin_protocol::java::client::status::CPingResponse {
                payload: data.payload.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        ClientboundPacket::StatusCStatusResponse(data) => {
            let p = pumpkin_protocol::java::client::status::CStatusResponse {
                json_response: data.json_response.clone(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::java::JavaClient::write_packet_for_version(&p, version, &mut buf);
            Some(buf.into())
        }
        _ => None,
    }
}

#[must_use]
pub fn deserialize_java_serverbound_packet(
    id: i32,
    mut payload: &[u8],
    version: JavaMinecraftVersion,
) -> Option<ServerboundPacket> {
    match id {
        id if id
            == pumpkin_protocol::java::server::config::SClientInformationConfig::to_id(version) =>
        {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::config::SClientInformationConfig as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::ConfigSClientInformationConfig(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::ConfigSClientInformationConfig {
                locale: p.locale.into(),
                view_distance: p.view_distance.try_into().unwrap_or_default(),
                chat_mode: p.chat_mode.0.try_into().unwrap_or_default(),
                chat_colors: p.chat_colors.try_into().unwrap_or_default(),
                skin_parts: p.skin_parts.try_into().unwrap_or_default(),
                main_hand: p.main_hand.0.try_into().unwrap_or_default(),
                text_filtering: p.text_filtering.try_into().unwrap_or_default(),
                server_listing: p.server_listing.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::config::SKeepAlive::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::config::SKeepAlive as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::ConfigSKeepAlive(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::ConfigSKeepAlive {
                keep_alive_id: p.keep_alive_id.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::config::SPluginMessage::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::config::SPluginMessage as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::ConfigSPluginMessage(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::ConfigSPluginMessage {
                channel: p.channel.into(),
                data: p.data.iter().map(|v| *v as _).collect(),
            }))
        }
        id if id == pumpkin_protocol::java::server::config::SConfigResourcePack::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::config::SConfigResourcePack as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::ConfigSConfigResourcePack(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::ConfigSConfigResourcePack {
                uuid: crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::uuid::Uuid { high: p.uuid.as_u64_pair().1, low: p.uuid.as_u64_pair().0 },
                result: p.result.0.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SAttack::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SAttack as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SAttack(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SAttack {
                entity_id: p.entity_id.0.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SBundleItemSelected::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SBundleItemSelected as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SBundleItemSelected(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SBundleItemSelected {
                slot_id: p.slot_id.0.try_into().unwrap_or_default(),
                selected_item_index: p.selected_item_index.0.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SChatCommand::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SChatCommand as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SChatCommand(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SChatCommand {
                command: p.command.into(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SChunkBatch::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SChunkBatch as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SChunkBatch(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SChunkBatch {
                chunks_per_tick: p.chunks_per_tick.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SClientCommand::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SClientCommand as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SClientCommand(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SClientCommand {
                action_id: p.action_id.0.try_into().unwrap_or_default(),
            }))
        }
        id if id
            == pumpkin_protocol::java::server::play::SClientInformationPlay::to_id(version) =>
        {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SClientInformationPlay as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SClientInformationPlay(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SClientInformationPlay {
                locale: p.locale.into(),
                view_distance: p.view_distance.try_into().unwrap_or_default(),
                chat_mode: p.chat_mode.0.try_into().unwrap_or_default(),
                chat_colors: p.chat_colors.try_into().unwrap_or_default(),
                skin_parts: p.skin_parts.try_into().unwrap_or_default(),
                main_hand: p.main_hand.0.try_into().unwrap_or_default(),
                text_filtering: p.text_filtering.try_into().unwrap_or_default(),
                server_listing: p.server_listing.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SCloseContainer::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SCloseContainer as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SCloseContainer(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SCloseContainer {
                window_id: p.window_id.0.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SCommandSuggestion::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SCommandSuggestion as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SCommandSuggestion(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SCommandSuggestion {
                id: p.id.0.try_into().unwrap_or_default(),
                command: p.command.into(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SConfirmTeleport::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SConfirmTeleport as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SConfirmTeleport(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SConfirmTeleport {
                teleport_id: p.teleport_id.0.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SContainerButtonClick::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SContainerButtonClick as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SContainerButtonClick(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SContainerButtonClick {
                window_id: p.window_id.0.try_into().unwrap_or_default(),
                button_id: p.button_id.0.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SCustomPayload::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SCustomPayload as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SCustomPayload(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SCustomPayload {
                channel: p.channel.into(),
                data: p.data.iter().map(|v| *v as _).collect(),
            }))
        }
        id if id
            == pumpkin_protocol::java::server::play::SDebugSampleSubscription::to_id(version) =>
        {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SDebugSampleSubscription as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SDebugSampleSubscription(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SDebugSampleSubscription {
                sample_type: p.sample_type.0.try_into().unwrap_or_default(),
            }))
        }
        id if id
            == pumpkin_protocol::java::server::play::SDebugSubscriptionRequest::to_id(version) =>
        {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SDebugSubscriptionRequest as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SDebugSubscriptionRequest(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SDebugSubscriptionRequest {
                sample_type: p.sample_type.0.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SJigsawGenerate::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SJigsawGenerate as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SJigsawGenerate(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SJigsawGenerate {
                pos: (p.pos.0.x, p.pos.0.y, p.pos.0.z),
                levels: p.levels.0.try_into().unwrap_or_default(),
                keep_jigsaws: p.keep_jigsaws.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SKeepAlive::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SKeepAlive as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SKeepAlive(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SKeepAlive {
                keep_alive_id: p.keep_alive_id.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SMoveVehicle::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SMoveVehicle as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SMoveVehicle(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SMoveVehicle {
                x: p.x.try_into().unwrap_or_default(),
                y: p.y.try_into().unwrap_or_default(),
                z: p.z.try_into().unwrap_or_default(),
                yaw: p.yaw.try_into().unwrap_or_default(),
                pitch: p.pitch.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SPaddleBoat::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SPaddleBoat as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SPaddleBoat(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SPaddleBoat {
                left_paddle: p.left_paddle.try_into().unwrap_or_default(),
                right_paddle: p.right_paddle.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SPickItemFromBlock::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SPickItemFromBlock as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SPickItemFromBlock(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SPickItemFromBlock {
                pos: (p.pos.0.x, p.pos.0.y, p.pos.0.z),
                include_data: p.include_data.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SPickItemFromEntity::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SPickItemFromEntity as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SPickItemFromEntity(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SPickItemFromEntity {
                id: p.id.0.try_into().unwrap_or_default(),
                include_data: p.include_data.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SPlayPingRequest::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SPlayPingRequest as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SPlayPingRequest(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SPlayPingRequest {
                payload: p.payload.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SPlaceRecipe::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SPlaceRecipe as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SPlaceRecipe(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SPlaceRecipe {
                container_id: p.container_id.try_into().unwrap_or_default(),
                recipe_display_id: p.recipe_display_id.0.try_into().unwrap_or_default(),
                use_max_items: p.use_max_items.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SPlayerAbilities::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SPlayerAbilities as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SPlayerAbilities(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SPlayerAbilities {
                flags: p.flags.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SPlayerAction::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SPlayerAction as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SPlayerAction(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SPlayerAction {
                status: p.status.0.try_into().unwrap_or_default(),
                position: (p.position.0.x, p.position.0.y, p.position.0.z),
                face: p.face.try_into().unwrap_or_default(),
                sequence: p.sequence.0.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SSetPlayerGround::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SSetPlayerGround as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SSetPlayerGround(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SSetPlayerGround {
                on_ground: p.on_ground.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SPlayerInput::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SPlayerInput as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SPlayerInput(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SPlayerInput {
                input: p.input.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SPlayerPosition::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SPlayerPosition as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SPlayerPosition(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SPlayerPosition {
                position: (p.position.x as _, p.position.y as _, p.position.z as _),
                collision: p.collision.try_into().unwrap_or_default(),
            }))
        }
        id if id
            == pumpkin_protocol::java::server::play::SPlayerPositionRotation::to_id(version) =>
        {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SPlayerPositionRotation as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SPlayerPositionRotation(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SPlayerPositionRotation {
                position: (p.position.x as _, p.position.y as _, p.position.z as _),
                yaw: p.yaw.try_into().unwrap_or_default(),
                pitch: p.pitch.try_into().unwrap_or_default(),
                collision: p.collision.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SPlayerRotation::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SPlayerRotation as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SPlayerRotation(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SPlayerRotation {
                yaw: p.yaw.try_into().unwrap_or_default(),
                pitch: p.pitch.try_into().unwrap_or_default(),
                ground: p.ground.try_into().unwrap_or_default(),
            }))
        }
        id if id
            == pumpkin_protocol::java::server::play::SRecipeBookChangeSettings::to_id(version) =>
        {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SRecipeBookChangeSettings as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SRecipeBookChangeSettings(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SRecipeBookChangeSettings {
                book_type: p.book_type.0.try_into().unwrap_or_default(),
                is_open: p.is_open.try_into().unwrap_or_default(),
                is_filtering: p.is_filtering.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SRecipeBookSeenRecipe::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SRecipeBookSeenRecipe as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SRecipeBookSeenRecipe(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SRecipeBookSeenRecipe {
                recipe_display_id: p.recipe_display_id.0.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SRenameItem::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SRenameItem as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SRenameItem(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SRenameItem {
                item_name: p.item_name.into(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SSeenAdvancement::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SSeenAdvancement as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(match p {
                pumpkin_protocol::java::server::play::SSeenAdvancement::OpenTab(identifier) => ServerboundPacket::SSeenAdvancement(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SSeenAdvancement::OpenTab(identifier.to_string())),
                pumpkin_protocol::java::server::play::SSeenAdvancement::CloseTab => ServerboundPacket::SSeenAdvancement(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SSeenAdvancement::CloseTab),
            })
        }
        id if id == pumpkin_protocol::java::server::play::SSelectTrade::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SSelectTrade as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SSelectTrade(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SSelectTrade {
                selected_slot: p.selected_slot.0.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SSetCommandBlock::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SSetCommandBlock as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SSetCommandBlock(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SSetCommandBlock {
                pos: (p.pos.0.x, p.pos.0.y, p.pos.0.z),
                command: p.command.into(),
                mode: p.mode.0.try_into().unwrap_or_default(),
                flags: p.flags.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SSetHeldItem::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SSetHeldItem as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SSetHeldItem(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SSetHeldItem {
                slot: p.slot.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SSetJigsawBlock::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SSetJigsawBlock as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SSetJigsawBlock(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SSetJigsawBlock {
                pos: (p.pos.0.x, p.pos.0.y, p.pos.0.z),
                name: p.name.into(),
                target: p.target.into(),
                pool: p.pool.into(),
                final_state: p.final_state.into(),
                joint: p.joint.into(),
                selection_priority: p.selection_priority.0.try_into().unwrap_or_default(),
                placement_priority: p.placement_priority.0.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SSwingArm::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SSwingArm as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SSwingArm(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SSwingArm {
                hand: p.hand.0.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::STeleportToEntity::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::STeleportToEntity as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::STeleportToEntity(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::STeleportToEntity {
                target: crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::uuid::Uuid { high: p.target.as_u64_pair().1, low: p.target.as_u64_pair().0 },
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SUpdateSign::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SUpdateSign as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SUpdateSign(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SUpdateSign {
                location: (p.location.0.x, p.location.0.y, p.location.0.z),
                is_front_text: p.is_front_text.try_into().unwrap_or_default(),
                line_1: p.line_1.into(),
                line_2: p.line_2.into(),
                line_3: p.line_3.into(),
                line_4: p.line_4.into(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SUseItem::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SUseItem as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SUseItem(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SUseItem {
                hand: p.hand.0.try_into().unwrap_or_default(),
                sequence: p.sequence.0.try_into().unwrap_or_default(),
                yaw: p.yaw.try_into().unwrap_or_default(),
                pitch: p.pitch.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::play::SUseItemOn::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::play::SUseItemOn as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::SUseItemOn(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::SUseItemOn {
                hand: p.hand.0.try_into().unwrap_or_default(),
                position: (p.position.0.x, p.position.0.y, p.position.0.z),
                face: p.face.0.try_into().unwrap_or_default(),
                cursor_pos: (p.cursor_pos.x as _, p.cursor_pos.y as _, p.cursor_pos.z as _),
                inside_block: p.inside_block.try_into().unwrap_or_default(),
                is_against_world_border: p.is_against_world_border.try_into().unwrap_or_default(),
                sequence: p.sequence.0.try_into().unwrap_or_default(),
            }))
        }
        id if id == pumpkin_protocol::java::server::status::SStatusPingRequest::to_id(version) => {
            use pumpkin_protocol::ServerPacket;
            let p = <pumpkin_protocol::java::server::status::SStatusPingRequest as pumpkin_protocol::ServerPacket>::read(&mut payload, &version).ok()?;
            Some(ServerboundPacket::StatusSStatusPingRequest(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::StatusSStatusPingRequest {
                payload: p.payload.try_into().unwrap_or_default(),
            }))
        }
        _ => None,
    }
}

pub trait ToWitClientboundJava {
    fn to_wit(&self) -> ClientboundPacket;
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::config::CConfigDisconnect<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::ConfigCConfigDisconnect(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::ConfigCConfigDisconnect {
                reason: self.reason.to_string(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::config::CPluginMessage<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::ConfigCPluginMessage(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::ConfigCPluginMessage {
                channel: self.channel.to_string(),
                data: self.data.iter().map(|v| *v as _).collect(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::config::CTransfer<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::ConfigCTransfer(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::ConfigCTransfer {
                host: self.host.to_string(),
                port: self.port.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::login::CEncryptionRequest<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::LoginCEncryptionRequest(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::LoginCEncryptionRequest {
                server_id: self.server_id.to_string(),
                public_key: self.public_key.iter().map(|v| *v as _).collect(),
                verify_token: self.verify_token.iter().map(|v| *v as _).collect(),
                should_authenticate: self.should_authenticate.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::login::CLoginDisconnect {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::LoginCLoginDisconnect(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::LoginCLoginDisconnect {
                json_reason: self.json_reason.to_string(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::login::CLoginPluginRequest<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::LoginCLoginPluginRequest(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::LoginCLoginPluginRequest {
                message_id: self.message_id.0.try_into().unwrap_or_default(),
                channel: self.channel.to_string(),
                data: self.data.iter().map(|v| *v as _).collect(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::login::CSetCompression {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::LoginCSetCompression(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::LoginCSetCompression {
                threshold: self.threshold.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CAcknowledgeBlockChange {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CAcknowledgeBlockChange(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CAcknowledgeBlockChange {
                sequence_id: self.sequence_id.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CActionBar<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CActionBar(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CActionBar {
                action_bar: serde_json::to_string(&self.action_bar).unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CSetBlockDestroyStage {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CSetBlockDestroyStage(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CSetBlockDestroyStage {
                entity_id: self.entity_id.0.try_into().unwrap_or_default(),
                location: (self.location.0.x, self.location.0.y, self.location.0.z),
                destroy_stage: self.destroy_stage.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CBlockEvent {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CBlockEvent(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CBlockEvent {
                location: (self.location.0.x, self.location.0.y, self.location.0.z),
                action_id: self.action_id.try_into().unwrap_or_default(),
                action_parameter: self.action_parameter.try_into().unwrap_or_default(),
                block_type: self.block_type.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CBlockUpdate {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CBlockUpdate(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CBlockUpdate {
                location: (self.location.0.x, self.location.0.y, self.location.0.z),
                state_id: self.state_id.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CCenterChunk {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CCenterChunk(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CCenterChunk {
                chunk_x: self.chunk_x.0.try_into().unwrap_or_default(),
                chunk_z: self.chunk_z.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CChangeDifficulty {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CChangeDifficulty(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CChangeDifficulty {
                difficulty: self.difficulty.try_into().unwrap_or_default(),
                locked: self.locked.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CChunkBatchEnd {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CChunkBatchEnd(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CChunkBatchEnd {
                batch_size: self.batch_size.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CClearTitle {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CClearTitle(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CClearTitle {
                reset: self.reset.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CCloseContainer {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CCloseContainer(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CCloseContainer {
                sync_id: self.sync_id.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CCombatDeath<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CCombatDeath(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CCombatDeath {
                player_id: self.player_id.0.try_into().unwrap_or_default(),
                message: serde_json::to_string(&self.message).unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CCustomPayload<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CCustomPayload(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CCustomPayload {
                channel: self.channel.to_string(),
                data: self.data.iter().map(|v| *v as _).collect(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CDebugSample<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CDebugSample(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CDebugSample {
                sample: self.sample.iter().map(|v| *v as _).collect(),
                sample_type: self.sample_type.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CPlayDisconnect<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CPlayDisconnect(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CPlayDisconnect {
                reason: serde_json::to_string(&self.reason).unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CDisplayObjective {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CDisplayObjective(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CDisplayObjective {
                position: self.position.0.try_into().unwrap_or_default(),
                score_name: self.score_name.to_string(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CEntityAnimation {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CEntityAnimation(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CEntityAnimation {
                entity_id: self.entity_id.0.try_into().unwrap_or_default(),
                animation: self.animation.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CEntityPositionSync {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CEntityPositionSync(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CEntityPositionSync {
                entity_id: self.entity_id.0.try_into().unwrap_or_default(),
                position: (self.position.x as _, self.position.y as _, self.position.z as _),
                delta: (self.delta.x as _, self.delta.y as _, self.delta.z as _),
                yaw: self.yaw.try_into().unwrap_or_default(),
                pitch: self.pitch.try_into().unwrap_or_default(),
                on_ground: self.on_ground.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CEntityStatus {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CEntityStatus(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CEntityStatus {
                entity_id: self.entity_id.try_into().unwrap_or_default(),
                entity_status: self.entity_status.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CGameEvent {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CGameEvent(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CGameEvent {
                event: self.event.try_into().unwrap_or_default(),
                value: self.value.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CHeadRot {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CHeadRot(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CHeadRot {
                entity_id: self.entity_id.0.try_into().unwrap_or_default(),
                head_yaw: self.head_yaw.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CHurtAnimation {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CHurtAnimation(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CHurtAnimation {
                entity_id: self.entity_id.0.try_into().unwrap_or_default(),
                yaw: self.yaw.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CInitializeWorldBorder {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CInitializeWorldBorder(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CInitializeWorldBorder {
                x: self.x.try_into().unwrap_or_default(),
                z: self.z.try_into().unwrap_or_default(),
                old_diameter: self.old_diameter.try_into().unwrap_or_default(),
                new_diameter: self.new_diameter.try_into().unwrap_or_default(),
                speed: self.speed.0.try_into().unwrap_or_default(),
                portal_teleport_boundary: self.portal_teleport_boundary.0.try_into().unwrap_or_default(),
                warning_blocks: self.warning_blocks.0.try_into().unwrap_or_default(),
                warning_time: self.warning_time.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CItemCooldown {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CItemCooldown(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CItemCooldown {
                group: self.group.to_string(),
                cooldown: self.cooldown.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CKeepAlive {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CKeepAlive(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CKeepAlive {
                keep_alive_id: self.keep_alive_id.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CLevelEvent {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CLevelEvent(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CLevelEvent {
                event: self.event.try_into().unwrap_or_default(),
                location: (self.location.0.x, self.location.0.y, self.location.0.z),
                data: self.data.try_into().unwrap_or_default(),
                disable_relative_volume: self.disable_relative_volume.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::COpenScreen<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::COpenScreen(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::COpenScreen {
                sync_id: self.sync_id.0.try_into().unwrap_or_default(),
                window_type: self.window_type.0.try_into().unwrap_or_default(),
                window_title: serde_json::to_string(&self.window_title).unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::COpenSignEditor {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::COpenSignEditor(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::COpenSignEditor {
                location: (self.location.0.x, self.location.0.y, self.location.0.z),
                is_front_text: self.is_front_text.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CParticle<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CParticle(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CParticle {
                force_spawn: self.force_spawn.try_into().unwrap_or_default(),
                important: self.important.try_into().unwrap_or_default(),
                position: (self.position.x as _, self.position.y as _, self.position.z as _),
                offset: (self.offset.x as _, self.offset.y as _, self.offset.z as _),
                max_speed: self.max_speed.try_into().unwrap_or_default(),
                particle_count: self.particle_count.try_into().unwrap_or_default(),
                particle_id: self.particle_id.0.try_into().unwrap_or_default(),
                data: self.data.iter().map(|v| *v as _).collect(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CPingResponse {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CPingResponse(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CPingResponse {
                payload: self.payload.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CPlayerAbilities {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CPlayerAbilities(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CPlayerAbilities {
                flags: self.flags.try_into().unwrap_or_default(),
                flying_speed: self.flying_speed.try_into().unwrap_or_default(),
                field_of_view: self.field_of_view.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CRemovePlayerInfo<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CRemovePlayerInfo(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CRemovePlayerInfo {
                players: self.players.iter().map(|u| crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::uuid::Uuid { high: u.as_u64_pair().1, low: u.as_u64_pair().0 }).collect(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CPlayerSpawnPosition {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CPlayerSpawnPosition(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CPlayerSpawnPosition {
                dimension_name: self.dimension_name.to_string(),
                location: (self.location.0.x, self.location.0.y, self.location.0.z),
                yaw: self.yaw.try_into().unwrap_or_default(),
                pitch: self.pitch.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CRecipeBookSettings {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CRecipeBookSettings(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CRecipeBookSettings {
                crafting_open: self.crafting_open.try_into().unwrap_or_default(),
                crafting_filtering: self.crafting_filtering.try_into().unwrap_or_default(),
                furnace_open: self.furnace_open.try_into().unwrap_or_default(),
                furnace_filtering: self.furnace_filtering.try_into().unwrap_or_default(),
                blast_furnace_open: self.blast_furnace_open.try_into().unwrap_or_default(),
                blast_furnace_filtering: self.blast_furnace_filtering.try_into().unwrap_or_default(),
                smoker_open: self.smoker_open.try_into().unwrap_or_default(),
                smoker_filtering: self.smoker_filtering.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CRemoveEntities<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CRemoveEntities(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CRemoveEntities {
                entity_ids: self.entity_ids.iter().map(|v| v.0 as _).collect(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CRemoveMobEffect {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CRemoveMobEffect(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CRemoveMobEffect {
                entity_id: self.entity_id.0.try_into().unwrap_or_default(),
                effect_id: self.effect_id.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CSetBorderCenter {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CSetBorderCenter(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CSetBorderCenter {
                x: self.x.try_into().unwrap_or_default(),
                z: self.z.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CSetBorderLerpSize {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CSetBorderLerpSize(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CSetBorderLerpSize {
                old_diameter: self.old_diameter.try_into().unwrap_or_default(),
                new_diameter: self.new_diameter.try_into().unwrap_or_default(),
                speed: self.speed.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CSetBorderSize {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CSetBorderSize(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CSetBorderSize {
                diameter: self.diameter.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CSetBorderWarningDelay {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CSetBorderWarningDelay(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CSetBorderWarningDelay {
                warning_time: self.warning_time.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CSetBorderWarningDistance {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CSetBorderWarningDistance(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CSetBorderWarningDistance {
                warning_blocks: self.warning_blocks.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CSetContainerProperty {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CSetContainerProperty(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CSetContainerProperty {
                window_id: self.window_id.0.try_into().unwrap_or_default(),
                property: self.property.try_into().unwrap_or_default(),
                value: self.value.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CSetEntityLink {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CSetEntityLink(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CSetEntityLink {
                attached_entity_id: self.attached_entity_id.try_into().unwrap_or_default(),
                holding_entity_id: self.holding_entity_id.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CSetExperience {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CSetExperience(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CSetExperience {
                progress: self.progress.try_into().unwrap_or_default(),
                level: self.level.0.try_into().unwrap_or_default(),
                total_experience: self.total_experience.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CSetHealth {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CSetHealth(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CSetHealth {
                health: self.health.try_into().unwrap_or_default(),
                food: self.food.0.try_into().unwrap_or_default(),
                food_saturation: self.food_saturation.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CSetPassengers<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CSetPassengers(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CSetPassengers {
                entity_id: self.entity_id.0.try_into().unwrap_or_default(),
                passengers: self.passengers.iter().map(|v| v.0 as _).collect(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CTitleText<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CTitleText(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CTitleText {
                title: serde_json::to_string(&self.title).unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CTitleAnimation {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CTitleAnimation(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CTitleAnimation {
                fade_in_ticks: self.fade_in_ticks.try_into().unwrap_or_default(),
                stay_ticks: self.stay_ticks.try_into().unwrap_or_default(),
                fade_out_ticks: self.fade_out_ticks.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CSubtitle<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CSubtitle(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CSubtitle {
                subtitle: serde_json::to_string(&self.subtitle).unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CSystemChatMessage<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CSystemChatMessage(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CSystemChatMessage {
                content: serde_json::to_string(&self.content).unwrap_or_default(),
                overlay: self.overlay.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CTabList<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CTabList(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CTabList {
                header: serde_json::to_string(&self.header).unwrap_or_default(),
                footer: serde_json::to_string(&self.footer).unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CTakeItemEntity {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CTakeItemEntity(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CTakeItemEntity {
                entity_id: self.entity_id.0.try_into().unwrap_or_default(),
                collector_entity_id: self.collector_entity_id.0.try_into().unwrap_or_default(),
                stack_amount: self.stack_amount.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CTickingState {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CTickingState(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CTickingState {
                tick_rate: self.tick_rate.try_into().unwrap_or_default(),
                is_frozen: self.is_frozen.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CTickingStep {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CTickingStep(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CTickingStep {
                tick_steps: self.tick_steps.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CTransfer<'_> {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CTransfer(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CTransfer {
                host: self.host.to_string(),
                port: self.port.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CUnloadChunk {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CUnloadChunk(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CUnloadChunk {
                z: self.z.try_into().unwrap_or_default(),
                x: self.x.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CUpdateEntityPos {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CUpdateEntityPos(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CUpdateEntityPos {
                entity_id: self.entity_id.0.try_into().unwrap_or_default(),
                delta: (self.delta.x as _, self.delta.y as _, self.delta.z as _),
                on_ground: self.on_ground.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CUpdateEntityPosRot {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CUpdateEntityPosRot(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CUpdateEntityPosRot {
                entity_id: self.entity_id.0.try_into().unwrap_or_default(),
                delta: (self.delta.x as _, self.delta.y as _, self.delta.z as _),
                yaw: self.yaw.try_into().unwrap_or_default(),
                pitch: self.pitch.try_into().unwrap_or_default(),
                on_ground: self.on_ground.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CUpdateEntityRot {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CUpdateEntityRot(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CUpdateEntityRot {
                entity_id: self.entity_id.0.try_into().unwrap_or_default(),
                yaw: self.yaw.try_into().unwrap_or_default(),
                pitch: self.pitch.try_into().unwrap_or_default(),
                on_ground: self.on_ground.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CUpdateMobEffect {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CUpdateMobEffect(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CUpdateMobEffect {
                entity_id: self.entity_id.0.try_into().unwrap_or_default(),
                effect_id: self.effect_id.0.try_into().unwrap_or_default(),
                amplifier: self.amplifier.0.try_into().unwrap_or_default(),
                duration: self.duration.0.try_into().unwrap_or_default(),
                flags: self.flags.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::play::CWorldEvent {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::CWorldEvent(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::CWorldEvent {
                event: self.event.try_into().unwrap_or_default(),
                location: (self.location.0.x, self.location.0.y, self.location.0.z),
                data: self.data.try_into().unwrap_or_default(),
                disable_relative_volume: self.disable_relative_volume.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::status::CPingResponse {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::StatusCPingResponse(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::StatusCPingResponse {
                payload: self.payload.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundJava for pumpkin_protocol::java::client::status::CStatusResponse {
    fn to_wit(&self) -> ClientboundPacket {
        ClientboundPacket::StatusCStatusResponse(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::java_packets::StatusCStatusResponse {
                json_response: self.json_response.to_string(),
        })
    }
}

#[must_use]
pub fn clientbound_java_any_to_wit(any: &dyn Any) -> Option<ClientboundPacket> {
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::config::CConfigDisconnect>()
    {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::config::CPluginMessage>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::config::CTransfer>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::login::CEncryptionRequest>()
    {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::login::CLoginDisconnect>() {
        return Some(p.to_wit());
    }
    if let Some(p) =
        any.downcast_ref::<pumpkin_protocol::java::client::login::CLoginPluginRequest>()
    {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::login::CSetCompression>() {
        return Some(p.to_wit());
    }
    if let Some(p) =
        any.downcast_ref::<pumpkin_protocol::java::client::play::CAcknowledgeBlockChange>()
    {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CActionBar>() {
        return Some(p.to_wit());
    }
    if let Some(p) =
        any.downcast_ref::<pumpkin_protocol::java::client::play::CSetBlockDestroyStage>()
    {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CBlockEvent>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CBlockUpdate>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CCenterChunk>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CChangeDifficulty>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CChunkBatchEnd>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CClearTitle>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CCloseContainer>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CCombatDeath>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CCustomPayload>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CDebugSample>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CPlayDisconnect>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CDisplayObjective>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CEntityAnimation>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CEntityPositionSync>()
    {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CEntityStatus>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CGameEvent>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CHeadRot>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CHurtAnimation>() {
        return Some(p.to_wit());
    }
    if let Some(p) =
        any.downcast_ref::<pumpkin_protocol::java::client::play::CInitializeWorldBorder>()
    {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CItemCooldown>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CKeepAlive>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CLevelEvent>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::COpenScreen>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::COpenSignEditor>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CParticle>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CPingResponse>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CPlayerAbilities>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CRemovePlayerInfo>() {
        return Some(p.to_wit());
    }
    if let Some(p) =
        any.downcast_ref::<pumpkin_protocol::java::client::play::CPlayerSpawnPosition>()
    {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CRecipeBookSettings>()
    {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CRemoveEntities>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CRemoveMobEffect>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CSetBorderCenter>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CSetBorderLerpSize>()
    {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CSetBorderSize>() {
        return Some(p.to_wit());
    }
    if let Some(p) =
        any.downcast_ref::<pumpkin_protocol::java::client::play::CSetBorderWarningDelay>()
    {
        return Some(p.to_wit());
    }
    if let Some(p) =
        any.downcast_ref::<pumpkin_protocol::java::client::play::CSetBorderWarningDistance>()
    {
        return Some(p.to_wit());
    }
    if let Some(p) =
        any.downcast_ref::<pumpkin_protocol::java::client::play::CSetContainerProperty>()
    {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CSetEntityLink>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CSetExperience>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CSetHealth>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CSetPassengers>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CTitleText>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CTitleAnimation>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CSubtitle>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CSystemChatMessage>()
    {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CTabList>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CTakeItemEntity>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CTickingState>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CTickingStep>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CTransfer>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CUnloadChunk>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CUpdateEntityPos>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CUpdateEntityPosRot>()
    {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CUpdateEntityRot>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CUpdateMobEffect>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::play::CWorldEvent>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::status::CPingResponse>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::java::client::status::CStatusResponse>() {
        return Some(p.to_wit());
    }
    None
}

use crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::{
    ClientboundPacket as BClientboundPacket, ServerboundPacket as BServerboundPacket,
};

#[must_use]
pub fn serialize_bedrock_packet(packet: &BClientboundPacket) -> Option<Bytes> {
    match packet {
        BClientboundPacket::CChangeDimension(data) => {
            let p = pumpkin_protocol::bedrock::client::CChangeDimension {
                dimension: VarInt(data.dimension),
                position: pumpkin_util::math::vector3::Vector3::new(
                    data.position.0 as _,
                    data.position.1 as _,
                    data.position.2 as _,
                ),
                respawn: data.respawn.try_into().unwrap_or_default(),
                loading_screen_id: data.has_loading_screen_id.then_some(0),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CChunkRadiusUpdate(data) => {
            let p = pumpkin_protocol::bedrock::client::CChunkRadiusUpdate {
                chunk_radius: VarInt(data.chunk_radius),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CContainerOpen(data) => {
            let p = pumpkin_protocol::bedrock::client::CContainerOpen {
                container_id: data.container_id.try_into().unwrap_or_default(),
                container_type: data.container_type.try_into().unwrap_or_default(),
                position: pumpkin_util::math::position::BlockPos::new(
                    data.position.0,
                    data.position.1,
                    data.position.2,
                ),
                target_entity_id: pumpkin_protocol::codec::var_long::VarLong(
                    data.target_entity_id.try_into().unwrap_or_default(),
                ),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CCorrectPlayerMove(data) => {
            let p = pumpkin_protocol::bedrock::client::CCorrectPlayerMove {
                prediction_type: data.prediction_type.try_into().unwrap_or_default(),
                pos: pumpkin_util::math::vector3::Vector3::new(
                    data.pos.0 as _,
                    data.pos.1 as _,
                    data.pos.2 as _,
                ),
                pos_delta: pumpkin_util::math::vector3::Vector3::new(
                    data.pos_delta.0 as _,
                    data.pos_delta.1 as _,
                    data.pos_delta.2 as _,
                ),
                rotation: pumpkin_util::math::vector2::Vector2::new(0.0, 0.0),
                vehicle_angular_velocity: None,
                on_ground: data.on_ground.try_into().unwrap_or_default(),
                tick: pumpkin_protocol::codec::var_ulong::VarULong(
                    data.tick.try_into().unwrap_or_default(),
                ),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CDisconnectPlayer(data) => {
            let p = pumpkin_protocol::bedrock::client::CDisconnectPlayer {
                reason: VarInt(data.reason),
                skip_message: data.skip_message.try_into().unwrap_or_default(),
                message: data.message.clone(),
                filtered_message: data.filtered_message.clone(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CLevelEvent(data) => {
            let p = pumpkin_protocol::bedrock::client::CLevelEvent {
                event_id: VarInt(data.event_id),
                position: pumpkin_util::math::vector3::Vector3::new(
                    data.position.0 as _,
                    data.position.1 as _,
                    data.position.2 as _,
                ),
                data: VarInt(data.data),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CLevelSoundEvent(data) => {
            let position = pumpkin_util::math::vector3::Vector3::new(
                data.position.0 as _,
                data.position.1 as _,
                data.position.2 as _,
            );
            let p = pumpkin_protocol::bedrock::client::CLevelSoundEvent {
                sound_id: data.sound_id.to_string(),
                position,
                extra_data: VarInt(data.extra_data),
                entity_type: data.entity_type.clone(),
                is_baby_mob: data.is_baby_mob.try_into().unwrap_or_default(),
                is_global: data.is_global.try_into().unwrap_or_default(),
                actor_unique_id: 0,
                fire_at_position: Some(position),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CModalFormRequest(data) => {
            let p = pumpkin_protocol::bedrock::client::CModalFormRequest {
                form_id: VarUInt(data.form_id.try_into().unwrap_or_default()),
                form_data: data.form_data.clone(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CMoveActorAbsolute(data) => {
            let p = pumpkin_protocol::bedrock::client::CMoveActorAbsolute {
                entity_runtime_id: pumpkin_protocol::codec::var_ulong::VarULong(
                    data.entity_runtime_id.try_into().unwrap_or_default(),
                ),
                flags: data.flags.try_into().unwrap_or_default(),
                position: pumpkin_util::math::vector3::Vector3::new(
                    data.position.0 as _,
                    data.position.1 as _,
                    data.position.2 as _,
                ),
                pitch: data.pitch.try_into().unwrap_or_default(),
                yaw: data.yaw.try_into().unwrap_or_default(),
                head_yaw: data.head_yaw.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CMoveActorDelta(data) => {
            let p = pumpkin_protocol::bedrock::client::CMoveActorDelta {
                entity_runtime_id: pumpkin_protocol::codec::var_ulong::VarULong(
                    data.entity_runtime_id.try_into().unwrap_or_default(),
                ),
                flags: data.flags.try_into().unwrap_or_default(),
                x: data.x.try_into().unwrap_or_default(),
                y: data.y.try_into().unwrap_or_default(),
                z: data.z.try_into().unwrap_or_default(),
                pitch: data.pitch.try_into().unwrap_or_default(),
                yaw: data.yaw.try_into().unwrap_or_default(),
                head_yaw: data.head_yaw.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CMovePlayer(data) => {
            let p = pumpkin_protocol::bedrock::client::CMovePlayer {
                player_runtime_id: pumpkin_protocol::codec::var_ulong::VarULong(
                    data.player_runtime_id.try_into().unwrap_or_default(),
                ),
                position: pumpkin_util::math::vector3::Vector3::new(
                    data.position.0 as _,
                    data.position.1 as _,
                    data.position.2 as _,
                ),
                pitch: data.pitch.try_into().unwrap_or_default(),
                yaw: data.yaw.try_into().unwrap_or_default(),
                head_yaw: data.head_yaw.try_into().unwrap_or_default(),
                mode: data.mode.try_into().unwrap_or_default(),
                on_ground: data.on_ground.try_into().unwrap_or_default(),
                riding_runtime_id: pumpkin_protocol::codec::var_ulong::VarULong(
                    data.riding_runtime_id.try_into().unwrap_or_default(),
                ),
                teleport_cause: data.teleport_cause.try_into().unwrap_or_default(),
                teleport_source_entity_type: data
                    .teleport_source_entity_type
                    .try_into()
                    .unwrap_or_default(),
                tick: pumpkin_protocol::codec::var_ulong::VarULong(
                    data.tick.try_into().unwrap_or_default(),
                ),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CNetworkSettings(data) => {
            let p = pumpkin_protocol::bedrock::client::CNetworkSettings {
                compression_threshold: data.compression_threshold.try_into().unwrap_or_default(),
                compression_method: data.compression_method.try_into().unwrap_or_default(),
                client_throttle_enabled: data
                    .client_throttle_enabled
                    .try_into()
                    .unwrap_or_default(),
                client_throttle_threshold: data
                    .client_throttle_threshold
                    .try_into()
                    .unwrap_or_default(),
                client_throttle_scalar: data.client_throttle_scalar.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CPlayStatus(data) => {
            let p = match data {
                crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::LoginSuccess => pumpkin_protocol::bedrock::client::CPlayStatus::LoginSuccess,
                crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::OutdatedClient => pumpkin_protocol::bedrock::client::CPlayStatus::OutdatedClient,
                crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::OutdatedServer => pumpkin_protocol::bedrock::client::CPlayStatus::OutdatedServer,
                crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::PlayerSpawn => pumpkin_protocol::bedrock::client::CPlayStatus::PlayerSpawn,
                crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::InvalidTenant => pumpkin_protocol::bedrock::client::CPlayStatus::InvalidTenant,
                crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::EditionMismatchEduToVanilla => pumpkin_protocol::bedrock::client::CPlayStatus::EditionMismatchEduToVanilla,
                crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::EditionMismatchVanillaToEdu => pumpkin_protocol::bedrock::client::CPlayStatus::EditionMismatchVanillaToEdu,
                crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::ServerFullSubClient => pumpkin_protocol::bedrock::client::CPlayStatus::ServerFullSubClient,
                crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::EditorMismatchEditorToVanilla => pumpkin_protocol::bedrock::client::CPlayStatus::EditorMismatchEditorToVanilla,
                crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::EditorMismatchVanillaToEditor => pumpkin_protocol::bedrock::client::CPlayStatus::EditorMismatchVanillaToEditor,
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CPlayerHotbar(data) => {
            let p = pumpkin_protocol::bedrock::client::CPlayerHotbar {
                selected_slot: pumpkin_protocol::codec::var_uint::VarUInt(
                    data.selected_slot.try_into().unwrap_or_default(),
                ),
                container_id: data.container_id.try_into().unwrap_or_default(),
                should_select_block: data.should_select_block.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CRemoveActor(data) => {
            let p = pumpkin_protocol::bedrock::client::CRemoveActor {
                entity_unique_id: pumpkin_protocol::codec::var_long::VarLong(
                    data.entity_unique_id.try_into().unwrap_or_default(),
                ),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CSetDisplayObjective(data) => {
            let p = pumpkin_protocol::bedrock::client::CSetDisplayObjective {
                display_slot: data.display_slot.clone(),
                objective_name: data.objective_name.clone(),
                display_name: data.display_name.clone(),
                criteria_name: data.criteria_name.clone(),
                sort_order: VarInt(data.sort_order),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CRemoveObjective(data) => {
            let p = pumpkin_protocol::bedrock::client::CRemoveObjective {
                objective_name: data.objective_name.clone(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CSetActorMotion(data) => {
            let p = pumpkin_protocol::bedrock::client::CSetActorMotion {
                target_runtime_id: pumpkin_protocol::codec::var_ulong::VarULong(
                    data.target_runtime_id.try_into().unwrap_or_default(),
                ),
                motion: pumpkin_util::math::vector3::Vector3::new(
                    data.motion.0 as _,
                    data.motion.1 as _,
                    data.motion.2 as _,
                ),
                tick: pumpkin_protocol::codec::var_ulong::VarULong(
                    data.tick.try_into().unwrap_or_default(),
                ),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CSetDifficulty(data) => {
            let p = pumpkin_protocol::bedrock::client::CSetDifficulty {
                difficulty: pumpkin_protocol::codec::var_uint::VarUInt(
                    data.difficulty.try_into().unwrap_or_default(),
                ),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CSetHealth(data) => {
            let p = pumpkin_protocol::bedrock::client::CSetHealth {
                health: VarInt(data.health),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CSetSpawnPosition(data) => {
            let p = pumpkin_protocol::bedrock::client::CSetSpawnPosition {
                spawn_type: VarInt(data.spawn_type),
                position: pumpkin_util::math::position::BlockPos::new(
                    data.position.0,
                    data.position.1,
                    data.position.2,
                ),
                dimension: VarInt(data.dimension),
                spawn_position: pumpkin_util::math::position::BlockPos::new(
                    data.spawn_position.0,
                    data.spawn_position.1,
                    data.spawn_position.2,
                ),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CSetTime(data) => {
            let p = pumpkin_protocol::bedrock::client::CSetTime {
                time: VarInt(data.time),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CSetTitle(data) => {
            let p = pumpkin_protocol::bedrock::client::CSetTitle {
                action_type: VarInt(data.action_type),
                text: data.text.clone(),
                fade_in_duration: VarInt(data.fade_in_duration),
                remain_duration: VarInt(data.remain_duration),
                fade_out_duration: VarInt(data.fade_out_duration),
                xuid: data.xuid.clone(),
                platform_online_id: data.platform_online_id.clone(),
                filtered_message: data.filtered_message.clone(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CShowCredits(data) => {
            let p = pumpkin_protocol::bedrock::client::CShowCredits {
                player_runtime_id: pumpkin_protocol::codec::var_ulong::VarULong(
                    data.player_runtime_id.try_into().unwrap_or_default(),
                ),
                status: VarInt(data.status),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CTakeItemActor(data) => {
            let p = pumpkin_protocol::bedrock::client::CTakeItemActor {
                item_runtime_id: pumpkin_protocol::codec::var_ulong::VarULong(
                    data.item_runtime_id.try_into().unwrap_or_default(),
                ),
                actor_runtime_id: pumpkin_protocol::codec::var_ulong::VarULong(
                    data.actor_runtime_id.try_into().unwrap_or_default(),
                ),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CTransfer(data) => {
            let p = pumpkin_protocol::bedrock::client::CTransfer {
                address: data.address.clone(),
                port: data.port.try_into().unwrap_or_default(),
                reload_world: data.reload_world.try_into().unwrap_or_default(),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        BClientboundPacket::CUpdateBlock(data) => {
            let p = pumpkin_protocol::bedrock::client::CUpdateBlock {
                position: pumpkin_util::math::position::BlockPos::new(
                    data.position.0,
                    data.position.1,
                    data.position.2,
                ),
                block_runtime_id: pumpkin_protocol::codec::var_uint::VarUInt(
                    data.block_runtime_id.try_into().unwrap_or_default(),
                ),
                flags: pumpkin_protocol::codec::var_uint::VarUInt(
                    data.flags.try_into().unwrap_or_default(),
                ),
                layer: pumpkin_protocol::codec::var_uint::VarUInt(
                    data.layer.try_into().unwrap_or_default(),
                ),
            };
            let mut buf = Vec::new();
            let _ = crate::net::bedrock::BedrockClient::write_raw_packet(&p, &mut buf);
            Some(buf.into())
        }
        _ => None,
    }
}

#[must_use]
pub fn deserialize_bedrock_serverbound_packet(
    id: i32,
    payload: &[u8],
) -> Option<BServerboundPacket> {
    match id {
        id if id == <pumpkin_protocol::bedrock::server::SBlockPickRequest as pumpkin_protocol::Packet>::PACKET_ID as i32 => {
            use pumpkin_protocol::BServerPacket;
            let p = <pumpkin_protocol::bedrock::server::SBlockPickRequest as pumpkin_protocol::BServerPacket>::read(&mut Cursor::new(payload)).ok()?;
            Some(BServerboundPacket::SBlockPickRequest(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::SBlockPickRequest {
                block_pos: (p.block_pos.0.x, p.block_pos.0.y, p.block_pos.0.z),
                add_block_nbt: p.add_block_nbt.try_into().unwrap_or_default(),
                hotbar_slot: p.hotbar_slot.try_into().unwrap_or_default(),
            }))
        }
        id if id == <pumpkin_protocol::bedrock::server::SClientCacheStatus as pumpkin_protocol::Packet>::PACKET_ID as i32 => {
            use pumpkin_protocol::BServerPacket;
            let p = <pumpkin_protocol::bedrock::server::SClientCacheStatus as pumpkin_protocol::BServerPacket>::read(&mut Cursor::new(payload)).ok()?;
            Some(BServerboundPacket::SClientCacheStatus(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::SClientCacheStatus {
                cache_supported: p.cache_supported.try_into().unwrap_or_default(),
            }))
        }
        id if id == <pumpkin_protocol::bedrock::server::SContainerClose as pumpkin_protocol::Packet>::PACKET_ID as i32 => {
            use pumpkin_protocol::BServerPacket;
            let p = <pumpkin_protocol::bedrock::server::SContainerClose as pumpkin_protocol::BServerPacket>::read(&mut Cursor::new(payload)).ok()?;
            Some(BServerboundPacket::SContainerClose(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::SContainerClose {
                container_id: p.container_id.try_into().unwrap_or_default(),
                container_type: p.container_type.try_into().unwrap_or_default(),
                server_initiated: p.server_initiated.try_into().unwrap_or_default(),
            }))
        }
        id if id == <pumpkin_protocol::bedrock::server::SPlayerHotbar as pumpkin_protocol::Packet>::PACKET_ID as i32 => {
            use pumpkin_protocol::BServerPacket;
            let p = <pumpkin_protocol::bedrock::server::SPlayerHotbar as pumpkin_protocol::BServerPacket>::read(&mut Cursor::new(payload)).ok()?;
            Some(BServerboundPacket::SPlayerHotbar(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::SPlayerHotbar {
                selected_slot: p.selected_slot.0.try_into().unwrap_or_default(),
                container_id: p.container_id.try_into().unwrap_or_default(),
                select_slot: p.select_slot.try_into().unwrap_or_default(),
            }))
        }
        id if id == <pumpkin_protocol::bedrock::server::SRequestChunkRadius as pumpkin_protocol::Packet>::PACKET_ID as i32 => {
            use pumpkin_protocol::BServerPacket;
            let p = <pumpkin_protocol::bedrock::server::SRequestChunkRadius as pumpkin_protocol::BServerPacket>::read(&mut Cursor::new(payload)).ok()?;
            Some(BServerboundPacket::SRequestChunkRadius(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::SRequestChunkRadius {
                chunk_radius: p.chunk_radius.0.try_into().unwrap_or_default(),
                max_radius: p.max_radius.try_into().unwrap_or_default(),
            }))
        }
        id if id == <pumpkin_protocol::bedrock::server::SRequestNetworkSettings as pumpkin_protocol::Packet>::PACKET_ID as i32 => {
            use pumpkin_protocol::BServerPacket;
            let p = <pumpkin_protocol::bedrock::server::SRequestNetworkSettings as pumpkin_protocol::BServerPacket>::read(&mut Cursor::new(payload)).ok()?;
            Some(BServerboundPacket::SRequestNetworkSettings(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::SRequestNetworkSettings {
                protocol_version: p.protocol_version.try_into().unwrap_or_default(),
            }))
        }
        id if id == <pumpkin_protocol::bedrock::server::SResourcePackResponse as pumpkin_protocol::Packet>::PACKET_ID as i32 => {
            use pumpkin_protocol::BServerPacket;
            let p = <pumpkin_protocol::bedrock::server::SResourcePackResponse as pumpkin_protocol::BServerPacket>::read(&mut Cursor::new(payload)).ok()?;
            Some(BServerboundPacket::SResourcePackResponse(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::SResourcePackResponse {
                response: p.response.try_into().unwrap_or_default(),
                download_size: p.download_size.try_into().unwrap_or_default(),
            }))
        }
        id if id == <pumpkin_protocol::bedrock::server::SSetLocalPlayerAsInitialized as pumpkin_protocol::Packet>::PACKET_ID as i32 => {
            use pumpkin_protocol::BServerPacket;
            let p = <pumpkin_protocol::bedrock::server::SSetLocalPlayerAsInitialized as pumpkin_protocol::BServerPacket>::read(&mut Cursor::new(payload)).ok()?;
            Some(BServerboundPacket::SSetLocalPlayerAsInitialized(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::SSetLocalPlayerAsInitialized {
                runtime_entity_id: p.runtime_entity_id.0.try_into().unwrap_or_default(),
            }))
        }
        id if id == <pumpkin_protocol::bedrock::server::SSetPlayerInventoryOptions as pumpkin_protocol::Packet>::PACKET_ID as i32 => {
            use pumpkin_protocol::BServerPacket;
            let p = <pumpkin_protocol::bedrock::server::SSetPlayerInventoryOptions as pumpkin_protocol::BServerPacket>::read(&mut Cursor::new(payload)).ok()?;
            Some(BServerboundPacket::SSetPlayerInventoryOptions(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::SSetPlayerInventoryOptions {
                left_inventory_tab: p.left_inventory_tab.0.try_into().unwrap_or_default(),
                right_inventory_tab: p.right_inventory_tab.0.try_into().unwrap_or_default(),
                filtering: p.filtering.try_into().unwrap_or_default(),
                inventory_layout: p.inventory_layout.0.try_into().unwrap_or_default(),
                crafting_layout: p.crafting_layout.0.try_into().unwrap_or_default(),
            }))
        }
        _ => None,
    }
}

pub trait ToWitClientboundBedrock {
    fn to_wit(&self) -> BClientboundPacket;
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CChangeDimension {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CChangeDimension(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CChangeDimension {
                dimension: self.dimension.0.try_into().unwrap_or_default(),
                position: (self.position.x as _, self.position.y as _, self.position.z as _),
                respawn: self.respawn.try_into().unwrap_or_default(),
                has_loading_screen_id: self.loading_screen_id.is_some().try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CChunkRadiusUpdate {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CChunkRadiusUpdate(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CChunkRadiusUpdate {
                chunk_radius: self.chunk_radius.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CContainerOpen {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CContainerOpen(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CContainerOpen {
                container_id: self.container_id.try_into().unwrap_or_default(),
                container_type: self.container_type.try_into().unwrap_or_default(),
                position: (self.position.0.x, self.position.0.y, self.position.0.z),
                target_entity_id: self.target_entity_id.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CCorrectPlayerMove {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CCorrectPlayerMove(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CCorrectPlayerMove {
                prediction_type: self.prediction_type.try_into().unwrap_or_default(),
                pos: (self.pos.x as _, self.pos.y as _, self.pos.z as _),
                pos_delta: (self.pos_delta.x as _, self.pos_delta.y as _, self.pos_delta.z as _),
                on_ground: self.on_ground.try_into().unwrap_or_default(),
                tick: self.tick.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CDisconnectPlayer {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CDisconnectPlayer(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CDisconnectPlayer {
                reason: self.reason.0.try_into().unwrap_or_default(),
                skip_message: self.skip_message.try_into().unwrap_or_default(),
                message: self.message.to_string(),
                filtered_message: self.filtered_message.to_string(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CLevelEvent {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CLevelEvent(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CLevelEvent {
                event_id: self.event_id.0.try_into().unwrap_or_default(),
                position: (self.position.x as _, self.position.y as _, self.position.z as _),
                data: self.data.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CLevelSoundEvent {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CLevelSoundEvent(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CLevelSoundEvent {
                sound_id: self.sound_id.parse().unwrap_or_default(),
                position: (self.position.x as _, self.position.y as _, self.position.z as _),
                extra_data: self.extra_data.0.try_into().unwrap_or_default(),
                entity_type: self.entity_type.to_string(),
                is_baby_mob: self.is_baby_mob.try_into().unwrap_or_default(),
                is_global: self.is_global.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CModalFormRequest {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CModalFormRequest(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CModalFormRequest {
                form_id: self.form_id.0.try_into().unwrap_or_default(),
                form_data: self.form_data.to_string(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CMoveActorAbsolute {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CMoveActorAbsolute(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CMoveActorAbsolute {
                entity_runtime_id: self.entity_runtime_id.0.try_into().unwrap_or_default(),
                flags: self.flags.try_into().unwrap_or_default(),
                position: (self.position.x as _, self.position.y as _, self.position.z as _),
                pitch: self.pitch.try_into().unwrap_or_default(),
                yaw: self.yaw.try_into().unwrap_or_default(),
                head_yaw: self.head_yaw.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CMoveActorDelta {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CMoveActorDelta(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CMoveActorDelta {
                entity_runtime_id: self.entity_runtime_id.0.try_into().unwrap_or_default(),
                flags: self.flags.try_into().unwrap_or_default(),
                x: self.x.try_into().unwrap_or_default(),
                y: self.y.try_into().unwrap_or_default(),
                z: self.z.try_into().unwrap_or_default(),
                pitch: self.pitch.try_into().unwrap_or_default(),
                yaw: self.yaw.try_into().unwrap_or_default(),
                head_yaw: self.head_yaw.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CMovePlayer {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CMovePlayer(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CMovePlayer {
                player_runtime_id: self.player_runtime_id.0.try_into().unwrap_or_default(),
                position: (self.position.x as _, self.position.y as _, self.position.z as _),
                pitch: self.pitch.try_into().unwrap_or_default(),
                yaw: self.yaw.try_into().unwrap_or_default(),
                head_yaw: self.head_yaw.try_into().unwrap_or_default(),
                mode: self.mode.try_into().unwrap_or_default(),
                on_ground: self.on_ground.try_into().unwrap_or_default(),
                riding_runtime_id: self.riding_runtime_id.0.try_into().unwrap_or_default(),
                teleport_cause: self.teleport_cause.try_into().unwrap_or_default(),
                teleport_source_entity_type: self.teleport_source_entity_type.try_into().unwrap_or_default(),
                tick: self.tick.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CNetworkSettings {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CNetworkSettings(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CNetworkSettings {
                compression_threshold: self.compression_threshold.try_into().unwrap_or_default(),
                compression_method: self.compression_method.try_into().unwrap_or_default(),
                client_throttle_enabled: self.client_throttle_enabled.try_into().unwrap_or_default(),
                client_throttle_threshold: self.client_throttle_threshold.try_into().unwrap_or_default(),
                client_throttle_scalar: self.client_throttle_scalar.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CPlayStatus {
    fn to_wit(&self) -> BClientboundPacket {
        match self {
            Self::LoginSuccess => BClientboundPacket::CPlayStatus(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::LoginSuccess),
            Self::OutdatedClient => BClientboundPacket::CPlayStatus(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::OutdatedClient),
            Self::OutdatedServer => BClientboundPacket::CPlayStatus(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::OutdatedServer),
            Self::PlayerSpawn => BClientboundPacket::CPlayStatus(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::PlayerSpawn),
            Self::InvalidTenant => BClientboundPacket::CPlayStatus(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::InvalidTenant),
            Self::EditionMismatchEduToVanilla => BClientboundPacket::CPlayStatus(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::EditionMismatchEduToVanilla),
            Self::EditionMismatchVanillaToEdu => BClientboundPacket::CPlayStatus(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::EditionMismatchVanillaToEdu),
            Self::ServerFullSubClient => BClientboundPacket::CPlayStatus(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::ServerFullSubClient),
            Self::EditorMismatchEditorToVanilla => BClientboundPacket::CPlayStatus(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::EditorMismatchEditorToVanilla),
            Self::EditorMismatchVanillaToEditor => BClientboundPacket::CPlayStatus(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayStatus::EditorMismatchVanillaToEditor),
        }
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CPlayerHotbar {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CPlayerHotbar(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CPlayerHotbar {
                selected_slot: self.selected_slot.0.try_into().unwrap_or_default(),
                container_id: self.container_id.try_into().unwrap_or_default(),
                should_select_block: self.should_select_block.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CRemoveActor {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CRemoveActor(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CRemoveActor {
                entity_unique_id: self.entity_unique_id.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CSetDisplayObjective {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CSetDisplayObjective(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CSetDisplayObjective {
                display_slot: self.display_slot.to_string(),
                objective_name: self.objective_name.to_string(),
                display_name: self.display_name.to_string(),
                criteria_name: self.criteria_name.to_string(),
                sort_order: self.sort_order.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CRemoveObjective {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CRemoveObjective(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CRemoveObjective {
                objective_name: self.objective_name.to_string(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CSetActorMotion {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CSetActorMotion(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CSetActorMotion {
                target_runtime_id: self.target_runtime_id.0.try_into().unwrap_or_default(),
                motion: (self.motion.x as _, self.motion.y as _, self.motion.z as _),
                tick: self.tick.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CSetDifficulty {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CSetDifficulty(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CSetDifficulty {
                difficulty: self.difficulty.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CSetHealth {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CSetHealth(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CSetHealth {
                health: self.health.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CSetSpawnPosition {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CSetSpawnPosition(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CSetSpawnPosition {
                spawn_type: self.spawn_type.0.try_into().unwrap_or_default(),
                position: (self.position.0.x, self.position.0.y, self.position.0.z),
                dimension: self.dimension.0.try_into().unwrap_or_default(),
                spawn_position: (self.spawn_position.0.x, self.spawn_position.0.y, self.spawn_position.0.z),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CSetTime {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CSetTime(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CSetTime {
                time: self.time.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CSetTitle {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CSetTitle(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CSetTitle {
                action_type: self.action_type.0.try_into().unwrap_or_default(),
                text: self.text.to_string(),
                fade_in_duration: self.fade_in_duration.0.try_into().unwrap_or_default(),
                remain_duration: self.remain_duration.0.try_into().unwrap_or_default(),
                fade_out_duration: self.fade_out_duration.0.try_into().unwrap_or_default(),
                xuid: self.xuid.to_string(),
                platform_online_id: self.platform_online_id.to_string(),
                filtered_message: self.filtered_message.to_string(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CShowCredits {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CShowCredits(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CShowCredits {
                player_runtime_id: self.player_runtime_id.0.try_into().unwrap_or_default(),
                status: self.status.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CTakeItemActor {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CTakeItemActor(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CTakeItemActor {
                item_runtime_id: self.item_runtime_id.0.try_into().unwrap_or_default(),
                actor_runtime_id: self.actor_runtime_id.0.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CTransfer {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CTransfer(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CTransfer {
                address: self.address.to_string(),
                port: self.port.try_into().unwrap_or_default(),
                reload_world: self.reload_world.try_into().unwrap_or_default(),
        })
    }
}

impl ToWitClientboundBedrock for pumpkin_protocol::bedrock::client::CUpdateBlock {
    fn to_wit(&self) -> BClientboundPacket {
        BClientboundPacket::CUpdateBlock(crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::bedrock_packets::CUpdateBlock {
                position: (self.position.0.x, self.position.0.y, self.position.0.z),
                block_runtime_id: self.block_runtime_id.0.try_into().unwrap_or_default(),
                flags: self.flags.0.try_into().unwrap_or_default(),
                layer: self.layer.0.try_into().unwrap_or_default(),
        })
    }
}

#[must_use]
pub fn clientbound_bedrock_any_to_wit(any: &dyn Any) -> Option<BClientboundPacket> {
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CChangeDimension>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CChunkRadiusUpdate>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CContainerOpen>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CCorrectPlayerMove>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CDisconnectPlayer>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CLevelEvent>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CLevelSoundEvent>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CModalFormRequest>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CMoveActorAbsolute>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CMoveActorDelta>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CMovePlayer>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CNetworkSettings>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CPlayStatus>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CPlayerHotbar>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CRemoveActor>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CSetDisplayObjective>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CRemoveObjective>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CSetActorMotion>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CSetDifficulty>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CSetHealth>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CSetSpawnPosition>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CSetTime>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CSetTitle>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CShowCredits>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CTakeItemActor>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CTransfer>() {
        return Some(p.to_wit());
    }
    if let Some(p) = any.downcast_ref::<pumpkin_protocol::bedrock::client::CUpdateBlock>() {
        return Some(p.to_wit());
    }
    None
}
