From 8b156908790bac340399182f0d87c660031a1354 Mon Sep 17 00:00:00 2001 From: peytonplayz585 <106421860+PeytonPlayz595@users.noreply.github.com> Date: Thu, 27 Jul 2023 09:26:05 -0700 Subject: [PATCH] Fixed walking while Inventory is open. --- .../java/net/minecraft/client/Minecraft.java | 25 ++++++++++----- .../player/MovementInputFromOptions.java | 31 ++++++++++--------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/teavm/java/net/minecraft/client/Minecraft.java b/src/teavm/java/net/minecraft/client/Minecraft.java index a768426..88c90de 100644 --- a/src/teavm/java/net/minecraft/client/Minecraft.java +++ b/src/teavm/java/net/minecraft/client/Minecraft.java @@ -74,6 +74,8 @@ public final class Minecraft implements Runnable { public boolean inventoryScreen; private int prevFrameTime; public boolean inGameHasFocus; + + public static Minecraft mc; public Minecraft(int var3, int var4) { new ModelBiped(0.0F); @@ -93,6 +95,7 @@ public final class Minecraft implements Runnable { this.displayWidth = var3; this.displayHeight = var4; this.fullscreen = false; + mc = this; } public final void setServer(String var1, int var2) { @@ -487,13 +490,15 @@ public final class Minecraft implements Runnable { } if(this.playerController instanceof PlayerControllerCreative) { - if(GL11.getEventKey() == this.options.keyBindLoad.keyCode) { - this.thePlayer.preparePlayerToSpawn(); - } + if(this.inventoryScreen) { + if(GL11.getEventKey() == this.options.keyBindLoad.keyCode) { + this.thePlayer.preparePlayerToSpawn(); + } - if(GL11.getEventKey() == this.options.keyBindSave.keyCode) { - this.theWorld.setSpawnLocation((int)this.thePlayer.posX, (int)this.thePlayer.posY, (int)this.thePlayer.posZ, this.thePlayer.rotationYaw); - this.thePlayer.preparePlayerToSpawn(); + if(GL11.getEventKey() == this.options.keyBindSave.keyCode) { + this.theWorld.setSpawnLocation((int)this.thePlayer.posX, (int)this.thePlayer.posY, (int)this.thePlayer.posZ, this.thePlayer.rotationYaw); + this.thePlayer.preparePlayerToSpawn(); + } } } @@ -505,7 +510,7 @@ public final class Minecraft implements Runnable { this.displayGuiScreen(new GuiInventory(this.thePlayer.inventory)); } - if(GL11.getEventKey() == this.options.keyBindDrop.keyCode) { + if(GL11.getEventKey() == this.options.keyBindDrop.keyCode && this.inventoryScreen) { this.thePlayer.dropPlayerItemWithRandomChoice(this.thePlayer.inventory.decrStackSize(this.thePlayer.inventory.currentItem, 1), false); } } @@ -516,7 +521,7 @@ public final class Minecraft implements Runnable { } } - if(GL11.getEventKey() == this.options.keyBindToggleFog.keyCode) { + if(GL11.getEventKey() == this.options.keyBindToggleFog.keyCode && this.inventoryScreen) { this.options.setOptionValue(4, !GL11.isKeyDown(42) && !GL11.isKeyDown(54) ? 1 : -1); } } @@ -646,4 +651,8 @@ public final class Minecraft implements Runnable { System.gc(); } + + public static Minecraft getMinecraft() { + return mc; + } } diff --git a/src/teavm/java/net/minecraft/client/player/MovementInputFromOptions.java b/src/teavm/java/net/minecraft/client/player/MovementInputFromOptions.java index e271221..4ed332f 100644 --- a/src/teavm/java/net/minecraft/client/player/MovementInputFromOptions.java +++ b/src/teavm/java/net/minecraft/client/player/MovementInputFromOptions.java @@ -1,6 +1,7 @@ package net.minecraft.client.player; import net.minecraft.client.GameSettings; +import net.minecraft.client.Minecraft; public final class MovementInputFromOptions extends MovementInput { private boolean[] movementKeyStates = new boolean[10]; @@ -12,24 +13,26 @@ public final class MovementInputFromOptions extends MovementInput { public final void checkKeyForMovementInput(int var1, boolean var2) { byte var3 = -1; - if(var1 == this.gameSettings.keyBindForward.keyCode) { - var3 = 0; - } + if(Minecraft.getMinecraft().inventoryScreen) { + if(var1 == this.gameSettings.keyBindForward.keyCode) { + var3 = 0; + } - if(var1 == this.gameSettings.keyBindBack.keyCode) { - var3 = 1; - } + if(var1 == this.gameSettings.keyBindBack.keyCode) { + var3 = 1; + } - if(var1 == this.gameSettings.keyBindLeft.keyCode) { - var3 = 2; - } + if(var1 == this.gameSettings.keyBindLeft.keyCode) { + var3 = 2; + } - if(var1 == this.gameSettings.keyBindRight.keyCode) { - var3 = 3; - } + if(var1 == this.gameSettings.keyBindRight.keyCode) { + var3 = 3; + } - if(var1 == this.gameSettings.keyBindJump.keyCode) { - var3 = 4; + if(var1 == this.gameSettings.keyBindJump.keyCode) { + var3 = 4; + } } if(var3 >= 0) {