package dev.crucifixbeta.api.utils.render;

import com.mojang.blaze3d.systems.RenderSystem;
import dev.crucifixbeta.api.utils.Wrapper;
import dev.crucifixbeta.mod.modules.impl.render.AntiAlias;
import java.awt.Color;
import java.util.function.DoubleFunction;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.VertexFormat.DrawMode;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import org.joml.Matrix4f;

@Environment(EnvType.CLIENT)
public class Render2DUtil implements Wrapper {
   public static void rect(MatrixStack stack, float x1, float y1, float x2, float y2, int color) {
      rectFilled(stack, x1, y1, x2, y2, color);
   }

   public static void arrow(MatrixStack matrixStack, float x, float y, Color color) {
      drawRectWithOutline(matrixStack, x - 1.0F, y - 1.0F, 2.0F, 2.0F, color, Color.BLACK);
   }

   public static void rectFilled(MatrixStack matrix, float x1, float y1, float x2, float y2, int color) {
      float var6 = (float)(color >> 24 & 0xFF) / 255.0F;
      float var7 = (float)(color >> 16 & 0xFF) / 255.0F;
      float var8 = (float)(color >> 8 & 0xFF) / 255.0F;
      float var9 = (float)(color & 0xFF) / 255.0F;
      if (!((double)var6 <= 0.01)) {
         if (x1 < x2) {
            float var10 = x1;
            x1 = x2;
            x2 = var10;
         }

         if (y1 < y2) {
            float var12 = y1;
            y1 = y2;
            y2 = var12;
         }

         RenderSystem.enableBlend();
         RenderSystem.setShader(GameRenderer::getPositionColorProgram);
         BufferBuilder var11 = Tessellator.getInstance().begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
         var11.vertex(matrix.peek().getPositionMatrix(), x1, y2, 0.0F).color(var7, var8, var9, var6);
         var11.vertex(matrix.peek().getPositionMatrix(), x2, y2, 0.0F).color(var7, var8, var9, var6);
         var11.vertex(matrix.peek().getPositionMatrix(), x2, y1, 0.0F).color(var7, var8, var9, var6);
         var11.vertex(matrix.peek().getPositionMatrix(), x1, y1, 0.0F).color(var7, var8, var9, var6);
         BufferRenderer.drawWithGlobalProgram(var11.end());
         RenderSystem.disableBlend();
      }
   }

   public static void horizontalGradient(MatrixStack matrices, float x1, float y1, float x2, float y2, Color startColor, Color endColor) {
      Matrix4f var7 = matrices.peek().getPositionMatrix();
      RenderSystem.enableBlend();
      RenderSystem.setShader(GameRenderer::getPositionColorProgram);
      BufferBuilder var8 = Tessellator.getInstance().begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
      var8.vertex(var7, x1, y1, 0.0F).color(startColor.getRGB());
      var8.vertex(var7, x1, y2, 0.0F).color(startColor.getRGB());
      var8.vertex(var7, x2, y2, 0.0F).color(endColor.getRGB());
      var8.vertex(var7, x2, y1, 0.0F).color(endColor.getRGB());
      BufferRenderer.drawWithGlobalProgram(var8.end());
      RenderSystem.disableBlend();
   }

   public static void horizontalGradient(MatrixStack matrices, float x1, float y1, float x2, float y2, int startColor, int endColor) {
      Matrix4f var7 = matrices.peek().getPositionMatrix();
      RenderSystem.enableBlend();
      RenderSystem.setShader(GameRenderer::getPositionColorProgram);
      BufferBuilder var8 = Tessellator.getInstance().begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
      var8.vertex(var7, x1, y1, 0.0F).color(startColor);
      var8.vertex(var7, x1, y2, 0.0F).color(startColor);
      var8.vertex(var7, x2, y2, 0.0F).color(endColor);
      var8.vertex(var7, x2, y1, 0.0F).color(endColor);
      BufferRenderer.drawWithGlobalProgram(var8.end());
      RenderSystem.disableBlend();
   }

   public static void verticalGradient(MatrixStack matrices, float x1, float y1, float x2, float y2, Color startColor, Color endColor) {
      Matrix4f var7 = matrices.peek().getPositionMatrix();
      RenderSystem.enableBlend();
      RenderSystem.setShader(GameRenderer::getPositionColorProgram);
      BufferBuilder var8 = Tessellator.getInstance().begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
      var8.vertex(var7, x1, y1, 0.0F).color(startColor.getRGB());
      var8.vertex(var7, x2, y1, 0.0F).color(startColor.getRGB());
      var8.vertex(var7, x2, y2, 0.0F).color(endColor.getRGB());
      var8.vertex(var7, x1, y2, 0.0F).color(endColor.getRGB());
      BufferRenderer.drawWithGlobalProgram(var8.end());
      RenderSystem.disableBlend();
   }

