Fix crash and shaders, add controller support

This commit is contained in:
PeytonPlayz595 2024-01-15 21:29:03 +00:00
parent b713c4e31d
commit 0fda59393f
13 changed files with 107362 additions and 107258 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -83,9 +83,7 @@ let upDownAxis1 = 0;
let leftRightAxis2 = 0; let leftRightAxis2 = 0;
let upDownAxis2 = 0; let upDownAxis2 = 0;
//in-game controller const buttonStates = {};
let jump = false;
let crouch = false;
window.addEventListener("gamepadconnected", (event) => { window.addEventListener("gamepadconnected", (event) => {
const gamepad = event.gamepad; const gamepad = event.gamepad;
@ -124,22 +122,6 @@ function controllerConnected() {
return false; return false;
} }
function handleButtons(buttons) {
for(let i = 0; i < buttons.length; i++) {
const button = buttons[i];
if(button.value > 0) {
if(i == 0) {
jump = true;
}
if(i == 1) {
crouch = true;
}
}
}
}
function getCameraX() { function getCameraX() {
return leftRightAxis2; return leftRightAxis2;
} }
@ -176,14 +158,32 @@ function isWalkingRight() {
return false; return false;
} }
function isKeyDown(buttonID) { function isKeyDown(keyCode) {
const gamepad = navigator.getGamepads()[controllerIndex]; const gamepads = navigator.getGamepads();
const buttons = gamepad.buttons; if (gamepads.length > 0) {
const button = buttons[buttonID]; const gamepad = gamepads[0];
if (gamepad) { if (gamepad) {
const buttons = gamepad.buttons; const button = gamepad.buttons.find(btn => btn.value !== 0 && btn.keyCode === keyCode);
const button = buttons[buttonID]; return !!button;
return button.value > 0; }
}
return false;
}
function isPressed(keyCode) {
const gamepads = navigator.getGamepads();
if (gamepads.length > 0) {
const gamepad = gamepads[0];
if (gamepad) {
const button = gamepad.buttons.find(btn => btn.keyCode === keyCode);
if (button.pressed && !buttonStates[keyCode]) {
buttonStates[keyCode] = true;
return true;
} else {
buttonStates[keyCode] = button.pressed;
return false;
}
}
} }
return false; return false;
} }
@ -193,10 +193,12 @@ function updateController() {
if(controllerIndex != null) { if(controllerIndex != null) {
const gamepad = navigator.getGamepads()[controllerIndex]; const gamepad = navigator.getGamepads()[controllerIndex];
handleSticks(gamepad.axes); handleSticks(gamepad.axes);
handleButtons(gamepad.buttons);
} }
} }
requestAnimationFrame(updateController);
} }
requestAnimationFrame(updateController);
</script> </script>
<link type="image/png" rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAR/SURBVEhLtZXZK3ZRFMYPcqXc+gv413DHxVuGIpIhkciQWaRccCNjSCkligwXSOZ5nmfv9zvn2e8+58V753sudmuvvdZ61l5r7XOc8H+GS/D19aUNkPz5+aktQH5/f//4+LBKZKuRkpUtQjCUYG5gD2T38vLy/PwsDfL9/f3Dw8PT05M0b29vnKLhCKCBT4L4gvBLBIei4//4+Hh1dUVEQutUuLu7E83FxQUGnKLBWKfQaA3S+AREVxaEOD8/Pzk50XpzcyMDcH19zdZG3N3d3dzc3Nvb01aX5pQUpQGGQJxcQpfNysoKhUIdHR1o1tbWbInYAgxIPDMzMy8vLzc3FxqOdMoRqwJK8G8ALUYIhHMiSEhIwI6CyIb0qQzC4eGhsXCc1tZWnZIEKzdQJQSXgKxfX18RCM3Z5eWlcfVAxKOjo+Pj49PTU88lTOk2NjbMsePc3t6SAfcgFdszOyMuAdeBg0CQi2lhYUHOeOLDCisN8FzcPFZXV3t7ezHY3t5GQ+6it+2xMASsKhEEWKsmRLRBBUpPvpJ/TpFKFBwKYAiITmicsbYhdHfJAltqhUCVsCQhwslmeXmZxiBQT9c0Ar9E2O3v72sYSE0N1yQArkKy0kBMXLqlZqIZHR3t6empqqqSDcBdhXEJSJ/bUc3q6uq+vj629GB9fR1WsLW1NTs7u7S0RN2locMjIyOEm5ubQ7+4uJienk4/+vv77Y1hwhLBEKhwWHitdVFfX9/Y2Gg2HuLi4owUAysrK8yCG97rh0+ApP5Q2ZycHFlPTExUVFRIBvn5+WhKSkp2dnaMKhptbW2426Gg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zBDoWQM1g98snyB+VSoRW8C/UwR81/SvhgNj9JOTkwwVERUdRBEI0BAdLRVERkhLS8vIyEDQlrsTPTU1lVFhKxARvZgUlFLbegCf4BvIsbi4mIg4E5EogIHhiKCMtU0WUFiVy06j5fAJIDdSBDQw+PegDfBRcbOPwH4F9LuFWIIQdQNKwWqzIE0aoFUaBsw+SQuFw0uNtC9A+F4i3QNrbg3IDn+SAsHh+wYiEpeyBEMLv/cAO6KzAijxxB+Y4wisBhssJUhjEbPJf4Nw+B+JXqLW3bw+wQAAAABJRU5ErkJggg==" />
</head> </head>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -8,9 +8,7 @@ let upDownAxis1 = 0;
let leftRightAxis2 = 0; let leftRightAxis2 = 0;
let upDownAxis2 = 0; let upDownAxis2 = 0;
//in-game controller const buttonStates = {};
let jump = false;
let crouch = false;
window.addEventListener("gamepadconnected", (event) => { window.addEventListener("gamepadconnected", (event) => {
const gamepad = event.gamepad; const gamepad = event.gamepad;
@ -49,22 +47,6 @@ function controllerConnected() {
return false; return false;
} }
function handleButtons(buttons) {
for(let i = 0; i < buttons.length; i++) {
const button = buttons[i];
if(button.value > 0) {
if(i == 0) {
jump = true;
}
if(i == 1) {
crouch = true;
}
}
}
}
function getCameraX() { function getCameraX() {
return leftRightAxis2; return leftRightAxis2;
} }
@ -101,14 +83,32 @@ function isWalkingRight() {
return false; return false;
} }
function isKeyDown(buttonID) { function isKeyDown(keyCode) {
const gamepad = navigator.getGamepads()[controllerIndex]; const gamepads = navigator.getGamepads();
const buttons = gamepad.buttons; if (gamepads.length > 0) {
const button = buttons[buttonID]; const gamepad = gamepads[0];
if (gamepad) { if (gamepad) {
const buttons = gamepad.buttons; const button = gamepad.buttons.find(btn => btn.value !== 0 && btn.keyCode === keyCode);
const button = buttons[buttonID]; return !!button;
return button.value > 0; }
}
return false;
}
function isPressed(keyCode) {
const gamepads = navigator.getGamepads();
if (gamepads.length > 0) {
const gamepad = gamepads[0];
if (gamepad) {
const button = gamepad.buttons.find(btn => btn.keyCode === keyCode);
if (button.pressed && !buttonStates[keyCode]) {
buttonStates[keyCode] = true;
return true;
} else {
buttonStates[keyCode] = button.pressed;
return false;
}
}
} }
return false; return false;
} }
@ -118,7 +118,9 @@ function updateController() {
if(controllerIndex != null) { if(controllerIndex != null) {
const gamepad = navigator.getGamepads()[controllerIndex]; const gamepad = navigator.getGamepads()[controllerIndex];
handleSticks(gamepad.axes); handleSticks(gamepad.axes);
handleButtons(gamepad.buttons);
} }
} }
requestAnimationFrame(updateController);
} }
requestAnimationFrame(updateController);

