Clientbound Packets: use ids from JSON

This commit is contained in:
Snowiiii 2024-10-27 14:18:18 +01:00
parent 5507b2069f
commit a6f3b3f748
81 changed files with 125 additions and 396 deletions

View File

@ -50,7 +50,7 @@ and customizable experience. It prioritizes performance and player enjoyment whi
- [x] Chunk Loading
- [x] Chunk Generation
- [x] Scoreboard
- [ ] World Borders
- [x] World Borders
- [ ] World Saving
- Player
- [x] Player Skins

View File

@ -12,4 +12,4 @@ maven_group=de.snowii
archives_base_name=extractor
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.106.1+1.21.3
fabric_version=0.107.0+1.21.3

View File

@ -2,6 +2,8 @@ use proc_macro::TokenStream;
use quote::quote;
extern crate proc_macro;
mod packet;
#[proc_macro_attribute]
pub fn client_packet(input: TokenStream, item: TokenStream) -> TokenStream {
let ast: syn::DeriveInput = syn::parse(item.clone()).unwrap();
@ -10,13 +12,13 @@ pub fn client_packet(input: TokenStream, item: TokenStream) -> TokenStream {
let (impl_generics, ty_generics, _) = ast.generics.split_for_impl();
let input: proc_macro2::TokenStream = input.into();
let input: proc_macro2::TokenStream = packet::packet_clientbound(input);
let item: proc_macro2::TokenStream = item.into();
let gen = quote! {
#item
impl #impl_generics crate::bytebuf::packet_id::ClientPacketID for #name #ty_generics {
const PACKET_ID: i32 = #input;
const PACKET_ID: i32 = #input as i32;
}
};

View File

@ -0,0 +1,42 @@
use std::{collections::HashMap, sync::LazyLock};
use proc_macro::TokenStream;
use quote::quote;
use serde::Deserialize;
#[derive(Deserialize)]
pub struct Packet {
name: String,
phase: String,
side: String,
id: u16,
}
static PACKETS: LazyLock<HashMap<String, u16>> = LazyLock::new(|| {
serde_json::from_str::<Vec<Packet>>(include_str!("../../assets/packets.json"))
.expect("Could not parse packets.json registry.")
.into_iter()
.map(|val| (format!("{}:{}:{}", val.side, val.phase, val.name), val.id))
.collect()
});
pub(crate) fn packet_clientbound(item: TokenStream) -> proc_macro2::TokenStream {
let input_string = item.to_string();
let packet_name = input_string.trim_matches('"');
let id = PACKETS
.get(&format!("clientbound:{}", packet_name))
.expect("Invalid Packet");
quote! { #id }
}
#[expect(dead_code)]
pub(crate) fn packet_serverbound(item: TokenStream) -> proc_macro2::TokenStream {
let input_string = item.to_string();
let packet_name = input_string.trim_matches('"');
let id = PACKETS
.get(&format!("serverbound:{}", packet_name))
.expect("Invalid Packet");
quote! { #id }
}

View File

@ -7,10 +7,10 @@ use serde::Deserialize;
#[derive(Deserialize)]
pub struct Particle {
name: String,
id: u32,
id: u16,
}
static SOUNDS: LazyLock<HashMap<String, u32>> = LazyLock::new(|| {
static SOUNDS: LazyLock<HashMap<String, u16>> = LazyLock::new(|| {
serde_json::from_str::<Vec<Particle>>(include_str!("../../assets/particles.json"))
.expect("Could not parse particles.json registry.")
.into_iter()

View File

@ -7,10 +7,10 @@ use serde::Deserialize;
#[derive(Deserialize)]
pub struct Sound {
name: String,
id: u32,
id: u16,
}
static SOUNDS: LazyLock<HashMap<String, u32>> = LazyLock::new(|| {
static SOUNDS: LazyLock<HashMap<String, u16>> = LazyLock::new(|| {
serde_json::from_str::<Vec<Sound>>(include_str!("../../assets/sounds.json"))
.expect("Could not parse sounds.json registry.")
.into_iter()

View File

@ -3,10 +3,8 @@ use pumpkin_core::text::TextComponent;
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundConfigPackets;
#[derive(Serialize)]
#[client_packet(ClientboundConfigPackets::AddResourcePack as i32)]
#[client_packet("configuration:resource_pack_push")]
pub struct CConfigAddResourcePack<'a> {
uuid: uuid::Uuid,
url: &'a str,

View File

@ -1,9 +1,7 @@
use pumpkin_macros::client_packet;
use super::ClientboundConfigPackets;
#[derive(serde::Serialize)]
#[client_packet(ClientboundConfigPackets::Disconnect as i32)]
#[client_packet("configuration:disconnect")]
pub struct CConfigDisconnect<'a> {
reason: &'a str,
}

View File

@ -2,10 +2,8 @@ use pumpkin_macros::client_packet;
use crate::Identifier;
use super::ClientboundConfigPackets;
#[derive(serde::Serialize)]
#[client_packet(ClientboundConfigPackets::CookieRequest as i32)]
#[client_packet("configuration:cookie_request")]
pub struct CCookieRequest {
key: Identifier,
}

View File

@ -1,9 +1,7 @@
use pumpkin_macros::client_packet;
use super::ClientboundConfigPackets;
#[derive(serde::Serialize)]
#[client_packet(ClientboundConfigPackets::Finish as i32)]
#[client_packet("configuration:finish_configuration")]
pub struct CFinishConfig {}
impl Default for CFinishConfig {

View File

@ -2,9 +2,7 @@ use pumpkin_macros::client_packet;
use crate::{bytebuf::ByteBuffer, ClientPacket, KnownPack};
use super::ClientboundConfigPackets;
#[client_packet(ClientboundConfigPackets::KnownPacks as i32)]
#[client_packet("configuration:select_known_packs")]
pub struct CKnownPacks<'a> {
known_packs: &'a [KnownPack<'a>],
}

View File

@ -1,10 +1,8 @@
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundConfigPackets;
#[derive(Serialize)]
#[client_packet(ClientboundConfigPackets::PluginMessage as i32)]
#[client_packet("configuration:custom_payload")]
pub struct CPluginMessage<'a> {
channel: &'a str,
data: &'a [u8],

View File

@ -2,9 +2,7 @@ use pumpkin_macros::client_packet;
use crate::{bytebuf::ByteBuffer, ClientPacket};
use super::ClientboundConfigPackets;
#[client_packet(ClientboundConfigPackets::RegistryData as i32)]
#[client_packet("configuration:registry_data")]
pub struct CRegistryData<'a> {
registry_id: &'a str,
entries: &'a [RegistryEntry<'a>],

View File

@ -13,26 +13,3 @@ pub use c_finish_config::*;
pub use c_known_packs::*;
pub use c_plugin_message::*;
pub use c_registry_data::*;
/// DO NOT CHANGE ORDER
/// This Enum has the exact order like vanilla, Vanilla parses their Packet IDs from the enum order. Its also way easier to port.
#[repr(i32)]
pub enum ClientboundConfigPackets {
CookieRequest,
PluginMessage,
Disconnect,
Finish,
KeepAlive,
Ping,
ResetChat,
RegistryData,
RemoveResourcePack,
AddResourcePack,
StoreCookie,
Transfer,
FeatureFlags,
UpdateTags,
KnownPacks,
CustomReportDetails,
ServerLinks,
}

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundLoginPackets;
#[derive(Serialize)]
#[client_packet(ClientboundLoginPackets::EncryptionRequest as i32)]
#[client_packet("login:hello")]
pub struct CEncryptionRequest<'a> {
server_id: &'a str, // 20
public_key_length: VarInt,

View File

@ -1,10 +1,8 @@
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundLoginPackets;
#[derive(Serialize)]
#[client_packet(ClientboundLoginPackets::Disconnect as i32)]
#[client_packet("login:login_disconnect")]
pub struct CLoginDisconnect<'a> {
json_reason: &'a str,
}

View File

@ -2,9 +2,7 @@ use pumpkin_macros::client_packet;
use crate::{bytebuf::ByteBuffer, ClientPacket, Property};
use super::ClientboundLoginPackets;
#[client_packet(ClientboundLoginPackets::LoginSuccess as i32)]
#[client_packet("login:login_finished")]
pub struct CLoginSuccess<'a> {
pub uuid: &'a uuid::Uuid,
pub username: &'a str, // 16

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundLoginPackets;
#[derive(Serialize)]
#[client_packet(ClientboundLoginPackets::LoginPluginRequest as i32)]
#[client_packet("login:custom_query")]
pub struct CLoginPluginRequest<'a> {
message_id: VarInt,
channel: &'a str,

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundLoginPackets;
#[derive(Serialize)]
#[client_packet(ClientboundLoginPackets::SetCompression as i32)]
#[client_packet("login:login_compression")]
pub struct CSetCompression {
threshold: VarInt,
}

View File

@ -9,15 +9,3 @@ pub use c_login_disconnect::*;
pub use c_login_success::*;
pub use c_plugin_request::*;
pub use c_set_compression::*;
/// DO NOT CHANGE ORDER
/// This Enum has the exact order like vanilla, Vanilla parses their Packet IDs from the enum order. Its also way easier to port.
#[repr(i32)]
pub enum ClientboundLoginPackets {
Disconnect,
EncryptionRequest,
LoginSuccess,
SetCompression,
LoginPluginRequest,
CookieRequest,
}

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::AcknowledgeBlockChanges as i32)]
#[client_packet("play:block_changed_ack")]
pub struct CAcknowledgeBlockChange {
sequence_id: VarInt,
}

View File

@ -3,10 +3,8 @@ use pumpkin_core::text::TextComponent;
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::ActionBar as i32)]
#[client_packet("play:set_action_bar_text")]
pub struct CActionBar<'a> {
action_bar: TextComponent<'a>,
}

View File

@ -5,10 +5,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::BlockBreakAnimation as i32)]
#[client_packet("play:block_destruction")]
pub struct CSetBlockDestroyStage {
entity_id: VarInt,
location: WorldPosition,

View File

@ -5,10 +5,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::BlockChange as i32)]
#[client_packet("play:block_update")]
pub struct CBlockUpdate<'a> {
location: &'a WorldPosition,
block_id: VarInt,

