diff options
| author | EightFactorial <murphkev000@gmail.com> | 2022-12-06 18:48:48 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-06 20:48:48 -0600 |
| commit | 9f5e5c092be9167e4d5222fdee4a1d2c419e5052 (patch) | |
| tree | 1d0a8b57434e0afd14b4a02cbbc579a3ad70da61 /azalea-protocol/src/packets/game/clientbound_command_suggestions_packet.rs | |
| parent | e99a822995c80e1f95c5f7a69e0d8c5d131af20f (diff) | |
| download | azalea-drasl-9f5e5c092be9167e4d5222fdee4a1d2c419e5052.tar.xz | |
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 <unconfigured@null.spigotmc.org>
Co-authored-by: mat <github@matdoes.dev>
Diffstat (limited to 'azalea-protocol/src/packets/game/clientbound_command_suggestions_packet.rs')
| -rwxr-xr-x | azalea-protocol/src/packets/game/clientbound_command_suggestions_packet.rs | 48 |
1 files changed, 26 insertions, 22 deletions
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<Component>, } -impl McBufReadable for ClientboundCommandSuggestionsPacket { - fn read_from(_buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { - // 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); } } |