View File

@ -12,6 +12,7 @@
<meta property="og:description" content="test directory HTML page" /> <meta property="og:description" content="test directory HTML page" />
<link type="image/png" rel="shortcut icon" href="favicon.png" /> <link type="image/png" rel="shortcut icon" href="favicon.png" />
<script type="text/javascript" src="classes.js"></script> <script type="text/javascript" src="classes.js"></script>
<script type="text/javascript" src="controller.js"></script>
<script type="text/javascript" src="fix-webm-duration.js"></script> <script type="text/javascript" src="fix-webm-duration.js"></script>
<script type="text/javascript"> <script type="text/javascript">
"use strict"; "use strict";

View File

@ -0,0 +1,76 @@
package net.PeytonPlayz585.shadow.input;
import org.teavm.jso.JSBody;
public class Controller {
@JSBody(params = {"i"}, script = "return isKeyDown(i);")
private static native boolean isKeyDown2(int i);
@JSBody(params = {"i"}, script = "return isPressed(i);")
private static native boolean isPressed2(int i);
@JSBody(params = {}, script = "return isWalkingForward();")
public static native boolean isWalkingForward();
@JSBody(params = {}, script = "return isWalkingBackward();")
public static native boolean isWalkingBackward();
@JSBody(params = {}, script = "return isWalkingLeft();")
public static native boolean isWalkingLeft();
@JSBody(params = {}, script = "return isWalkingRight();")
public static native boolean isWalkingRight();
@JSBody(params = {}, script = "return getCameraX();")
public static native int getCameraX();
@JSBody(params = {}, script = "return getCameraY();")
public static native int getCameraY();
public static boolean isKeyDown(String i) {
if(keyboardToGamepad(i) == -1) {
return false;
}
return isKeyDown2(keyboardToGamepad(i));
}
public static boolean isPressed(String i) {
if(keyboardToGamepad(i) == -1) {
return false;
}
return isPressed2(keyboardToGamepad(i));
}
public static int getEventDWheel() {
if(isPressed2(4)) {
return -1;
} else if(isPressed2(5)) {
return 1;
}
return 0;
}
public static int keyboardToGamepad(String s) {
if(s.contains("attack")) {
return 7;
} else if(s.contains("use")) {
return 6;
} else if(s.contains("drop")) {
return 13;
} else if(s.contains("togglePerspective")) {
return 12;
} else if(s.contains("inventory")) {
return 3;
} else if(s.contains("jump")) {
return 0;
} else if(s.contains("sneak")) {
return 1;
} else if(s.contains("sprint")) {
return 10;
}
return -1;
}
}

