Compare commits

...

3 Commits

Author SHA1 Message Date
PeytonPlayz595
54806c33c7 Controller cursor 2024-07-06 11:54:24 -07:00
PeytonPlayz595
b7e70b9368 Fix walking with inventory open 2024-07-06 10:05:15 -07:00
PeytonPlayz595
60be872ee2 Invert jump and crouch controller mappings 2024-07-06 10:01:17 -07:00
4 changed files with 90 additions and 5 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ desktopRuntime/options.txt
desktopRuntime/_eagstorage* desktopRuntime/_eagstorage*
desktopRuntime/filesystem/* desktopRuntime/filesystem/*
desktopRuntime/downloads/* desktopRuntime/downloads/*
javascript/Shadow_Client_en_US.zip

View File

@ -6,7 +6,12 @@ import java.util.List;
import org.teavm.jso.browser.Navigator; import org.teavm.jso.browser.Navigator;
import org.teavm.jso.browser.Window; import org.teavm.jso.browser.Window;
import org.teavm.jso.dom.events.EventListener; import org.teavm.jso.dom.events.EventListener;
import org.teavm.jso.dom.html.HTMLBodyElement;
import org.teavm.jso.dom.html.HTMLImageElement;
import org.teavm.jso.gamepad.GamepadEvent; import org.teavm.jso.gamepad.GamepadEvent;
import net.lax1dude.eaglercraft.v1_8.Display;
import org.teavm.jso.gamepad.Gamepad; import org.teavm.jso.gamepad.Gamepad;
public class Controller { public class Controller {
@ -28,6 +33,8 @@ public class Controller {
private static int activeController = -1; private static int activeController = -1;
private static ButtonState[] states = new ButtonState[30]; private static ButtonState[] states = new ButtonState[30];
public static HTMLImageElement cursor;
public static final int getDX() { public static final int getDX() {
if(dx < 0.0) { if(dx < 0.0) {
if(dx < -cameraThreshold) { if(dx < -cameraThreshold) {
@ -71,11 +78,11 @@ public class Controller {
} }
public static boolean jump() { public static boolean jump() {
return isButtonPressed(1) || isButtonDown(1); return isButtonPressed(0) || isButtonDown(0);
} }
public static boolean crouch() { public static boolean crouch() {
return isButtonPressed(0) || isButtonDown(0) || isButtonPressed(11) || isButtonDown(11); return isButtonPressed(1) || isButtonDown(1) || isButtonPressed(11) || isButtonDown(11);
} }
public static boolean sprint() { public static boolean sprint() {
@ -134,6 +141,38 @@ public class Controller {
*/ */
dy = -axes[3] * multiplier; dy = -axes[3] * multiplier;
if(cursor != null) {
double dx1;
double dy1 = dy;
if(dx1 < 0.0) {
if(dx1 < -cameraThreshold) {
dx1 = dx;
}
} else if(dx > 0.0) {
if(dx > cameraThreshold) {
dx1 = dx;
}
} else {
dx1 = 0;
}
if(dy1 < 0.0) {
if(dy1 < -cameraThreshold) {
dy1 = dy;
}
} else if(dy1 > 0.0) {
if(dy1 > cameraThreshold) {
dy1 = dy;
}
} else {
dy1 = 0;
}
updateCursor((int)dx1, (int)dy1);
}
forward = axes[1] < -threshold; forward = axes[1] < -threshold;
backwards = axes[1] > threshold; backwards = axes[1] > threshold;
left = axes[0] < -threshold; left = axes[0] < -threshold;
@ -169,6 +208,38 @@ public class Controller {
} }
} }
public static void addCursor(int x, int y) {
cursor = (HTMLImageElement) Window.current().getDocument().createElement("img");
cursor.setAttribute("id", "cursor");
cursor.setSrc(cursorSrc);
cursor.setAttribute("draggable", "false");
cursor.getStyle().setProperty("left", "0px");
cursor.getStyle().setProperty("top", "0px");
cursor.getStyle().setProperty("width", "auto");
cursor.getStyle().setProperty("height", "auto");
HTMLBodyElement body = (HTMLBodyElement) Window.current().getDocument().getBody();
body.appendChild(cursor);
}
public static void removeCursor() {
if (cursor != null) {
cursor.getParentNode().removeChild(cursor);
}
cursor = null;
}
private static void updateCursor(int dx, int dy) {
int dx1 = cursor.getAbsoluteLeft() + dx;
int dy1 = cursor.getAbsoluteTop() + dy;
int x = Math.min(Math.max(dx1, 0), Display.getWidth() - cursor.getWidth());
int y = Math.min(Math.max(dy1, 0), Display.getHeight() - cursor.getHeight());
cursor.getStyle().setProperty("left", dx1 + "px");
cursor.getStyle().setProperty("top", dy1 + "px");
}
private static Gamepad getGamepad(int index) { private static Gamepad getGamepad(int index) {
return Navigator.getGamepads()[index]; return Navigator.getGamepads()[index];
} }
@ -205,4 +276,6 @@ public class Controller {
resetButtonStates(); resetButtonStates();
} }
private static String cursorSrc = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAWCAYAAAAmaHdCAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV/TiiIVBzOIOGSoThbELxylikWwUNoKrTqYXPoFTRqSFBdHwbXg4Mdi1cHFWVcHV0EQ/ABxc3NSdJES/5cUWsR4cNyPd/ced+8AoVFhmhUaBzTdNlPxmJTNrUrdrwhDRAjTiMrMMhLpxQx8x9c9Any9i/Is/3N/jj41bzEgIBHPMcO0iTeIZzZtg/M+schKskp8Tjxm0gWJH7muePzGueiywDNFM5OaJxaJpWIHKx3MSqZGPEUcUTWd8oWsxyrnLc5apcZa9+QvDOf1lTTXaQ4jjiUkkIQEBTWUUYGNKK06KRZStB/z8Q+5/iS5FHKVwcixgCo0yK4f/A9+d2sVJie8pHAM6HpxnI8RoHsXaNYd5/vYcZonQPAZuNLb/moDmP0kvd7WIkdA/zZwcd3WlD3gcgcYfDJkU3alIE2hUADez+ibcsDALdC75vXW2sfpA5ChrpZvgINDYLRI2es+7+7p7O3fM63+fgDbd3LRJJH9vQAAAAZiS0dEAJ0AnQCdq6CchAAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAeJJREFUOMvdlL9rFEEUx7+Zd0x3tWSQEEEIXBUCueawELQQERULxdZObMXGVrh/wuqqtEKapEihFtlA7kT8EUjpjhHhjsO9c3dv3jwLM+vmbr1TsPILC7Ps7me+b7/vDWGOSJumovonRfWWovqR8LcYfyvSRoJIG/ndewr/QP87hLRpkjY7VT+StJHTZ82FiURRt0iknI6ISBR1pQQzfxTr9JqZhbSRV6/3f4GC9WBzHoSZZTKZCGkjo9FI9vZeCmmzA9JGYnsisT0JIKlSAKRpKqSNDIdD6ff7QtqIArALAGb5HFwWX60q0XsP7z2YGcyM/tcPYGY454p0nq6sbuzaz18AAE8eP5qNUCnUajWMx2NkWVYACgjnNgKwtbK6sQ0At25eq5yRwWBw5v4MBAA4t88BNA4OerK5ub5U/jBcQUmSIE1TOOdw2H0LAO+XStE+AHDbZfF17z2UUjO7J0lSrJkZF9da7emO7QBo7EeH8N4vBJyWchfAVgHh3OYAnrUu3dhm5p/uiCob0jmH3pt3APCdc9ubnp0OgEYUdUFExY5pmhYOQjr37j9sA3gxM4DBzeUrd9rlGJ1zBTD0SigFAGoVbjsAPs4DeO8BgDi3vUoI5zYnbY6Xz69fWHCMHIXFD7PBln0/6ZSqAAAAAElFTkSuQmCC";
} }

