From c5eba78bf636efec43ff0e84effb2441cbb23fb9 Mon Sep 17 00:00:00 2001 From: kirillsaint Date: Wed, 25 Oct 2023 11:30:36 +0600 Subject: [PATCH] Better Image Positions --- .../client/gui/util/RenderUtil.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/silentclient/client/gui/util/RenderUtil.java b/src/main/java/net/silentclient/client/gui/util/RenderUtil.java index 2b2f68d..3606e0c 100644 --- a/src/main/java/net/silentclient/client/gui/util/RenderUtil.java +++ b/src/main/java/net/silentclient/client/gui/util/RenderUtil.java @@ -5,6 +5,9 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.ResourceLocation; import net.silentclient.client.Client; import net.silentclient.client.cosmetics.StaticResourceLocation; @@ -185,7 +188,7 @@ public class RenderUtil { } else { Minecraft.getMinecraft().getTextureManager().bindTexture(image); } - Gui.drawModalRectWithCustomSizedTexture((int) x, (int) y, (float) 0.0f, (float) 0.0f, (int) width, (int) height, (float) width, (float) height); + drawModalRectWithCustomSizedTexture(x, y, 0.0f, 0.0f, width, height, width, height); GL11.glDepthMask((boolean) true); GL11.glDisable((int) 3042); GL11.glEnable((int) 2929); @@ -194,6 +197,20 @@ public class RenderUtil { GL11.glColor4f((float) 1.0f, (float) 1.0f, (float) 1.0f, 1f); } + public static void drawModalRectWithCustomSizedTexture(float x, float y, float u, float v, float width, float height, float textureWidth, float textureHeight) + { + float f = 1.0F / textureWidth; + float f1 = 1.0F / textureHeight; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); + worldrenderer.pos((double)x, (double)(y + height), 0.0D).tex((double)(u * f), (double)((v + (float)height) * f1)).endVertex(); + worldrenderer.pos((double)(x + width), (double)(y + height), 0.0D).tex((double)((u + (float)width) * f), (double)((v + (float)height) * f1)).endVertex(); + worldrenderer.pos((double)(x + width), (double)y, 0.0D).tex((double)((u + (float)width) * f), (double)(v * f1)).endVertex(); + worldrenderer.pos((double)x, (double)y, 0.0D).tex((double)(u * f), (double)(v * f1)).endVertex(); + tessellator.draw(); + } + public static void drawImage(ResourceLocation image, float x, float y, float width, float height, boolean mip) { drawImage(image, x, y, width, height, mip, -1); }