Skip to content

Commit c3397f6

Browse files
ScribbleScribble
authored andcommitted
Removed weirdness in VirtualKeybindings, fixed Unicode issues again
-Removed doubled code -Removed deprecated code -Made VirtualKeybindings able to be played back or recorded. This will theoretically come up in #41 -Added more blocked keybindings
1 parent 9d9a26f commit c3397f6

File tree

3 files changed

+14
-39
lines changed

3 files changed

+14
-39
lines changed

src/main/java/de/scribble/lp/tasmod/ClientProxy.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,15 @@ public void init(FMLInitializationEvent ev) {
9090
ClientRegistry.registerKeyBinding(infoGuiKey);
9191
ClientRegistry.registerKeyBinding(bufferViewKey);
9292

93-
VirtualKeybindings.registerBlockedKeyBinding(infoGuiKey);
93+
9494
VirtualKeybindings.registerBlockedKeyBinding(tickratezeroKey);
9595
VirtualKeybindings.registerBlockedKeyBinding(tickAdvance);
9696
VirtualKeybindings.registerBlockedKeyBinding(stopkey);
97+
VirtualKeybindings.registerBlockedKeyBinding(savestateSaveKey);
98+
VirtualKeybindings.registerBlockedKeyBinding(savestateLoadKey);
9799
VirtualKeybindings.registerBlockedKeyBinding(testingKey);
100+
VirtualKeybindings.registerBlockedKeyBinding(infoGuiKey);
101+
VirtualKeybindings.registerBlockedKeyBinding(bufferViewKey);
98102

99103
createTASDir();
100104
createSavestatesDir();

src/main/java/de/scribble/lp/tasmod/util/ContainerSerialiser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.File;
44
import java.io.IOException;
55
import java.nio.charset.Charset;
6+
import java.nio.charset.StandardCharsets;
67
import java.util.ArrayList;
78
import java.util.List;
89

@@ -112,14 +113,14 @@ public int getFileVersion(File file) throws IOException {
112113

113114
public InputContainer fromEntireFileV1(File file) throws IOException {
114115

115-
List<String> lines = FileUtils.readLines(file, Charset.defaultCharset());
116+
List<String> lines = FileUtils.readLines(file, StandardCharsets.UTF_8);
116117

117118
File monitorFile=new File(file, "../"+file.getName().replace(".tas", "")+".mon");
118119

119120
List<String> monitorLines=null;
120121

121122
if(monitorFile.exists()) {
122-
monitorLines = FileUtils.readLines(monitorFile, Charset.defaultCharset());
123+
monitorLines = FileUtils.readLines(monitorFile, StandardCharsets.UTF_8);
123124
}
124125

125126
InputContainer container = new InputContainer();

src/main/java/de/scribble/lp/tasmod/virtual/VirtualKeybindings.java

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import com.google.common.collect.Maps;
1010

11+
import de.scribble.lp.tasmod.ClientProxy;
1112
import net.minecraft.client.Minecraft;
1213
import net.minecraft.client.gui.GuiChat;
1314
import net.minecraft.client.gui.GuiControls;
@@ -31,7 +32,6 @@ public class VirtualKeybindings {
3132
private static long cooldown = 20;
3233
private static HashMap<KeyBinding, Long> cooldownHashMap = Maps.<KeyBinding, Long>newHashMap();
3334
private static List<KeyBinding> blockedKeys = new ArrayList<>();
34-
private static List<KeyBinding> blockedDuringRecordingKeys = new ArrayList<>();
3535
private static long cooldowntimer = 0;
3636
public static boolean focused = false;
3737

@@ -45,7 +45,10 @@ public static void increaseCooldowntimer() {
4545
* @return
4646
*/
4747
public static boolean isKeyDown(KeyBinding keybind) {
48-
boolean down = Keyboard.isKeyDown(keybind.getKeyCode());
48+
49+
int keycode=keybind.getKeyCode();
50+
boolean down = isKeyCodeAlwaysBlocked(keycode) ? Keyboard.isKeyDown(keycode) : ClientProxy.virtual.willKeyBeDown(keycode);
51+
4952
if (down) {
5053
if (cooldownHashMap.containsKey(keybind)) {
5154
if (cooldown <= cooldowntimer - (long) cooldownHashMap.get(keybind)) {
@@ -73,22 +76,7 @@ public static boolean isKeyDownExceptTextfield(KeyBinding keybind) {
7376
if (mc.currentScreen instanceof GuiChat || mc.currentScreen instanceof GuiEditSign || (focused && mc.currentScreen != null) || mc.currentScreen instanceof GuiControls) {
7477
return false;
7578
}
76-
boolean down = Keyboard.isKeyDown(keybind.getKeyCode());
77-
if (down) {
78-
if (cooldownHashMap.containsKey(keybind)) {
79-
if (cooldown <= cooldowntimer - (long) cooldownHashMap.get(keybind)) {
80-
cooldownHashMap.put(keybind, cooldowntimer);
81-
cooldown=Minecraft.getDebugFPS()/3;
82-
return true;
83-
}
84-
return false;
85-
} else {
86-
cooldownHashMap.put(keybind, cooldowntimer);
87-
cooldown=Minecraft.getDebugFPS()/3;
88-
return true;
89-
}
90-
}
91-
return false;
79+
return isKeyDown(keybind);
9280
}
9381

9482
/**
@@ -99,11 +87,6 @@ public static void registerBlockedKeyBinding(KeyBinding keybind) {
9987
blockedKeys.add(keybind);
10088
}
10189

102-
@Deprecated
103-
public static void registerBlockedDuringRecordingKeyBinding(KeyBinding keybind) {
104-
blockedDuringRecordingKeys.add(keybind);
105-
}
106-
10790
/**
10891
* Checks whether the keycode should not be recorded or played back in a TAS
10992
* @param keycode to block
@@ -116,18 +99,5 @@ public static boolean isKeyCodeAlwaysBlocked(int keycode) {
11699
}
117100
return false;
118101
}
119-
@Deprecated
120-
public static boolean isKeyCodeBlockedDuringRecording(int keycode) {
121-
for (KeyBinding keybind : blockedDuringRecordingKeys) {
122-
if (keycode == keybind.getKeyCode()) {
123-
blockedDuringRecordingKeys.remove(keybind);
124-
return true;
125-
}
126-
}
127-
return false;
128-
}
129102

130-
public static void setCooldown(long cooldown) {
131-
VirtualKeybindings.cooldown = cooldown;
132-
}
133103
}

0 commit comments

Comments
 (0)