44import me .shedaniel .math .Color ;
55import net .minecraft .client .MinecraftClient ;
66import net .minecraft .client .font .TextRenderer ;
7- import net .minecraft .client .gl .ShaderProgramKey ;
8- import net .minecraft .client .gl .ShaderProgramKeys ;
7+ // import net.minecraft.client.gl.ShaderProgramKey;
8+ // import net.minecraft.client.gl.ShaderProgramKeys;
99import net .minecraft .client .gui .DrawContext ;
10+ import net .minecraft .client .gui .screen .ButtonTextures ;
1011import net .minecraft .client .gui .screen .Screen ;
1112import net .minecraft .client .gui .widget .ButtonWidget ;
1213import net .minecraft .client .render .*;
1314import net .minecraft .client .util .NarratorManager ;
1415import net .minecraft .text .MutableText ;
1516import net .minecraft .text .Text ;
1617import net .minecraft .util .DyeColor ;
18+ import net .minecraft .util .Identifier ;
1719import win .baruna .blockmeter .BlockMeterClient ;
1820import win .baruna .blockmeter .ModConfig ;
1921import win .baruna .blockmeter .measurebox .ClientMeasureBox ;
@@ -36,14 +38,14 @@ protected void init() {
3638 final int colorIndex = i * 4 + j ;
3739 this .addDrawableChild (new ColorButton (this .width / 2 - 44 + j * 22 ,
3840 this .height / 2 - 88 + i * 22 , 20 , 20 , null ,
39- Color .ofOpaque (DyeColor .byId (colorIndex )
41+ Color .ofOpaque (DyeColor .byIndex (colorIndex )
4042 .getMapColor ().color ), config .colorIndex == colorIndex , false ,
4143 button -> {
4244 ClientMeasureBox .setColorIndex (colorIndex );
4345
4446 final ClientMeasureBox currentBox = BlockMeterClient .getInstance ().getCurrentBox ();
4547 if (currentBox != null )
46- currentBox .setColor (DyeColor .byId (colorIndex ));
48+ currentBox .setColor (DyeColor .byIndex (colorIndex ));
4749 MinecraftClient .getInstance ().setScreen (null );
4850 }));
4951 }
@@ -107,6 +109,9 @@ class ColorButton extends ButtonWidget {
107109 boolean selected ;
108110 boolean texture ;
109111 MutableText text ;
112+ private static final ButtonTextures TEXTURES = new ButtonTextures (
113+ Identifier .ofVanilla ("widget/button" ), Identifier .ofVanilla ("widget/button_disabled" ), Identifier .ofVanilla ("widget/button_highlighted" )
114+ );
110115
111116 @ Override
112117 public void onPress () {
@@ -136,23 +141,28 @@ public void onPress() {
136141 @ Override
137142 public void renderWidget (DrawContext context , final int int_1 , final int int_2 , final float float_1 ) {
138143
139- Tessellator tessellator = Tessellator .getInstance ();
140- var bufferBuilder = tessellator .begin (VertexFormat .DrawMode .QUADS , VertexFormats .POSITION_COLOR );
141- RenderSystem .setShader (ShaderProgramKeys .POSITION_COLOR );
142-
143- int r = this .color .getRed ();
144- int g = this .color .getGreen ();
145- int b = this .color .getBlue ();
146- int a = texture ? 102 : 255 ;
147- bufferBuilder .vertex (this .x - (texture ? 1 : 0 ), this .y - (texture ? 1 : 0 ), 0f )
148- .color (r , g , b , a );
149- bufferBuilder .vertex (this .x - (texture ? 1 : 0 ), this .y + this .height + (texture ? 1 : 0 ), 0f )
150- .color (r , g , b , a );
151- bufferBuilder .vertex (this .x + this .width + (texture ? 1 : 0 ), this .y + this .height + (texture ? 1 : 0 ), 0f )
152- .color (r , g , b , a );
153- bufferBuilder .vertex (this .x + this .width + (texture ? 1 : 0 ), this .y - (texture ? 1 : 0 ), 0f )
154- .color (r , g , b , a );
155- BufferRenderer .drawWithGlobalProgram (bufferBuilder .end ());
144+ context .drawGuiTexture (
145+ RenderLayer ::getGuiTextured ,
146+ TEXTURES .get (this .active , this .isSelected ()),
147+ x , y , width , height , color .getColor ()
148+ );
149+ // Tessellator tessellator = Tessellator.getInstance();
150+ // var bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
151+ // RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
152+ //
153+ // int r = this.color.getRed();
154+ // int g = this.color.getGreen();
155+ // int b = this.color.getBlue();
156+ // int a = texture ? 102 : 255;
157+ // bufferBuilder.vertex(this.x - (texture ? 1 : 0), this.y - (texture ? 1 : 0), 0f)
158+ // .color(r, g, b, a);
159+ // bufferBuilder.vertex(this.x - (texture ? 1 : 0), this.y + this.height + (texture ? 1 : 0), 0f)
160+ // .color(r, g, b, a);
161+ // bufferBuilder.vertex(this.x + this.width + (texture ? 1 : 0), this.y + this.height + (texture ? 1 : 0), 0f)
162+ // .color(r, g, b, a);
163+ // bufferBuilder.vertex(this.x + this.width + (texture ? 1 : 0), this.y - (texture ? 1 : 0), 0f)
164+ // .color(r, g, b, a);
165+ // BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
156166
157167 if (text != null ) {
158168 boolean dark = (0.299f * color .getRed () + 0.587f * color .getBlue () + 0.114f * color .getRed ()) / 255f < 0.8f ;
0 commit comments