From 49dd72180517e669a15ac5a982514f1db8db29cd Mon Sep 17 00:00:00 2001 From: David Luedtke Date: Fri, 10 Mar 2023 22:43:37 +0100 Subject: [PATCH 1/2] change minimessage rainbow tag colors --- .../minimessage/tag/standard/RainbowTag.java | 25 +- .../tag/standard/RainbowTagTest.java | 326 +++++++++--------- .../tag/standard/ResetTagTest.java | 10 +- 3 files changed, 174 insertions(+), 187 deletions(-) diff --git a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/RainbowTag.java b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/RainbowTag.java index 5183e5589..5fed5de08 100644 --- a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/RainbowTag.java +++ b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/RainbowTag.java @@ -30,7 +30,7 @@ import net.kyori.adventure.text.minimessage.tag.Tag; import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; -import net.kyori.adventure.util.ShadyPines; +import net.kyori.adventure.util.HSVLike; import net.kyori.examination.ExaminableProperty; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -49,10 +49,6 @@ final class RainbowTag extends AbstractColorChangingTag { private final boolean reversed; private final int phase; - private float center = 128; - private float width = 127; - private double frequency = 1; - private int colorIndex = 0; static Tag create(final ArgumentQueue args, final Context ctx) { @@ -84,9 +80,6 @@ private RainbowTag(final boolean reversed, final int phase) { @Override protected void init() { - this.center = 128; - this.width = 127; - this.frequency = Math.PI * 2 / this.size(); if (this.reversed) { this.colorIndex = this.size() - 1; } @@ -107,11 +100,9 @@ protected void advanceColor() { @Override protected TextColor color() { - final int index = this.colorIndex; - final int red = (int) (Math.sin(this.frequency * index + 2 + this.phase) * this.width + this.center); - final int green = (int) (Math.sin(this.frequency * index + 0 + this.phase) * this.width + this.center); - final int blue = (int) (Math.sin(this.frequency * index + 4 + this.phase) * this.width + this.center); - return TextColor.color(red, green, blue); + final float index = this.colorIndex; + final float hue = (index / size() + this.phase / 10f) % 1; + return TextColor.color(HSVLike.hsvLike(hue, 1f, 1f)); } @Override @@ -124,15 +115,11 @@ public boolean equals(final @Nullable Object other) { if (this == other) return true; if (other == null || this.getClass() != other.getClass()) return false; final RainbowTag that = (RainbowTag) other; - return this.colorIndex == that.colorIndex - && ShadyPines.equals(that.center, this.center) - && ShadyPines.equals(that.width, this.width) - && ShadyPines.equals(that.frequency, this.frequency) - && this.phase == that.phase; + return this.colorIndex == that.colorIndex && this.phase == that.phase; } @Override public int hashCode() { - return Objects.hash(this.colorIndex, this.center, this.width, this.frequency, this.phase); + return Objects.hash(this.colorIndex, this.phase); } } diff --git a/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/RainbowTagTest.java b/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/RainbowTagTest.java index 34b3a849b..fce94c976 100644 --- a/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/RainbowTagTest.java +++ b/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/RainbowTagTest.java @@ -59,30 +59,30 @@ void testRainbow() { final Component expected = empty().color(YELLOW) .append(text("Woo: ")) .append(empty() - .append(text("|", color(0xf3801f))) - .append(text("|", color(0xe1a00d))) - .append(text("|", color(0xc9bf03))) - .append(text("|", color(0xacd901))) - .append(text("|", color(0x8bed08))) - .append(text("|", color(0x6afa16))) - .append(text("|", color(0x4bff2c))) - .append(text("|", color(0x2ffa48))) - .append(text("|", color(0x18ed68))) - .append(text("|", color(0x08d989))) - .append(text("|", color(0x01bfa9))) - .append(text("|", color(0x02a0c7))) - .append(text("|", color(0x0c80e0))) - .append(text("|", color(0x1e5ff2))) - .append(text("|", color(0x3640fc))) - .append(text("|", color(0x5326fe))) - .append(text("|", color(0x7412f7))) - .append(text("|", color(0x9505e9))) - .append(text("|", color(0xb401d3))) - .append(text("|", color(0xd005b7))) - .append(text("|", color(0xe71297))) - .append(text("|", color(0xf72676))) - .append(text("|", color(0xfe4056))) - .append(text("|", color(0xfd5f38))) + .append(text("|", color(0xff0000))) + .append(text("|", color(0xff3f00))) + .append(text("|", color(0xff7f00))) + .append(text("|", color(0xffbf00))) + .append(text("|", color(0xffff00))) + .append(text("|", color(0xbfff00))) + .append(text("|", color(0x7fff00))) + .append(text("|", color(0x3fff00))) + .append(text("|", color(0x00ff00))) + .append(text("|", color(0x00ff3f))) + .append(text("|", color(0x00ff7f))) + .append(text("|", color(0x00ffbf))) + .append(text("|", color(0x00ffff))) + .append(text("|", color(0x00bfff))) + .append(text("|", color(0x007fff))) + .append(text("|", color(0x003fff))) + .append(text("|", color(0x0000ff))) + .append(text("|", color(0x3f00ff))) + .append(text("|", color(0x7f00ff))) + .append(text("|", color(0xbf00ff))) + .append(text("|", color(0xff00ff))) + .append(text("|", color(0xff00bf))) + .append(text("|", color(0xff007f))) + .append(text("|", color(0xff003f))) ) .append(text("!")); @@ -95,30 +95,30 @@ void testRainbowBackwards() { final Component expected = empty().color(YELLOW) .append(text("Woo: ")) .append(empty() - .append(text("|", color(0xfd5f38))) - .append(text("|", color(0xfe4056))) - .append(text("|", color(0xf72676))) - .append(text("|", color(0xe71297))) - .append(text("|", color(0xd005b7))) - .append(text("|", color(0xb401d3))) - .append(text("|", color(0x9505e9))) - .append(text("|", color(0x7412f7))) - .append(text("|", color(0x5326fe))) - .append(text("|", color(0x3640fc))) - .append(text("|", color(0x1e5ff2))) - .append(text("|", color(0x0c80e0))) - .append(text("|", color(0x02a0c7))) - .append(text("|", color(0x01bfa9))) - .append(text("|", color(0x08d989))) - .append(text("|", color(0x18ed68))) - .append(text("|", color(0x2ffa48))) - .append(text("|", color(0x4bff2c))) - .append(text("|", color(0x6afa16))) - .append(text("|", color(0x8bed08))) - .append(text("|", color(0xacd901))) - .append(text("|", color(0xc9bf03))) - .append(text("|", color(0xe1a00d))) - .append(text("|", color(0xf3801f))) + .append(text("|", color(0xff003f))) + .append(text("|", color(0xff007f))) + .append(text("|", color(0xff00bf))) + .append(text("|", color(0xff00ff))) + .append(text("|", color(0xbf00ff))) + .append(text("|", color(0x7f00ff))) + .append(text("|", color(0x3f00ff))) + .append(text("|", color(0x0000ff))) + .append(text("|", color(0x003fff))) + .append(text("|", color(0x007fff))) + .append(text("|", color(0x00bfff))) + .append(text("|", color(0x00ffff))) + .append(text("|", color(0x00ffbf))) + .append(text("|", color(0x00ff7f))) + .append(text("|", color(0x00ff3f))) + .append(text("|", color(0x00ff00))) + .append(text("|", color(0x3fff00))) + .append(text("|", color(0x7fff00))) + .append(text("|", color(0xbfff00))) + .append(text("|", color(0xffff00))) + .append(text("|", color(0xffbf00))) + .append(text("|", color(0xff7f00))) + .append(text("|", color(0xff3f00))) + .append(text("|", color(0xff0000))) ) .append(text("!")); @@ -131,30 +131,30 @@ void testRainbowPhase() { final Component expected = empty().color(YELLOW) .append(text("Woo: ")) .append(empty() - .append(text("|", color(0x1ff35c))) - .append(text("|", color(0x0de17d))) - .append(text("|", color(0x03c99e))) - .append(text("|", color(0x01acbd))) - .append(text("|", color(0x088bd7))) - .append(text("|", color(0x166aec))) - .append(text("|", color(0x2c4bf9))) - .append(text("|", color(0x482ffe))) - .append(text("|", color(0x6818fb))) - .append(text("|", color(0x8908ef))) - .append(text("|", color(0xa901db))) - .append(text("|", color(0xc702c1))) - .append(text("|", color(0xe00ca3))) - .append(text("|", color(0xf21e82))) - .append(text("|", color(0xfc3661))) - .append(text("|", color(0xfe5342))) - .append(text("|", color(0xf77428))) - .append(text("|", color(0xe99513))) - .append(text("|", color(0xd3b406))) - .append(text("|", color(0xb7d001))) - .append(text("|", color(0x97e704))) - .append(text("|", color(0x76f710))) - .append(text("|", color(0x56fe24))) - .append(text("|", color(0x38fd3e))) + .append(text("|", color(0xcbff00))) + .append(text("|", color(0x8cff00))) + .append(text("|", color(0x4cff00))) + .append(text("|", color(0x0cff00))) + .append(text("|", color(0x00ff33))) + .append(text("|", color(0x00ff72))) + .append(text("|", color(0x00ffb2))) + .append(text("|", color(0x00fff2))) + .append(text("|", color(0x00cbff))) + .append(text("|", color(0x008cff))) + .append(text("|", color(0x004cff))) + .append(text("|", color(0x000cff))) + .append(text("|", color(0x3200ff))) + .append(text("|", color(0x7200ff))) + .append(text("|", color(0xb200ff))) + .append(text("|", color(0xf200ff))) + .append(text("|", color(0xff00cc))) + .append(text("|", color(0xff008c))) + .append(text("|", color(0xff004c))) + .append(text("|", color(0xff000c))) + .append(text("|", color(0xff3200))) + .append(text("|", color(0xff7200))) + .append(text("|", color(0xffb200))) + .append(text("|", color(0xfff200))) ) .append(text("!")); @@ -167,30 +167,30 @@ void testRainbowPhaseBackwards() { final Component expected = empty().color(YELLOW) .append(text("Woo: ")) .append(empty() - .append(text("|", color(0x38fd3e))) - .append(text("|", color(0x56fe24))) - .append(text("|", color(0x76f710))) - .append(text("|", color(0x97e704))) - .append(text("|", color(0xb7d001))) - .append(text("|", color(0xd3b406))) - .append(text("|", color(0xe99513))) - .append(text("|", color(0xf77428))) - .append(text("|", color(0xfe5342))) - .append(text("|", color(0xfc3661))) - .append(text("|", color(0xf21e82))) - .append(text("|", color(0xe00ca3))) - .append(text("|", color(0xc702c1))) - .append(text("|", color(0xa901db))) - .append(text("|", color(0x8908ef))) - .append(text("|", color(0x6818fb))) - .append(text("|", color(0x482ffe))) - .append(text("|", color(0x2c4bf9))) - .append(text("|", color(0x166aec))) - .append(text("|", color(0x088bd7))) - .append(text("|", color(0x01acbd))) - .append(text("|", color(0x03c99e))) - .append(text("|", color(0x0de17d))) - .append(text("|", color(0x1ff35c))) + .append(text("|", color(0xfff200))) + .append(text("|", color(0xffb200))) + .append(text("|", color(0xff7200))) + .append(text("|", color(0xff3200))) + .append(text("|", color(0xff000c))) + .append(text("|", color(0xff004c))) + .append(text("|", color(0xff008c))) + .append(text("|", color(0xff00cc))) + .append(text("|", color(0xf200ff))) + .append(text("|", color(0xb200ff))) + .append(text("|", color(0x7200ff))) + .append(text("|", color(0x3200ff))) + .append(text("|", color(0x000cff))) + .append(text("|", color(0x004cff))) + .append(text("|", color(0x008cff))) + .append(text("|", color(0x00cbff))) + .append(text("|", color(0x00fff2))) + .append(text("|", color(0x00ffb2))) + .append(text("|", color(0x00ff72))) + .append(text("|", color(0x00ff33))) + .append(text("|", color(0x0cff00))) + .append(text("|", color(0x4cff00))) + .append(text("|", color(0x8cff00))) + .append(text("|", color(0xcbff00))) ) .append(text("!")); @@ -204,30 +204,30 @@ void testRainbowWithInsertion() { .append(text("Woo: ")) .append(empty().insertion("test") .append(empty() - .append(text("|", color(0xf3801f))) - .append(text("|", color(0xe1a00d))) - .append(text("|", color(0xc9bf03))) - .append(text("|", color(0xacd901))) - .append(text("|", color(0x8bed08))) - .append(text("|", color(0x6afa16))) - .append(text("|", color(0x4bff2c))) - .append(text("|", color(0x2ffa48))) - .append(text("|", color(0x18ed68))) - .append(text("|", color(0x08d989))) - .append(text("|", color(0x01bfa9))) - .append(text("|", color(0x02a0c7))) - .append(text("|", color(0x0c80e0))) - .append(text("|", color(0x1e5ff2))) - .append(text("|", color(0x3640fc))) - .append(text("|", color(0x5326fe))) - .append(text("|", color(0x7412f7))) - .append(text("|", color(0x9505e9))) - .append(text("|", color(0xb401d3))) - .append(text("|", color(0xd005b7))) - .append(text("|", color(0xe71297))) - .append(text("|", color(0xf72676))) - .append(text("|", color(0xfe4056))) - .append(text("|", color(0xfd5f38))) + .append(text("|", color(0xff0000))) + .append(text("|", color(0xff3f00))) + .append(text("|", color(0xff7f00))) + .append(text("|", color(0xffbf00))) + .append(text("|", color(0xffff00))) + .append(text("|", color(0xbfff00))) + .append(text("|", color(0x7fff00))) + .append(text("|", color(0x3fff00))) + .append(text("|", color(0x00ff00))) + .append(text("|", color(0x00ff3f))) + .append(text("|", color(0x00ff7f))) + .append(text("|", color(0x00ffbf))) + .append(text("|", color(0x00ffff))) + .append(text("|", color(0x00bfff))) + .append(text("|", color(0x007fff))) + .append(text("|", color(0x003fff))) + .append(text("|", color(0x0000ff))) + .append(text("|", color(0x3f00ff))) + .append(text("|", color(0x7f00ff))) + .append(text("|", color(0xbf00ff))) + .append(text("|", color(0xff00ff))) + .append(text("|", color(0xff00bf))) + .append(text("|", color(0xff007f))) + .append(text("|", color(0xff003f))) ).append(text("!")) ); @@ -241,30 +241,30 @@ void testRainbowBackwardsWithInsertion() { .append(text("Woo: ")) .append(empty().insertion("test") .append(empty() - .append(text("|", color(0xfd5f38))) - .append(text("|", color(0xfe4056))) - .append(text("|", color(0xf72676))) - .append(text("|", color(0xe71297))) - .append(text("|", color(0xd005b7))) - .append(text("|", color(0xb401d3))) - .append(text("|", color(0x9505e9))) - .append(text("|", color(0x7412f7))) - .append(text("|", color(0x5326fe))) - .append(text("|", color(0x3640fc))) - .append(text("|", color(0x1e5ff2))) - .append(text("|", color(0x0c80e0))) - .append(text("|", color(0x02a0c7))) - .append(text("|", color(0x01bfa9))) - .append(text("|", color(0x08d989))) - .append(text("|", color(0x18ed68))) - .append(text("|", color(0x2ffa48))) - .append(text("|", color(0x4bff2c))) - .append(text("|", color(0x6afa16))) - .append(text("|", color(0x8bed08))) - .append(text("|", color(0xacd901))) - .append(text("|", color(0xc9bf03))) - .append(text("|", color(0xe1a00d))) - .append(text("|", color(0xf3801f))) + .append(text("|", color(0xff003f))) + .append(text("|", color(0xff007f))) + .append(text("|", color(0xff00bf))) + .append(text("|", color(0xff00ff))) + .append(text("|", color(0xbf00ff))) + .append(text("|", color(0x7f00ff))) + .append(text("|", color(0x3f00ff))) + .append(text("|", color(0x0000ff))) + .append(text("|", color(0x003fff))) + .append(text("|", color(0x007fff))) + .append(text("|", color(0x00bfff))) + .append(text("|", color(0x00ffff))) + .append(text("|", color(0x00ffbf))) + .append(text("|", color(0x00ff7f))) + .append(text("|", color(0x00ff3f))) + .append(text("|", color(0x00ff00))) + .append(text("|", color(0x3fff00))) + .append(text("|", color(0x7fff00))) + .append(text("|", color(0xbfff00))) + .append(text("|", color(0xffff00))) + .append(text("|", color(0xffbf00))) + .append(text("|", color(0xff7f00))) + .append(text("|", color(0xff3f00))) + .append(text("|", color(0xff0000))) ).append(text("!")) ); @@ -276,8 +276,8 @@ void testRainbowWithInnerClick() { final String input = "Rainbow: GH"; final Component expected = text("Rainbow: ") .append(empty().clickEvent(openUrl("https://github.com")) - .append(text("G").color(color(0xf3801f))) - .append(text("H").color(color(0x0c80e0))) + .append(text("G").color(color(0xff0000))) + .append(text("H").color(color(0x00ffff))) ); this.assertParsedEquals(expected, input); @@ -288,8 +288,8 @@ void testRainbowBackwardsWithInnerClick() { final String input = "Rainbow: GH"; final Component expected = text("Rainbow: ") .append(empty().clickEvent(openUrl("https://github.com")) - .append(text("G").color(color(0x0c80e0))) - .append(text("H").color(color(0xf3801f))) + .append(text("G").color(color(0x00ffff))) + .append(text("H").color(color(0xff0000))) ); this.assertParsedEquals(expected, input); @@ -299,13 +299,13 @@ void testRainbowBackwardsWithInnerClick() { @Test void testNoRepeatedTextAfterUnclosedRainbow() { final Component expected = text() - .append(text('r', color(0xf3801f))) - .append(text('a', color(0xcdbb04))) - .append(text('i', color(0x96e805))) - .append(text('n', color(0x59fe22))) - .append(text('b', color(0x25f654))) - .append(text('o', color(0x06d490))) - .append(text('w', color(0x039ec9))) + .append(text('r', color(0xff0000))) + .append(text('a', color(0xff7500))) + .append(text('i', color(0xffeb00))) + .append(text('n', color(0x9cff00))) + .append(text('b', color(0x27ff00))) + .append(text('o', color(0x00ff4e))) + .append(text('w', color(0x00ffc4))) .append(text("yellow", YELLOW)) .build(); final String input = "rainbowyellow"; @@ -316,15 +316,15 @@ void testNoRepeatedTextAfterUnclosedRainbow() { @Test void testRainbowOrGradientContinuesAfterColoredInner() { final Component expectedRainbow = text() - .append(text('r', color(0xf3801f))) - .append(text('a', color(0xc9bf03))) - .append(text('i', color(0x8bed08))) - .append(text('n', color(0x4bff2c))) + .append(text('r', color(0xff0000))) + .append(text('a', color(0xff7f00))) + .append(text('i', color(0xffff00))) + .append(text('n', color(0x7fff00))) .append(text("white", WHITE)) .append(text() - .append(text('b', color(0xb401d3))) - .append(text('o', color(0xe71297))) - .append(text('w', color(0xfe4056)))) + .append(text('b', color(0x7f00ff))) + .append(text('o', color(0xff00ff))) + .append(text('w', color(0xff007f)))) .build(); final String rainbowInput = "rainwhitebow"; @@ -366,7 +366,7 @@ void gh137() { @Test void gh147() { final String input = ""; - final Component expected1 = text().append(text("y", color(0xf3801f)), text("o", color(0x0c80e0))).build(); + final Component expected1 = text().append(text("y", color(0xff0000)), text("o", color(0x00ffff))).build(); this.assertParsedEquals(expected1, input, component("msg", text("yo"))); } } diff --git a/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/ResetTagTest.java b/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/ResetTagTest.java index 7a77956b3..ed92e8f59 100644 --- a/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/ResetTagTest.java +++ b/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/standard/ResetTagTest.java @@ -41,11 +41,11 @@ void testReset() { .append(empty().color(YELLOW).insertion("test") .append(text("this")) .append(empty() - .append(text(" ", color(0xf3801f))) - .append(text("w", color(0x71f813))) - .append(text("o", color(0x03ca9c))) - .append(text("o", color(0x4135fe))) - .append(text("o", color(0xd507b1))) + .append(text(" ", color(0xff0000))) + .append(text("w", color(0xcbff00))) + .append(text("o", color(0x00ff66))) + .append(text("o", color(0x0065ff))) + .append(text("o", color(0xcc00ff))) ) ).append(text(" to insert!")); From 9271592dad1662e81becfa20663806cc789a55fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20L=C3=BCdtke?= Date: Sun, 12 Mar 2023 22:17:09 +0100 Subject: [PATCH 2/2] fix codestyle Co-authored-by: Riley Park --- .../adventure/text/minimessage/tag/standard/RainbowTag.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/RainbowTag.java b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/RainbowTag.java index 5fed5de08..6abd32ff9 100644 --- a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/RainbowTag.java +++ b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/RainbowTag.java @@ -101,7 +101,7 @@ protected void advanceColor() { @Override protected TextColor color() { final float index = this.colorIndex; - final float hue = (index / size() + this.phase / 10f) % 1; + final float hue = (index / this.size() + this.phase / 10f) % 1; return TextColor.color(HSVLike.hsvLike(hue, 1f, 1f)); }