Skip to content

Commit

Permalink
Add Fonts in Text Style (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
Commandcracker authored Nov 26, 2024
1 parent 9491aed commit 47964f1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pumpkin-core/src/text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions pumpkin-core/src/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
10 changes: 10 additions & 0 deletions pumpkin-core/src/text/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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
}
}

0 comments on commit 47964f1

Please sign in to comment.