View File

@ -2,10 +2,8 @@ use pumpkin_macros::client_packet;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(serde::Serialize)]
#[client_packet(ClientboundPlayPackets::UpdateViewPosition as i32)]
#[client_packet("play:set_chunk_cache_center")]
pub struct CCenterChunk {
pub chunk_x: VarInt,
pub chunk_z: VarInt,

View File

@ -1,10 +1,8 @@
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::ServerDifficulty as i32)]
#[client_packet("play:change_difficulty")]
pub struct CChangeDifficulty {
difficulty: u8,
locked: bool,

View File

@ -6,9 +6,7 @@ use itertools::Itertools;
use pumpkin_macros::client_packet;
use pumpkin_world::{chunk::ChunkData, DIRECT_PALETTE_BITS};
use super::ClientboundPlayPackets;
#[client_packet(ClientboundPlayPackets::ChunkData as i32)]
#[client_packet("play:level_chunk_with_light")]
pub struct CChunkData<'a>(pub &'a ChunkData);
impl<'a> ClientPacket for CChunkData<'a> {

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::CloseWindow as i32)]
#[client_packet("play:container_close")]
pub struct CCloseContainer {
window_id: VarInt,
}

View File

@ -5,10 +5,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::DisguisedChat as i32)]
#[client_packet("play:disguised_chat")]
pub struct CDisguisedChatMessage<'a> {
message: TextComponent<'a>,
chat_type: VarInt,

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::DisplayScoreboard as i32)]
#[client_packet("play:set_display_objective")]
pub struct CDisplayObjective<'a> {
position: VarInt,
score_name: &'a str,

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::EntityAnimation as i32)]
#[client_packet("play:animate")]
pub struct CEntityAnimation {
entity_id: VarInt,
/// See `Animation`

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::EntityMetadata as i32)]
#[client_packet("play:set_entity_data")]
pub struct CSetEntityMetadata<T> {
entity_id: VarInt,
metadata: Metadata<T>,

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::{SoundCategory, VarInt};
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::EntitySoundEffect as i32)]
#[client_packet("play:sound_entity")]
pub struct CEntitySoundEffect {
sound_id: VarInt,
// TODO: add sound from name

View File

@ -1,10 +1,8 @@
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::EntityStatus as i32)]
#[client_packet("play:entity_event")]
pub struct CEntityStatus {
entity_id: i32,
entity_status: i8,

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::EntityVelocity as i32)]
#[client_packet("play:set_entity_motion")]
pub struct CEntityVelocity<'a> {
entity_id: &'a VarInt,
velocity_x: i16,

