55import net .minecraft .client .font .TextRenderer ;
66import net .minecraft .client .gui .DrawContext ;
77import net .minecraft .client .render .*;
8+ import net .minecraft .client .util .math .MatrixStack ;
89import net .minecraft .item .ItemStack ;
910import org .jetbrains .annotations .NotNull ;
1011import org .lwjgl .opengl .GL11 ;
@@ -30,15 +31,13 @@ public static void init(){
3031 //draw a rectangle
3132 public static void drawRect (DrawContext context , float x , float y , float width , float height , int color ) {
3233 buffer = tessellator .begin (VertexFormat .DrawMode .QUADS , VertexFormats .POSITION_COLOR );
33-
34+
3435 buffer .vertex (context .getMatrices ().peek ().getPositionMatrix (), x , y , z ).color (color );
3536 buffer .vertex (context .getMatrices ().peek ().getPositionMatrix (), x , y + height , z ).color (color );
3637 buffer .vertex (context .getMatrices ().peek ().getPositionMatrix (), x + width , y + height , z ).color (color );
3738 buffer .vertex (context .getMatrices ().peek ().getPositionMatrix (), x + width , y , z ).color (color );
3839
3940 RenderSystem .setShader (GameRenderer ::getPositionColorProgram );
40- //RenderSystem.setShaderColor(0.0F, 0.0F, 0.0F, 0.0F);
41-
4241 BufferRenderer .drawWithGlobalProgram (buffer .end ());
4342 }
4443
@@ -157,14 +156,11 @@ public static void drawLoadingCircle(DrawContext context, float x, float y, floa
157156
158157 //draws a rounded rectangle with a given radius and color and size
159158 public static void drawRoundedRect (DrawContext context , int x , int y , int width , int height , int radius , @ NotNull int color ) {
160-
161159 //draw the two rectangles
162160 drawRect (context , x + radius , y , width - radius * 2 , height , color );
163161 drawRect (context , x , y + radius , radius , height - radius * 2 , color );
164162 drawRect (context , x + width - radius , y + radius , radius , height - radius * 2 , color );
165163
166- //drawRect(x + radius, y, width - radius - radius, height, color.getRGB());
167- //drawRect(x, y + radius, width, height - radius - radius, color.getRGB());
168164 //draw the circles
169165 //drawArc(x + radius, y + radius, radius, 180, 270, color);
170166 //drawArc(x + width - radius, y + radius, radius, 90, 180, color);
@@ -229,41 +225,34 @@ public static void drawCenteredStringWithShadow(DrawContext context, String text
229225 true
230226 );
231227 }
232- /*
228+
233229 //draws a string with custom scale
234- public static void drawString(String text, int x, int y, int color, int scale) {
235- drawContext.drawText(textRenderer, text, x, y, color, false);
230+ private static void drawString (DrawContext context , String text , int x , int y , int color , int scale , boolean centered , boolean shadow ) {
231+ MatrixStack ms = context .getMatrices ();
232+ ms .push ();
233+ ms .scale (scale ,scale ,0 );
234+ context .drawText (textRenderer , text , centered ? x - textRenderer .getWidth (text ) / 2 : x , y , color , shadow );
235+ ms .pop ();
236236 }
237237
238- //draws a string with custom scale and shadow
239- public static void drawStringWithShadow(String text, int x, int y, Color color, int scale) {
240- setColor(color);
241- FontRenderer fr = mc.fontRendererObj;
242- fr.drawStringWithShadow(text, x, y, color.getRGB());
238+ //draws a string with custom scale
239+ public static void drawString (DrawContext context , String text , int x , int y , int color , int scale ) {
240+ drawString (context , text , x , y , color , scale , false , false );
243241 }
244242
245- public static void drawCenteredString(String text, int x, int y, Color color, int scale) {
246- setColor(color);
247- FontRenderer fr = mc.fontRendererObj;
248- fr.drawString(text, x - fr.getStringWidth(text) / 2, y, color.getRGB());
243+ //draws a string with custom scale and shadow
244+ public static void drawStringWithShadow (DrawContext context , String text , int x , int y , int color , int scale ) {
245+ drawString (context , text , x , y , color , scale , false , true );
249246 }
250247
251- public static void drawCenteredStringWithShadow(String text, int x, int y, Color color, int scale) {
252- setColor(color);
253- FontRenderer fr = mc.fontRendererObj;
254- fr.drawStringWithShadow(text, x - fr.getStringWidth(text) / 2, y, color.getRGB());
248+ public static void drawCenteredString (DrawContext context , String text , int x , int y , int color , int scale ) {
249+ drawString (context , text , x , y , color , scale , true , false );
255250 }
256251
257- public static void drawCenteredStringWithShadow(String text, int x, int y, Color color, int scale, boolean centered) {
258- setColor(color);
259- FontRenderer fr = mc.fontRendererObj;
260- if (centered) {
261- fr.drawStringWithShadow(text, x - fr.getStringWidth(text) / 2, y, color.getRGB());
262- } else {
263- fr.drawStringWithShadow(text, x, y, color.getRGB());
264- }
252+ public static void drawCenteredStringWithShadow (DrawContext context , String text , int x , int y , int color , int scale ) {
253+ drawString (context , text , x , y , color , scale , true , true );
265254 }
266- */
255+
267256 //draws an ItemStack at a given position with a given scale
268257 public static void drawItemStack (DrawContext context , ItemStack itemStack , int x , int y , float scale ) {
269258 context .drawItem (itemStack , x , y , 0 , z );
0 commit comments