   public static void verticalGradient(MatrixStack matrices, float x1, float y1, float x2, float y2, int startColor, int endColor) {
      Matrix4f var7 = matrices.peek().getPositionMatrix();
      RenderSystem.enableBlend();
      RenderSystem.setShader(GameRenderer::getPositionColorProgram);
      BufferBuilder var8 = Tessellator.getInstance().begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
      var8.vertex(var7, x1, y1, 0.0F).color(startColor);
      var8.vertex(var7, x2, y1, 0.0F).color(startColor);
      var8.vertex(var7, x2, y2, 0.0F).color(endColor);
      var8.vertex(var7, x1, y2, 0.0F).color(endColor);
      BufferRenderer.drawWithGlobalProgram(var8.end());
      RenderSystem.disableBlend();
   }

   public static void drawLine(MatrixStack matrices, float x, float y, float x1, float y1, int color) {
      Matrix4f var6 = matrices.peek().getPositionMatrix();
      RenderSystem.enableBlend();
      RenderSystem.setShader(GameRenderer::getPositionColorProgram);
      BufferBuilder var7 = Tessellator.getInstance().begin(DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR);
      var7.vertex(var6, x, y, 0.0F).color(color);
      var7.vertex(var6, x1, y1, 0.0F).color(color);
      BufferRenderer.drawWithGlobalProgram(var7.end());
      RenderSystem.disableBlend();
   }

   public static void drawRectWithOutline(MatrixStack matrices, float x, float y, float width, float height, Color c, Color c2) {
      Matrix4f var7 = matrices.peek().getPositionMatrix();
      RenderSystem.enableBlend();
      RenderSystem.setShader(GameRenderer::getPositionColorProgram);
      BufferBuilder var8 = Tessellator.getInstance().begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
      var8.vertex(var7, x, y + height, 0.0F).color(c.getRGB());
      var8.vertex(var7, x + width, y + height, 0.0F).color(c.getRGB());
      var8.vertex(var7, x + width, y, 0.0F).color(c.getRGB());
      var8.vertex(var7, x, y, 0.0F).color(c.getRGB());
      BufferRenderer.drawWithGlobalProgram(var8.end());
      var8 = Tessellator.getInstance().begin(DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR);
      var8.vertex(var7, x, y + height, 0.0F).color(c2.getRGB());
      var8.vertex(var7, x + width, y + height, 0.0F).color(c2.getRGB());
      var8.vertex(var7, x + width, y, 0.0F).color(c2.getRGB());
      var8.vertex(var7, x, y, 0.0F).color(c2.getRGB());
      var8.vertex(var7, x, y + height, 0.0F).color(c2.getRGB());
      BufferRenderer.drawWithGlobalProgram(var8.end());
      RenderSystem.disableBlend();
   }

   public static void drawRect(MatrixStack matrices, float x, float y, float width, float height, int c) {
      Matrix4f var6 = matrices.peek().getPositionMatrix();
      RenderSystem.enableBlend();
      RenderSystem.setShader(GameRenderer::getPositionColorProgram);
      BufferBuilder var7 = Tessellator.getInstance().begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
      var7.vertex(var6, x, y + height, 0.0F).color(c);
      var7.vertex(var6, x + width, y + height, 0.0F).color(c);
      var7.vertex(var6, x + width, y, 0.0F).color(c);
      var7.vertex(var6, x, y, 0.0F).color(c);
      BufferRenderer.drawWithGlobalProgram(var7.end());
      RenderSystem.disableBlend();
   }

   public static void drawRect(MatrixStack matrices, float x, float y, float width, float height, Color c) {
      drawRect(matrices, x, y, width, height, c.getRGB());
   }

   public static void drawRect(DrawContext drawContext, float x, float y, float width, float height, Color c) {
      drawRect(drawContext.getMatrices(), x, y, width, height, c);
   }

   public static void drawSegmentedRect(MatrixStack matrices, float x, float y, float width, float height, float segment, DoubleFunction<Integer> colorAtY) {
      if (!(width <= 0.0F) && !(height <= 0.0F) && !(segment <= 0.0F)) {
         float var8 = y + height;
         float var9 = Math.min(y, var8);
         float var10 = Math.max(y, var8);

         for (float var11 = var9; var11 < var10; var11 += segment) {
            float var12 = Math.min(var11 + segment, var10);
            int var13 = (Integer)colorAtY.apply((double)var11);
            drawRect(matrices, x, var11, width, var12 - var11, var13);
         }
      }
   }