View File

@ -1,10 +1,8 @@
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::ChangeGameState as i32)]
#[client_packet("play:game_event")]
pub struct CGameEvent {
event: u8,
value: f32,

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::EntityHeadLook as i32)]
#[client_packet("play:rotate_head")]
pub struct CHeadRot {
entity_id: VarInt,
head_yaw: u8,

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::HurtAnimation as i32)]
#[client_packet("play:hurt_animation")]
pub struct CHurtAnimation<'a> {
entity_id: &'a VarInt,
yaw: f32,

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::{VarInt, VarLong};
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::InitializeWorldBorder as i32)]
#[client_packet("play:initialize_border")]
pub struct CInitializeWorldBorder {
x: f64,
z: f64,

View File

@ -1,10 +1,8 @@
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::KeepAlive as i32)]
#[client_packet("play:keep_alive")]
pub struct CKeepAlive {
keep_alive_id: i64,
}

View File

@ -5,10 +5,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::JoinGame as i32)]
#[client_packet("play:login")]
pub struct CLogin<'a> {
entity_id: i32,
is_hardcore: bool,

View File

@ -5,10 +5,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::OpenWindow as i32)]
#[client_packet("play:open_screen")]
pub struct COpenScreen<'a> {
window_id: VarInt,
window_type: VarInt,

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::Particle as i32)]
#[client_packet("play:level_particles")]
pub struct CParticle<'a> {
/// If true, particle distance increases from 256 to 65536.
long_distance: bool,

