Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change minimessage rainbow tag colors #882

Merged
merged 2 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
MrKinau marked this conversation as resolved.
Show resolved Hide resolved
return TextColor.color(HSVLike.hsvLike(hue, 1f, 1f));
}

@Override
Expand All @@ -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);
}
}