diff --git a/Cargo.lock b/Cargo.lock index 2475436a4..540f83e59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1235,6 +1235,7 @@ dependencies = [ "fastnbt 2.5.0 (git+https://github.com/owengage/fastnbt.git)", "fastsnbt", "pumpkin-protocol", + "pumpkin-text", "serde", ] diff --git a/pumpkin-protocol/src/client/config/c_plugin_message.rs b/pumpkin-protocol/src/client/config/c_plugin_message.rs index 9eb3d6757..bdb7692b4 100644 --- a/pumpkin-protocol/src/client/config/c_plugin_message.rs +++ b/pumpkin-protocol/src/client/config/c_plugin_message.rs @@ -1,7 +1,9 @@ use pumpkin_macros::packet; +use serde::Serialize; use crate::{bytebuf::ByteBuffer, ClientPacket}; +#[derive(Serialize)] #[packet(0x01)] pub struct CPluginMessage<'a> { channel: &'a str, @@ -13,10 +15,3 @@ impl<'a> CPluginMessage<'a> { Self { channel, data } } } - -impl<'a> ClientPacket for CPluginMessage<'a> { - fn write(&self, bytebuf: &mut ByteBuffer) { - bytebuf.put_string(self.channel); - bytebuf.put_slice(self.data); - } -} diff --git a/pumpkin-protocol/src/client/login/c_encryption_request.rs b/pumpkin-protocol/src/client/login/c_encryption_request.rs index a7f0a7f01..1ce55c020 100644 --- a/pumpkin-protocol/src/client/login/c_encryption_request.rs +++ b/pumpkin-protocol/src/client/login/c_encryption_request.rs @@ -8,24 +8,24 @@ use crate::{RawBytes, VarInt}; pub struct CEncryptionRequest<'a> { server_id: &'a str, // 20 public_key_length: VarInt, - public_key: RawBytes<'a>, + public_key: &'a [u8], verify_token_length: VarInt, - verify_token: RawBytes<'a>, + verify_token: &'a [u8], should_authenticate: bool, } impl<'a> CEncryptionRequest<'a> { pub fn new( server_id: &'a str, - public_key: RawBytes<'a>, - verify_token: RawBytes<'a>, + public_key: &'a [u8], + verify_token: &'a [u8], should_authenticate: bool, ) -> Self { Self { server_id, - public_key_length: public_key.0.len().into(), + public_key_length: public_key.len().into(), public_key, - verify_token_length: verify_token.0.len().into(), + verify_token_length: verify_token.len().into(), verify_token, should_authenticate, } diff --git a/pumpkin-protocol/src/client/play/c_player_chat_message.rs b/pumpkin-protocol/src/client/play/c_player_chat_message.rs index e207575ba..22da96a0c 100644 --- a/pumpkin-protocol/src/client/play/c_player_chat_message.rs +++ b/pumpkin-protocol/src/client/play/c_player_chat_message.rs @@ -3,12 +3,12 @@ use pumpkin_macros::packet; use pumpkin_text::TextComponent; use serde::Serialize; -use crate::{BitSet, VarInt}; +use crate::{uuid::UUID, BitSet, VarInt}; #[derive(Serialize, Clone)] #[packet(0x39)] pub struct CPlayerChatMessage<'a> { - sender: uuid::Uuid, + sender: UUID, index: VarInt, message_signature: Option<&'a [u8]>, message: String, @@ -29,7 +29,7 @@ pub struct CPlayerChatMessage<'a> { impl<'a> CPlayerChatMessage<'a> { #[allow(clippy::too_many_arguments)] pub fn new( - sender: uuid::Uuid, + sender: UUID, index: VarInt, message_signature: Option<&'a [u8]>, message: String, diff --git a/pumpkin-protocol/src/client/play/c_spawn_player.rs b/pumpkin-protocol/src/client/play/c_spawn_player.rs index 1efec8c5a..295860788 100644 --- a/pumpkin-protocol/src/client/play/c_spawn_player.rs +++ b/pumpkin-protocol/src/client/play/c_spawn_player.rs @@ -1,12 +1,13 @@ use pumpkin_macros::packet; +use serde::Serialize; -use crate::{ClientPacket, VarInt}; +use crate::{uuid::UUID, VarInt}; -#[derive(Clone)] +#[derive(Serialize, Clone)] #[packet(0x01)] pub struct CSpawnEntity { entity_id: VarInt, - entity_uuid: uuid::Uuid, + entity_uuid: UUID, typ: VarInt, x: f64, y: f64, @@ -24,7 +25,7 @@ impl CSpawnEntity { #[allow(clippy::too_many_arguments)] pub fn new( entity_id: VarInt, - entity_uuid: uuid::Uuid, + entity_uuid: UUID, typ: VarInt, x: f64, y: f64, @@ -54,21 +55,3 @@ impl CSpawnEntity { } } } - -impl ClientPacket for CSpawnEntity { - fn write(&self, bytebuf: &mut crate::bytebuf::ByteBuffer) { - bytebuf.put_var_int(&self.entity_id); - bytebuf.put_uuid(self.entity_uuid); - bytebuf.put_var_int(&self.typ); - bytebuf.put_f64(self.x); - bytebuf.put_f64(self.y); - bytebuf.put_f64(self.z); - bytebuf.put_u8(self.pitch); - bytebuf.put_u8(self.yaw); - bytebuf.put_u8(self.head_yaw); - bytebuf.put_var_int(&self.data); - bytebuf.put_i16(self.velocity_x); - bytebuf.put_i16(self.velocity_y); - bytebuf.put_i16(self.velocity_z); - } -} diff --git a/pumpkin-protocol/src/lib.rs b/pumpkin-protocol/src/lib.rs index 70af5148f..f64eca8f6 100644 --- a/pumpkin-protocol/src/lib.rs +++ b/pumpkin-protocol/src/lib.rs @@ -91,16 +91,6 @@ impl VarInt { } } -pub struct RawBytes<'a>(pub &'a [u8]); -impl<'a> Serialize for RawBytes<'a> { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - serializer.serialize_bytes(self.0) - } -} - impl From for VarInt { fn from(value: i32) -> Self { VarInt(value) diff --git a/pumpkin-protocol/src/uuid.rs b/pumpkin-protocol/src/uuid.rs index 49691becd..ab70ef83a 100644 --- a/pumpkin-protocol/src/uuid.rs +++ b/pumpkin-protocol/src/uuid.rs @@ -1,5 +1,6 @@ use serde::Serialize; +#[derive(Clone)] pub struct UUID(pub uuid::Uuid); impl Serialize for UUID { diff --git a/pumpkin-registry/Cargo.toml b/pumpkin-registry/Cargo.toml index e557bc927..3087a0ec3 100644 --- a/pumpkin-registry/Cargo.toml +++ b/pumpkin-registry/Cargo.toml @@ -5,6 +5,8 @@ edition.workspace = true [dependencies] pumpkin-protocol = { path = "../pumpkin-protocol"} +pumpkin-text = { path = "../pumpkin-text"} + # nbt fastnbt = { git = "https://github.com/owengage/fastnbt.git" } fastsnbt = "0.2" diff --git a/pumpkin-registry/src/chat_type.rs b/pumpkin-registry/src/chat_type.rs index 0614c2b4b..45f324c26 100644 --- a/pumpkin-registry/src/chat_type.rs +++ b/pumpkin-registry/src/chat_type.rs @@ -1,3 +1,4 @@ +use pumpkin_text::style::Style; use serde::Serialize; #[derive(Debug, Clone, Serialize)] @@ -9,9 +10,8 @@ pub struct ChatType { #[derive(Debug, Clone, Serialize)] pub struct Decoration { translation_key: String, - style: u8, - // TODO - // style: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + style: Option