   public static void drawLutRect(MatrixStack matrices, float x, float y, float width, float height, Identifier texture, int lutHeight, int alpha) {
      if (width != 0.0F && height != 0.0F && lutHeight > 0) {
         float var9 = x + width;
         float var11 = y + height;
         float var12 = Math.min(x, var9);
         float var13 = Math.max(x, var9);
         float var14 = Math.min(y, var11);
         float var15 = Math.max(y, var11);
         float var16 = (float)Math.max(1, lutHeight - 1);
         float var17 = Math.max(0.0F, Math.min(1.0F, var14 / var16));
         float var18 = Math.max(0.0F, Math.min(1.0F, var15 / var16));
         float var19 = (float)Math.max(0, Math.min(255, alpha)) / 255.0F;
         Matrix4f var20 = matrices.peek().getPositionMatrix();
         RenderSystem.enableBlend();
         RenderSystem.setShader(GameRenderer::getPositionTexColorProgram);
         RenderSystem.setShaderTexture(0, texture);
         BufferBuilder var21 = Tessellator.getInstance().begin(DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
         float var22 = 0.5F;
         var21.vertex(var20, var12, var15, 0.0F).texture(var22, var18).color(1.0F, 1.0F, 1.0F, var19);
         var21.vertex(var20, var13, var15, 0.0F).texture(var22, var18).color(1.0F, 1.0F, 1.0F, var19);
         var21.vertex(var20, var13, var14, 0.0F).texture(var22, var17).color(1.0F, 1.0F, 1.0F, var19);
         var21.vertex(var20, var12, var14, 0.0F).texture(var22, var17).color(1.0F, 1.0F, 1.0F, var19);
         BufferRenderer.drawWithGlobalProgram(var21.end());
         RenderSystem.disableBlend();
      }
   }

   public static boolean isHovered(double mouseX, double mouseY, double x, double y, double width, double height) {
      return mouseX >= x && mouseX - width <= x && mouseY >= y && mouseY - height <= y;
   }

   public static void drawGlow(MatrixStack matrices, float x, float y, float width, float height, int color) {
      Matrix4f var6 = matrices.peek().getPositionMatrix();
      int var7 = ColorUtil.injectAlpha(color, 20);
      RenderSystem.setShader(GameRenderer::getPositionColorProgram);
      RenderSystem.disableCull();
      RenderSystem.enableBlend();
      BufferBuilder var8 = Tessellator.getInstance().begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
      float var9 = width / 2.0F;
      float var10 = height / 2.0F;
      float var11 = x + var9;
      float var12 = y + var10;
      float var13 = x + width;
      float var14 = y + height;
      var8.vertex(var6, var11, var12, 0.0F).color(color);
      var8.vertex(var6, x, var12, 0.0F).color(var7);
      var8.vertex(var6, x, y, 0.0F).color(var7);
      var8.vertex(var6, var11, y, 0.0F).color(var7);
      var8.vertex(var6, var11, var12, 0.0F).color(color);
      var8.vertex(var6, var11, y, 0.0F).color(var7);
      var8.vertex(var6, var13, y, 0.0F).color(var7);
      var8.vertex(var6, var13, var12, 0.0F).color(var7);
      var8.vertex(var6, var11, var12, 0.0F).color(color);
      var8.vertex(var6, x, var12, 0.0F).color(var7);
      var8.vertex(var6, x, var14, 0.0F).color(var7);
      var8.vertex(var6, var11, var14, 0.0F).color(var7);
      var8.vertex(var6, var11, var12, 0.0F).color(color);
      var8.vertex(var6, var13, var12, 0.0F).color(var7);
      var8.vertex(var6, var13, var14, 0.0F).color(var7);
      var8.vertex(var6, var11, var14, 0.0F).color(var7);
      BufferRenderer.drawWithGlobalProgram(var8.end());
      RenderSystem.disableBlend();
      RenderSystem.enableCull();
   }

   public static void drawCircle(MatrixStack matrices, float cx, float cy, float r, Color c, int segments) {
      Matrix4f var6 = matrices.peek().getPositionMatrix();
      RenderSystem.enableBlend();
      RenderSystem.disableCull();
      RenderSystem.setShader(GameRenderer::getPositionColorProgram);
      BufferBuilder var7 = Tessellator.getInstance().begin(DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
      var7.vertex(var6, cx, cy, 0.0F).color(c.getRGB());

      for (int var8 = 0; var8 <= segments; var8++) {
         double var9 = (double)var8 * (Math.PI * 2) / (double)segments;
         float var11 = (float)((double)cx + Math.cos(var9) * (double)r);
         float var12 = (float)((double)cy + Math.sin(var9) * (double)r);
         var7.vertex(var6, var11, var12, 0.0F).color(c.getRGB());
      }

      BufferRenderer.drawWithGlobalProgram(var7.end());
      RenderSystem.enableCull();
      RenderSystem.disableBlend();
   }

   public static void drawPill(MatrixStack matrices, float x, float y, float width, float height, Color c) {
      float var6 = height / 2.0F;
      drawRect(matrices, x + var6, y, width - 2.0F * var6, height, c);
      drawCircle(matrices, x + var6, y + var6, var6, c, 64);
      drawCircle(matrices, x + width - var6, y + var6, var6, c, 64);
   }

   public static void drawRoundedStroke(MatrixStack matrices, float x, float y, float width, float height, float radius, Color c, int seg) {
      Matrix4f var8 = matrices.peek().getPositionMatrix();
      RenderSystem.enableBlend();
      RenderSystem.setShader(GameRenderer::getPositionColorProgram);
      BufferBuilder var9 = Tessellator.getInstance().begin(DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR);
      float var10 = Math.min(radius, Math.min(width, height) / 2.0F);
      seg = Math.max(6, Math.min(16, seg));
      float var11 = x + var10;
      float var12 = y + var10;
      float var13 = x + width - var10;
      float var14 = y + height - var10;

      for (int var15 = 0; var15 <= seg; var15++) {
         double var16 = (-Math.PI / 2) + (double)var15 * (Math.PI / 2) / (double)seg;
         var9.vertex(var8, (float)((double)var13 + Math.cos(var16) * (double)var10), (float)((double)var12 + Math.sin(var16) * (double)var10), 0.0F)
            .color(c.getRGB());
      }

      for (int var19 = 0; var19 <= seg; var19++) {
         double var22 = 0.0 + (double)var19 * (Math.PI / 2) / (double)seg;
         var9.vertex(var8, (float)((double)var13 + Math.cos(var22) * (double)var10), (float)((double)var14 + Math.sin(var22) * (double)var10), 0.0F)
            .color(c.getRGB());
      }

      for (int var20 = 0; var20 <= seg; var20++) {
         double var23 = (Math.PI / 2) + (double)var20 * (Math.PI / 2) / (double)seg;
         var9.vertex(var8, (float)((double)var11 + Math.cos(var23) * (double)var10), (float)((double)var14 + Math.sin(var23) * (double)var10), 0.0F)
            .color(c.getRGB());
      }

      for (int var21 = 0; var21 <= seg; var21++) {
         double var24 = Math.PI + (double)var21 * (Math.PI / 2) / (double)seg;
         var9.vertex(var8, (float)((double)var11 + Math.cos(var24) * (double)var10), (float)((double)var12 + Math.sin(var24) * (double)var10), 0.0F)
            .color(c.getRGB());
      }

      BufferRenderer.drawWithGlobalProgram(var9.end());
      RenderSystem.disableBlend();
   }

   public static void drawRainbowRoundedStroke(MatrixStack matrices, float x, float y, float width, float height, float radius, int seg, float speed, int alpha) {
      Matrix4f var9 = matrices.peek().getPositionMatrix();
      RenderSystem.enableBlend();
      RenderSystem.setShader(GameRenderer::getPositionColorProgram);
      BufferBuilder var10 = Tessellator.getInstance().begin(DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR);
      float var11 = Math.min(radius, Math.min(width, height) / 2.0F);
      float var12 = x + var11;
      float var13 = y + var11;
      float var14 = x + width - var11;
      float var15 = y + height - var11;
      double var16 = (double)(System.currentTimeMillis() % (long)(1000.0F / Math.max(0.001F, speed))) / (double)(1000.0F / Math.max(0.001F, speed));

      for (int var18 = 0; var18 <= seg; var18++) {
         double var19 = (-Math.PI / 2) + (double)var18 * (Math.PI / 2) / (double)seg;
         float var21 = (float)((var19 + (Math.PI * 2)) / (Math.PI * 2) + var16) % 1.0F;
         int var22 = Color.HSBtoRGB(var21, 1.0F, 1.0F);
         int var23 = alpha << 24 | var22 & 16777215;
         var10.vertex(var9, (float)((double)var14 + Math.cos(var19) * (double)var11), (float)((double)var13 + Math.sin(var19) * (double)var11), 0.0F)
            .color(var23);
      }

      for (int var32 = 0; var32 <= seg; var32++) {
         double var35 = 0.0 + (double)var32 * (Math.PI / 2) / (double)seg;
         float var38 = (float)((var35 + (Math.PI * 2)) / (Math.PI * 2) + var16) % 1.0F;
         int var41 = Color.HSBtoRGB(var38, 1.0F, 1.0F);
         int var44 = alpha << 24 | var41 & 16777215;
         var10.vertex(var9, (float)((double)var14 + Math.cos(var35) * (double)var11), (float)((double)var15 + Math.sin(var35) * (double)var11), 0.0F)
            .color(var44);
      }

      for (int var33 = 0; var33 <= seg; var33++) {
         double var36 = (Math.PI / 2) + (double)var33 * (Math.PI / 2) / (double)seg;
         float var39 = (float)((var36 + (Math.PI * 2)) / (Math.PI * 2) + var16) % 1.0F;
         int var42 = Color.HSBtoRGB(var39, 1.0F, 1.0F);
         int var45 = alpha << 24 | var42 & 16777215;
         var10.vertex(var9, (float)((double)var12 + Math.cos(var36) * (double)var11), (float)((double)var15 + Math.sin(var36) * (double)var11), 0.0F)
            .color(var45);
      }

      for (int var34 = 0; var34 <= seg; var34++) {
         double var37 = Math.PI + (double)var34 * (Math.PI / 2) / (double)seg;
         float var40 = (float)((var37 + (Math.PI * 2)) / (Math.PI * 2) + var16) % 1.0F;
         int var43 = Color.HSBtoRGB(var40, 1.0F, 1.0F);
         int var46 = alpha << 24 | var43 & 16777215;
         var10.vertex(var9, (float)((double)var12 + Math.cos(var37) * (double)var11), (float)((double)var13 + Math.sin(var37) * (double)var11), 0.0F)
            .color(var46);
      }

      BufferRenderer.drawWithGlobalProgram(var10.end());
      BufferBuilder var24 = Tessellator.getInstance().begin(DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR);
      float var25 = Math.max(0.5F, var11 - 1.2F);

      for (int var26 = 0; var26 <= seg; var26++) {
         double var27 = (-Math.PI / 2) + (double)var26 * (Math.PI / 2) / (double)seg;
         float var29 = (float)((var27 + (Math.PI * 2)) / (Math.PI * 2) + var16) % 1.0F;
         int var30 = Color.HSBtoRGB(var29, 1.0F, 1.0F);
         int var31 = alpha << 24 | var30 & 16777215;
         var24.vertex(var9, (float)((double)var14 + Math.cos(var27) * (double)var25), (float)((double)var13 + Math.sin(var27) * (double)var25), 0.0F)
            .color(var31);
      }

      for (int var47 = 0; var47 <= seg; var47++) {
         double var50 = 0.0 + (double)var47 * (Math.PI / 2) / (double)seg;
         float var53 = (float)((var50 + (Math.PI * 2)) / (Math.PI * 2) + var16) % 1.0F;
         int var56 = Color.HSBtoRGB(var53, 1.0F, 1.0F);
         int var59 = alpha << 24 | var56 & 16777215;
         var24.vertex(var9, (float)((double)var14 + Math.cos(var50) * (double)var25), (float)((double)var15 + Math.sin(var50) * (double)var25), 0.0F)
            .color(var59);
      }

      for (int var48 = 0; var48 <= seg; var48++) {
         double var51 = (Math.PI / 2) + (double)var48 * (Math.PI / 2) / (double)seg;
         float var54 = (float)((var51 + (Math.PI * 2)) / (Math.PI * 2) + var16) % 1.0F;
         int var57 = Color.HSBtoRGB(var54, 1.0F, 1.0F);
         int var60 = alpha << 24 | var57 & 16777215;
         var24.vertex(var9, (float)((double)var12 + Math.cos(var51) * (double)var25), (float)((double)var15 + Math.sin(var51) * (double)var25), 0.0F)
            .color(var60);
      }

      for (int var49 = 0; var49 <= seg; var49++) {
         double var52 = Math.PI + (double)var49 * (Math.PI / 2) / (double)seg;
         float var55 = (float)((var52 + (Math.PI * 2)) / (Math.PI * 2) + var16) % 1.0F;
         int var58 = Color.HSBtoRGB(var55, 1.0F, 1.0F);
         int var61 = alpha << 24 | var58 & 16777215;
         var24.vertex(var9, (float)((double)var12 + Math.cos(var52) * (double)var25), (float)((double)var13 + Math.sin(var52) * (double)var25), 0.0F)
            .color(var61);
      }

      BufferRenderer.drawWithGlobalProgram(var24.end());
      RenderSystem.disableBlend();
   }

   public static void drawRoundedRect(MatrixStack matrices, float x, float y, float width, float height, float radius, Color c) {
      if (AntiAlias.isShapeAAEnabled()) {
         drawRoundedRectAA(matrices, x, y, width, height, radius, c);
      } else if (radius <= 0.0F) {
         drawRect(matrices, x, y, width, height, c);
      } else {
         float var7 = Math.min(radius, Math.min(width, height) / 2.0F);
         drawRect(matrices, x + var7, y, width - 2.0F * var7, height, c);
         drawRect(matrices, x, y + var7, var7, height - 2.0F * var7, c);
         drawRect(matrices, x + width - var7, y + var7, var7, height - 2.0F * var7, c);
         Matrix4f var8 = matrices.peek().getPositionMatrix();
         RenderSystem.enableBlend();
         RenderSystem.disableCull();
         RenderSystem.setShader(GameRenderer::getPositionColorProgram);
         int var9 = Math.max(6, Math.min(16, (int)Math.ceil((double)var7 * 1.5)));
         float var10 = x + var7;
         float var11 = y + var7;
         BufferBuilder var12 = Tessellator.getInstance().begin(DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
         var12.vertex(var8, var10, var11, 0.0F).color(c.getRGB());

         for (int var13 = 0; var13 <= var9; var13++) {
            double var14 = Math.PI + (double)var13 * (Math.PI / 2) / (double)var9;
            var12.vertex(var8, (float)((double)var10 + Math.cos(var14) * (double)var7), (float)((double)var11 + Math.sin(var14) * (double)var7), 0.0F)
               .color(c.getRGB());
         }

         BufferRenderer.drawWithGlobalProgram(var12.end());
         var10 = x + width - var7;
         var11 = y + var7;
         var12 = Tessellator.getInstance().begin(DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
         var12.vertex(var8, var10, var11, 0.0F).color(c.getRGB());

         for (int var25 = 0; var25 <= var9; var25++) {
            double var28 = (Math.PI * 3.0 / 2.0) + (double)var25 * (Math.PI / 2) / (double)var9;
            var12.vertex(var8, (float)((double)var10 + Math.cos(var28) * (double)var7), (float)((double)var11 + Math.sin(var28) * (double)var7), 0.0F)
               .color(c.getRGB());
         }

         BufferRenderer.drawWithGlobalProgram(var12.end());
         var10 = x + width - var7;
         var11 = y + height - var7;
         var12 = Tessellator.getInstance().begin(DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
         var12.vertex(var8, var10, var11, 0.0F).color(c.getRGB());

         for (int var26 = 0; var26 <= var9; var26++) {
            double var29 = 0.0 + (double)var26 * (Math.PI / 2) / (double)var9;
            var12.vertex(var8, (float)((double)var10 + Math.cos(var29) * (double)var7), (float)((double)var11 + Math.sin(var29) * (double)var7), 0.0F)
               .color(c.getRGB());
         }

         BufferRenderer.drawWithGlobalProgram(var12.end());
         var10 = x + var7;
         var11 = y + height - var7;
         var12 = Tessellator.getInstance().begin(DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
         var12.vertex(var8, var10, var11, 0.0F).color(c.getRGB());

         for (int var27 = 0; var27 <= var9; var27++) {
            double var30 = (Math.PI / 2) + (double)var27 * (Math.PI / 2) / (double)var9;
            var12.vertex(var8, (float)((double)var10 + Math.cos(var30) * (double)var7), (float)((double)var11 + Math.sin(var30) * (double)var7), 0.0F)
               .color(c.getRGB());
         }

         BufferRenderer.drawWithGlobalProgram(var12.end());
         RenderSystem.enableCull();
         RenderSystem.disableBlend();
      }
   }

   public static void drawRoundedRectForcedAA(MatrixStack matrices, float x, float y, float width, float height, float radius, Color c) {
      drawRoundedRectAA(matrices, x, y, width, height, radius, c);
   }

   public static void drawRoundedStrokeForcedAA(MatrixStack matrices, float x, float y, float width, float height, float radius, float thickness, Color c) {
      if (!(width <= 0.0F) && !(height <= 0.0F) && c.getAlpha() > 0) {
         float var8 = Math.min(radius, Math.min(width, height) / 2.0F);
         float var9 = Math.min(Math.max(0.35F, thickness), Math.min(width, height) / 2.0F);
         float var11 = x + width;
         float var13 = y + height;
         float var14 = Math.max(0.0F, var8 - var9);
         float var15 = 1.15F;
         drawRect(matrices, x + var8, y, Math.max(0.0F, width - 2.0F * var8), var9, c);
         drawRect(matrices, x + var8, var13 - var9, Math.max(0.0F, width - 2.0F * var8), var9, c);
         drawRect(matrices, x, y + var8, var9, Math.max(0.0F, height - 2.0F * var8), c);
         drawRect(matrices, var11 - var9, y + var8, var9, Math.max(0.0F, height - 2.0F * var8), c);
         drawCornerRingAA(matrices, x + var8, y + var8, var14, var8, (float) Math.PI, (float) (Math.PI * 3.0 / 2.0), c, c);
         drawCornerRingAA(matrices, var11 - var8, y + var8, var14, var8, (float) (Math.PI * 3.0 / 2.0), (float) (Math.PI * 2), c, c);
         drawCornerRingAA(matrices, var11 - var8, var13 - var8, var14, var8, 0.0F, (float) (Math.PI / 2), c, c);
         drawCornerRingAA(matrices, x + var8, var13 - var8, var14, var8, (float) (Math.PI / 2), (float) Math.PI, c, c);
         Color var16 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 0);
         drawEdgeAA(matrices, x + var8, y - var15, var11 - var8, y, var16, c);
         drawEdgeAA(matrices, x + var8, var13, var11 - var8, var13 + var15, c, var16);
         drawVerticalEdgeAA(matrices, x - var15, y + var8, x, var13 - var8, var16, c);
         drawVerticalEdgeAA(matrices, var11, y + var8, var11 + var15, var13 - var8, c, var16);
         drawCornerRingAA(matrices, x + var8, y + var8, var8, var8 + var15, (float) Math.PI, (float) (Math.PI * 3.0 / 2.0), c, var16);
         drawCornerRingAA(matrices, var11 - var8, y + var8, var8, var8 + var15, (float) (Math.PI * 3.0 / 2.0), (float) (Math.PI * 2), c, var16);
         drawCornerRingAA(matrices, var11 - var8, var13 - var8, var8, var8 + var15, 0.0F, (float) (Math.PI / 2), c, var16);
         drawCornerRingAA(matrices, x + var8, var13 - var8, var8, var8 + var15, (float) (Math.PI / 2), (float) Math.PI, c, var16);
         if (var9 > 0.7F && var14 > 0.0F) {
            float var17 = Math.min(0.75F, var9);
            drawEdgeAA(matrices, x + var8, y + var9 - var17, var11 - var8, y + var9, c, var16);
            drawEdgeAA(matrices, x + var8, var13 - var9, var11 - var8, var13 - var9 + var17, var16, c);
            drawVerticalEdgeAA(matrices, x + var9 - var17, y + var8, x + var9, var13 - var8, c, var16);
            drawVerticalEdgeAA(matrices, var11 - var9, y + var8, var11 - var9 + var17, var13 - var8, var16, c);
            drawCornerRingAA(matrices, x + var8, y + var8, var14, var14 + var17, (float) Math.PI, (float) (Math.PI * 3.0 / 2.0), var16, c);
            drawCornerRingAA(matrices, var11 - var8, y + var8, var14, var14 + var17, (float) (Math.PI * 3.0 / 2.0), (float) (Math.PI * 2), var16, c);
            drawCornerRingAA(matrices, var11 - var8, var13 - var8, var14, var14 + var17, 0.0F, (float) (Math.PI / 2), var16, c);
            drawCornerRingAA(matrices, x + var8, var13 - var8, var14, var14 + var17, (float) (Math.PI / 2), (float) Math.PI, var16, c);
         }
      }
   }

   private static void drawRoundedRectAA(MatrixStack matrices, float x, float y, float width, float height, float radius, Color c) {
      if (!(width <= 0.0F) && !(height <= 0.0F) && c.getAlpha() > 0) {
         if (radius <= 0.0F) {
            drawRect(matrices, x, y, width, height, c);
         } else {
            float var7 = Math.min(radius, Math.min(width, height) / 2.0F);
            float var8 = 1.15F;
            float var9 = Math.max(0.0F, var7 - var8);
            float var11 = x + width;
            float var13 = y + height;
            drawRect(matrices, x + var7, y, Math.max(0.0F, width - 2.0F * var7), height, c);
            drawRect(matrices, x, y + var7, var7, Math.max(0.0F, height - 2.0F * var7), c);
            drawRect(matrices, var11 - var7, y + var7, var7, Math.max(0.0F, height - 2.0F * var7), c);
            drawCorner(matrices, x + var7, y + var7, var9, (float) Math.PI, (float) (Math.PI * 3.0 / 2.0), c);
            drawCorner(matrices, var11 - var7, y + var7, var9, (float) (Math.PI * 3.0 / 2.0), (float) (Math.PI * 2), c);
            drawCorner(matrices, var11 - var7, var13 - var7, var9, 0.0F, (float) (Math.PI / 2), c);
            drawCorner(matrices, x + var7, var13 - var7, var9, (float) (Math.PI / 2), (float) Math.PI, c);
            Color var14 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 0);
            drawEdgeAA(matrices, x + var7, y - var8, var11 - var7, y, var14, c);
            drawEdgeAA(matrices, x + var7, var13, var11 - var7, var13 + var8, c, var14);
            drawVerticalEdgeAA(matrices, x - var8, y + var7, x, var13 - var7, var14, c);
            drawVerticalEdgeAA(matrices, var11, y + var7, var11 + var8, var13 - var7, c, var14);
            drawCornerRingAA(matrices, x + var7, y + var7, var9, var7 + var8, (float) Math.PI, (float) (Math.PI * 3.0 / 2.0), c, var14);
            drawCornerRingAA(matrices, var11 - var7, y + var7, var9, var7 + var8, (float) (Math.PI * 3.0 / 2.0), (float) (Math.PI * 2), c, var14);
            drawCornerRingAA(matrices, var11 - var7, var13 - var7, var9, var7 + var8, 0.0F, (float) (Math.PI / 2), c, var14);
            drawCornerRingAA(matrices, x + var7, var13 - var7, var9, var7 + var8, (float) (Math.PI / 2), (float) Math.PI, c, var14);
         }
      }
   }

   private static void drawCorner(MatrixStack matrices, float cx, float cy, float radius, float start, float end, Color c) {
      if (!(radius <= 0.0F)) {
         Matrix4f var7 = matrices.peek().getPositionMatrix();
         RenderSystem.enableBlend();
         RenderSystem.disableCull();
         RenderSystem.setShader(GameRenderer::getPositionColorProgram);
         BufferBuilder var8 = Tessellator.getInstance().begin(DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
         var8.vertex(var7, cx, cy, 0.0F).color(c.getRGB());
         int var9 = Math.max(5, Math.min(10, (int)Math.ceil((double)radius * 1.25)));

         for (int var10 = 0; var10 <= var9; var10++) {
            float var11 = start + (end - start) * (float)var10 / (float)var9;
            var8.vertex(var7, cx + MathHelper.cos(var11) * radius, cy + MathHelper.sin(var11) * radius, 0.0F).color(c.getRGB());
         }

         BufferRenderer.drawWithGlobalProgram(var8.end());
         RenderSystem.enableCull();
         RenderSystem.disableBlend();
      }
   }

   private static void drawCornerRingAA(MatrixStack matrices, float cx, float cy, float innerR, float outerR, float start, float end, Color inner, Color outer) {
      Matrix4f var9 = matrices.peek().getPositionMatrix();
      RenderSystem.enableBlend();
      RenderSystem.disableCull();
      RenderSystem.setShader(GameRenderer::getPositionColorProgram);
      BufferBuilder var10 = Tessellator.getInstance().begin(DrawMode.TRIANGLE_STRIP, VertexFormats.POSITION_COLOR);
      int var11 = Math.max(5, Math.min(12, (int)Math.ceil((double)outerR * 1.25)));

      for (int var12 = 0; var12 <= var11; var12++) {
         float var13 = start + (end - start) * (float)var12 / (float)var11;
         float var14 = MathHelper.cos(var13);
         float var15 = MathHelper.sin(var13);
         var10.vertex(var9, cx + var14 * innerR, cy + var15 * innerR, 0.0F).color(inner.getRGB());
         var10.vertex(var9, cx + var14 * outerR, cy + var15 * outerR, 0.0F).color(outer.getRGB());
      }

      BufferRenderer.drawWithGlobalProgram(var10.end());
      RenderSystem.enableCull();
      RenderSystem.disableBlend();
   }

   private static void drawEdgeAA(MatrixStack matrices, float x1, float y1, float x2, float y2, Color top, Color bottom) {
      Matrix4f var7 = matrices.peek().getPositionMatrix();
      RenderSystem.enableBlend();
      RenderSystem.setShader(GameRenderer::getPositionColorProgram);
      BufferBuilder var8 = Tessellator.getInstance().begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
      var8.vertex(var7, x1, y1, 0.0F).color(top.getRGB());
      var8.vertex(var7, x2, y1, 0.0F).color(top.getRGB());
      var8.vertex(var7, x2, y2, 0.0F).color(bottom.getRGB());
      var8.vertex(var7, x1, y2, 0.0F).color(bottom.getRGB());
      BufferRenderer.drawWithGlobalProgram(var8.end());
      RenderSystem.disableBlend();
   }

   private static void drawVerticalEdgeAA(MatrixStack matrices, float x1, float y1, float x2, float y2, Color leftColor, Color rightColor) {
      Matrix4f var7 = matrices.peek().getPositionMatrix();
      RenderSystem.enableBlend();
      RenderSystem.setShader(GameRenderer::getPositionColorProgram);
      BufferBuilder var8 = Tessellator.getInstance().begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
      var8.vertex(var7, x1, y1, 0.0F).color(leftColor.getRGB());
      var8.vertex(var7, x2, y1, 0.0F).color(rightColor.getRGB());
      var8.vertex(var7, x2, y2, 0.0F).color(rightColor.getRGB());
      var8.vertex(var7, x1, y2, 0.0F).color(leftColor.getRGB());
      BufferRenderer.drawWithGlobalProgram(var8.end());
      RenderSystem.disableBlend();
   }

   public static void drawRightRoundedRect(MatrixStack matrices, float x, float y, float width, float height, float radius, Color c) {
      if (!(width <= 0.0F) && !(height <= 0.0F)) {
         if (radius <= 0.0F) {
            drawRect(matrices, x, y, width, height, c);
         } else {
            float var7 = Math.min(radius, Math.min(width, height) / 2.0F);
            int var8 = Math.max(0, Math.min(255, (int)Math.round((double)c.getRed() * 0.85)));
            int var9 = Math.max(0, Math.min(255, (int)Math.round((double)c.getGreen() * 0.85)));
            int var10 = Math.max(0, Math.min(255, (int)Math.round((double)c.getBlue() * 0.85)));
            drawCircle(matrices, x + width - var7, y + height / 2.0F, var7, new Color(var8, var9, var10, c.getAlpha()), 64);
            drawRect(matrices, x, y, width - var7, height, c);
            if (height > 2.0F * var7) {
               drawRect(matrices, x + width - var7, y + var7, var7, height - 2.0F * var7, c);
            }

            Matrix4f var11 = matrices.peek().getPositionMatrix();
            RenderSystem.enableBlend();
            RenderSystem.disableCull();
            RenderSystem.setShader(GameRenderer::getPositionColorProgram);
            byte var12 = 48;
            float var13 = x + width - var7;
            float var14 = y + var7;
            BufferBuilder var15 = Tessellator.getInstance().begin(DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
            var15.vertex(var11, var13, var14, 0.0F).color(c.getRGB());

            for (int var16 = 0; var16 <= var12; var16++) {
               double var17 = (Math.PI * 3.0 / 2.0) + (double)var16 * (Math.PI / 2) / (double)var12;
               var15.vertex(var11, (float)((double)var13 + Math.cos(var17) * (double)var7), (float)((double)var14 + Math.sin(var17) * (double)var7), 0.0F)
                  .color(c.getRGB());
            }

            BufferRenderer.drawWithGlobalProgram(var15.end());
            var13 = x + width - var7;
            var14 = y + height - var7;
            var15 = Tessellator.getInstance().begin(DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
            var15.vertex(var11, var13, var14, 0.0F).color(c.getRGB());

            for (int var22 = 0; var22 <= var12; var22++) {
               double var23 = 0.0 + (double)var22 * (Math.PI / 2) / (double)var12;
               var15.vertex(var11, (float)((double)var13 + Math.cos(var23) * (double)var7), (float)((double)var14 + Math.sin(var23) * (double)var7), 0.0F)
                  .color(c.getRGB());
            }

            BufferRenderer.drawWithGlobalProgram(var15.end());
            RenderSystem.enableCull();
            RenderSystem.disableBlend();
         }
      }
   }

   public static void drawDropShadow(MatrixStack matrices, float x, float y, float width, float height, float radius) {
   }
}
