diff --git a/pumpkin-protocol/src/lib.rs b/pumpkin-protocol/src/lib.rs index c74ccf65a..2cf603f7a 100644 --- a/pumpkin-protocol/src/lib.rs +++ b/pumpkin-protocol/src/lib.rs @@ -8,6 +8,7 @@ use thiserror::Error; pub mod bytebuf; pub mod client; pub mod server; +pub mod text; pub mod packet_decoder; pub mod packet_encoder; diff --git a/pumpkin-protocol/src/text.rs b/pumpkin-protocol/src/text.rs new file mode 100644 index 000000000..bb56d9226 --- /dev/null +++ b/pumpkin-protocol/src/text.rs @@ -0,0 +1,17 @@ +use core::str; + +use fastnbt::SerOpts; +use serde::{Deserialize, Serialize}; + +// represents a text component +// Reference: https://wiki.vg/Text_formatting#Text_components +#[derive(Clone, PartialEq, Default, Debug, Serialize, Deserialize)] +pub struct Text { + pub text: String, +} + +impl Text { + pub fn encode(&self) -> Vec { + fastnbt::to_bytes_with_opts(&self, SerOpts::network_nbt()).unwrap() + } +}