| 1 | package thunder.hack.utility.render;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.vertex.BufferBuilder;
|
| 4 | import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
| 5 | import com.mojang.blaze3d.vertex.MeshData;
|
| 6 | import thunder.hack.utility.render.Tesselator;
|
| 7 | import com.mojang.blaze3d.vertex.VertexFormat;
|
| 8 |
|
| 9 | import com.mojang.blaze3d.platform.GlStateManager;
|
| 10 | import com.mojang.blaze3d.platform.NativeImage;
|
| 11 | import thunder.hack.utility.render.compat.RenderSystem;
|
| 12 | import thunder.hack.utility.render.ShaderProgramKeys;
|
| 13 | import thunder.hack.utility.render.BufferRenderer;
|
| 14 | import net.minecraft.client.renderer.texture.DynamicTexture;
|
| 15 | import net.minecraft.util.Mth;
|
| 16 | import org.apache.commons.lang3.RandomStringUtils;
|
| 17 | import org.jetbrains.annotations.NotNull;
|
| 18 | import org.joml.Matrix4f;
|
| 19 | import org.joml.Vector4f;
|
| 20 | import org.lwjgl.BufferUtils;
|
| 21 | import org.lwjgl.opengl.GL40C;
|
| 22 | import thunder.hack.features.modules.client.HudEditor;
|
| 23 | import thunder.hack.gui.font.Texture;
|
| 24 | import thunder.hack.utility.math.MathUtility;
|
| 25 | import thunder.hack.utility.render.shaders.*;
|
| 26 |
|
| 27 | import javax.imageio.ImageIO;
|
| 28 | import java.awt.*;
|
| 29 | import java.awt.image.BufferedImage;
|
| 30 | import java.io.ByteArrayOutputStream;
|
| 31 | import java.nio.ByteBuffer;
|
| 32 | import java.util.HashMap;
|
| 33 | import java.util.Stack;
|
| 34 |
|
| 35 | import static thunder.hack.features.modules.Module.mc;
|
| 36 |
|
| 37 | public class Render2DEngine {
|
| 38 | public static TextureColorProgram TEXTURE_COLOR_PROGRAM;
|
| 39 | public static HudShader HUD_SHADER;
|
| 40 | public static RectangleShader RECTANGLE_SHADER;
|
| 41 | public static MainMenuProgram MAIN_MENU_PROGRAM;
|
| 42 | public static ArcShader ARC_PROGRAM;
|
| 43 | public static BlurProgram BLUR_PROGRAM;
|
| 44 | public static HashMap<Integer, BlurredShadow> shadowCache = new HashMap<>();
|
| 45 | public static HashMap<Integer, BlurredShadow> shadowCache1 = new HashMap<>();
|
| 46 | final static Stack<Rectangle> clipStack = new Stack<>();
|
| 47 |
|
| 48 | public static void addWindow(Object stack, Rectangle r1) {
|
| 49 | Matrix4f matrix = GuiMatrix.positionMatrix(stack);
|
| 50 | Vector4f coord = new Vector4f(r1.x, r1.y, 0, 1);
|
| 51 | Vector4f end = new Vector4f(r1.x1, r1.y1, 0, 1);
|
| 52 | coord.mulTranspose(matrix);
|
| 53 | end.mulTranspose(matrix);
|
| 54 | float x = coord.x();
|
| 55 | float y = coord.y();
|
| 56 | float endX = end.x();
|
| 57 | float endY = end.y();
|
| 58 | Rectangle r = new Rectangle(x, y, endX, endY);
|
| 59 | if (clipStack.empty()) {
|
| 60 | clipStack.push(r);
|
| 61 | beginScissor(r.x, r.y, r.x1, r.y1);
|
| 62 | } else {
|
| 63 | Rectangle lastClip = clipStack.peek();
|
| 64 | float lsx = lastClip.x;
|
| 65 | float lsy = lastClip.y;
|
| 66 | float lstx = lastClip.x1;
|
| 67 | float lsty = lastClip.y1;
|
| 68 | float nsx = Mth.clamp(r.x, lsx, lstx);
|
| 69 | float nsy = Mth.clamp(r.y, lsy, lsty);
|
| 70 | float nstx = Mth.clamp(r.x1, nsx, lstx);
|
| 71 | float nsty = Mth.clamp(r.y1, nsy, lsty);
|
| 72 | clipStack.push(new Rectangle(nsx, nsy, nstx, nsty));
|
| 73 | beginScissor(nsx, nsy, nstx, nsty);
|
| 74 | }
|
| 75 | }
|
| 76 |
|
| 77 | public static void popWindow() {
|
| 78 | clipStack.pop();
|
| 79 | if (clipStack.empty()) {
|
| 80 | endScissor();
|
| 81 | } else {
|
| 82 | Rectangle r = clipStack.peek();
|
| 83 | beginScissor(r.x, r.y, r.x1, r.y1);
|
| 84 | }
|
| 85 | }
|
| 86 |
|
| 87 | public static void beginScissor(double x, double y, double endX, double endY) {
|
| 88 | double width = endX - x;
|
| 89 | double height = endY - y;
|
| 90 | width = Math.max(0, width);
|
| 91 | height = Math.max(0, height);
|
| 92 | float d = (float) Render3DEngine.getScaleFactor();
|
| 93 | int ay = (int) ((mc.getWindow().getGuiScaledHeight() - (y + height)) * d);
|
| 94 | RenderSystem.enableScissor((int) (x * d), ay, (int) (width * d), (int) (height * d));
|
| 95 | }
|
| 96 |
|
| 97 | public static void endScissor() {
|
| 98 | RenderSystem.disableScissor();
|
| 99 | }
|
| 100 |
|
| 101 | public static void resetScissorStack() {
|
| 102 | if (!clipStack.empty()) {
|
| 103 | clipStack.clear();
|
| 104 | endScissor();
|
| 105 | }
|
| 106 | }
|
| 107 |
|
| 108 | public static void addWindow(Object stack, float x, float y, float x1, float y1, double animation_factor) {
|
| 109 | float h = y + y1;
|
| 110 | float h2 = (float) (h * (1d - MathUtility.clamp(animation_factor, 0, 1.0025f)));
|
| 111 |
|
| 112 | float x3 = x;
|
| 113 | float y3 = y + h2;
|
| 114 | float x4 = x1;
|
| 115 | float y4 = y1 - h2;
|
| 116 |
|
| 117 | if (x4 < x3) x4 = x3;
|
| 118 | if (y4 < y3) y4 = y3;
|
| 119 | addWindow(stack, new Rectangle(x3, y3, x4, y4));
|
| 120 | }
|
| 121 |
|
| 122 | public static void horizontalGradient(Object matrices, float x1, float y1, float x2, float y2, Color startColor, Color endColor) {
|
| 123 | Matrix4f matrix = GuiMatrix.positionMatrix(matrices);
|
| 124 | setupRender();
|
| 125 | RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
| 126 | BufferBuilder buffer = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
| 127 | buffer.addVertex(matrix, x1, y1, 0.0F).setColor(startColor.getRGB());
|
| 128 | buffer.addVertex(matrix, x1, y2, 0.0F).setColor(startColor.getRGB());
|
| 129 | buffer.addVertex(matrix, x2, y2, 0.0F).setColor(endColor.getRGB());
|
| 130 | buffer.addVertex(matrix, x2, y1, 0.0F).setColor(endColor.getRGB());
|
| 131 | BufferRenderer.drawWithGlobalProgram(buffer.buildOrThrow());
|
| 132 | endRender();
|
| 133 | }
|
| 134 |
|
| 135 | public static void verticalGradient(Object matrices, float left, float top, float right, float bottom, Color startColor, Color endColor) {
|
| 136 | Matrix4f matrix = GuiMatrix.positionMatrix(matrices);
|
| 137 | setupRender();
|
| 138 | RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
| 139 | BufferBuilder buffer = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
| 140 | buffer.addVertex(matrix, left, top, 0.0F).setColor(startColor.getRGB());
|
| 141 | buffer.addVertex(matrix, left, bottom, 0.0F).setColor(endColor.getRGB());
|
| 142 | buffer.addVertex(matrix, right, bottom, 0.0F).setColor(endColor.getRGB());
|
| 143 | buffer.addVertex(matrix, right, top, 0.0F).setColor(startColor.getRGB());
|
| 144 | BufferRenderer.drawWithGlobalProgram(buffer.buildOrThrow());
|
| 145 | endRender();
|
| 146 | }
|
| 147 |
|
| 148 | public static void drawRect(Object matrices, float x, float y, float width, float height, Color c) {
|
| 149 | Matrix4f matrix = GuiMatrix.positionMatrix(matrices);
|
| 150 | setupRender();
|
| 151 | RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
| 152 | BufferBuilder buffer = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
| 153 | buffer.addVertex(matrix, x, y + height, 0.0F).setColor(c.getRGB());
|
| 154 | buffer.addVertex(matrix, x + width, y + height, 0.0F).setColor(c.getRGB());
|
| 155 | buffer.addVertex(matrix, x + width, y, 0.0F).setColor(c.getRGB());
|
| 156 | buffer.addVertex(matrix, x, y, 0.0F).setColor(c.getRGB());
|
| 157 | BufferRenderer.drawWithGlobalProgram(buffer.buildOrThrow());
|
| 158 | endRender();
|
| 159 | }
|
| 160 |
|
| 161 | public static void drawRectWithOutline(Object matrices, float x, float y, float width, float height, Color c, Color c2) {
|
| 162 | Matrix4f matrix = GuiMatrix.positionMatrix(matrices);
|
| 163 | setupRender();
|
| 164 | RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
| 165 | BufferBuilder buffer = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
| 166 | buffer.addVertex(matrix, x, y + height, 0.0F).setColor(c.getRGB());
|
| 167 | buffer.addVertex(matrix, x + width, y + height, 0.0F).setColor(c.getRGB());
|
| 168 | buffer.addVertex(matrix, x + width, y, 0.0F).setColor(c.getRGB());
|
| 169 | buffer.addVertex(matrix, x, y, 0.0F).setColor(c.getRGB());
|
| 170 | BufferRenderer.drawWithGlobalProgram(buffer.buildOrThrow());
|
| 171 |
|
| 172 | buffer = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR);
|
| 173 | buffer.addVertex(matrix, x, y + height, 0.0F).setColor(c2.getRGB());
|
| 174 | buffer.addVertex(matrix, x + width, y + height, 0.0F).setColor(c2.getRGB());
|
| 175 | buffer.addVertex(matrix, x + width, y, 0.0F).setColor(c2.getRGB());
|
| 176 | buffer.addVertex(matrix, x, y, 0.0F).setColor(c2.getRGB());
|
| 177 | buffer.addVertex(matrix, x, y + height, 0.0F).setColor(c2.getRGB());
|
| 178 | BufferRenderer.drawWithGlobalProgram(buffer.buildOrThrow());
|
| 179 | endRender();
|
| 180 | }
|
| 181 |
|
| 182 | public static void drawRectDumbWay(Object matrices, float x, float y, float x1, float y1, Color c1) {
|
| 183 | Matrix4f matrix = GuiMatrix.positionMatrix(matrices);
|
| 184 | setupRender();
|
| 185 | RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
| 186 | BufferBuilder buffer = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
| 187 | buffer.addVertex(matrix, x, y1, 0.0F).setColor(c1.getRGB());
|
| 188 | buffer.addVertex(matrix, x1, y1, 0.0F).setColor(c1.getRGB());
|
| 189 | buffer.addVertex(matrix, x1, y, 0.0F).setColor(c1.getRGB());
|
| 190 | buffer.addVertex(matrix, x, y, 0.0F).setColor(c1.getRGB());
|
| 191 | BufferRenderer.drawWithGlobalProgram(buffer.buildOrThrow());
|
| 192 | endRender();
|
| 193 | }
|
| 194 |
|
| 195 | public static void setRectPoints(BufferBuilder bufferBuilder, Matrix4f matrix, float x, float y, float x1, float y1, Color c1, Color c2, Color c3, Color c4) {
|
| 196 | bufferBuilder.addVertex(matrix, x, y1, 0.0F).setColor(c1.getRGB());
|
| 197 | bufferBuilder.addVertex(matrix, x1, y1, 0.0F).setColor(c2.getRGB());
|
| 198 | bufferBuilder.addVertex(matrix, x1, y, 0.0F).setColor(c3.getRGB());
|
| 199 | bufferBuilder.addVertex(matrix, x, y, 0.0F).setColor(c4.getRGB());
|
| 200 | }
|
| 201 |
|
| 202 | public static boolean isHovered(double mouseX, double mouseY, double x, double y, double width, double height) {
|
| 203 | return mouseX >= x && mouseX - width <= x && mouseY >= y && mouseY - height <= y;
|
| 204 | }
|
| 205 |
|
| 206 | public static void drawBlurredShadow(Object matrices, float x, float y, float width, float height, int blurRadius, Color color) {
|
| 207 | if (!HudEditor.glow.getValue()) return;
|
| 208 | width = width + blurRadius * 2;
|
| 209 | height = height + blurRadius * 2;
|
| 210 | x = x - blurRadius;
|
| 211 | y = y - blurRadius;
|
| 212 |
|
| 213 | int identifier = (int) (width * height + width * blurRadius);
|
| 214 | if (shadowCache.containsKey(identifier)) {
|
| 215 | shadowCache.get(identifier).bind();
|
| 216 | } else {
|
| 217 | BufferedImage original = new BufferedImage((int) width, (int) height, BufferedImage.TYPE_INT_ARGB);
|
| 218 | Graphics g = original.getGraphics();
|
| 219 | g.setColor(new Color(-1));
|
| 220 | g.fillRect(blurRadius, blurRadius, (int) (width - blurRadius * 2), (int) (height - blurRadius * 2));
|
| 221 | g.dispose();
|
| 222 | GaussianFilter op = new GaussianFilter(blurRadius);
|
| 223 | BufferedImage blurred = op.filter(original, null);
|
| 224 | shadowCache.put(identifier, new BlurredShadow(blurred));
|
| 225 | return;
|
| 226 | }
|
| 227 |
|
| 228 | setupRender();
|
| 229 | RenderSystem.setShaderColor(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f);
|
| 230 | renderTexture(matrices, x, y, width, height, 0, 0, width, height, width, height);
|
| 231 | endRender();
|
| 232 | }
|
| 233 |
|
| 234 | public static void drawGradientBlurredShadow(Object matrices, float x, float y, float width, float height, int blurRadius, Color color1, Color color2, Color color3, Color color4) {
|
| 235 | if (!HudEditor.glow.getValue()) return;
|
| 236 | width = width + blurRadius * 2;
|
| 237 | height = height + blurRadius * 2;
|
| 238 | x = x - blurRadius;
|
| 239 | y = y - blurRadius;
|
| 240 |
|
| 241 | int identifier = (int) (width * height + width * blurRadius);
|
| 242 | if (shadowCache.containsKey(identifier)) {
|
| 243 | shadowCache.get(identifier).bind();
|
| 244 | } else {
|
| 245 | BufferedImage original = new BufferedImage((int) width, (int) height, BufferedImage.TYPE_INT_ARGB);
|
| 246 | Graphics g = original.getGraphics();
|
| 247 | g.setColor(new Color(-1));
|
| 248 | g.fillRect(blurRadius, blurRadius, (int) (width - blurRadius * 2), (int) (height - blurRadius * 2));
|
| 249 | g.dispose();
|
| 250 | GaussianFilter op = new GaussianFilter(blurRadius);
|
| 251 | BufferedImage blurred = op.filter(original, null);
|
| 252 | shadowCache.put(identifier, new BlurredShadow(blurred));
|
| 253 | return;
|
| 254 | }
|
| 255 |
|
| 256 | setupRender();
|
| 257 | renderGradientTexture(matrices, x, y, width, height, 0, 0, width, height, width, height, color1, color2, color3, color4);
|
| 258 | endRender();
|
| 259 | }
|
| 260 |
|
| 261 | public static void drawGradientBlurredShadow1(Object matrices, float x, float y, float width, float height, int blurRadius, Color color1, Color color2, Color color3, Color color4) {
|
| 262 | if (!HudEditor.glow.getValue()) return;
|
| 263 | width = width + blurRadius * 2;
|
| 264 | height = height + blurRadius * 2;
|
| 265 | x = x - blurRadius;
|
| 266 | y = y - blurRadius;
|
| 267 |
|
| 268 | int identifier = (int) (width * height + width * blurRadius);
|
| 269 | if (shadowCache1.containsKey(identifier)) {
|
| 270 | shadowCache1.get(identifier).bind();
|
| 271 | } else {
|
| 272 | BufferedImage original = new BufferedImage((int) width, (int) height, BufferedImage.TYPE_INT_ARGB);
|
| 273 | Graphics g = original.getGraphics();
|
| 274 | g.setColor(new Color(-1));
|
| 275 | g.fillRect(blurRadius, blurRadius, (int) (width - blurRadius * 2), (int) (height - blurRadius * 2));
|
| 276 | g.dispose();
|
| 277 | BufferedImage blurred = new GaussianFilter(blurRadius).filter(original, null);
|
| 278 |
|
| 279 | BufferedImage black = new BufferedImage((int) width + blurRadius * 2, (int) height + blurRadius * 2, BufferedImage.TYPE_INT_ARGB);
|
| 280 | Graphics g2 = black.getGraphics();
|
| 281 | g2.setColor(new Color(0x000000));
|
| 282 | g2.fillRect(0, 0, (int) width + blurRadius * 2, (int) height + blurRadius * 2);
|
| 283 | g2.dispose();
|
| 284 |
|
| 285 | BufferedImage combined = new BufferedImage((int) width, (int) height, BufferedImage.TYPE_INT_ARGB);
|
| 286 | Graphics g1 = combined.getGraphics();
|
| 287 | g1.drawImage(black, -blurRadius, -blurRadius, null);
|
| 288 | g1.drawImage(blurred, 0, 0, null);
|
| 289 | g1.dispose();
|
| 290 |
|
| 291 | shadowCache1.put(identifier, new BlurredShadow(combined));
|
| 292 | return;
|
| 293 | }
|
| 294 |
|
| 295 | setupRender();
|
| 296 | RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE);
|
| 297 | renderGradientTexture(matrices, x, y, width, height, 0, 0, width, height, width, height, color1, color2, color3, color4);
|
| 298 | endRender();
|
| 299 | }
|
| 300 |
|
| 301 | public static void registerBufferedImageTexture(Texture i, BufferedImage bi) {
|
| 302 | try {
|
| 303 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
| 304 | ImageIO.write(bi, "png", baos);
|
| 305 | byte[] bytes = baos.toByteArray();
|
| 306 | registerTexture(i, bytes);
|
| 307 | } catch (Exception ignored) {
|
| 308 | }
|
| 309 | }
|
| 310 |
|
| 311 | private static void registerTexture(Texture i, byte[] content) {
|
| 312 | try {
|
| 313 | ByteBuffer data = BufferUtils.createByteBuffer(content.length).put(content);
|
| 314 | data.flip();
|
| 315 | DynamicTexture tex = new DynamicTexture(() -> i.getId().toString(), NativeImage.read(data));
|
| 316 | mc.execute(() -> mc.getTextureManager().register(i.getId(), tex));
|
| 317 | } catch (Exception ignored) {
|
| 318 | }
|
| 319 | }
|
| 320 |
|
| 321 | public static void renderTexture(Object matrices, double x0, double y0, double width, double height, float u, float v, double regionWidth, double regionHeight, double textureWidth, double textureHeight) {
|
| 322 | double x1 = x0 + width;
|
| 323 | double y1 = y0 + height;
|
| 324 | double z = 0;
|
| 325 | Matrix4f matrix = GuiMatrix.positionMatrix(matrices);
|
| 326 | RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX);
|
| 327 | BufferBuilder buffer = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION_TEX);
|
| 328 | buffer.addVertex(matrix, (float) x0, (float) y1, (float) z).setUv((u) / (float) textureWidth, (v + (float) regionHeight) / (float) textureHeight);
|
| 329 | buffer.addVertex(matrix, (float) x1, (float) y1, (float) z).setUv((u + (float) regionWidth) / (float) textureWidth, (v + (float) regionHeight) / (float) textureHeight);
|
| 330 | buffer.addVertex(matrix, (float) x1, (float) y0, (float) z).setUv((u + (float) regionWidth) / (float) textureWidth, (v) / (float) textureHeight);
|
| 331 | buffer.addVertex(matrix, (float) x0, (float) y0, (float) z).setUv((u) / (float) textureWidth, (v + 0.0F) / (float) textureHeight);
|
| 332 | BufferRenderer.drawWithGlobalProgram(buffer.buildOrThrow());
|
| 333 | }
|
| 334 |
|
| 335 | public static void renderGradientTexture(Object matrices, double x0, double y0, double width, double height, float u, float v, double regionWidth, double regionHeight, double textureWidth, double textureHeight, Color c1, Color c2, Color c3, Color c4) {
|
| 336 | RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX_COLOR);
|
| 337 | BufferBuilder buffer = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
| 338 | renderGradientTextureInternal(buffer, matrices, x0, y0, width, height, u, v, regionWidth, regionHeight, textureWidth, textureHeight, c1, c2, c3, c4);
|
| 339 | BufferRenderer.drawWithGlobalProgram(buffer.buildOrThrow());
|
| 340 | }
|
| 341 |
|
| 342 | public static void renderGradientTextureInternal(BufferBuilder buff, Object matrices, double x0, double y0, double width, double height, float u, float v, double regionWidth, double regionHeight, double textureWidth, double textureHeight, Color c1, Color c2, Color c3, Color c4) {
|
| 343 | double x1 = x0 + width;
|
| 344 | double y1 = y0 + height;
|
| 345 | double z = 0;
|
| 346 | Matrix4f matrix = GuiMatrix.positionMatrix(matrices);
|
| 347 | buff.addVertex(matrix, (float) x0, (float) y1, (float) z).setUv((u) / (float) textureWidth, (v + (float) regionHeight) / (float) textureHeight).setColor(c1.getRGB());
|
| 348 | buff.addVertex(matrix, (float) x1, (float) y1, (float) z).setUv((u + (float) regionWidth) / (float) textureWidth, (v + (float) regionHeight) / (float) textureHeight).setColor(c2.getRGB());
|
| 349 | buff.addVertex(matrix, (float) x1, (float) y0, (float) z).setUv((u + (float) regionWidth) / (float) textureWidth, (v) / (float) textureHeight).setColor(c3.getRGB());
|
| 350 | buff.addVertex(matrix, (float) x0, (float) y0, (float) z).setUv((u) / (float) textureWidth, (v + 0.0F) / (float) textureHeight).setColor(c4.getRGB());
|
| 351 | }
|
| 352 |
|
| 353 | public static void renderRoundedGradientRect(Object matrices, Color color1, Color color2, Color color3, Color color4, float x, float y, float width, float height, float Radius) {
|
| 354 | Matrix4f matrix = GuiMatrix.positionMatrix(matrices);
|
| 355 | RenderSystem.colorMask(false, false, false, true);
|
| 356 | RenderSystem.clearColor(0.0F, 0.0F, 0.0F, 0.0F);
|
| 357 | RenderSystem.clear(GL40C.GL_COLOR_BUFFER_BIT);
|
| 358 | RenderSystem.colorMask(true, true, true, true);
|
| 359 |
|
| 360 | Render2DEngine.drawRound(matrices, x, y, width, height, Radius, color1);
|
| 361 | setupRender();
|
| 362 | RenderSystem.blendFunc(GL40C.GL_DST_ALPHA, GL40C.GL_ONE_MINUS_DST_ALPHA);
|
| 363 | BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR);
|
| 364 | bufferBuilder.addVertex(matrix, x, y + height, 0.0F).setColor(color1.getRGB());
|
| 365 | bufferBuilder.addVertex(matrix, x + width, y + height, 0.0F).setColor(color2.getRGB());
|
| 366 | bufferBuilder.addVertex(matrix, x + width, y, 0.0F).setColor(color3.getRGB());
|
| 367 | bufferBuilder.addVertex(matrix, x, y, 0.0F).setColor(color4.getRGB());
|
| 368 | BufferRenderer.drawWithGlobalProgram(bufferBuilder.buildOrThrow());
|
| 369 | endRender();
|
| 370 | }
|
| 371 |
|
| 372 | public static void drawRound(Object matrices, float x, float y, float width, float height, float radius, Color color) {
|
| 373 | renderRoundedQuad(matrices, color, x, y, width + x, height + y, radius, 4);
|
| 374 | }
|
| 375 |
|
| 376 | public static void renderRoundedQuad(Object matrices, Color c, double fromX, double fromY, double toX, double toY, double radius, double samples) {
|
| 377 | setupRender();
|
| 378 | RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
| 379 | renderRoundedQuadInternal(GuiMatrix.positionMatrix(matrices), c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f, c.getAlpha() / 255f, fromX, fromY, toX, toY, radius, samples);
|
| 380 | endRender();
|
| 381 | }
|
| 382 |
|
| 383 | public static void renderRoundedQuad2(Object matrices, Color c, Color c2, Color c3, Color c4, double fromX, double fromY, double toX, double toY, double radius) {
|
| 384 | setupRender();
|
| 385 | RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
| 386 | renderRoundedQuadInternal2(GuiMatrix.positionMatrix(matrices), c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f, c.getAlpha() / 255f, c2.getRed() / 255f, c2.getGreen() / 255f, c2.getBlue() / 255f, c2.getAlpha() / 255f, c3.getRed() / 255f, c3.getGreen() / 255f, c3.getBlue() / 255f, c3.getAlpha() / 255f, c4.getRed() / 255f, c4.getGreen() / 255f, c4.getBlue() / 255f, c4.getAlpha() / 255f, fromX, fromY, toX, toY, radius);
|
| 387 | endRender();
|
| 388 | }
|
| 389 |
|
| 390 | public static void renderRoundedQuadInternal(Matrix4f matrix, float cr, float cg, float cb, float ca, double fromX, double fromY, double toX, double toY, double radius, double samples) {
|
| 391 | BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR);
|
| 392 | double[][] map = new double[][]{new double[]{toX - radius, toY - radius, radius}, new double[]{toX - radius, fromY + radius, radius}, new double[]{fromX + radius, fromY + radius, radius}, new double[]{fromX + radius, toY - radius, radius}};
|
| 393 | for (int i = 0; i < 4; i++) {
|
| 394 | double[] current = map[i];
|
| 395 | double rad = current[2];
|
| 396 | for (double r = i * 90d; r < (360 / 4d + i * 90d); r += (90 / samples)) {
|
| 397 | float rad1 = (float) Math.toRadians(r);
|
| 398 | float sin = (float) (Math.sin(rad1) * rad);
|
| 399 | float cos = (float) (Math.cos(rad1) * rad);
|
| 400 | bufferBuilder.addVertex(matrix, (float) current[0] + sin, (float) current[1] + cos, 0.0F).setColor(cr, cg, cb, ca);
|
| 401 | }
|
| 402 | float rad1 = (float) Math.toRadians((360 / 4d + i * 90d));
|
| 403 | float sin = (float) (Math.sin(rad1) * rad);
|
| 404 | float cos = (float) (Math.cos(rad1) * rad);
|
| 405 | bufferBuilder.addVertex(matrix, (float) current[0] + sin, (float) current[1] + cos, 0.0F).setColor(cr, cg, cb, ca);
|
| 406 | }
|
| 407 | BufferRenderer.drawWithGlobalProgram(bufferBuilder.buildOrThrow());
|
| 408 | }
|
| 409 |
|
| 410 | public static void renderRoundedQuadInternal2(Matrix4f matrix, float cr, float cg, float cb, float ca, float cr1, float cg1, float cb1, float ca1, float cr2, float cg2, float cb2, float ca2, float cr3, float cg3, float cb3, float ca3, double fromX, double fromY, double toX, double toY, double radC1) {
|
| 411 | BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR);
|
| 412 |
|
| 413 | double[][] map = new double[][]{new double[]{toX - radC1, toY - radC1, radC1}, new double[]{toX - radC1, fromY + radC1, radC1}, new double[]{fromX + radC1, fromY + radC1, radC1}, new double[]{fromX + radC1, toY - radC1, radC1}};
|
| 414 |
|
| 415 | for (int i = 0; i < 4; i++) {
|
| 416 | double[] current = map[i];
|
| 417 | double rad = current[2];
|
| 418 | for (double r = i * 90; r < (90 + i * 90); r += 10) {
|
| 419 | float rad1 = (float) Math.toRadians(r);
|
| 420 | float sin = (float) (Math.sin(rad1) * rad);
|
| 421 | float cos = (float) (Math.cos(rad1) * rad);
|
| 422 | switch (i) {
|
| 423 | case 0 ->
|
| 424 | bufferBuilder.addVertex(matrix, (float) current[0] + sin, (float) current[1] + cos, 0.0F).setColor(cr1, cg1, cb1, ca1);
|
| 425 | case 1 ->
|
| 426 | bufferBuilder.addVertex(matrix, (float) current[0] + sin, (float) current[1] + cos, 0.0F).setColor(cr, cg, cb, ca);
|
| 427 | case 2 ->
|
| 428 | bufferBuilder.addVertex(matrix, (float) current[0] + sin, (float) current[1] + cos, 0.0F).setColor(cr2, cg2, cb2, ca2);
|
| 429 | default ->
|
| 430 | bufferBuilder.addVertex(matrix, (float) current[0] + sin, (float) current[1] + cos, 0.0F).setColor(cr3, cg3, cb3, ca3);
|
| 431 | }
|
| 432 | }
|
| 433 | }
|
| 434 | BufferRenderer.drawWithGlobalProgram(bufferBuilder.buildOrThrow());
|
| 435 | }
|
| 436 |
|
| 437 | public static void draw2DGradientRect(Object matrices, float left, float top, float right, float bottom, Color leftBottomColor, Color leftTopColor, Color rightBottomColor, Color rightTopColor) {
|
| 438 | Matrix4f matrix = GuiMatrix.positionMatrix(matrices);
|
| 439 | setupRender();
|
| 440 | RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
| 441 | BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
| 442 | bufferBuilder.addVertex(matrix, right, top, 0.0F).setColor(rightTopColor.getRGB());
|
| 443 | bufferBuilder.addVertex(matrix, left, top, 0.0F).setColor(leftTopColor.getRGB());
|
| 444 | bufferBuilder.addVertex(matrix, left, bottom, 0.0F).setColor(leftBottomColor.getRGB());
|
| 445 | bufferBuilder.addVertex(matrix, right, bottom, 0.0F).setColor(rightBottomColor.getRGB());
|
| 446 | BufferRenderer.drawWithGlobalProgram(bufferBuilder.buildOrThrow());
|
| 447 | endRender();
|
| 448 | }
|
| 449 |
|
| 450 | public static void setupRender() {
|
| 451 | RenderSystem.enableBlend();
|
| 452 | RenderSystem.defaultBlendFunc();
|
| 453 | RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
|
| 454 | }
|
| 455 |
|
| 456 | public static void drawTracerPointer(Object matrices, float x, float y, float size, float tracerWidth, float downHeight, boolean down, boolean glow, int color) {
|
| 457 | switch (HudEditor.arrowsStyle.getValue()) {
|
| 458 | case Default -> drawDefaultArrow(matrices, x, y, size, tracerWidth, downHeight, down, glow, color);
|
| 459 | case New -> drawNewArrow(matrices, x, y, size + 8, new Color(color));
|
| 460 | }
|
| 461 | }
|
| 462 |
|
| 463 | public static void drawNewArrow(Object matrices, float x, float y, float size, Color color) {
|
| 464 | RenderSystem.setShaderTexture(0, TextureStorage.arrow);
|
| 465 | setupRender();
|
| 466 | RenderSystem.setShaderColor(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f);
|
| 467 | RenderSystem.disableDepthTest();
|
| 468 | RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE);
|
| 469 | Matrix4f matrix = GuiMatrix.positionMatrix(matrices);
|
| 470 | RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX);
|
| 471 | BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION_TEX);
|
| 472 | bufferBuilder.addVertex(matrix, x - (size / 2f), y + size, 0).setUv(0f, 1f);
|
| 473 | bufferBuilder.addVertex(matrix, x + size / 2f, y + size, 0).setUv(1f, 1f);
|
| 474 | bufferBuilder.addVertex(matrix, x + size / 2f, y, 0).setUv(1f, 0);
|
| 475 | bufferBuilder.addVertex(matrix, x - (size / 2f), y, 0).setUv(0, 0);
|
| 476 | BufferRenderer.drawWithGlobalProgram(bufferBuilder.buildOrThrow());
|
| 477 | RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
|
| 478 | RenderSystem.defaultBlendFunc();
|
| 479 | RenderSystem.enableDepthTest();
|
| 480 | endRender();
|
| 481 | }
|
| 482 |
|
| 483 | public static void drawDefaultArrow(Object matrices, float x, float y, float size, float tracerWidth, float downHeight, boolean down, boolean glow, int color) {
|
| 484 | if (glow)
|
| 485 | Render2DEngine.drawBlurredShadow(matrices, x - size * tracerWidth, y, (x + size * tracerWidth) - (x - size * tracerWidth), size, 10, Render2DEngine.injectAlpha(new Color(color), 140));
|
| 486 |
|
| 487 | GuiMatrix.push(matrices);
|
| 488 | setupRender();
|
| 489 | Matrix4f matrix = GuiMatrix.positionMatrix(matrices);
|
| 490 |
|
| 491 | RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
| 492 | BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
| 493 | bufferBuilder.addVertex(matrix, x, y, 0.0F).setColor(color);
|
| 494 | bufferBuilder.addVertex(matrix, (x - size * tracerWidth), (y + size), 0.0F).setColor(color);
|
| 495 | bufferBuilder.addVertex(matrix, x, (y + size - downHeight), 0.0F).setColor(color);
|
| 496 | bufferBuilder.addVertex(matrix, x, y, 0.0F).setColor(color);
|
| 497 | color = Render2DEngine.darker(new Color(color), 0.8f).getRGB();
|
| 498 | bufferBuilder.addVertex(matrix, x, y, 0.0F).setColor(color);
|
| 499 | bufferBuilder.addVertex(matrix, x, (y + size - downHeight), 0.0F).setColor(color);
|
| 500 | bufferBuilder.addVertex(matrix, (x + size * tracerWidth), (y + size), 0.0F).setColor(color);
|
| 501 | bufferBuilder.addVertex(matrix, x, y, 0.0F).setColor(color);
|
| 502 |
|
| 503 | if (down) {
|
| 504 | color = Render2DEngine.darker(new Color(color), 0.6f).getRGB();
|
| 505 | bufferBuilder.addVertex(matrix, (x - size * tracerWidth), (y + size), 0.0F).setColor(color);
|
| 506 | bufferBuilder.addVertex(matrix, (x + size * tracerWidth), (y + size), 0.0F).setColor(color);
|
| 507 | bufferBuilder.addVertex(matrix, x, (y + size - downHeight), 0.0F).setColor(color);
|
| 508 | bufferBuilder.addVertex(matrix, (x - size * tracerWidth), (y + size), 0.0F).setColor(color);
|
| 509 | }
|
| 510 |
|
| 511 | BufferRenderer.drawWithGlobalProgram(bufferBuilder.buildOrThrow());
|
| 512 | endRender();
|
| 513 | GuiMatrix.pop(matrices);
|
| 514 | }
|
| 515 |
|
| 516 |
|
| 517 | public static void endRender() {
|
| 518 | RenderSystem.defaultBlendFunc();
|
| 519 | RenderSystem.disableBlend();
|
| 520 | RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
|
| 521 | }
|
| 522 |
|
| 523 | public static void drawGradientRound(Object ms, float v, float v1, float i, float i1, float v2, Color darker, Color darker1, Color darker2, Color darker3) {
|
| 524 | renderRoundedQuad2(ms, darker, darker1, darker2, darker3, v, v1, v + i, v1 + i1, v2);
|
| 525 | }
|
| 526 |
|
| 527 | public static float scrollAnimate(float endPoint, float current, float speed) {
|
| 528 | boolean shouldContinueAnimation = endPoint > current;
|
| 529 | if (speed < 0.0f) {
|
| 530 | speed = 0.0f;
|
| 531 | } else if (speed > 1.0f) {
|
| 532 | speed = 1.0f;
|
| 533 | }
|
| 534 |
|
| 535 | float dif = Math.max(endPoint, current) - Math.min(endPoint, current);
|
| 536 | float factor = dif * speed;
|
| 537 | return current + (shouldContinueAnimation ? factor : -factor);
|
| 538 | }
|
| 539 |
|
| 540 | public static Color injectAlpha(final Color color, final int alpha) {
|
| 541 | return new Color(color.getRed(), color.getGreen(), color.getBlue(), Mth.clamp(alpha, 0, 255));
|
| 542 | }
|
| 543 |
|
| 544 | public static Color TwoColoreffect(Color cl1, Color cl2, double speed, double count) {
|
| 545 | int angle = (int) (((System.currentTimeMillis()) / speed + count) % 360);
|
| 546 | angle = (angle >= 180 ? 360 - angle : angle) * 2;
|
| 547 | return interpolateColorC(cl1, cl2, angle / 360f);
|
| 548 | }
|
| 549 |
|
| 550 | public static Color astolfo(boolean clickgui, int yOffset) {
|
| 551 | float speed = clickgui ? 35 * 100 : 30 * 100;
|
| 552 | float hue = (System.currentTimeMillis() % (int) speed) + yOffset;
|
| 553 | if (hue > speed) {
|
| 554 | hue -= speed;
|
| 555 | }
|
| 556 | hue /= speed;
|
| 557 | if (hue > 0.5F) {
|
| 558 | hue = 0.5F - (hue - 0.5F);
|
| 559 | }
|
| 560 | hue += 0.5F;
|
| 561 | return Color.getHSBColor(hue, 0.4F, 1F);
|
| 562 | }
|
| 563 |
|
| 564 | public static Color rainbow(int delay, float saturation, float brightness) {
|
| 565 | double rainbow = Math.ceil((System.currentTimeMillis() + delay) / 16f);
|
| 566 | rainbow %= 360;
|
| 567 | return Color.getHSBColor((float) (rainbow / 360), saturation, brightness);
|
| 568 | }
|
| 569 |
|
| 570 | public static Color skyRainbow(int speed, int index) {
|
| 571 | int angle = (int) ((System.currentTimeMillis() / speed + index) % 360);
|
| 572 | return Color.getHSBColor((double) ((float) ((angle %= 360) / 360.0)) < 0.5 ? -((float) (angle / 360.0)) : (float) (angle / 360.0), 0.5F, 1.0F);
|
| 573 | }
|
| 574 |
|
| 575 | public static Color fade(int speed, int index, Color color, float alpha) {
|
| 576 | float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
|
| 577 | int angle = (int) ((System.currentTimeMillis() / speed + index) % 360);
|
| 578 | angle = (angle > 180 ? 360 - angle : angle) + 180;
|
| 579 |
|
| 580 | Color colorHSB = new Color(Color.HSBtoRGB(hsb[0], hsb[1], angle / 360f));
|
| 581 |
|
| 582 | return new Color(colorHSB.getRed(), colorHSB.getGreen(), colorHSB.getBlue(), Math.max(0, Math.min(255, (int) (alpha * 255))));
|
| 583 | }
|
| 584 |
|
| 585 | public static Color getAnalogousColor(Color color) {
|
| 586 | float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
|
| 587 | float degree = 0.84f;
|
| 588 | float newHueSubtracted = hsb[0] - degree;
|
| 589 | return new Color(Color.HSBtoRGB(newHueSubtracted, hsb[1], hsb[2]));
|
| 590 | }
|
| 591 |
|
| 592 | public static Color applyOpacity(Color color, float opacity) {
|
| 593 | opacity = Math.min(1, Math.max(0, opacity));
|
| 594 | return new Color(color.getRed(), color.getGreen(), color.getBlue(), (int) (color.getAlpha() * opacity));
|
| 595 | }
|
| 596 |
|
| 597 | public static int applyOpacity(int color_int, float opacity) {
|
| 598 | opacity = Math.min(1, Math.max(0, opacity));
|
| 599 | Color color = new Color(color_int);
|
| 600 | return new Color(color.getRed(), color.getGreen(), color.getBlue(), (int) (color.getAlpha() * opacity)).getRGB();
|
| 601 | }
|
| 602 |
|
| 603 | public static Color darker(Color color, float factor) {
|
| 604 | return new Color(Math.max((int) (color.getRed() * factor), 0), Math.max((int) (color.getGreen() * factor), 0), Math.max((int) (color.getBlue() * factor), 0), color.getAlpha());
|
| 605 | }
|
| 606 |
|
| 607 | public static Color rainbow(int speed, int index, float saturation, float brightness, float opacity) {
|
| 608 | int angle = (int) ((System.currentTimeMillis() / speed + index) % 360);
|
| 609 | float hue = angle / 360f;
|
| 610 | Color color = new Color(Color.HSBtoRGB(hue, saturation, brightness));
|
| 611 | return new Color(color.getRed(), color.getGreen(), color.getBlue(), Math.max(0, Math.min(255, (int) (opacity * 255))));
|
| 612 | }
|
| 613 |
|
| 614 | public static Color interpolateColorsBackAndForth(int speed, int index, Color start, Color end, boolean trueColor) {
|
| 615 | int angle = (int) (((System.currentTimeMillis()) / speed + index) % 360);
|
| 616 | angle = (angle >= 180 ? 360 - angle : angle) * 2;
|
| 617 | return trueColor ? interpolateColorHue(start, end, angle / 360f) : interpolateColorC(start, end, angle / 360f);
|
| 618 | }
|
| 619 |
|
| 620 | public static Color interpolateColorC(Color color1, Color color2, float amount) {
|
| 621 | amount = Math.min(1, Math.max(0, amount));
|
| 622 | return new Color(interpolateInt(color1.getRed(), color2.getRed(), amount), interpolateInt(color1.getGreen(), color2.getGreen(), amount), interpolateInt(color1.getBlue(), color2.getBlue(), amount), interpolateInt(color1.getAlpha(), color2.getAlpha(), amount));
|
| 623 | }
|
| 624 |
|
| 625 | public static Color interpolateColorHue(Color color1, Color color2, float amount) {
|
| 626 | amount = Math.min(1, Math.max(0, amount));
|
| 627 |
|
| 628 | float[] color1HSB = Color.RGBtoHSB(color1.getRed(), color1.getGreen(), color1.getBlue(), null);
|
| 629 | float[] color2HSB = Color.RGBtoHSB(color2.getRed(), color2.getGreen(), color2.getBlue(), null);
|
| 630 |
|
| 631 | Color resultColor = Color.getHSBColor(interpolateFloat(color1HSB[0], color2HSB[0], amount), interpolateFloat(color1HSB[1], color2HSB[1], amount), interpolateFloat(color1HSB[2], color2HSB[2], amount));
|
| 632 |
|
| 633 | return new Color(resultColor.getRed(), resultColor.getGreen(), resultColor.getBlue(), interpolateInt(color1.getAlpha(), color2.getAlpha(), amount));
|
| 634 | }
|
| 635 |
|
| 636 | public static double interpolate(double oldValue, double newValue, double interpolationValue) {
|
| 637 | return (oldValue + (newValue - oldValue) * interpolationValue);
|
| 638 | }
|
| 639 |
|
| 640 | public static float interpolateFloat(float oldValue, float newValue, double interpolationValue) {
|
| 641 | return (float) interpolate(oldValue, newValue, (float) interpolationValue);
|
| 642 | }
|
| 643 |
|
| 644 | public static int interpolateInt(int oldValue, int newValue, double interpolationValue) {
|
| 645 | return (int) interpolate(oldValue, newValue, (float) interpolationValue);
|
| 646 | }
|
| 647 |
|
| 648 | public static void drawArc(Object matrices, float x, float y, float width, float height, float radius, float thickness, float start, float end, Color c1, Color c2) {
|
| 649 | BufferBuilder bb = preShaderDraw(matrices, x - width / 2f, y - height / 2f, x + width / 2f, y + height / 2f);
|
| 650 | ARC_PROGRAM.setParameters(x, y, width, height, radius, thickness, start, end, c1, c2);
|
| 651 | ARC_PROGRAM.use();
|
| 652 | BufferRenderer.drawWithGlobalProgram(bb.buildOrThrow());
|
| 653 | endRender();
|
| 654 | }
|
| 655 |
|
| 656 | public static void drawRect(Object matrices, float x, float y, float width, float height, float radius, float alpha) {
|
| 657 | BufferBuilder bb = preShaderDraw(matrices, x - 10, y - 10, width + 20, height + 20);
|
| 658 | RECTANGLE_SHADER.setParameters(x, y, width, height, radius, alpha);
|
| 659 | RECTANGLE_SHADER.use();
|
| 660 | BufferRenderer.drawWithGlobalProgram(bb.buildOrThrow());
|
| 661 | endRender();
|
| 662 | }
|
| 663 |
|
| 664 | public static void drawRect(Object matrices, float x, float y, float width, float height, float radius, float alpha, Color c1, Color c2, Color c3, Color c4) {
|
| 665 | BufferBuilder bb = preShaderDraw(matrices, x - 10, y - 10, width + 20, height + 20);
|
| 666 | RECTANGLE_SHADER.setParameters(x, y, width, height, radius, alpha, c1, c2, c3, c4);
|
| 667 | RECTANGLE_SHADER.use();
|
| 668 | BufferRenderer.drawWithGlobalProgram(bb.buildOrThrow());
|
| 669 | endRender();
|
| 670 | }
|
| 671 |
|
| 672 | public static void drawHudBase(Object matrices, float x, float y, float width, float height, float radius) {
|
| 673 | if (HudEditor.hudStyle.is(HudEditor.HudStyle.Blurry)) {
|
| 674 | drawRoundedBlur(matrices, x, y, width, height, radius, HudEditor.blurColor.getValue().getColorObject());
|
| 675 | } else {
|
| 676 | BufferBuilder bb = preShaderDraw(matrices, x - 10, y - 10, width + 20, height + 20);
|
| 677 | HUD_SHADER.setParameters(x, y, width, height, radius, HudEditor.alpha.getValue(), HudEditor.alpha.getValue());
|
| 678 | HUD_SHADER.use();
|
| 679 | BufferRenderer.drawWithGlobalProgram(bb.buildOrThrow());
|
| 680 | endRender();
|
| 681 | }
|
| 682 | }
|
| 683 |
|
| 684 | public static void drawHudBase2(Object matrices, float x, float y, float width, float height, float radius, float blurStrenth, float blurOpacity, float animationFactor) {
|
| 685 | if (HudEditor.hudStyle.is(HudEditor.HudStyle.Blurry)) {
|
| 686 | blurStrenth *= animationFactor;
|
| 687 | blurOpacity = (float) Render2DEngine.interpolate(1f, blurOpacity, animationFactor);
|
| 688 | Color c = Render2DEngine.interpolateColorC(Color.BLACK, HudEditor.blurColor.getValue().getColorObject(), animationFactor);
|
| 689 | drawRoundedBlur(matrices, x, y, width, height, radius, c, blurStrenth, blurOpacity);
|
| 690 | } else {
|
| 691 | BufferBuilder bb = preShaderDraw(matrices, x - 10, y - 10, width + 20, height + 20);
|
| 692 | HUD_SHADER.setParameters(x, y, width, height, radius, HudEditor.alpha.getValue(), HudEditor.alpha.getValue());
|
| 693 | HUD_SHADER.use();
|
| 694 | BufferRenderer.drawWithGlobalProgram(bb.buildOrThrow());
|
| 695 | endRender();
|
| 696 | }
|
| 697 | }
|
| 698 |
|
| 699 | public static void drawHudBase(Object matrices, float x, float y, float width, float height, float radius, boolean hud) {
|
| 700 | BufferBuilder bb = preShaderDraw(matrices, x - 10, y - 10, width + 20, height + 20);
|
| 701 | HUD_SHADER.setParameters(x, y, width, height, radius, HudEditor.alpha.getValue(), HudEditor.alpha.getValue());
|
| 702 | HUD_SHADER.use();
|
| 703 | BufferRenderer.drawWithGlobalProgram(bb.buildOrThrow());
|
| 704 | endRender();
|
| 705 | }
|
| 706 |
|
| 707 | public static void drawRoundedBlur(Object matrices, float x, float y, float width, float height, float radius, Color c1) {
|
| 708 | drawRoundedBlur(matrices, x, y, width, height, radius, c1, HudEditor.blurStrength.getValue(), HudEditor.blurOpacity.getValue());
|
| 709 | }
|
| 710 |
|
| 711 | public static void drawRoundedBlur(Object matrices, float x, float y, float width, float height, float radius, Color c1, float blurStrenth, float blurOpacity) {
|
| 712 | BufferBuilder bb = preShaderDraw(matrices, x - 10, y - 10, width + 20, height + 20);
|
| 713 | BLUR_PROGRAM.setParameters(x, y, width, height, radius, c1, blurStrenth, blurOpacity);
|
| 714 | BLUR_PROGRAM.use();
|
| 715 | BufferRenderer.drawWithGlobalProgram(bb.buildOrThrow());
|
| 716 | endRender();
|
| 717 | }
|
| 718 |
|
| 719 | public static void drawHudBase(Object matrices, float x, float y, float width, float height, float radius, float alpha) {
|
| 720 | BufferBuilder bb = preShaderDraw(matrices, x - 10, y - 10, width + 20, height + 20);
|
| 721 | HUD_SHADER.setParameters(x, y, width, height, radius, alpha, HudEditor.alpha.getValue());
|
| 722 | HUD_SHADER.use();
|
| 723 | BufferRenderer.drawWithGlobalProgram(bb.buildOrThrow());
|
| 724 | endRender();
|
| 725 | }
|
| 726 |
|
| 727 | public static void drawGuiBase(Object matrices, float x, float y, float width, float height, float radius, float opacity) {
|
| 728 | BufferBuilder bb = preShaderDraw(matrices, x - 10, y - 10, width + 20, height + 20);
|
| 729 | HUD_SHADER.setParameters(x, y, width, height, radius, 1f, opacity);
|
| 730 | HUD_SHADER.use();
|
| 731 | BufferRenderer.drawWithGlobalProgram(bb.buildOrThrow());
|
| 732 | endRender();
|
| 733 | }
|
| 734 |
|
| 735 | public static void drawMainMenuShader(Object matrices, float x, float y, float width, float height) {
|
| 736 | BufferBuilder bb = preShaderDraw(matrices, x, y, width, height);
|
| 737 | MAIN_MENU_PROGRAM.setParameters(x, y, width, height);
|
| 738 | MAIN_MENU_PROGRAM.use();
|
| 739 | BufferRenderer.drawWithGlobalProgram(bb.buildOrThrow());
|
| 740 | endRender();
|
| 741 | }
|
| 742 |
|
| 743 | public static BufferBuilder preShaderDraw(Object matrices, float x, float y, float width, float height) {
|
| 744 | setupRender();
|
| 745 | Matrix4f matrix = GuiMatrix.positionMatrix(matrices);
|
| 746 | BufferBuilder buffer = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION);
|
| 747 | setRectanglePoints(buffer, matrix, x, y, x + width, y + height);
|
| 748 | return buffer;
|
| 749 | }
|
| 750 |
|
| 751 | public static void setRectanglePoints(BufferBuilder buffer, Matrix4f matrix, float x, float y, float x1, float y1) {
|
| 752 | buffer.addVertex(matrix, x, y, 0);
|
| 753 | buffer.addVertex(matrix, x, y1, 0);
|
| 754 | buffer.addVertex(matrix, x1, y1, 0);
|
| 755 | buffer.addVertex(matrix, x1, y, 0);
|
| 756 | }
|
| 757 |
|
| 758 | public static void drawOrbiz(Object matrices, float z, final double r, Color c) {
|
| 759 | Matrix4f matrix = GuiMatrix.positionMatrix(matrices);
|
| 760 | setupRender();
|
| 761 | RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
| 762 | BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR);
|
| 763 | for (int i = 0; i <= 20; i++) {
|
| 764 | final float x2 = (float) (Math.sin(((i * 56.548656f) / 180f)) * r);
|
| 765 | final float y2 = (float) (Math.cos(((i * 56.548656f) / 180f)) * r);
|
| 766 | bufferBuilder.addVertex(matrix, x2, y2, z).setColor(c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f, 0.4f);
|
| 767 | }
|
| 768 | BufferRenderer.drawWithGlobalProgram(bufferBuilder.buildOrThrow());
|
| 769 | endRender();
|
| 770 | }
|
| 771 |
|
| 772 | public static void drawStar(Object matrices, Color c, float scale) {
|
| 773 | setupRender();
|
| 774 | RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE);
|
| 775 | RenderSystem.setShaderTexture(0, TextureStorage.star);
|
| 776 | RenderSystem.setShaderColor(c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f, c.getAlpha() / 255f);
|
| 777 | Render2DEngine.renderGradientTexture(matrices, 0, 0, scale, scale, 0, 0, 128, 128, 128, 128, c, c, c, c);
|
| 778 | endRender();
|
| 779 | }
|
| 780 |
|
| 781 | public static void drawHeart(Object matrices, Color c, float scale) {
|
| 782 | setupRender();
|
| 783 | RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE);
|
| 784 | RenderSystem.setShaderTexture(0, TextureStorage.heart);
|
| 785 | RenderSystem.setShaderColor(c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f, c.getAlpha() / 255f);
|
| 786 | Render2DEngine.renderGradientTexture(matrices, 0, 0, scale, scale, 0, 0, 128, 128, 128, 128, c, c, c, c);
|
| 787 | endRender();
|
| 788 | }
|
| 789 |
|
| 790 | public static void drawBloom(Object matrices, Color c, float scale) {
|
| 791 | setupRender();
|
| 792 | RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE);
|
| 793 | RenderSystem.setShaderTexture(0, TextureStorage.firefly);
|
| 794 | RenderSystem.setShaderColor(c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f, c.getAlpha() / 255f);
|
| 795 | Render2DEngine.renderGradientTexture(matrices, 0, 0, scale, scale, 0, 0, 128, 128, 128, 128, c, c, c, c);
|
| 796 | endRender();
|
| 797 | }
|
| 798 |
|
| 799 | public static void drawBubble(Object matrices, float angle, float factor) {
|
| 800 | setupRender();
|
| 801 | RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE);
|
| 802 | RenderSystem.setShaderTexture(0, TextureStorage.bubble);
|
| 803 | GuiMatrix.rotateZDegrees(matrices, angle);
|
| 804 | float scale = factor * 2f;
|
| 805 | Render2DEngine.renderGradientTexture(matrices, -scale / 2, -scale / 2, scale, scale, 0, 0, 128, 128, 128, 128, applyOpacity(HudEditor.getColor(270), 1f - factor), applyOpacity(HudEditor.getColor(0), 1f - factor), applyOpacity(HudEditor.getColor(180), 1f - factor), applyOpacity(HudEditor.getColor(90), 1f - factor));
|
| 806 | endRender();
|
| 807 | }
|
| 808 |
|
| 809 | public static void drawLine(float x, float y, float x1, float y1, int color) {
|
| 810 | RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
| 811 | BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.DEBUG_LINE_STRIP, DefaultVertexFormat.POSITION_COLOR);
|
| 812 | bufferBuilder.addVertex(x, y, 0f).setColor(color);
|
| 813 | bufferBuilder.addVertex(x1, y1, 0f).setColor(color);
|
| 814 | BufferRenderer.drawWithGlobalProgram(bufferBuilder.buildOrThrow());
|
| 815 | }
|
| 816 |
|
| 817 | //http://www.java2s.com/example/java/2d-graphics/check-if-a-color-is-more-dark-than-light.html
|
| 818 | public static boolean isDark(Color color) {
|
| 819 | return isDark(color.getRed() / 255.0f, color.getGreen() / 255.0f, color.getBlue() / 255.0f);
|
| 820 | }
|
| 821 |
|
| 822 | public static boolean isDark(float r, float g, float b) {
|
| 823 | return colorDistance(r, g, b, 0f, 0f, 0f) < colorDistance(r, g, b, 1f, 1f, 1f);
|
| 824 | }
|
| 825 |
|
| 826 | public static float colorDistance(float r1, float g1, float b1, float r2, float g2, float b2) {
|
| 827 | float a = r2 - r1;
|
| 828 | float b = g2 - g1;
|
| 829 | float c = b2 - b1;
|
| 830 | return (float) Math.sqrt(a * a + b * b + c * c);
|
| 831 | }
|
| 832 |
|
| 833 | public static void initShaders() {
|
| 834 | HUD_SHADER = new HudShader();
|
| 835 | MAIN_MENU_PROGRAM = new MainMenuProgram();
|
| 836 | TEXTURE_COLOR_PROGRAM = new TextureColorProgram();
|
| 837 | ARC_PROGRAM = new ArcShader();
|
| 838 | RECTANGLE_SHADER = new RectangleShader();
|
| 839 | BLUR_PROGRAM = new BlurProgram();
|
| 840 | }
|
| 841 |
|
| 842 | public static @NotNull Color getColor(@NotNull Color start, @NotNull Color end, float progress, boolean smooth) {
|
| 843 | if (!smooth)
|
| 844 | return progress >= 0.95 ? end : start;
|
| 845 |
|
| 846 | final int rDiff = end.getRed() - start.getRed();
|
| 847 | final int gDiff = end.getGreen() - start.getGreen();
|
| 848 | final int bDiff = end.getBlue() - start.getBlue();
|
| 849 | final int aDiff = end.getAlpha() - start.getAlpha();
|
| 850 |
|
| 851 | return new Color(
|
| 852 | fixColorValue(start.getRed() + (int) (rDiff * progress)),
|
| 853 | fixColorValue(start.getGreen() + (int) (gDiff * progress)),
|
| 854 | fixColorValue(start.getBlue() + (int) (bDiff * progress)),
|
| 855 | fixColorValue(start.getAlpha() + (int) (aDiff * progress)));
|
| 856 | }
|
| 857 |
|
| 858 | private static int fixColorValue(int colorVal) {
|
| 859 | return colorVal > 255 ? 255 : Math.max(colorVal, 0);
|
| 860 | }
|
| 861 |
|
| 862 | public static void endBuilding(BufferBuilder bb) {
|
| 863 | MeshData builtBuffer = bb.build();
|
| 864 | if (builtBuffer != null)
|
| 865 | BufferRenderer.drawWithGlobalProgram(builtBuffer);
|
| 866 | }
|
| 867 |
|
| 868 | public static class BlurredShadow {
|
| 869 | Texture id;
|
| 870 |
|
| 871 | public BlurredShadow(BufferedImage bufferedImage) {
|
| 872 | this.id = new Texture("texture/remote/" + RandomStringUtils.randomAlphanumeric(16));
|
| 873 | registerBufferedImageTexture(id, bufferedImage);
|
| 874 | }
|
| 875 |
|
| 876 | public void bind() {
|
| 877 | RenderSystem.setShaderTexture(0, id.getId());
|
| 878 | }
|
| 879 | }
|
| 880 |
|
| 881 | public record Rectangle(float x, float y, float x1, float y1) {
|
| 882 | public boolean contains(double x, double y) {
|
| 883 | return x >= this.x && x <= x1 && y >= this.y && y <= y1;
|
| 884 | }
|
| 885 | }
|
| 886 | }
|
| 887 |
|