Skip to content

Instantly share code, notes, and snippets.

@solaritygh
Last active December 29, 2025 20:22
Show Gist options
  • Select an option

  • Save solaritygh/0727e78d909ad53f46bf5fc1759bdf01 to your computer and use it in GitHub Desktop.

Select an option

Save solaritygh/0727e78d909ad53f46bf5fc1759bdf01 to your computer and use it in GitHub Desktop.
An edited version of the DraggableComponent file by quickdaffy.
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import org.lwjgl.input.Mouse;
public class DraggableComponent {
private int x, y;
private int width, height;
private int color;
private int lastX, lastY;
private boolean dragging;
public DraggableComponent(int x, int y, int width, int height, int color) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.color = color;
}
public int getxPosition() {
return this.x;
}
public int getyPosition() {
return this.y;
}
public void setxPosition(int x) {
this.x = x;
}
public void setyPosition(int y) {
this.y = y;
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
public int getColor() {
return this.color;
}
public void setColor(int color) {
this.color = color;
}
public void renderDummy(int mouseX, int mouseY) {
if(this.dragging) {
this.x = mouseX + this.lastX;
this.y = mouseY + this.lastY;
if(!Mouse.isButtonDown(0)) {this.dragging = false;}
}
boolean mouseOverX = (mouseX >= this.getxPosition() && mouseX <= this.getxPosition()+this.getWidth());
boolean mouseOverY = (mouseY >= this.getyPosition() && mouseY <= this.getyPosition()+this.getHeight());
if(mouseOverX && mouseOverY) {
if(Mouse.isButtonDown(0)) {
if(!this.dragging) {
this.lastX = this.x - mouseX;
this.lastY = this.y - mouseY;
this.dragging = true;
}
}
}
}
public void render() {
Gui.drawRect(this.getxPosition(), this.getyPosition(), this.getxPosition()+this.getWidth(), this.getyPosition()+this.getHeight(), this.getColor());
}
}
<!-- ... -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.42</version>
<scope>provided</scope>
</dependency>
<!-- ... -->
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
public class RoundedHelper {
final static Minecraft mc = Minecraft.getMinecraft();
final static FontRenderer fr = mc.fontRendererObj;
public static void enableGL2D() {
GL11.glDisable(2929);
GL11.glEnable(3042);
GL11.glDisable(3553);
GL11.glBlendFunc(770, 771);
GL11.glDepthMask(true);
GL11.glEnable(2848);
GL11.glHint(3154, 4354);
GL11.glHint(3155, 4354);
}
public static void disableGL2D() {
GL11.glEnable(3553);
GL11.glDisable(3042);
GL11.glEnable(2929);
GL11.glDisable(2848);
GL11.glHint(3154, 4352);
GL11.glHint(3155, 4352);
}
/*
*
* NORMAL
*
*/
/**
* @param x : X pos
* @param y : Y pos
* @param x1 : X2 pos
* @param y1 : Y2 pos
* @param radius : round of edges;
* @param color : color;
*/
public static void drawSmoothRoundedRect(float x, float y, float x1, float y1, float radius, int color) {
glPushAttrib(0);
glScaled(0.5D, 0.5D, 0.5D);
x *= 2.0D;
y *= 2.0D;
x1 *= 2.0D;
y1 *= 2.0D;
glEnable(3042);
glDisable(3553);
glEnable(GL_LINE_SMOOTH);
setColor(color);
glEnable(2848);
glBegin(GL_POLYGON);
int i;
for (i = 0; i <= 90; i += 3)
glVertex2d(x + radius + Math.sin(i * Math.PI / 180.0D) * radius * -1.0D, y + radius + Math.cos(i * Math.PI / 180.0D) * radius * -1.0D);
for (i = 90; i <= 180; i += 3)
glVertex2d(x + radius + Math.sin(i * Math.PI / 180.0D) * radius * -1.0D, y1 - radius + Math.cos(i * Math.PI / 180.0D) * radius * -1.0D);
for (i = 0; i <= 90; i += 3)
glVertex2d(x1 - radius + Math.sin(i * Math.PI / 180.0D) * radius, y1 - radius + Math.cos(i * Math.PI / 180.0D) * radius);
for (i = 90; i <= 180; i += 3)
glVertex2d(x1 - radius + Math.sin(i * Math.PI / 180.0D) * radius, y + radius + Math.cos(i * Math.PI / 180.0D) * radius);
glEnd();
glBegin(GL_LINE_LOOP);
for (i = 0; i <= 90; i += 3)
glVertex2d(x + radius + Math.sin(i * Math.PI / 180.0D) * radius * -1.0D, y + radius + Math.cos(i * Math.PI / 180.0D) * radius * -1.0D);
for (i = 90; i <= 180; i += 3)
glVertex2d(x + radius + Math.sin(i * Math.PI / 180.0D) * radius * -1.0D, y1 - radius + Math.cos(i * Math.PI / 180.0D) * radius * -1.0D);
for (i = 0; i <= 90; i += 3)
glVertex2d(x1 - radius + Math.sin(i * Math.PI / 180.0D) * radius, y1 - radius + Math.cos(i * Math.PI / 180.0D) * radius);
for (i = 90; i <= 180; i += 3)
glVertex2d(x1 - radius + Math.sin(i * Math.PI / 180.0D) * radius, y + radius + Math.cos(i * Math.PI / 180.0D) * radius);
glEnd();
glEnable(3553);
glDisable(3042);
glDisable(2848);
glDisable(3042);
glDisable(GL_LINE_SMOOTH);
glEnable(3553);
glScaled(2.0D, 2.0D, 2.0D);
glPopAttrib();
}
public static void drawRoundedRect(float x, float y, float x1, float y1, float radius, int color) {
glPushAttrib(0);
glScaled(0.5D, 0.5D, 0.5D);
x *= 2.0D;
y *= 2.0D;
x1 *= 2.0D;
y1 *= 2.0D;
glEnable(3042);
glDisable(3553);
glEnable(GL_LINE_SMOOTH);
setColor(color);
glEnable(2848);
glBegin(GL_POLYGON);
int i;
for (i = 0; i <= 90; i += 3)
glVertex2d(x + radius + Math.sin(i * Math.PI / 180.0D) * radius * -1.0D, y + radius + Math.cos(i * Math.PI / 180.0D) * radius * -1.0D);
for (i = 90; i <= 180; i += 3)
glVertex2d(x + radius + Math.sin(i * Math.PI / 180.0D) * radius * -1.0D, y1 - radius + Math.cos(i * Math.PI / 180.0D) * radius * -1.0D);
for (i = 0; i <= 90; i += 3)
glVertex2d(x1 - radius + Math.sin(i * Math.PI / 180.0D) * radius, y1 - radius + Math.cos(i * Math.PI / 180.0D) * radius);
for (i = 90; i <= 180; i += 3)
glVertex2d(x1 - radius + Math.sin(i * Math.PI / 180.0D) * radius, y + radius + Math.cos(i * Math.PI / 180.0D) * radius);
glEnd();
glEnable(3553);
glDisable(3042);
glDisable(2848);
glDisable(3042);
glDisable(GL_LINE_SMOOTH);
glEnable(3553);
glScaled(2.0D, 2.0D, 2.0D);
glPopAttrib();
}
/**
* @param x : X pos
* @param y : Y pos
* @param x1 : X2 pos
* @param y1 : Y2 pos
* @param radius : round of edges;
* @param lineWidth : width of outline line;
* @param color : color;
*/
public static void drawRoundedOutline(float x, float y, float x1, float y1, float radius,float lineWidth, int color) {
glPushAttrib(0);
glScaled(0.5D, 0.5D, 0.5D);
x *= 2.0D;
y *= 2.0D;
x1 *= 2.0D;
y1 *= 2.0D;
glEnable(3042);
glDisable(3553);
setColor(color);
glEnable(2848);
glLineWidth(lineWidth);
glBegin(GL_LINE_LOOP);
int i;
for (i = 0; i <= 90; i += 3)
glVertex2d(x + radius + Math.sin(i * Math.PI / 180.0D) * radius * -1.0D, y + radius + Math.cos(i * Math.PI / 180.0D) * radius * -1.0D);
for (i = 90; i <= 180; i += 3)
glVertex2d(x + radius + Math.sin(i * Math.PI / 180.0D) * radius * -1.0D, y1 - radius + Math.cos(i * Math.PI / 180.0D) * radius * -1.0D);
for (i = 0; i <= 90; i += 3)
glVertex2d(x1 - radius + Math.sin(i * Math.PI / 180.0D) * radius, y1 - radius + Math.cos(i * Math.PI / 180.0D) * radius);
for (i = 90; i <= 180; i += 3)
glVertex2d(x1 - radius + Math.sin(i * Math.PI / 180.0D) * radius, y + radius + Math.cos(i * Math.PI / 180.0D) * radius);
glEnd();
glEnable(3553);
glDisable(3042);
glDisable(2848);
glDisable(3042);
glEnable(3553);
glScaled(2.0D, 2.0D, 2.0D);
glPopAttrib();
}
/*
*
* SELECTED EDGES
*
*/
/**
* @param x : X pos
* @param y : Y pos
* @param x1 : X2 pos
* @param y1 : Y2 pos
* @param radius1 : round of left top edges;
* @param radius2 : round of right top edges;
* @param radius3 : round of left bottom edges;
* @param radius4 : round of right bottom edges;
* @param color : color;
*/
public static void drawSelectRoundedRect(float x, float y, float x1, float y1, float radius1,float radius2,float radius3,float radius4, int color) {
glPushAttrib(0);
glScaled(0.5D, 0.5D, 0.5D);
x *= 2.0D;
y *= 2.0D;
x1 *= 2.0D;
y1 *= 2.0D;
glEnable(3042);
glDisable(3553);
setColor(color);
glEnable(2848);
glBegin(9);
int i;
for (i = 0; i <= 90; i += 3)
glVertex2d(x + radius1 + Math.sin(i * Math.PI / 180.0D) * radius1 * -1.0D, y + radius1 + Math.cos(i * Math.PI / 180.0D) * radius1 * -1.0D);
for (i = 90; i <= 180; i += 3)
glVertex2d(x + radius2 + Math.sin(i * Math.PI / 180.0D) * radius2 * -1.0D, y1 - radius2 + Math.cos(i * Math.PI / 180.0D) * radius2 * -1.0D);
for (i = 0; i <= 90; i += 3)
glVertex2d(x1 - radius3 + Math.sin(i * Math.PI / 180.0D) * radius3, y1 - radius3 + Math.cos(i * Math.PI / 180.0D) * radius3);
for (i = 90; i <= 180; i += 3)
glVertex2d(x1 - radius4 + Math.sin(i * Math.PI / 180.0D) * radius4, y + radius4 + Math.cos(i * Math.PI / 180.0D) * radius4);
glEnd();
glEnable(3553);
glDisable(3042);
glDisable(2848);
glDisable(3042);
glEnable(3553);
glScaled(2.0D, 2.0D, 2.0D);
glPopAttrib();
}
/**
* @param x : X pos
* @param y : Y pos
* @param x1 : X2 pos
* @param y1 : Y2 pos
* @param radius1 : round of left top edges;
* @param radius2 : round of right top edges;
* @param radius3 : round of left bottom edges;
* @param radius4 : round of right bottom edges;
* @param lineWidth : width of outline line;
* @param color : color;
*/
public static void drawSelectRoundedOutline(float x, float y, float x1, float y1, float radius1,float radius2,float radius3,float radius4,float lineWidth, int color) {
glPushAttrib(0);
glScaled(0.5D, 0.5D, 0.5D);
x *= 2.0D;
y *= 2.0D;
x1 *= 2.0D;
y1 *= 2.0D;
glEnable(3042);
glDisable(3553);
setColor(color);
glEnable(2848);
glLineWidth(lineWidth);
glBegin(GL_LINE_LOOP);
int i;
for (i = 0; i <= 90; i += 3)
glVertex2d(x + radius1 + Math.sin(i * Math.PI / 180.0D) * radius1 * -1.0D, y + radius1 + Math.cos(i * Math.PI / 180.0D) * radius1 * -1.0D);
for (i = 90; i <= 180; i += 3)
glVertex2d(x + radius2 + Math.sin(i * Math.PI / 180.0D) * radius2 * -1.0D, y1 - radius2 + Math.cos(i * Math.PI / 180.0D) * radius2 * -1.0D);
for (i = 0; i <= 90; i += 3)
glVertex2d(x1 - radius3 + Math.sin(i * Math.PI / 180.0D) * radius3, y1 - radius3 + Math.cos(i * Math.PI / 180.0D) * radius3);
for (i = 90; i <= 180; i += 3)
glVertex2d(x1 - radius4 + Math.sin(i * Math.PI / 180.0D) * radius4, y + radius4 + Math.cos(i * Math.PI / 180.0D) * radius4);
glEnd();
glEnable(3553);
glDisable(3042);
glDisable(2848);
glDisable(3042);
glEnable(3553);
glScaled(2.0D, 2.0D, 2.0D);
glPopAttrib();
}
public static void setColor(int color) {
float a = (color >> 24 & 0xFF) / 255.0F;
float r = (color >> 16 & 0xFF) / 255.0F;
float g = (color >> 8 & 0xFF) / 255.0F;
float b = (color & 0xFF) / 255.0F;
glColor4f(r, g, b, a);
}
/*
*
* GRADIENT
*
*/
/**
* @param x : X pos
* @param y : Y pos
* @param x1 : X2 pos
* @param y1 : Y2 pos
* @param radius : round of edges;
* @param color : color;
* @param color2 : color2;
* @param color3 : color3;
* @param color4 : color4;
*/
public static void drawRoundedGradientRectCorner(float x, float y, float x1, float y1, float radius, int color, int color2, int color3, int color4) {
GL11.glEnable(3042);
GL11.glDisable(3553);
GL11.glBlendFunc(770, 771);
GL11.glEnable(2848);
GL11.glShadeModel(7425);
glPushAttrib(0);
glScaled(0.5D, 0.5D, 0.5D);
x *= 2.0D;
y *= 2.0D;
x1 *= 2.0D;
y1 *= 2.0D;
glEnable(3042);
glDisable(3553);
setColor(color);
glEnable(2848);
GL11.glShadeModel(7425);
glBegin(9);
int i;
for (i = 0; i <= 90; i += 3)
setColor(color);
glVertex2d(x + radius + Math.sin(i * Math.PI / 180.0D) * radius * -1.0D, y + radius + Math.cos(i * Math.PI / 180.0D) * radius * -1.0D);
for (i = 90; i <= 180; i += 3)
setColor(color2);
glVertex2d(x + radius + Math.sin(i * Math.PI / 180.0D) * radius * -1.0D, y1 - radius + Math.cos(i * Math.PI / 180.0D) * radius * -1.0D);
for (i = 0; i <= 90; i += 3)
setColor(color3);
glVertex2d(x1 - radius + Math.sin(i * Math.PI / 180.0D) * radius, y1 - radius + Math.cos(i * Math.PI / 180.0D) * radius);
for (i = 90; i <= 180; i += 3)
setColor(color4);
glVertex2d(x1 - radius + Math.sin(i * Math.PI / 180.0D) * radius, y + radius + Math.cos(i * Math.PI / 180.0D) * radius);
glEnd();
glEnable(3553);
glDisable(3042);
glDisable(2848);
glDisable(3042);
glEnable(3553);
glScaled(2.0D, 2.0D, 2.0D);
glPopAttrib();
GL11.glEnable(3553);
GL11.glDisable(3042);
GL11.glDisable(2848);
GL11.glShadeModel(7424);
}
/*NOT WORKING ATM*/
/*
*
* IMAGE
*
*/
/**
*
* @see dont worget to bind a texture to it!
*
* @param x : X pos
* @param y : Y pos
* @param x1 : X2 pos
* @param y1 : Y2 pos
* @param radius : round of edges;
*/
}
// from eric golde
import java.awt.image.BufferedImage;
import org.apache.commons.io.FilenameUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IImageBuffer;
import net.minecraft.client.renderer.ImageBufferDownload;
import net.minecraft.client.renderer.ThreadDownloadImageData;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;
public class UrlTextureUtil
{
public static void downloadAndSetTexture(String url, ResourceLocationCallback callback)
{
if (url != null && !url.isEmpty())
{
String baseName = FilenameUtils.getBaseName(url);
final ResourceLocation resourcelocation = new ResourceLocation("clientname_temp/" + baseName);
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
ITextureObject itextureobject = texturemanager.getTexture(resourcelocation);
if (itextureobject != null && itextureobject instanceof ThreadDownloadImageData)
{
ThreadDownloadImageData threaddownloadimagedata = (ThreadDownloadImageData)itextureobject;
if (threaddownloadimagedata.imageFound != null)
{
if (threaddownloadimagedata.imageFound.booleanValue())
{
callback.onTextureLoaded(resourcelocation);
}
return;
}
}
IImageBuffer iimagebuffer = new IImageBuffer()
{
ImageBufferDownload ibd = new ImageBufferDownload();
public BufferedImage parseUserSkin(BufferedImage image)
{
return image;
}
public void skinAvailable()
{
callback.onTextureLoaded(resourcelocation);
}
};
ThreadDownloadImageData threaddownloadimagedata1 = new ThreadDownloadImageData(null, url, null, iimagebuffer);
threaddownloadimagedata1.pipeline = true;
texturemanager.loadTexture(resourcelocation, threaddownloadimagedata1);
}
}
public interface ResourceLocationCallback {
public void onTextureLoaded(ResourceLocation rl);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment