Skip to content

Commit 48f8a49

Browse files
Controller mouse click
1 parent f20012c commit 48f8a49

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

src/main/java/net/minecraft/client/gui/GuiButton.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class GuiButton extends Gui {
4040
public int id;
4141
public boolean enabled;
4242
public boolean visible;
43-
protected boolean hovered;
43+
public boolean hovered;
4444
public float fontScale = 1.0f;
4545

4646
public GuiButton(int buttonId, int x, int y, String buttonText) {

src/teavm/java/net/PeytonPlayz585/shadow/input/Controller.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import org.teavm.jso.gamepad.GamepadEvent;
1212

1313
import net.lax1dude.eaglercraft.v1_8.Display;
14+
import net.lax1dude.eaglercraft.v1_8.Mouse;
1415
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
16+
import net.minecraft.client.Minecraft;
1517

1618
import org.teavm.jso.gamepad.Gamepad;
1719

@@ -27,8 +29,8 @@ public class Controller {
2729
private static boolean left = false;
2830
private static boolean right = false;
2931

30-
private static double threshold = 0.3;
3132
//Fixes 'slight' issues of stick drift people have been complaining about
33+
private static double threshold = 0.3;
3234
private static double cameraThreshold = 4.0;
3335
private static double cursorThreshold = 0.4;
3436

@@ -189,6 +191,10 @@ public static void tick() {
189191
updateAxes(gamePad);
190192
updateButtons(gamePad, index);
191193
}
194+
195+
if(cursor != null && isButtonPressed(0) || isButtonDown(0)) {
196+
Minecraft.getMinecraft().currentScreen.controllerClicked(Mouse.getX(), Mouse.getY());
197+
}
192198
}
193199

194200
public static void addCursor(int x, int y) {

src/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/PlatformInput.java

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.teavm.jso.webgl.WebGLFramebuffer;
2222
import org.teavm.jso.webgl.WebGLRenderbuffer;
2323

24+
import net.PeytonPlayz585.shadow.input.Controller;
2425
import net.lax1dude.eaglercraft.v1_8.EagUtils;
2526
import net.lax1dude.eaglercraft.v1_8.internal.teavm.EarlyLoadScreen;
2627
import net.lax1dude.eaglercraft.v1_8.internal.teavm.WebGL2RenderingContext;
@@ -503,10 +504,16 @@ public static int mouseGetEventDWheel() {
503504
}
504505

505506
public static int mouseGetX() {
507+
if(Controller.cursor != null) {
508+
return Controller.cursor.getOffsetLeft();
509+
}
506510
return mouseX;
507511
}
508512

509513
public static int mouseGetY() {
514+
if(Controller.cursor != null) {
515+
return canvas.getClientHeight() - Controller.cursor.getOffsetTop();
516+
}
510517
return mouseY;
511518
}
512519

src/teavm/java/net/minecraft/client/gui/GuiScreen.java

+11
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,17 @@ public void sendChatMessage(String msg, boolean addToChat) {
425425

426426
this.mc.thePlayer.sendChatMessage(msg);
427427
}
428+
429+
public void controllerClicked(int x, int y) {
430+
for (int i = 0; i < this.buttonList.size(); ++i) {
431+
GuiButton guibutton = (GuiButton) this.buttonList.get(i);
432+
if (guibutton.enabled && guibutton.visible && guibutton.hovered) {
433+
this.selectedButton = guibutton;
434+
guibutton.playPressSound(this.mc.getSoundHandler());
435+
this.actionPerformed(guibutton);
436+
}
437+
}
438+
}
428439

429440
/**+
430441
* Called when the mouse is clicked. Args : mouseX, mouseY,

0 commit comments

Comments
 (0)