From 51b142dc6d98ac972d0dd7ea6d035509840f5ac7 Mon Sep 17 00:00:00 2001 From: Commandcracker <49335821+Commandcracker@users.noreply.github.com> Date: Thu, 5 Dec 2024 23:08:42 +0100 Subject: [PATCH] shadow_color (#371) --- pumpkin-core/src/text/README.md | 2 +- pumpkin-core/src/text/color.rs | 28 ++++++++++++++++++++++++++++ pumpkin-core/src/text/mod.rs | 7 +++++++ pumpkin-core/src/text/style.rs | 16 ++++++++++++++-- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/pumpkin-core/src/text/README.md b/pumpkin-core/src/text/README.md index 421edeee8..2a827977e 100644 --- a/pumpkin-core/src/text/README.md +++ b/pumpkin-core/src/text/README.md @@ -27,6 +27,7 @@ Here we build Mojang's Textcomponent, Which is used across many places, Often wh - [x] Strikethrough - [x] Obfuscated - [x] Insertion + - [x] Shadow Color - Click Event - [x] Open URL - [x] Run Command @@ -42,4 +43,3 @@ Here we build Mojang's Textcomponent, Which is used across many places, Often wh - [x] Uniform (Unicode) - [x] Alt - [x] Illageralt - diff --git a/pumpkin-core/src/text/color.rs b/pumpkin-core/src/text/color.rs index 2b7a6b3f0..260a35cfd 100644 --- a/pumpkin-core/src/text/color.rs +++ b/pumpkin-core/src/text/color.rs @@ -101,6 +101,34 @@ impl Serialize for RGBColor { } } +#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq, Deserialize)] +pub struct ARGBColor { + alpha: u8, + red: u8, + green: u8, + blue: u8, +} + +impl ARGBColor { + pub fn new(alpha: u8, red: u8, green: u8, blue: u8) -> Self { + ARGBColor { + alpha, + red, + green, + blue, + } + } +} + +impl Serialize for ARGBColor { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + serializer.serialize_bytes([self.alpha, self.red, self.green, self.blue].as_ref()) + } +} + /// Named Minecraft color #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] diff --git a/pumpkin-core/src/text/mod.rs b/pumpkin-core/src/text/mod.rs index bdab8b531..2284f60f9 100644 --- a/pumpkin-core/src/text/mod.rs +++ b/pumpkin-core/src/text/mod.rs @@ -1,6 +1,7 @@ use core::str; use std::borrow::Cow; +use crate::text::color::ARGBColor; use click::ClickEvent; use color::Color; use colored::Colorize; @@ -174,6 +175,12 @@ impl<'a> TextComponent<'a> { self } + /// Overrides the shadow properties of text. + pub fn shadow_color(mut self, color: ARGBColor) -> Self { + self.style.shadow_color = Some(color); + self + } + pub fn encode(&self) -> Vec { // TODO: Somehow fix this ugly mess #[derive(serde::Serialize)] diff --git a/pumpkin-core/src/text/style.rs b/pumpkin-core/src/text/style.rs index 3a0726f4c..1049e14c6 100644 --- a/pumpkin-core/src/text/style.rs +++ b/pumpkin-core/src/text/style.rs @@ -1,10 +1,10 @@ -use serde::{Deserialize, Serialize}; - use super::{ click::ClickEvent, color::{self, Color}, hover::HoverEvent, }; +use crate::text::color::ARGBColor; +use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq, Eq, Hash)] #[serde(rename_all = "camelCase")] @@ -38,6 +38,12 @@ pub struct Style<'a> { /// Allows you to change the font of the text. #[serde(default, skip_serializing_if = "Option::is_none")] pub font: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "shadow_color" + )] + pub shadow_color: Option, } impl<'a> Style<'a> { @@ -105,4 +111,10 @@ impl<'a> Style<'a> { self.font = Some(identifier); self } + + /// Overrides the shadow properties of text. + pub fn shadow_color(mut self, color: ARGBColor) -> Self { + self.shadow_color = Some(color); + self + } }