From 9f5e5c092be9167e4d5222fdee4a1d2c419e5052 Mon Sep 17 00:00:00 2001 From: EightFactorial Date: Tue, 6 Dec 2022 18:48:48 -0800 Subject: Complete ClientboundCommand{Suggestion}sPacket, Serde support for NBT Tags (#49) * Serializing ClientboundStatusResponsePacket Enable serialization of ClientboundStatusResponsePacket * Update clientbound_status_response_packet.rs Add options previewsChat and enforcesSecureChat * Serialize Style and TextColor * Serialize BaseComponent * Serialize TextComponent * Fix Style * Serialize Component * Fix multiple formats per message, fix reset tag * Fix Style, again * Use FlatMapSerializer * Forgot italics * Count struct fields, reorganize logic * Serialize TranslatableComponent * Rewrite TextComponent Serializer * Fix using TextColor::Parse * Code Cleanup * Add default attribute, just in case * Clippy * use serde derive feature + preferred formatting choices * McBufWritable for BrigadierNodeStub * Thanks Clippy... * Implement suggestions in azalea-brigadier * Serde support for NBT Tags * Serde options * Forgot Options * Oops, that's McBufWritable for BrigadierParser * Fix McBufWritable for SlotData * Complete ClientboundUpdateRecipesPacket * fix some issues * better impl McBufReadable for Suggestions Co-authored-by: BuildTools Co-authored-by: mat --- .../game/clientbound_command_suggestions_packet.rs | 48 ++++++++++++---------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'azalea-protocol/src/packets/game/clientbound_command_suggestions_packet.rs') diff --git a/azalea-protocol/src/packets/game/clientbound_command_suggestions_packet.rs b/azalea-protocol/src/packets/game/clientbound_command_suggestions_packet.rs index c6f426a9..652ce78a 100755 --- a/azalea-protocol/src/packets/game/clientbound_command_suggestions_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_command_suggestions_packet.rs @@ -1,32 +1,36 @@ -// use azalea_brigadier::context::StringRange; -use azalea_buf::{ - // BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable, - BufReadError, - McBufReadable, - McBufWritable, -}; +use azalea_brigadier::suggestion::Suggestions; +use azalea_buf::McBuf; +use azalea_chat::Component; use azalea_protocol_macros::ClientboundGamePacket; -use std::io::{Cursor, Write}; -#[derive(Clone, Debug, ClientboundGamePacket)] +#[derive(Clone, Debug, McBuf, ClientboundGamePacket)] pub struct ClientboundCommandSuggestionsPacket { #[var] pub id: u32, - // pub suggestions: Suggestions, + pub suggestions: Suggestions, } -impl McBufReadable for ClientboundCommandSuggestionsPacket { - fn read_from(_buf: &mut Cursor<&[u8]>) -> Result { - // let id = u32::var_read_from(buf)?; - // let start = u32::var_read_from(buf)? as usize; - // let length = u32::var_read_from(buf)? as usize; - // let stringrange = StringRange::between(start, start + length); - todo!("Suggestions aren't implemented in azalea-brigadier yet") - } -} +#[cfg(test)] +mod tests { + use super::*; + use azalea_brigadier::{context::StringRange, suggestion::Suggestion}; + use azalea_buf::{McBufReadable, McBufWritable}; + use std::io::Cursor; -impl McBufWritable for ClientboundCommandSuggestionsPacket { - fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> { - todo!() + #[test] + fn test_suggestions() { + let suggestions = Suggestions { + range: StringRange::new(0, 5), + suggestions: vec![Suggestion { + text: "foo".to_string(), + range: StringRange::new(1, 4), + tooltip: Some(Component::from("bar".to_string())), + }], + }; + let mut buf = Vec::new(); + suggestions.write_into(&mut buf).unwrap(); + let mut cursor = Cursor::new(&buf[..]); + let suggestions = Suggestions::read_from(&mut cursor).unwrap(); + assert_eq!(suggestions, suggestions); } } -- cgit v1.2.3