diff --git a/src/main/java/de/florianmichael/viamcp/gui/AsyncVersionSlider.java b/src/main/java/de/florianmichael/viamcp/gui/AsyncVersionSlider.java index ad122903..e2eb3258 100644 --- a/src/main/java/de/florianmichael/viamcp/gui/AsyncVersionSlider.java +++ b/src/main/java/de/florianmichael/viamcp/gui/AsyncVersionSlider.java @@ -35,17 +35,16 @@ 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); } @@ -53,21 +52,17 @@ public void drawButton(Minecraft mc, int mouseX, int 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; @@ -79,8 +74,8 @@ 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); } } @@ -88,11 +83,9 @@ protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) * 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; @@ -101,9 +94,7 @@ public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) ViaLoadingBase.getInstance().reload(values.get(selectedProtocolIndex)); this.dragging = true; return true; - } - else - { + } else { return false; } } @@ -111,13 +102,11 @@ public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) /** * 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; diff --git a/src/main/java/dev/thoq/event/events/UpdateEvent.java b/src/main/java/dev/thoq/event/events/UpdateEvent.java index d9594507..d91a7b49 100644 --- a/src/main/java/dev/thoq/event/events/UpdateEvent.java +++ b/src/main/java/dev/thoq/event/events/UpdateEvent.java @@ -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 @@ -54,4 +54,6 @@ public boolean isCanceled() { public void cancel() { this.canceled = true; } + + } diff --git a/src/main/java/dev/thoq/lua/api/LuaMinecraftApi.java b/src/main/java/dev/thoq/lua/api/LuaMinecraftApi.java index 4021edd1..4e5bdfe6 100644 --- a/src/main/java/dev/thoq/lua/api/LuaMinecraftApi.java +++ b/src/main/java/dev/thoq/lua/api/LuaMinecraftApi.java @@ -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) diff --git a/src/main/java/dev/thoq/util/render/RenderUtility.java b/src/main/java/dev/thoq/util/render/RenderUtility.java index 02d0b5ce..f2d380be 100644 --- a/src/main/java/dev/thoq/util/render/RenderUtility.java +++ b/src/main/java/dev/thoq/util/render/RenderUtility.java @@ -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); @@ -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; + } + + } diff --git a/src/main/java/net/minecraft/client/gui/GuiButton.java b/src/main/java/net/minecraft/client/gui/GuiButton.java index 0e576411..6535115f 100644 --- a/src/main/java/net/minecraft/client/gui/GuiButton.java +++ b/src/main/java/net/minecraft/client/gui/GuiButton.java @@ -2,6 +2,7 @@ import dev.thoq.gui.UIConstants; import dev.thoq.util.font.AlyaFontRenderer; +import dev.thoq.util.render.RenderUtility; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.audio.SoundHandler; @@ -10,252 +11,270 @@ @SuppressWarnings("unused") public class GuiButton extends Gui { - protected static final ResourceLocation buttonTextures = - new ResourceLocation("textures/gui/widgets.png"); - - private static final int BACKGROUND_COLOR = 0x8D181818; - private static final int BACKGROUND_HOVER = 0x5A252525; - private static final int BACKGROUND_DISABLED = 0x40101010; - private static final int BORDER_COLOR = 0xFF303030; - private static final int BORDER_HOVER = UIConstants.ACCENT_COLOR; - private static final int TEXT_COLOR = 0xFFFFFFFF; - private static final int TEXT_HOVER = UIConstants.ACCENT_COLOR; - private static final int TEXT_DISABLED = 0xFF666666; - - private float hoverAnimation = 0.0F; - private long lastTime = System.currentTimeMillis(); - private static final float ANIMATION_SPEED = 6.0F; - - /** Button width in pixels */ - protected int width; - - /** Button height in pixels */ - protected int height; - - /** The x position of this control. */ - public int xPosition; - - /** The y position of this control. */ - public int yPosition; - - /** The string displayed on this control. */ - public String displayString; - - public int id; - - /** True if this control is enabled, false to disable. */ - public boolean enabled; - - /** Hides the button completely if false. */ - public boolean visible; - - protected boolean hovered; - - public AlyaFontRenderer customFont = null; - - public GuiButton(int buttonId, int x, int y, String buttonText) { - this(buttonId, x, y, 200, 20, buttonText); - } - - public GuiButton(int buttonId, int x, int y, int widthIn, int heightIn, String buttonText) { - this.width = 200; - this.height = 20; - this.enabled = true; - this.visible = true; - this.id = buttonId; - this.xPosition = x; - this.yPosition = y; - this.width = widthIn; - this.height = heightIn; - this.displayString = buttonText; - } - - /** - * 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) { - int i = 1; - - if (!this.enabled) { - i = 0; - } else if (mouseOver) { - i = 2; + protected static final ResourceLocation buttonTextures = + new ResourceLocation("textures/gui/widgets.png"); + + private static final int BACKGROUND_COLOR = 0x8D181818; + private static final int BACKGROUND_HOVER = 0x5A252525; + private static final int BACKGROUND_DISABLED = 0x40101010; + private static final int BORDER_COLOR = 0xFF303030; + private static final int BORDER_HOVER = UIConstants.ACCENT_COLOR; + private static final int TEXT_COLOR = 0xFFFFFFFF; + private static final int TEXT_HOVER = UIConstants.ACCENT_COLOR; + private static final int TEXT_DISABLED = 0xFF666666; + + private float hoverAnimation = 0.0F; + private long lastTime = System.currentTimeMillis(); + private static final float ANIMATION_SPEED = 6.0F; + + /** + * Button width in pixels + */ + protected int width; + + /** + * Button height in pixels + */ + protected int height; + + /** + * The x position of this control. + */ + public int xPosition; + + /** + * The y position of this control. + */ + public int yPosition; + + /** + * The string displayed on this control. + */ + public String displayString; + + public int id; + + /** + * True if this control is enabled, false to disable. + */ + public boolean enabled; + + /** + * Hides the button completely if false. + */ + public boolean visible; + + protected boolean hovered; + + public AlyaFontRenderer customFont = null; + + public GuiButton(int buttonId, int x, int y, String buttonText) { + this(buttonId, x, y, 200, 20, buttonText); } - return i; - } - - private int interpolateColor(int color1, int color2, float factor) { - int a1 = (color1 >> 24) & 0xFF; - int r1 = (color1 >> 16) & 0xFF; - int g1 = (color1 >> 8) & 0xFF; - int b1 = color1 & 0xFF; - - int a2 = (color2 >> 24) & 0xFF; - int r2 = (color2 >> 16) & 0xFF; - int g2 = (color2 >> 8) & 0xFF; - int b2 = color2 & 0xFF; - - int a = (int) (a1 + (a2 - a1) * factor); - int r = (int) (r1 + (r2 - r1) * factor); - int g = (int) (g1 + (g2 - g1) * factor); - int b = (int) (b1 + (b2 - b1) * factor); - - return (a << 24) | (r << 16) | (g << 8) | b; - } - - /** Draws this button to the screen. */ - public void drawButton(Minecraft mc, int mouseX, int mouseY) { - if (this.visible) { - long currentTime = System.currentTimeMillis(); - float deltaTime = (currentTime - lastTime) / 1000.0F; - this.lastTime = currentTime; - - this.hovered = - mouseX >= this.xPosition - && mouseY >= this.yPosition - && mouseX < this.xPosition + this.width - && mouseY < this.yPosition + this.height; - - if (this.hovered && this.enabled) { - hoverAnimation = Math.min(1.0F, hoverAnimation + deltaTime * ANIMATION_SPEED); - } else { - hoverAnimation = Math.max(0.0F, hoverAnimation - deltaTime * ANIMATION_SPEED); - } - - int bgColor; - int borderColor; - int textColor; - - if (!this.enabled) { - bgColor = BACKGROUND_DISABLED; - borderColor = BORDER_COLOR; - textColor = TEXT_DISABLED; - } else { - bgColor = interpolateColor(BACKGROUND_COLOR, BACKGROUND_HOVER, hoverAnimation); - borderColor = interpolateColor(BORDER_COLOR, BORDER_HOVER, hoverAnimation); - textColor = interpolateColor(TEXT_COLOR, TEXT_HOVER, hoverAnimation); - } - - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - - drawRect( - this.xPosition, - this.yPosition, - this.xPosition + this.width, - this.yPosition + this.height, - bgColor); - - drawRect( - this.xPosition, - this.yPosition, - this.xPosition + this.width, - this.yPosition + 1, - borderColor); - drawRect( - this.xPosition, - this.yPosition + this.height - 1, - this.xPosition + this.width, - this.yPosition + this.height, - borderColor); - drawRect( - this.xPosition, - this.yPosition, - this.xPosition + 1, - this.yPosition + this.height, - borderColor); - drawRect( - this.xPosition + this.width - 1, - this.yPosition, - this.xPosition + this.width, - this.yPosition + this.height, - borderColor); - - this.mouseDragged(mc, mouseX, mouseY); - this.drawButtonText(mc, textColor); - - GlStateManager.disableBlend(); + public GuiButton(int buttonId, int x, int y, int widthIn, int heightIn, String buttonText) { + this.width = 200; + this.height = 20; + this.enabled = true; + this.visible = true; + this.id = buttonId; + this.xPosition = x; + this.yPosition = y; + this.width = widthIn; + this.height = heightIn; + this.displayString = buttonText; } - } - - /** Draws the button text. Override this method to use a custom font renderer. */ - protected void drawButtonText(Minecraft mc, int textColor) { - if (this.customFont != null) { - String text = this.displayString; - int maxWidth = this.width - 6; - if (this.customFont.getStringWidth(text) > maxWidth) { - while (!text.isEmpty() && this.customFont.getStringWidth(text + "...") > maxWidth) { - text = text.substring(0, text.length() - 1); + + /** + * 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) { + int i = 1; + + if(!this.enabled) { + i = 0; + } else if(mouseOver) { + i = 2; + } + + return i; + } + + private int interpolateColor(int color1, int color2, float factor) { + int a1 = (color1 >> 24) & 0xFF; + int r1 = (color1 >> 16) & 0xFF; + int g1 = (color1 >> 8) & 0xFF; + int b1 = color1 & 0xFF; + + int a2 = (color2 >> 24) & 0xFF; + int r2 = (color2 >> 16) & 0xFF; + int g2 = (color2 >> 8) & 0xFF; + int b2 = color2 & 0xFF; + + return RenderUtility.extractColor(factor, a1, r1, g1, b1, a2, r2, g2, b2); + } + + /** + * Draws this button to the screen. + */ + public void drawButton(Minecraft mc, int mouseX, int mouseY) { + if(this.visible) { + long currentTime = System.currentTimeMillis(); + float deltaTime = (currentTime - lastTime) / 1000.0F; + this.lastTime = currentTime; + + this.hovered = + mouseX >= this.xPosition + && mouseY >= this.yPosition + && mouseX < this.xPosition + this.width + && mouseY < this.yPosition + this.height; + + if(this.hovered && this.enabled) { + hoverAnimation = Math.min(1.0F, hoverAnimation + deltaTime * ANIMATION_SPEED); + } else { + hoverAnimation = Math.max(0.0F, hoverAnimation - deltaTime * ANIMATION_SPEED); + } + + int bgColor; + int borderColor; + int textColor; + + if(!this.enabled) { + bgColor = BACKGROUND_DISABLED; + borderColor = BORDER_COLOR; + textColor = TEXT_DISABLED; + } else { + bgColor = interpolateColor(BACKGROUND_COLOR, BACKGROUND_HOVER, hoverAnimation); + borderColor = interpolateColor(BORDER_COLOR, BORDER_HOVER, hoverAnimation); + textColor = interpolateColor(TEXT_COLOR, TEXT_HOVER, hoverAnimation); + } + + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + + drawRect( + this.xPosition, + this.yPosition, + this.xPosition + this.width, + this.yPosition + this.height, + bgColor); + + drawRect( + this.xPosition, + this.yPosition, + this.xPosition + this.width, + this.yPosition + 1, + borderColor); + drawRect( + this.xPosition, + this.yPosition + this.height - 1, + this.xPosition + this.width, + this.yPosition + this.height, + borderColor); + drawRect( + this.xPosition, + this.yPosition, + this.xPosition + 1, + this.yPosition + this.height, + borderColor); + drawRect( + this.xPosition + this.width - 1, + this.yPosition, + this.xPosition + this.width, + this.yPosition + this.height, + borderColor); + + this.mouseDragged(mc, mouseX, mouseY); + this.drawButtonText(mc, textColor); + + GlStateManager.disableBlend(); } - text = text + "..."; - } - - float textWidth = this.customFont.getStringWidth(text); - float x = this.xPosition + (this.width - textWidth) / 2.0F; - float y = this.yPosition + (this.height - this.customFont.getHeight()) / 2.0F; - this.customFont.drawString(text, x, y, textColor); - } else { - FontRenderer fr = mc.fontRendererObj; - String text = this.displayString; - int maxWidth = this.width - 6; - if (fr.getStringWidth(text) > maxWidth) { - while (!text.isEmpty() && fr.getStringWidth(text + "...") > maxWidth) { - text = text.substring(0, text.length() - 1); + } + + /** + * Draws the button text. Override this method to use a custom font renderer. + */ + protected void drawButtonText(Minecraft mc, int textColor) { + if(this.customFont != null) { + String text = this.displayString; + int maxWidth = this.width - 6; + if(this.customFont.getStringWidth(text) > maxWidth) { + while(!text.isEmpty() && this.customFont.getStringWidth(text + "...") > maxWidth) { + text = text.substring(0, text.length() - 1); + } + text = text + "..."; + } + + float textWidth = this.customFont.getStringWidth(text); + float x = this.xPosition + (this.width - textWidth) / 2.0F; + float y = this.yPosition + (this.height - this.customFont.getHeight()) / 2.0F; + this.customFont.drawString(text, x, y, textColor); + } else { + FontRenderer fr = mc.fontRendererObj; + String text = this.displayString; + int maxWidth = this.width - 6; + if(fr.getStringWidth(text) > maxWidth) { + while(!text.isEmpty() && fr.getStringWidth(text + "...") > maxWidth) { + text = text.substring(0, text.length() - 1); + } + text = text + "..."; + } + drawCenteredString( + fr, + text, + this.xPosition + this.width / 2, + this.yPosition + (this.height - 8) / 2, + textColor); } - text = text + "..."; - } - drawCenteredString( - fr, - text, - this.xPosition + this.width / 2, - this.yPosition + (this.height - 8) / 2, - textColor); } - } - - /** - * Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e). - */ - protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) {} - - /** - * Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent - * e). - */ - public void mouseReleased(int mouseX, int mouseY) {} - - /** - * 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) { - return this.enabled - && this.visible - && mouseX >= this.xPosition - && mouseY >= this.yPosition - && mouseX < this.xPosition + this.width - && mouseY < this.yPosition + this.height; - } - - /** Whether the mouse cursor is currently over the button. */ - public boolean isMouseOver() { - return this.hovered; - } - - public void drawButtonForegroundLayer(int mouseX, int mouseY) {} - - public void playPressSound(SoundHandler soundHandlerIn) { - soundHandlerIn.playSound( - PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); - } - - public int getButtonWidth() { - return this.width; - } - - public void setWidth(int width) { - this.width = width; - } + + /** + * Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e). + */ + protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) { + } + + /** + * Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent + * e). + */ + public void mouseReleased(int mouseX, int mouseY) { + } + + /** + * 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) { + return this.enabled + && this.visible + && mouseX >= this.xPosition + && mouseY >= this.yPosition + && mouseX < this.xPosition + this.width + && mouseY < this.yPosition + this.height; + } + + /** + * Whether the mouse cursor is currently over the button. + */ + public boolean isMouseOver() { + return this.hovered; + } + + public void drawButtonForegroundLayer(int mouseX, int mouseY) { + } + + public void playPressSound(SoundHandler soundHandlerIn) { + soundHandlerIn.playSound( + PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); + } + + public int getButtonWidth() { + return this.width; + } + + public void setWidth(int width) { + this.width = width; + } } diff --git a/src/main/java/net/minecraft/client/gui/GuiTextField.java b/src/main/java/net/minecraft/client/gui/GuiTextField.java index 82406b98..e0ab5b5c 100644 --- a/src/main/java/net/minecraft/client/gui/GuiTextField.java +++ b/src/main/java/net/minecraft/client/gui/GuiTextField.java @@ -2,6 +2,8 @@ import com.google.common.base.Predicate; import com.google.common.base.Predicates; +import dev.thoq.gui.UIConstants; +import dev.thoq.util.render.RenderUtility; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; @@ -53,6 +55,13 @@ public class GuiTextField extends Gui { private GuiPageButtonList.GuiResponder field_175210_x; private Predicate field_175209_y = Predicates.alwaysTrue(); + /** Underline fade animation: 0.0 = gray (#555555), 1.0 = ACCENT_COLOR */ + private float underlineProgress = 0.0f; + + private static final int UNDERLINE_COLOR_UNFOCUSED = 0xFF555555; + private static final long FADE_DURATION_MS = 200; + private long lastUpdateTime = System.currentTimeMillis(); + public GuiTextField( int componentId, FontRenderer fontrendererObj, int x, int y, int par5Width, int par6Height) { this.id = componentId; @@ -398,22 +407,19 @@ public void mouseClicked(int p_146192_1_, int p_146192_2_, int p_146192_3_) { /** Draws the textbox */ public void drawTextBox() { - if (this.getVisible()) { - if (this.getEnableBackgroundDrawing()) { - drawRect( - this.xPosition - 1, - this.yPosition - 1, - this.xPosition + this.width + 1, - this.yPosition + this.height + 1, - -6250336); - drawRect( - this.xPosition, - this.yPosition, - this.xPosition + this.width, - this.yPosition + this.height, - -16777216); - } + long now = System.currentTimeMillis(); + long elapsed = now - lastUpdateTime; + lastUpdateTime = now; + float delta = (float) elapsed / FADE_DURATION_MS; + if (this.isFocused) { + underlineProgress = Math.min(1.0f, underlineProgress + delta); + } else { + underlineProgress = Math.max(0.0f, underlineProgress - delta); + } + + int underlineColor = RenderUtility.interpolateColor(UNDERLINE_COLOR_UNFOCUSED, UIConstants.ACCENT_COLOR, underlineProgress); + if (this.getVisible()) { int i = this.isEnabled ? this.enabledColor : this.disabledColor; int j = this.cursorPosition - this.lineScrollOffset; int k = this.selectionEnd - this.lineScrollOffset; @@ -431,7 +437,7 @@ public void drawTextBox() { k = s.length(); } - if (s.length() > 0) { + if (!s.isEmpty()) { String s1 = flag ? s.substring(0, j) : s; j1 = this.fontRendererInstance.drawStringWithShadow(s1, (float) l, (float) i1, i); } @@ -467,6 +473,9 @@ public void drawTextBox() { int l1 = l + this.fontRendererInstance.getStringWidth(s.substring(0, k)); this.drawCursorVertical(k1, i1 - 1, l1 - 1, i1 + 1 + this.fontRendererInstance.FONT_HEIGHT); } + + int underlineY = this.yPosition + this.height; + Gui.drawRect(this.xPosition, underlineY, this.xPosition + this.width, underlineY + 1, underlineColor); } } @@ -553,6 +562,7 @@ public void setFocused(boolean p_146195_1_) { } this.isFocused = p_146195_1_; + this.lastUpdateTime = System.currentTimeMillis(); } /** Getter for the focused field */ diff --git a/src/main/java/net/minecraft/client/network/NetHandlerPlayClient.java b/src/main/java/net/minecraft/client/network/NetHandlerPlayClient.java index 2ff24042..5bf5e1f1 100644 --- a/src/main/java/net/minecraft/client/network/NetHandlerPlayClient.java +++ b/src/main/java/net/minecraft/client/network/NetHandlerPlayClient.java @@ -278,7 +278,13 @@ public void handleSpawnPlayer(S0CPacketSpawnPlayer packetIn) { double d2 = (double) packetIn.getZ() / 32.0D; float f = (float) (packetIn.getYaw() * 360) / 256.0F; float f1 = (float) (packetIn.getPitch() * 360) / 256.0F; - EntityOtherPlayerMP entityotherplayermp = new EntityOtherPlayerMP(this.gameController.theWorld, this.getPlayerInfo(packetIn.getPlayer()).getGameProfile()); + NetworkPlayerInfo playerInfo = this.getPlayerInfo(packetIn.getPlayer()); + if (playerInfo == null) { + GameProfile fallbackProfile = new GameProfile(packetIn.getPlayer(), "Unknown"); + playerInfo = new NetworkPlayerInfo(fallbackProfile); + this.playerInfoMap.put(packetIn.getPlayer(), playerInfo); + } + EntityOtherPlayerMP entityotherplayermp = new EntityOtherPlayerMP(this.gameController.theWorld, playerInfo.getGameProfile()); entityotherplayermp.prevPosX = entityotherplayermp.lastTickPosX = (double) (entityotherplayermp.serverPosX = packetIn.getX()); entityotherplayermp.prevPosY = entityotherplayermp.lastTickPosY = (double) (entityotherplayermp.serverPosY = packetIn.getY()); entityotherplayermp.prevPosZ = entityotherplayermp.lastTickPosZ = (double) (entityotherplayermp.serverPosZ = packetIn.getZ()); diff --git a/src/main/resources/lua/modules/player/legitscaffold.lua b/src/main/resources/lua/modules/player/legitscaffold.lua index 7c570cae..eeb56602 100644 --- a/src/main/resources/lua/modules/player/legitscaffold.lua +++ b/src/main/resources/lua/modules/player/legitscaffold.lua @@ -79,8 +79,8 @@ alya.events.on("motion", function(event) local pitch = alya.mc.getCameraPitch() local yaw = alya.mc.getCameraYaw() - local pitchOk = alya.mathutil.isBetween(pitch, 72, 82) - local yawOk = alya.mathutil.isBetween(yaw, yaw - 102, yaw + 102) + local pitchOk = alya.mathutil.isBetween(pitch, 45, 90) + local yawOk = alya.mathutil.isBetween(yaw, yaw - 110, yaw + 110) shouldSneak = pitchOk and yawOk end