11
11
12
12
import dev .lambdaurora .spruceui .background .Background ;
13
13
import dev .lambdaurora .spruceui .background .SimpleColorBackground ;
14
+ import dev .lambdaurora .spruceui .util .ColorUtil ;
14
15
import dev .lambdaurora .spruceui .widget .SpruceWidget ;
15
- import io .github .queerbric .pride .PrideClient ;
16
- import io .github .queerbric .pride .PrideFlag ;
17
- import io .github .queerbric .pride .PrideFlagShapes ;
18
- import io .github .queerbric .pride .PrideFlags ;
16
+ import io .github .queerbric .pride .*;
17
+ import it .unimi .dsi .fastutil .ints .IntList ;
18
+ import net .minecraft .client .Minecraft ;
19
19
import net .minecraft .client .gui .GuiGraphics ;
20
+ import net .minecraft .network .chat .Text ;
20
21
import net .minecraft .resources .Identifier ;
21
22
22
23
import java .util .Random ;
27
28
* If you have an issue with this, I don't care.
28
29
*
29
30
* @author LambdAurora
30
- * @version 3.2.0
31
+ * @version 3.2.3
31
32
* @since 2.1.0
32
33
*/
33
34
public class RandomPrideFlagBackground implements Background {
34
35
private static final Background SECOND_LAYER = new SimpleColorBackground (0xe0101010 );
36
+ private static final IntList DEFAULT_RAINBOW_COLORS = IntList .of (
37
+ 0xffff0018 , 0xffffa52c , 0xffffff41 , 0xff008018 , 0xff0000f9 , 0xff86007d
38
+ );
39
+ private static final PrideFlagShape PROGRESS = PrideFlagShapes .get (Identifier .of ("pride" , "progress" ));
35
40
private static final Random RANDOM = new Random ();
36
41
37
42
private final PrideFlag flag ;
43
+ private final boolean nuhUh ;
38
44
39
- public RandomPrideFlagBackground (PrideFlag flag ) {
45
+ RandomPrideFlagBackground (PrideFlag flag , boolean nuhUh ) {
40
46
this .flag = flag ;
47
+ this .nuhUh = nuhUh ;
48
+ }
49
+
50
+ private IntList getColors () {
51
+ return this .nuhUh ? DEFAULT_RAINBOW_COLORS : this .flag .getColors ();
41
52
}
42
53
43
54
@ Override
44
55
public void render (GuiGraphics graphics , SpruceWidget widget , int vOffset , int mouseX , int mouseY , float delta ) {
45
56
int x = widget .getX ();
46
57
int y = widget .getY ();
58
+ int width = widget .getWidth ();
59
+ int height = widget .getHeight ();
47
60
48
- if (this .flag .getShape () == PrideFlagShapes .get (Identifier .of ("pride" , "horizontal_stripes" ))) {
61
+ if (this .nuhUh || this . flag .getShape () == PrideFlagShapes .get (Identifier .of ("pride" , "horizontal_stripes" ))) {
49
62
graphics .drawSpecial (bufferSource -> {
50
63
var buffer = bufferSource .getBuffer (PrideClient .FLAG_SHAPE_TRIANGLE_RENDER_TYPE );
51
64
52
- int width = widget .getWidth ();
53
- int height = widget .getHeight ();
65
+ var colors = this .getColors ();
54
66
55
- float partHeight = height / (this . flag . getColors () .size () - 1.f );
67
+ float partHeight = height / (colors .size () - 1.f );
56
68
57
69
// First one
58
70
float rightY = y ;
59
71
float leftY = y ;
60
72
61
- int color = this . flag . getColors () .getInt (0 );
73
+ int color = colors .getInt (0 );
62
74
buffer .addVertex (x + width , rightY + partHeight , 0 ).color (color );
63
75
buffer .addVertex (x + width , rightY , 0 ).color (color );
64
76
buffer .addVertex (x , leftY , 0 ).color (color );
65
77
66
78
rightY += partHeight ;
67
79
68
- for (int i = 1 ; i < this . flag . getColors () .size () - 1 ; i ++) {
69
- color = this . flag . getColors () .getInt (i );
80
+ for (int i = 1 ; i < colors .size () - 1 ; i ++) {
81
+ color = colors .getInt (i );
70
82
71
83
buffer .addVertex (x + width , rightY + partHeight , 0 ).color (color );
72
84
buffer .addVertex (x + width , rightY , 0 ).color (color );
@@ -81,7 +93,7 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int vOffset, int m
81
93
}
82
94
83
95
// Last one
84
- color = this . flag . getColors (). getInt (this . flag . getColors () .size () - 1 );
96
+ color = colors . getInt (colors .size () - 1 );
85
97
buffer .addVertex (x + width , rightY , 0 ).color (color );
86
98
buffer .addVertex (x , leftY , 0 ).color (color );
87
99
buffer .addVertex (x , y + height , 0 ).color (color );
@@ -91,6 +103,19 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int vOffset, int m
91
103
}
92
104
93
105
SECOND_LAYER .render (graphics , widget , vOffset , mouseX , mouseY , delta );
106
+
107
+ if (this .nuhUh ) {
108
+ var text = Text .literal ("Nuh uh, you're not going to remove this, try harder :3c" );
109
+ var font = Minecraft .getInstance ().font ;
110
+ var lines = font .wrapLines (text , width - 8 );
111
+
112
+ int startY = y + height - 24 - lines .size () * (font .lineHeight + 2 );
113
+
114
+ for (var line : lines ) {
115
+ graphics .drawCenteredShadowedText (font , line , x + width / 2 , startY , 0xffff0000 );
116
+ startY += font .lineHeight + 2 ;
117
+ }
118
+ }
94
119
}
95
120
96
121
/**
@@ -99,6 +124,39 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int vOffset, int m
99
124
* @return the background
100
125
*/
101
126
public static Background random () {
102
- return new RandomPrideFlagBackground (PrideFlags .getRandomFlag (RANDOM ));
127
+ var flag = PrideFlags .getRandomFlag (RANDOM );
128
+ boolean nuhUh = flag == null || (flag .getShape () != PROGRESS && areColorsSpoofed (flag .getColors ()));
129
+
130
+ return new RandomPrideFlagBackground (flag , nuhUh );
131
+ }
132
+
133
+ private static boolean areColorsSpoofed (IntList colors ) {
134
+ if (colors .size () < 2 ) {
135
+ return true ;
136
+ } else {
137
+ int maxDist = 0 ;
138
+
139
+ for (int colorA : colors ) {
140
+ for (int colorB : colors ) {
141
+ int dist = colorDist (colorA , colorB );
142
+
143
+ if (dist > maxDist ) {
144
+ maxDist = dist ;
145
+ }
146
+ }
147
+ }
148
+
149
+ return maxDist < 10 ;
150
+ }
151
+ }
152
+
153
+ private static int colorDist (int a , int b ) {
154
+ // https://en.wikipedia.org/wiki/Color_difference#sRGB
155
+ float r = (ColorUtil .argbUnpackRed (a ) + ColorUtil .argbUnpackRed (b )) / 2.f ;
156
+ int deltaR = ColorUtil .argbUnpackRed (a ) - ColorUtil .argbUnpackRed (b );
157
+ int deltaG = ColorUtil .argbUnpackGreen (a ) - ColorUtil .argbUnpackGreen (b );
158
+ int deltaB = ColorUtil .argbUnpackBlue (a ) - ColorUtil .argbUnpackBlue (b );
159
+
160
+ return (int ) Math .sqrt ((2 + r / 256.f ) * deltaR * deltaR + 4 * deltaG * deltaG + (2 + (255 - r ) / 256 ) * deltaB * deltaB );
103
161
}
104
162
}
0 commit comments