View File

@ -1,10 +1,8 @@
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::Ping as i32)]
#[client_packet("play:pong_response")]
pub struct CPingResponse {
payload: i64,
}

View File

@ -3,10 +3,8 @@ use pumpkin_core::text::TextComponent;
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::Disconnect as i32)]
#[client_packet("play:disconnect")]
pub struct CPlayDisconnect<'a> {
reason: &'a TextComponent<'a>,
}

View File

@ -1,10 +1,8 @@
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::PlayerAbilities as i32)]
#[client_packet("play:player_abilities")]
pub struct CPlayerAbilities {
flags: i8,
flying_speed: f32,

View File

@ -5,9 +5,8 @@ use serde::Serialize;
use crate::{BitSet, VarInt};
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::ChatMessage as i32)]
#[client_packet("play:player_chat")]
pub struct CPlayerChatMessage<'a> {
#[serde(with = "uuid::serde::compact")]
sender: uuid::Uuid,

View File

@ -2,9 +2,9 @@ use pumpkin_macros::client_packet;
use crate::{bytebuf::ByteBuffer, ClientPacket, Property};
use super::{ClientboundPlayPackets, PlayerAction};
use super::PlayerAction;
#[client_packet(ClientboundPlayPackets::PlayerInfoUpdate as i32)]
#[client_packet("play:player_info_update")]
pub struct CPlayerInfoUpdate<'a> {
pub actions: i8,
pub players: &'a [Player<'a>],

