Last active
August 16, 2023 14:46
-
-
Save chaarlottte/a4e455d635455efe3c78ccbbc071a631 to your computer and use it in GitHub Desktop.
Draggable Component made by someone i dont remember
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.minecraft.client.Minecraft; | |
import net.minecraft.client.gui.Gui; | |
import org.lwjgl.input.Mouse; | |
public class DraggableComponent { | |
private int x; | |
private int y; | |
private int width; | |
private int height; | |
private int color; | |
private int lastX; | |
private int lastY; | |
private boolean dragging; | |
public DraggableComponent(int x, int y, int width, int height, int color){ | |
this.width = width; | |
this.height = height; | |
this.x = x; | |
this.y = y; | |
this.color = color; | |
} | |
public int getxPosition() { | |
return x; | |
} | |
public int getyPosition() { | |
return y; | |
} | |
public void setxPosition(int x) { | |
this.x = x; | |
} | |
public void setyPosition(int y) { | |
this.y = y; | |
} | |
public int getHeight() { | |
return height; | |
} | |
public int getWidth() { | |
return width; | |
} | |
public int getColor() { | |
return color; | |
} | |
public void setColor(int color) { | |
this.color = color; | |
} | |
public void draw(int mouseX, int mouseY){ | |
draggingFix(mouseX, mouseY); | |
Gui.drawRect(this.getxPosition(), this.getyPosition(), this.getxPosition()+this.getWidth(), this.getyPosition()+this.getHeight(), this.getColor()); | |
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 = x - mouseX; | |
this.lastY = y - mouseY; | |
this.dragging = true; | |
} | |
} | |
} | |
} | |
private void draggingFix(int mouseX, int mouseY) { | |
if (this.dragging) { | |
this.x = mouseX + this.lastX; | |
this.y = mouseY + this.lastY; | |
if(!Mouse.isButtonDown(0)) this.dragging = false; | |
} | |
} | |
} |
go quick!!!111!!!
thx
nice
nice
lol
System.Out.Println("Thanks");
- hi again
- do stuff
BRUH
TY QUICCKKKKKKKKKKKKKK YOU THE BESTT
ha stole your code <3
*edit i know its free code i just think this would be funny to say ;D
thx quick
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thx m8