Skip to content

Commit c284c52

Browse files
committed
[Savestates] Fix SubtickGuiScreen being affected by modifier keys from virtualinput
Fixes an issue when you have a subtick screen open in tr0 while the player pressed CTRL, the CTRL key would be pressed constantly
1 parent 02337a1 commit c284c52

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/main/java/com/minecrafttas/tasmod/savestates/gui/GuiSavestateRename.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public GuiSavestateRename(ITextComponent msg, int index) {
2727

2828
@Override
2929
public void initGui() {
30+
super.initGui();
3031
this.buttonList.clear();
3132
int boxWidth = 200;
3233
buttonList.add(new GuiButton(1, width / 2 - (boxWidth / 2) - 1, height / 2 + 62, boxWidth + 3, 20, new TextComponentTranslation("gui.tasmod.savestate.save.rename.button").getFormattedText()));
@@ -84,8 +85,8 @@ public void updateScreen() {
8485

8586
@Override
8687
public void onGuiClosed() {
88+
super.onGuiClosed();
8789
TASmodClient.virtual.clearNext();
88-
Keyboard.enableRepeatEvents(false);
8990
}
9091

9192
@Override

src/main/java/com/minecrafttas/tasmod/virtual/SubtickGuiScreen.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.lwjgl.input.Keyboard;
44

5+
import com.minecrafttas.tasmod.TASmodClient;
6+
57
import net.minecraft.client.gui.GuiScreen;
68

79
/**
@@ -15,6 +17,11 @@
1517
*/
1618
public class SubtickGuiScreen extends GuiScreen {
1719

20+
@Override
21+
public void initGui() {
22+
TASmodClient.virtual.setUseVanillaIsKeyDown(true);
23+
}
24+
1825
/*
1926
* Make keyTyped public instead of protected, to be usable by VirtualInput#update()
2027
*/
@@ -33,6 +40,7 @@ public void mouseClicked(int i, int j, int k) {
3340

3441
@Override
3542
public void onGuiClosed() {
43+
TASmodClient.virtual.setUseVanillaIsKeyDown(false);
3644
Keyboard.enableRepeatEvents(false);
3745
}
3846
}

src/main/java/com/minecrafttas/tasmod/virtual/VirtualInput.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class VirtualInput {
4848

4949
public final VirtualInterpolationHandler interpolationHandler = new VirtualInterpolationHandler();
5050

51+
private boolean useVanillaIsKeyDown;
52+
5153
/**
5254
* Creates a new virtual input with an empty {@link VirtualKeyboardInput}, {@link VirtualMouseInput} and {@link VirtualCameraAngleInput}
5355
* @param logger The logger instance
@@ -138,6 +140,10 @@ private boolean updateSubtickGuiScreenMouse(GuiScreen currentScreen) {
138140
return false;
139141
}
140142

143+
public void setUseVanillaIsKeyDown(boolean isVanilla) {
144+
this.useVanillaIsKeyDown = isVanilla;
145+
}
146+
141147
/**
142148
* If the keyboard or mouse key is currently down.
143149
* If keycode >= 0 then {@link VirtualKeyboardInput#isKeyDown(int)} will be called,<br>
@@ -148,9 +154,15 @@ private boolean updateSubtickGuiScreenMouse(GuiScreen currentScreen) {
148154
*/
149155
public boolean isKeyDown(int keycode) {
150156
if (keycode >= 0) {
151-
return KEYBOARD.isKeyDown(keycode);
157+
if (!useVanillaIsKeyDown)
158+
return KEYBOARD.isKeyDown(keycode);
159+
else
160+
return Keyboard.isKeyDown(keycode);
152161
} else {
153-
return MOUSE.isKeyDown(keycode);
162+
if (!useVanillaIsKeyDown)
163+
return MOUSE.isKeyDown(keycode);
164+
else
165+
return Keyboard.isKeyDown(keycode);
154166
}
155167
}
156168

0 commit comments

Comments
 (0)