View File

@ -3,10 +3,8 @@ use serde::{ser::SerializeSeq, Serialize};
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::PlayerInfoRemove as i32)]
#[client_packet("play:player_info_remove")]
pub struct CRemovePlayerInfo<'a> {
players_count: VarInt,
#[serde(serialize_with = "serialize_slice_uuids")]

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::DestroyEntities as i32)]
#[client_packet("play:remove_entities")]
pub struct CRemoveEntities<'a> {
count: VarInt,
entity_ids: &'a [VarInt],

View File

@ -1,10 +1,8 @@
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::ResetScore as i32)]
#[client_packet("play:reset_score")]
pub struct CResetScore {
entity_name: String,
objective_name: Option<String>,

View File

@ -1,10 +1,8 @@
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::WorldBorderCenter as i32)]
#[client_packet("play:set_border_center")]
pub struct CSetBorderCenter {
x: f64,
z: f64,

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarLong;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::WorldBorderLerpSize as i32)]
#[client_packet("play:set_border_lerp_size")]
pub struct CSetBorderLerpSize {
old_diameter: f64,
new_diameter: f64,

View File

@ -1,10 +1,8 @@
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::WorldBorderSize as i32)]
#[client_packet("play:set_border_size")]
pub struct CSetBorderSize {
diameter: f64,
}

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::WorldBorderWarningDelay as i32)]
#[client_packet("play:set_border_warning_delay")]
pub struct CSetBorderWarningDelay {
warning_time: VarInt,
}

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::WorldBorderWarningReach as i32)]
#[client_packet("play:set_border_warning_distance")]
pub struct CSetBorderWarningDistance {
warning_blocks: VarInt,
}

View File

@ -4,10 +4,8 @@ use crate::VarInt;
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::WindowItems as i32)]
#[client_packet("play:container_set_content")]
pub struct CSetContainerContent<'a> {
window_id: VarInt,
state_id: VarInt,

View File

@ -3,9 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::WindowProperty as i32)]
#[client_packet("play:container_set_data")]
pub struct CSetContainerProperty {
window_id: VarInt,
property: i16,

View File

@ -4,9 +4,8 @@ use crate::VarInt;
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::SetSlot as i32)]
#[client_packet("play:container_set_slot")]
pub struct CSetContainerSlot<'a> {
window_id: i8,
state_id: VarInt,

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::UpdateHealth as i32)]
#[client_packet("play:set_health")]
pub struct CSetHealth {
health: f32,
food: VarInt,

View File

@ -1,10 +1,8 @@
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::HeldItemChange as i32)]
#[client_packet("play:set_held_slot")]
pub struct CSetHeldItem {
slot: i8,
}

View File

@ -3,10 +3,8 @@ use pumpkin_core::text::TextComponent;
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::SetTitleText as i32)]
#[client_packet("play:set_title_text")]
pub struct CTitleText<'a> {
title: TextComponent<'a>,
}

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::{SoundCategory, VarInt};
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::SoundEffect as i32)]
#[client_packet("play:sound")]
pub struct CSoundEffect {
sound_id: VarInt,
// TODO: add sound from name

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::SpawnEntity as i32)]
#[client_packet("play:add_entity")]
pub struct CSpawnEntity {
entity_id: VarInt,
#[serde(with = "uuid::serde::compact")]

View File

@ -3,10 +3,8 @@ use pumpkin_core::text::TextComponent;
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::SetTitleSubtitle as i32)]
#[client_packet("play:set_subtitle_text")]
pub struct CSubtitle<'a> {
subtitle: TextComponent<'a>,
}

View File

