Add Fonts in Text Style (#344)

This commit is contained in:
Commandcracker
2024-11-26 19:54:01 +01:00
committed by GitHub
parent 9491aedfc6
commit 47964f16d4
3 changed files with 20 additions and 3 deletions

View File

@@ -39,8 +39,8 @@ Here we build Mojang's Textcomponent, Which is used across many places, Often wh
- [x] ShowEntity
- Fonts
- [x] Default
- [ ] Uniform (Unicode)
- [ ] Alt
- [ ] Illageralt
- [x] Uniform (Unicode)
- [x] Alt
- [x] Illageralt
Reference: https://wiki.vg/Text_formatting

View File

@@ -158,6 +158,13 @@ impl<'a> TextComponent<'a> {
self
}
/// Allows you to change the font of the text.
/// Default fonts: `minecraft:default`, `minecraft:uniform`, `minecraft:alt`, `minecraft:illageralt`
pub fn font(mut self, identifier: String) -> Self {
self.style.font = Some(identifier);
self
}
pub fn encode(&self) -> Vec<u8> {
// TODO: Somehow fix this ugly mess
#[derive(serde::Serialize)]

View File

@@ -35,6 +35,9 @@ pub struct Style<'a> {
/// Allows for a tooltip to be displayed when the player hovers their mouse over text.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub hover_event: Option<HoverEvent<'a>>,
/// Allows you to change the font of the text.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub font: Option<String>,
}
impl<'a> Style<'a> {
@@ -95,4 +98,11 @@ impl<'a> Style<'a> {
self.hover_event = Some(event);
self
}
/// Allows you to change the font of the text.
/// Default fonts: `minecraft:default`, `minecraft:uniform`, `minecraft:alt`, `minecraft:illageralt`
pub fn font(mut self, identifier: String) -> Self {
self.font = Some(identifier);
self
}
}