Skip to content

Commit

Permalink
Merge pull request #882 from MrKinau/main/4
Browse files Browse the repository at this point in the history
change minimessage rainbow tag colors
  • Loading branch information
kashike committed Mar 13, 2023
2 parents 16fe42b + 9271592 commit 3a7cd9e
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 187 deletions.
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 / this.size() + this.phase / 10f) % 1;
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);
}
}

0 comments on commit 3a7cd9e

Please sign in to comment.