@ -3,9 +3,7 @@ use pumpkin_macros::client_packet;
use crate::{ClientPacket, PositionFlag, VarInt};
use super::ClientboundPlayPackets;
#[client_packet(ClientboundPlayPackets::PlayerPositionAndLook as i32)]
#[client_packet("play:player_position")]
pub struct CSyncPlayerPosition<'a> {
teleport_id: VarInt,
x: f64,

View File

@ -3,10 +3,8 @@ use pumpkin_core::text::TextComponent;
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::SystemChatMessage as i32)]
#[client_packet("play:system_chat")]
pub struct CSystemChatMessage<'a> {
content: &'a TextComponent<'a>,
overlay: bool,

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::EntityTeleport as i32)]
#[client_packet("play:teleport_entity")]
pub struct CTeleportEntitiy {
entity_id: VarInt,
x: f64,

View File

@ -1,10 +1,8 @@
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::UnloadChunk as i32)]
#[client_packet("play:forget_level_chunk")]
pub struct CUnloadChunk {
z: i32,
x: i32,

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::EntityRelativeMove as i32)]
#[client_packet("play:move_entity_pos")]
pub struct CUpdateEntityPos {
entity_id: VarInt,
delta_x: i16,

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::EntityRelativeMoveAndRotation as i32)]
#[client_packet("play:move_entity_pos_rot")]
pub struct CUpdateEntityPosRot {
entity_id: VarInt,
delta_x: i16,

View File

@ -3,10 +3,8 @@ use serde::Serialize;
use crate::VarInt;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::EntityRotation as i32)]
#[client_packet("play:move_entity_rot")]
pub struct CUpdateEntityRot {
entity_id: VarInt,
yaw: u8,

View File

@ -3,9 +3,7 @@ use pumpkin_macros::client_packet;
use crate::{ClientPacket, NumberFormat, VarInt};
use super::ClientboundPlayPackets;
#[client_packet(ClientboundPlayPackets::ScoreboardObjective as i32)]
#[client_packet("play:set_objective")]
pub struct CUpdateObjectives<'a> {
objective_name: &'a str,
mode: u8,

View File

@ -5,10 +5,8 @@ use serde::Serialize;
use crate::{NumberFormat, VarInt};
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::UpdateScore as i32)]
#[client_packet("play:set_score")]
pub struct CUpdateScore<'a> {
entity_name: &'a str,
objective_name: &'a str,

View File

@ -3,10 +3,8 @@ use pumpkin_core::math::position::WorldPosition;
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundPlayPackets;
#[derive(Serialize)]
#[client_packet(ClientboundPlayPackets::Effect as i32)]
#[client_packet("play:level_event")]
pub struct CWorldEvent<'a> {
event: i32,
location: &'a WorldPosition,

View File

