diff --git a/protocol-generator/src/main.rs b/protocol-generator/src/main.rs index c25e9a0..0b8c375 100644 --- a/protocol-generator/src/main.rs +++ b/protocol-generator/src/main.rs @@ -307,8 +307,8 @@ fn modify_field(packet_name: &str, field: output::Field) -> output::Field { }), ("Success", "uuid") => field.change_type(output::DataType::Uuid { hyphenated: true }), ("Disconnect", "reason") => field.change_type(output::DataType::Chat), - ("ClientBoundChatMessage", "message") => field.change_type(output::DataType::Chat), - ("ClientBoundChatMessage", "position") => field.change_type(output::DataType::RefType { + ("ClientBoundChat", "message") => field.change_type(output::DataType::Chat), + ("ClientBoundChat", "position") => field.change_type(output::DataType::RefType { ref_name: "MessagePosition".to_owned(), }), _ => field, diff --git a/protocol/src/lib.rs b/protocol/src/lib.rs index e7eee2b..fdcbbc2 100644 --- a/protocol/src/lib.rs +++ b/protocol/src/lib.rs @@ -225,6 +225,20 @@ impl DecoderReadExt for R { read_signed_var_int!(i64, read_var_i64, 10); } +impl Encoder for i8 { + fn encode(&self, writer: &mut W) -> Result<(), EncodeError> { + Ok(writer.write_i8(*self)?) + } +} + +impl Decoder for i8 { + type Output = Self; + + fn decode(reader: &mut R) -> Result { + Ok(reader.read_i8()?) + } +} + impl Encoder for u8 { fn encode(&self, writer: &mut W) -> Result<(), EncodeError> { Ok(writer.write_u8(*self)?) @@ -239,6 +253,20 @@ impl Decoder for u8 { } } +impl Encoder for i16 { + fn encode(&self, writer: &mut W) -> Result<(), EncodeError> { + Ok(writer.write_i16::(*self)?) + } +} + +impl Decoder for i16 { + type Output = Self; + + fn decode(reader: &mut R) -> Result { + Ok(reader.read_i16::()?) + } +} + impl Encoder for u16 { fn encode(&self, writer: &mut W) -> Result<(), EncodeError> { Ok(writer.write_u16::(*self)?) @@ -337,6 +365,34 @@ impl Decoder for bool { } } +impl Encoder for f32 { + fn encode(&self, writer: &mut W) -> Result<(), EncodeError> { + Ok(writer.write_f32::(*self)?) + } +} + +impl Decoder for f32 { + type Output = Self; + + fn decode(reader: &mut R) -> Result { + Ok(reader.read_f32::()?) + } +} + +impl Encoder for f64 { + fn encode(&self, writer: &mut W) -> Result<(), EncodeError> { + Ok(writer.write_f64::(*self)?) + } +} + +impl Decoder for f64 { + type Output = Self; + + fn decode(reader: &mut R) -> Result { + Ok(reader.read_f64::()?) + } +} + impl Encoder for Vec { fn encode(&self, writer: &mut W) -> Result<(), EncodeError> { Ok(writer.write_byte_array(self)?) diff --git a/protocol/src/packet/game.rs b/protocol/src/packet/game.rs index 85bf5ee..3441fcb 100644 --- a/protocol/src/packet/game.rs +++ b/protocol/src/packet/game.rs @@ -1,5 +1,7 @@ // This file is automatically generated. // It is not intended for manual editing. +use crate::data::chat::Message; +use crate::data::game::*; use crate::DecodeError; use crate::Decoder; use minecraft_protocol_derive::Packet; @@ -1641,7 +1643,7 @@ impl GameClientBoundPacket { Self::NbtQueryResponse(nbt_query_response) } - pub fn client_bound_chat(message: String, position: i8) -> Self { + pub fn client_bound_chat(message: Message, position: MessagePosition) -> Self { let client_bound_chat = ClientBoundChat { message, position }; Self::ClientBoundChat(client_bound_chat) @@ -2892,8 +2894,8 @@ pub struct NbtQueryResponse { #[derive(Packet, Debug)] pub struct ClientBoundChat { - pub message: String, - pub position: i8, + pub message: Message, + pub position: MessagePosition, } #[derive(Packet, Debug)] diff --git a/protocol/src/packet/login.rs b/protocol/src/packet/login.rs index 0f43adf..bb548cd 100644 --- a/protocol/src/packet/login.rs +++ b/protocol/src/packet/login.rs @@ -1,16 +1,16 @@ // This file is automatically generated. // It is not intended for manual editing. +use crate::data::chat::Message; use crate::DecodeError; use crate::Decoder; -use std::io::Read; use minecraft_protocol_derive::Packet; +use std::io::Read; use uuid::Uuid; -use crate::data::chat::Message; pub enum LoginServerBoundPacket { LoginStart(LoginStart), EncryptionResponse(EncryptionResponse), - LoginPluginResponse(LoginPluginResponse) + LoginPluginResponse(LoginPluginResponse), } impl LoginServerBoundPacket { @@ -18,7 +18,7 @@ impl LoginServerBoundPacket { match self { Self::LoginStart(_) => 0x00, Self::EncryptionResponse(_) => 0x01, - Self::LoginPluginResponse(_) => 0x02 + Self::LoginPluginResponse(_) => 0x02, } } @@ -39,14 +39,12 @@ impl LoginServerBoundPacket { Ok(Self::LoginPluginResponse(login_plugin_response)) } - _ => Err(DecodeError::UnknownPacketType { type_id }) + _ => Err(DecodeError::UnknownPacketType { type_id }), } } pub fn login_start(username: String) -> Self { - let login_start = LoginStart { - username - }; + let login_start = LoginStart { username }; Self::LoginStart(login_start) } @@ -54,17 +52,14 @@ impl LoginServerBoundPacket { pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { let encryption_response = EncryptionResponse { shared_secret, - verify_token + verify_token, }; Self::EncryptionResponse(encryption_response) } pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { - let login_plugin_response = LoginPluginResponse { - message_id, - data - }; + let login_plugin_response = LoginPluginResponse { message_id, data }; Self::LoginPluginResponse(login_plugin_response) } @@ -75,7 +70,7 @@ pub enum LoginClientBoundPacket { EncryptionRequest(EncryptionRequest), Success(Success), Compress(Compress), - LoginPluginRequest(LoginPluginRequest) + LoginPluginRequest(LoginPluginRequest), } impl LoginClientBoundPacket { @@ -85,7 +80,7 @@ impl LoginClientBoundPacket { Self::EncryptionRequest(_) => 0x01, Self::Success(_) => 0x02, Self::Compress(_) => 0x03, - Self::LoginPluginRequest(_) => 0x04 + Self::LoginPluginRequest(_) => 0x04, } } @@ -116,41 +111,38 @@ impl LoginClientBoundPacket { Ok(Self::LoginPluginRequest(login_plugin_request)) } - _ => Err(DecodeError::UnknownPacketType { type_id }) + _ => Err(DecodeError::UnknownPacketType { type_id }), } } pub fn disconnect(reason: Message) -> Self { - let disconnect = Disconnect { - reason - }; + let disconnect = Disconnect { reason }; Self::Disconnect(disconnect) } - pub fn encryption_request(server_id: String, public_key: Vec, verify_token: Vec) -> Self { + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { let encryption_request = EncryptionRequest { server_id, public_key, - verify_token + verify_token, }; Self::EncryptionRequest(encryption_request) } pub fn success(uuid: Uuid, username: String) -> Self { - let success = Success { - uuid, - username - }; + let success = Success { uuid, username }; Self::Success(success) } pub fn compress(threshold: i32) -> Self { - let compress = Compress { - threshold - }; + let compress = Compress { threshold }; Self::Compress(compress) } @@ -159,7 +151,7 @@ impl LoginClientBoundPacket { let login_plugin_request = LoginPluginRequest { message_id, channel, - data + data, }; Self::LoginPluginRequest(login_plugin_request) @@ -168,13 +160,13 @@ impl LoginClientBoundPacket { #[derive(Packet, Debug)] pub struct LoginStart { - pub username: String + pub username: String, } #[derive(Packet, Debug)] pub struct EncryptionResponse { pub shared_secret: Vec, - pub verify_token: Vec + pub verify_token: Vec, } #[derive(Packet, Debug)] @@ -182,33 +174,32 @@ pub struct LoginPluginResponse { #[packet(with = "var_int")] pub message_id: i32, #[packet(with = "rest")] - pub data: Vec + pub data: Vec, } - #[derive(Packet, Debug)] pub struct Disconnect { - pub reason: Message + pub reason: Message, } #[derive(Packet, Debug)] pub struct EncryptionRequest { pub server_id: String, pub public_key: Vec, - pub verify_token: Vec + pub verify_token: Vec, } #[derive(Packet, Debug)] pub struct Success { #[packet(with = "uuid_hyp_str")] pub uuid: Uuid, - pub username: String + pub username: String, } #[derive(Packet, Debug)] pub struct Compress { #[packet(with = "var_int")] - pub threshold: i32 + pub threshold: i32, } #[derive(Packet, Debug)] @@ -217,6 +208,5 @@ pub struct LoginPluginRequest { pub message_id: i32, pub channel: String, #[packet(with = "rest")] - pub data: Vec + pub data: Vec, } -