View File

@ -1292,6 +1292,16 @@ public class Minecraft extends ModData implements IThreadListener {
Controller.tick(); Controller.tick();
if(this.currentScreen != null) {
if(Controller.cursor == null) {
Controller.addCursor(0, 0);
}
} else {
if(Controller.cursor != null) {
Controller.removeCursor();
}
}
if (this.rightClickDelayTimer > 0) { if (this.rightClickDelayTimer > 0) {
--this.rightClickDelayTimer; --this.rightClickDelayTimer;
} }

View File

@ -1,6 +1,7 @@
package net.minecraft.util; package net.minecraft.util;
import net.PeytonPlayz585.shadow.input.Controller; import net.PeytonPlayz585.shadow.input.Controller;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.GameSettings; import net.minecraft.client.settings.GameSettings;
/**+ /**+
@ -49,8 +50,8 @@ public class MovementInputFromOptions extends MovementInput {
--this.moveStrafe; --this.moveStrafe;
} }
this.jump = this.gameSettings.keyBindJump.isKeyDown() || Controller.jump(); this.jump = this.gameSettings.keyBindJump.isKeyDown() || (Controller.jump() && Minecraft.getMinecraft().currentScreen == null);
this.sneak = this.gameSettings.keyBindSneak.isKeyDown() || Controller.crouch(); this.sneak = this.gameSettings.keyBindSneak.isKeyDown() || (Controller.crouch() && Minecraft.getMinecraft().currentScreen == null);
if (this.sneak) { if (this.sneak) {
this.moveStrafe = (float) ((double) this.moveStrafe * 0.3D); this.moveStrafe = (float) ((double) this.moveStrafe * 0.3D);
this.moveForward = (float) ((double) this.moveForward * 0.3D); this.moveForward = (float) ((double) this.moveForward * 0.3D);