diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2023-12-05 10:59:05 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-05 10:59:05 -0600 |
| commit | 7857a014b92e64361ee237ceae7ef1acc185ac46 (patch) | |
| tree | 5d70ea6b41943493873810e6a03c3483ff90a235 /azalea-chat/src/numbers.rs | |
| parent | ea3e8600126a58f5666d50fbf70dff8209d8979f (diff) | |
| download | azalea-drasl-7857a014b92e64361ee237ceae7ef1acc185ac46.tar.xz | |
1.20.3 (#110)
* 23w40a
* 23w41a
* 23w42a
* 23w43a
* 23w44a
* serialize FormattedText as nbt in network
* use azalea-nbt/serde in azalea-chat
* 23w45a
* fix 23w45a to compile
* handle Object in codegen
* 1.20.3-pre2
* remove unused clientbound_resource_pack_packet.rs
* merge main and make azalea-chat use simdnbt
* 1.20.3-rc1
* fix tests
* use simdnbt 0.3
* fix ServerboundSetJigsawBlockPacket
* 1.20.3
Diffstat (limited to 'azalea-chat/src/numbers.rs')
| -rw-r--r-- | azalea-chat/src/numbers.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/azalea-chat/src/numbers.rs b/azalea-chat/src/numbers.rs new file mode 100644 index 00000000..21c30591 --- /dev/null +++ b/azalea-chat/src/numbers.rs @@ -0,0 +1,52 @@ +//! Contains a few ways to style numbers. At the time of writing, Minecraft only +//! uses this for rendering scoreboard objectives. + +use std::io::{Cursor, Write}; + +#[cfg(feature = "azalea-buf")] +use azalea_buf::{McBufReadable, McBufWritable}; +use azalea_registry::NumberFormatKind; +use simdnbt::owned::Nbt; + +use crate::FormattedText; + +#[derive(Clone, Debug)] +pub enum NumberFormat { + Blank, + Styled { style: Nbt }, + Fixed { value: FormattedText }, +} + +#[cfg(feature = "azalea-buf")] +impl McBufReadable for NumberFormat { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> { + let kind = NumberFormatKind::read_from(buf)?; + match kind { + NumberFormatKind::Blank => Ok(NumberFormat::Blank), + NumberFormatKind::Styled => Ok(NumberFormat::Styled { + style: Nbt::read(buf)?, + }), + NumberFormatKind::Fixed => Ok(NumberFormat::Fixed { + value: FormattedText::read_from(buf)?, + }), + } + } +} + +#[cfg(feature = "azalea-buf")] +impl McBufWritable for NumberFormat { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + match self { + NumberFormat::Blank => NumberFormatKind::Blank.write_into(buf)?, + NumberFormat::Styled { style } => { + NumberFormatKind::Styled.write_into(buf)?; + style.write_into(buf)?; + } + NumberFormat::Fixed { value } => { + NumberFormatKind::Fixed.write_into(buf)?; + value.write_into(buf)?; + } + } + Ok(()) + } +} |
