Add Text component

currently very simple, Will be expanded later
This commit is contained in:
Snowiiii 2024-08-04 12:22:59 +02:00
parent 19af3618cb
commit a0d92fe45c
2 changed files with 18 additions and 0 deletions

View File

@ -8,6 +8,7 @@ use thiserror::Error;
pub mod bytebuf; pub mod bytebuf;
pub mod client; pub mod client;
pub mod server; pub mod server;
pub mod text;
pub mod packet_decoder; pub mod packet_decoder;
pub mod packet_encoder; pub mod packet_encoder;

View File

@ -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<u8> {
fastnbt::to_bytes_with_opts(&self, SerOpts::network_nbt()).unwrap()
}
}