-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,097 additions
and
902 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_nbt::Nbt; | ||
use azalea_registry::NumberFormatKind; | ||
|
||
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_from(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(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::{ | ||
fmt::{self, Display, Formatter}, | ||
str::FromStr, | ||
}; | ||
|
||
use azalea_buf::McBuf; | ||
|
||
#[derive(Clone, Copy, Debug, McBuf)] | ||
pub enum ObjectiveCriteria { | ||
Integer, | ||
Hearts, | ||
} | ||
|
||
impl Display for ObjectiveCriteria { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
match self { | ||
ObjectiveCriteria::Integer => write!(f, "integer"), | ||
ObjectiveCriteria::Hearts => write!(f, "hearts"), | ||
} | ||
} | ||
} | ||
|
||
impl FromStr for ObjectiveCriteria { | ||
type Err = (); | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s { | ||
"integer" => Ok(ObjectiveCriteria::Integer), | ||
"hearts" => Ok(ObjectiveCriteria::Hearts), | ||
_ => Err(()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.