@ -111,142 +111,3 @@ pub use c_update_objectives::*;
pub use c_update_score::*;
pub use c_worldevent::*;
pub use player_action::*;
/// DO NOT CHANGE ORDER
/// This Enum has the exact order like vanilla, Vanilla parses their Packet IDs from the enum order. Its also way easier to port.
#[repr(i32)]
pub enum ClientboundPlayPackets {
Bundle,
SpawnEntity,
SpawnExperienceOrb,
EntityAnimation,
Statistics,
AcknowledgeBlockChanges,
BlockBreakAnimation,
BlockEntityData,
BlockAction,
BlockChange,
BossBar,
ServerDifficulty,
ChunkBatchEnd,
ChunkBatchBegin,
ChunkBiomes,
ClearTitles,
TabComplete,
DeclareCommands,
CloseWindow,
WindowItems,
WindowProperty,
SetSlot,
CookieRequest,
SetCooldown,
CustomChatCompletions,
PluginMessage,
DamageEvent,
DebugSample,
DeleteChat,
Disconnect,
DisguisedChat,
EntityStatus,
EntityPositionSync,
Explosion,
UnloadChunk,
ChangeGameState,
OpenHorseWindow,
HurtAnimation,
InitializeWorldBorder,
KeepAlive,
ChunkData,
Effect,
Particle,
UpdateLight,
JoinGame,
MapData,
MerchantOffers,
EntityRelativeMove,
EntityRelativeMoveAndRotation,
MoveMinecart,
EntityRotation,
VehicleMove,
OpenBook,
OpenWindow,
OpenSignEditor,
Ping,
DebugPong,
CraftRecipeResponse,
PlayerAbilities,
ChatMessage,
EndCombatEvent,
EnterCombatEvent,
DeathCombatEvent,
PlayerInfoRemove,
PlayerInfoUpdate,
FacePlayer,
PlayerPositionAndLook,
PlayerRotation,
RecipeBookAdd,
RecipeBookRemove,
RecipeBookSettings,
DestroyEntities,
RemoveEntityEffect,
ResetScore,
ResourcePackRemove,
ResourcePackSend,
Respawn,
EntityHeadLook,
MultiBlockChange,
SelectAdvancementsTab,
ServerData,
ActionBar,
WorldBorderCenter,
WorldBorderLerpSize,
WorldBorderSize,
WorldBorderWarningDelay,
WorldBorderWarningReach,
Camera,
UpdateViewPosition,
UpdateViewDistance,
SetCursorItem,
SpawnPosition,
DisplayScoreboard,
EntityMetadata,
AttachEntity,
EntityVelocity,
EntityEquipment,
SetExperience,
UpdateHealth,
HeldItemChange,
ScoreboardObjective,
SetPassengers,
SetPlayerInventory,
Teams,
UpdateScore,
UpdateSimulationDistance,
SetTitleSubtitle,
TimeUpdate,
SetTitleText,
SetTitleTimes,
EntitySoundEffect,
SoundEffect,
ConfigurationStart,
StopSound,
StoreCookie,
SystemChatMessage,
PlayerListHeaderAndFooter,
NBTQueryResponse,
CollectItem,
EntityTeleport,
TickingState,
TickingStep,
Transfer,
UpdateAdvancements,
UpdateAttributes,
EntityEffect,
DeclareRecipes,
Tags,
ProjectilePower,
CustomReportDetails,
ServerLinks,
}

View File

@ -1,10 +1,8 @@
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundStatusPackets;
#[derive(Serialize)]
#[client_packet(ClientboundStatusPackets::PingRequest as i32)]
#[client_packet("status:pong_response")]
pub struct CPingResponse {
payload: i64, // must responde with the same as in `SPingRequest`
}

View File

@ -1,10 +1,8 @@
use pumpkin_macros::client_packet;
use serde::Serialize;
use super::ClientboundStatusPackets;
#[derive(Serialize)]
#[client_packet(ClientboundStatusPackets::StatusResponse as i32)]
#[client_packet("status:status_response")]
pub struct CStatusResponse<'a> {
json_response: &'a str, // 32767
}

View File

@ -3,11 +3,3 @@ mod c_status_response;
pub use c_ping_response::*;
pub use c_status_response::*;
/// DO NOT CHANGE ORDER
/// This Enum has the exact order like vanilla, Vanilla parses their Packet IDs from the enum order. Its also way easier to port.
#[repr(i32)]
pub enum ClientboundStatusPackets {
StatusResponse,
PingRequest,
}

View File

@ -117,7 +117,7 @@ pub(super) async fn spawn_sweep_particle(
0.0,
0.0,
0,
VarInt(particle!("minecraft:sweep_attack") as i32), // sweep
VarInt(i32::from(particle!("minecraft:sweep_attack"))), // sweep
&[],
))
.await;

View File

@ -108,13 +108,13 @@ impl World {
pub async fn play_sound(
&self,
sound_id: u32,
sound_id: u16,
category: SoundCategory,
posistion: &Vector3<f64>,
) {
let seed = thread_rng().gen::<f64>();
self.broadcast_packet_all(&CSoundEffect::new(
sound_id.into(),
VarInt(i32::from(sound_id)),
category,
posistion.x,
posistion.y,