From 48f8a49dd353cc809285be5dbf390ef48cec208a Mon Sep 17 00:00:00 2001 From: PeytonPlayz595 <106421860+PeytonPlayz595@users.noreply.github.com> Date: Mon, 8 Jul 2024 08:16:20 -0700 Subject: [PATCH] Controller mouse click --- src/main/java/net/minecraft/client/gui/GuiButton.java | 2 +- .../net/PeytonPlayz585/shadow/input/Controller.java | 8 +++++++- .../eaglercraft/v1_8/internal/PlatformInput.java | 7 +++++++ .../java/net/minecraft/client/gui/GuiScreen.java | 11 +++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minecraft/client/gui/GuiButton.java b/src/main/java/net/minecraft/client/gui/GuiButton.java index f7a6fbd..f77e6ef 100644 --- a/src/main/java/net/minecraft/client/gui/GuiButton.java +++ b/src/main/java/net/minecraft/client/gui/GuiButton.java @@ -40,7 +40,7 @@ public class GuiButton extends Gui { public int id; public boolean enabled; public boolean visible; - protected boolean hovered; + public boolean hovered; public float fontScale = 1.0f; public GuiButton(int buttonId, int x, int y, String buttonText) { diff --git a/src/teavm/java/net/PeytonPlayz585/shadow/input/Controller.java b/src/teavm/java/net/PeytonPlayz585/shadow/input/Controller.java index e2a1e4a..65b76af 100644 --- a/src/teavm/java/net/PeytonPlayz585/shadow/input/Controller.java +++ b/src/teavm/java/net/PeytonPlayz585/shadow/input/Controller.java @@ -11,7 +11,9 @@ import org.teavm.jso.dom.html.HTMLImageElement; import org.teavm.jso.gamepad.GamepadEvent; import net.lax1dude.eaglercraft.v1_8.Display; +import net.lax1dude.eaglercraft.v1_8.Mouse; import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime; +import net.minecraft.client.Minecraft; import org.teavm.jso.gamepad.Gamepad; @@ -27,8 +29,8 @@ public class Controller { private static boolean left = false; private static boolean right = false; - private static double threshold = 0.3; //Fixes 'slight' issues of stick drift people have been complaining about + private static double threshold = 0.3; private static double cameraThreshold = 4.0; private static double cursorThreshold = 0.4; @@ -189,6 +191,10 @@ public class Controller { updateAxes(gamePad); updateButtons(gamePad, index); } + + if(cursor != null && isButtonPressed(0) || isButtonDown(0)) { + Minecraft.getMinecraft().currentScreen.controllerClicked(Mouse.getX(), Mouse.getY()); + } } public static void addCursor(int x, int y) { diff --git a/src/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java b/src/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java index 94536b3..f85f3ec 100644 --- a/src/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java +++ b/src/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java @@ -21,6 +21,7 @@ import org.teavm.jso.dom.html.HTMLElement; import org.teavm.jso.webgl.WebGLFramebuffer; import org.teavm.jso.webgl.WebGLRenderbuffer; +import net.PeytonPlayz585.shadow.input.Controller; import net.lax1dude.eaglercraft.v1_8.EagUtils; import net.lax1dude.eaglercraft.v1_8.internal.teavm.EarlyLoadScreen; import net.lax1dude.eaglercraft.v1_8.internal.teavm.WebGL2RenderingContext; @@ -503,10 +504,16 @@ public class PlatformInput { } public static int mouseGetX() { + if(Controller.cursor != null) { + return Controller.cursor.getOffsetLeft(); + } return mouseX; } public static int mouseGetY() { + if(Controller.cursor != null) { + return canvas.getClientHeight() - Controller.cursor.getOffsetTop(); + } return mouseY; } diff --git a/src/teavm/java/net/minecraft/client/gui/GuiScreen.java b/src/teavm/java/net/minecraft/client/gui/GuiScreen.java index 0165809..439d092 100644 --- a/src/teavm/java/net/minecraft/client/gui/GuiScreen.java +++ b/src/teavm/java/net/minecraft/client/gui/GuiScreen.java @@ -425,6 +425,17 @@ public abstract class GuiScreen extends Gui implements GuiYesNoCallback { this.mc.thePlayer.sendChatMessage(msg); } + + public void controllerClicked(int x, int y) { + for (int i = 0; i < this.buttonList.size(); ++i) { + GuiButton guibutton = (GuiButton) this.buttonList.get(i); + if (guibutton.enabled && guibutton.visible && guibutton.hovered) { + this.selectedButton = guibutton; + guibutton.playPressSound(this.mc.getSoundHandler()); + this.actionPerformed(guibutton); + } + } + } /**+ * Called when the mouse is clicked. Args : mouseX, mouseY,