Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 18 additions & 29 deletions src/main/java/de/florianmichael/viamcp/gui/AsyncVersionSlider.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,34 @@ public class AsyncVersionSlider extends GuiButton {
private float sliderValue;
public boolean dragging;

public AsyncVersionSlider(int buttonId, int x, int y , int widthIn, int heightIn)
{
public AsyncVersionSlider(int buttonId, int x, int y, int widthIn, int heightIn) {
super(buttonId, x, y, Math.max(widthIn, 110), heightIn, "");
this.values = ViaLoadingBase.PROTOCOLS;
this.values = new java.util.ArrayList<>(ViaLoadingBase.PROTOCOLS);
Collections.reverse(values);
this.sliderValue = dragValue;
this.sliderValue = 1.0F - dragValue;
this.dragValue = this.sliderValue;
this.displayString = values.get((int) Math.ceil(this.sliderValue * (values.size() - 1))).getName();
}

public void drawButton(Minecraft mc, int mouseX, int mouseY)
{
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
super.drawButton(mc, mouseX, mouseY);
}

/**
* Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over
* this button.
*/
protected int getHoverState(boolean mouseOver)
{
protected int getHoverState(boolean mouseOver) {
return 0;
}

/**
* Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e).
*/
protected void mouseDragged(Minecraft mc, int mouseX, int mouseY)
{
if (this.visible)
{
if (this.dragging)
{
this.sliderValue = (float)(mouseX - (this.xPosition + 4)) / (float)(this.width - 8);
protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) {
if(this.visible) {
if(this.dragging) {
this.sliderValue = (float) (mouseX - (this.xPosition + 4)) / (float) (this.width - 8);
this.sliderValue = MathHelper.clamp_float(this.sliderValue, 0.0F, 1.0F);
this.dragValue = sliderValue;

Expand All @@ -79,20 +74,18 @@ protected void mouseDragged(Minecraft mc, int mouseX, int mouseY)

mc.getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.xPosition + (int)(this.sliderValue * (float)(this.width - 8)), this.yPosition, 0, 66, 4, 20);
this.drawTexturedModalRect(this.xPosition + (int)(this.sliderValue * (float)(this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
this.drawTexturedModalRect(this.xPosition + (int) (this.sliderValue * (float) (this.width - 8)), this.yPosition, 0, 66, 4, 20);
this.drawTexturedModalRect(this.xPosition + (int) (this.sliderValue * (float) (this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
}
}

/**
* Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent
* e).
*/
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
{
if (super.mousePressed(mc, mouseX, mouseY))
{
this.sliderValue = (float)(mouseX - (this.xPosition + 4)) / (float)(this.width - 8);
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
if(super.mousePressed(mc, mouseX, mouseY)) {
this.sliderValue = (float) (mouseX - (this.xPosition + 4)) / (float) (this.width - 8);
this.sliderValue = MathHelper.clamp_float(this.sliderValue, 0.0F, 1.0F);
this.dragValue = sliderValue;

Expand All @@ -101,23 +94,19 @@ public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
ViaLoadingBase.getInstance().reload(values.get(selectedProtocolIndex));
this.dragging = true;
return true;
}
else
{
} else {
return false;
}
}

/**
* Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
*/
public void mouseReleased(int mouseX, int mouseY)
{
public void mouseReleased(int mouseX, int mouseY) {
this.dragging = false;
}

public void setVersion(int protocol)
{
public void setVersion(int protocol) {
this.dragValue = (float) ViaLoadingBase.PROTOCOLS.indexOf(ProtocolVersion.getProtocol(protocol)) / (ViaLoadingBase.PROTOCOLS.size() - 1);
this.sliderValue = this.dragValue;

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/dev/thoq/event/events/UpdateEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public UpdateEvent() {
}

@Override
public boolean equals(Object o) {
return o instanceof UpdateEvent;
public boolean equals(Object object) {
return object instanceof UpdateEvent;
}

@Override
Expand All @@ -54,4 +54,6 @@ public boolean isCanceled() {
public void cancel() {
this.canceled = true;
}


}
2 changes: 1 addition & 1 deletion src/main/java/dev/thoq/lua/api/LuaMinecraftApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ public LuaValue call() {
double blockZ = Math.floor(z);
double fracX = x - blockX;
double fracZ = z - blockZ;
double edgeThreshold = 0.3;
double edgeThreshold = 0.55;
boolean nearEdge =
fracX < edgeThreshold
|| fracX > (1.0 - edgeThreshold)
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/dev/thoq/util/render/RenderUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

@SuppressWarnings("unused")
public final class RenderUtility {

public static void drawRect(
final float x, final float y, final float width, final float height, final int color) {
Gui.drawRect(x, y, x + width, y + height, color);
Expand Down Expand Up @@ -495,4 +496,22 @@ public static void drawImage(
GlStateManager.enableAlpha();
GlStateManager.disableBlend();
}

public static int interpolateColor(int from, int to, float t) {
int aFrom = (from >> 24) & 0xFF, rFrom = (from >> 16) & 0xFF,
gFrom = (from >> 8) & 0xFF, bFrom = from & 0xFF;
int aTo = (to >> 24) & 0xFF, rTo = (to >> 16) & 0xFF,
gTo = (to >> 8) & 0xFF, bTo = to & 0xFF;
return extractColor(t, aFrom, rFrom, gFrom, bFrom, aTo, rTo, gTo, bTo);
}

public static int extractColor(float t, int aFrom, int rFrom, int gFrom, int bFrom, int aTo, int rTo, int gTo, int bTo) {
int a = (int)(aFrom + (aTo - aFrom) * t);
int r = (int)(rFrom + (rTo - rFrom) * t);
int g = (int)(gFrom + (gTo - gFrom) * t);
int b = (int)(bFrom + (bTo - bFrom) * t);
return (a << 24) | (r << 16) | (g << 8) | b;
}


}
Loading
Loading