View File

@ -83,8 +83,8 @@ public class ImageData {
if (cw != dx2 - dx1 || ch != dy2 - dy1) { if (cw != dx2 - dx1 || ch != dy2 - dy1) {
throw new IllegalArgumentException("Width and height of the copied region must match the width and height of the pasted region"); throw new IllegalArgumentException("Width and height of the copied region must match the width and height of the pasted region");
} }
int[] srcPixels = input.pixels.array(); int[] srcPixels = input.getPixels();
int[] dstPixels = pixels.array(); int[] dstPixels = getPixels();
int srcOffset = sx1 + sy1 * input.width; int srcOffset = sx1 + sy1 * input.width;
int dstOffset = dx1 + dy1 * width; int dstOffset = dx1 + dy1 * width;
for (int y = 0; y < ch; y++) { for (int y = 0; y < ch; y++) {
@ -101,8 +101,8 @@ public class ImageData {
if (cw != dx2 - dx1 || ch != dy2 - dy1) { if (cw != dx2 - dx1 || ch != dy2 - dy1) {
throw new IllegalArgumentException("Width and height of the copied region must match the width and height of the pasted region"); throw new IllegalArgumentException("Width and height of the copied region must match the width and height of the pasted region");
} }
int[] srcPixels = input.pixels.array(); int[] srcPixels = input.getPixels();
int[] dstPixels = pixels.array(); int[] dstPixels = getPixels();
int srcOffset = sx1 + sy1 * input.width; int srcOffset = sx1 + sy1 * input.width;
int dstOffset = dx1 + dy1 * width; int dstOffset = dx1 + dy1 * width;
for (int y = 0; y < ch; y++) { for (int y = 0; y < ch; y++) {
@ -134,7 +134,7 @@ public class ImageData {
} }
public ImageData swapRB() { public ImageData swapRB() {
int[] dstPixels = pixels.array(); int[] dstPixels = getPixels();
for (int i = 0; i < dstPixels.length; i++) { for (int i = 0; i < dstPixels.length; i++) {
int j = dstPixels[i]; int j = dstPixels[i];
dstPixels[i] = (j & 0xFF00FF00) | ((j & 0x00FF0000) >> 16) | ((j & 0x000000FF) << 16); dstPixels[i] = (j & 0xFF00FF00) | ((j & 0x00FF0000) >> 16) | ((j & 0x000000FF) << 16);

View File

@ -22,6 +22,7 @@ import net.FatalCodes.shadow.Shadow;
import net.PeytonPlayz585.shadow.Config; import net.PeytonPlayz585.shadow.Config;
import net.PeytonPlayz585.shadow.chunk.ChunkBorders; import net.PeytonPlayz585.shadow.chunk.ChunkBorders;
import net.PeytonPlayz585.shadow.gui.GuiSecretMainMenu; import net.PeytonPlayz585.shadow.gui.GuiSecretMainMenu;
import net.PeytonPlayz585.shadow.input.Controller;
import net.lax1dude.eaglercraft.v1_8.Display; import net.lax1dude.eaglercraft.v1_8.Display;
import net.lax1dude.eaglercraft.v1_8.EagRuntime; import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.HString; import net.lax1dude.eaglercraft.v1_8.HString;
@ -1337,7 +1338,7 @@ public class Minecraft implements IThreadListener {
long i1 = getSystemTime() - this.systemTime; long i1 = getSystemTime() - this.systemTime;
if (i1 <= 200L) { if (i1 <= 200L) {
int j = Mouse.getEventDWheel(); int j = Mouse.getEventDWheel() + Controller.getEventDWheel();
if (j != 0) { if (j != 0) {
if (this.thePlayer.isSpectator()) { if (this.thePlayer.isSpectator()) {
j = j < 0 ? -1 : 1; j = j < 0 ? -1 : 1;

View File

@ -6,6 +6,7 @@ import java.util.Set;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import net.PeytonPlayz585.shadow.input.Controller;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.util.IntHashMap; import net.minecraft.util.IntHashMap;
@ -106,7 +107,7 @@ public class KeyBinding implements Comparable<KeyBinding> {
* querying). Should be used in tickers. * querying). Should be used in tickers.
*/ */
public boolean isKeyDown() { public boolean isKeyDown() {
return this.pressed; return this.pressed | Controller.isKeyDown(keyDescription);
} }
public String getKeyCategory() { public String getKeyCategory() {

View File

@ -1,5 +1,6 @@
package net.minecraft.util; package net.minecraft.util;
import net.PeytonPlayz585.shadow.input.Controller;
import net.lax1dude.eaglercraft.v1_8.Display; import net.lax1dude.eaglercraft.v1_8.Display;
import net.lax1dude.eaglercraft.v1_8.Mouse; import net.lax1dude.eaglercraft.v1_8.Mouse;
@ -44,7 +45,7 @@ public class MouseHelper {
} }
public void mouseXYChange() { public void mouseXYChange() {
this.deltaX = Mouse.getDX(); this.deltaX = Mouse.getDX() + Controller.getCameraX();
this.deltaY = Mouse.getDY(); this.deltaY = Mouse.getDY() + Controller.getCameraY() * -1;
} }
} }

View File

@ -1,5 +1,6 @@
package net.minecraft.util; package net.minecraft.util;
import net.PeytonPlayz585.shadow.input.Controller;
import net.minecraft.client.settings.GameSettings; import net.minecraft.client.settings.GameSettings;
/**+ /**+
@ -30,19 +31,19 @@ public class MovementInputFromOptions extends MovementInput {
public void updatePlayerMoveState() { public void updatePlayerMoveState() {
this.moveStrafe = 0.0F; this.moveStrafe = 0.0F;
this.moveForward = 0.0F; this.moveForward = 0.0F;
if (this.gameSettings.keyBindForward.isKeyDown()) { if (this.gameSettings.keyBindForward.isKeyDown() || Controller.isWalkingForward()) {
++this.moveForward; ++this.moveForward;
} }
if (this.gameSettings.keyBindBack.isKeyDown()) { if (this.gameSettings.keyBindBack.isKeyDown() || Controller.isWalkingBackward()) {
--this.moveForward; --this.moveForward;
} }
if (this.gameSettings.keyBindLeft.isKeyDown()) { if (this.gameSettings.keyBindLeft.isKeyDown() || Controller.isWalkingLeft()) {
++this.moveStrafe; ++this.moveStrafe;
} }
if (this.gameSettings.keyBindRight.isKeyDown()) { if (this.gameSettings.keyBindRight.isKeyDown() || Controller.isWalkingRight()) {
--this.moveStrafe; --this.moveStrafe;
} }