Get recording and replay working

This commit is contained in:
Jonas Herzig
2019-03-10 12:53:03 +01:00
parent 8705bbad9a
commit f8fc3462e8
22 changed files with 538 additions and 331 deletions

View File

@@ -3,18 +3,19 @@ package com.replaymod.replay;
import com.replaymod.core.utils.WrappedTimer;
import com.replaymod.replay.camera.CameraController;
import com.replaymod.replay.camera.CameraEntity;
import com.replaymod.replay.events.ReplayDispatchKeypressesEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.crash.CrashReport;
import net.minecraft.util.Timer;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.common.MinecraftForge;
//#if MC>=11300
import org.lwjgl.glfw.GLFW;
//#else
//$$ import com.replaymod.replay.events.ReplayDispatchKeypressesEvent;
//$$ import net.minecraft.client.gui.GuiScreen;
//$$ import net.minecraft.client.settings.GameSettings;
//$$ import net.minecraft.client.settings.KeyBinding;
//$$ import net.minecraft.crash.CrashReport;
//$$ import net.minecraftforge.client.ForgeHooksClient;
//$$ import net.minecraftforge.common.MinecraftForge;
//$$ import org.lwjgl.input.Keyboard;
//$$ import org.lwjgl.input.Mouse;
//#if MC>=10800
@@ -28,6 +29,7 @@ import net.minecraftforge.common.MinecraftForge;
//$$
//$$ import static com.replaymod.core.versions.MCVer.FML_BUS;
//#endif
//$$ import static com.replaymod.core.versions.MCVer.newReportedException;
//#endif
public class InputReplayTimer extends WrappedTimer {
@@ -40,10 +42,14 @@ public class InputReplayTimer extends WrappedTimer {
this.mc = mod.getCore().getMinecraft();
}
/* FIXME
@Override
public void updateTimer() {
super.updateTimer();
//#if MC>=11300
public void updateTimer(long sysClock) {
super.updateTimer(sysClock);
//#else
//$$ public void updateTimer() {
//$$ super.updateTimer();
//#endif
// 1.7.10: We have to run the scheduled executables (ours only) because MC would only run them every tick
//#if MC<=10710
@@ -53,43 +59,41 @@ public class InputReplayTimer extends WrappedTimer {
// If we are in a replay, we have to manually process key and mouse events as the
// tick speed may vary or there may not be any ticks at all (when the replay is paused)
if (mod.getReplayHandler() != null) {
//#if MC>=11300
if (mc.currentScreen == null || mc.currentScreen.allowUserInput) {
while (Mouse.next()) {
handleMouseEvent();
}
while (Keyboard.next()) {
handleKeyEvent();
}
} else {
GLFW.glfwPollEvents();
mc.processKeyBinds();
}
mc.keyboardListener.tick();
//#else
//$$ if (mc.currentScreen == null || mc.currentScreen.allowUserInput) {
//$$ while (Mouse.next()) {
//$$ handleMouseEvent();
//$$ }
//$$
//$$ while (Keyboard.next()) {
//$$ handleKeyEvent();
//$$ }
//$$ } else {
//#if MC<11300
//#if MC>=10800
try {
mc.currentScreen.handleInput();
} catch (IOException e) { // *SIGH*
e.printStackTrace();
}
//$$ try {
//$$ mc.currentScreen.handleInput();
//$$ } catch (IOException e) { // *SIGH*
//$$ e.printStackTrace();
//$$ }
//#else
//$$ mc.currentScreen.handleInput();
//#endif
}
//#endif
//$$ }
//#endif
}
}
protected void handleMouseEvent() {
if (ForgeHooksClient.postMouseEvent()) return;
int button = Mouse.getEventButton() - 100;
boolean pressed = Mouse.getEventButtonState();
// Update key binding states
KeyBinding.setKeyBindState(button, pressed);
if (pressed) {
KeyBinding.onTick(button);
}
int wheel = Mouse.getEventDWheel();
public static void handleScroll(int wheel) {
if (wheel != 0) {
ReplayHandler replayHandler = mod.getReplayHandler();
ReplayHandler replayHandler = ReplayModReplay.instance.getReplayHandler();
if (replayHandler != null) {
CameraEntity cameraEntity = replayHandler.getCameraEntity();
if (cameraEntity != null) {
@@ -105,164 +109,181 @@ public class InputReplayTimer extends WrappedTimer {
}
}
}
}
if (mc.currentScreen == null) {
if (!mc.inGameHasFocus && Mouse.getEventButtonState()) {
// Regrab mouse if the user clicks into the window
mc.setIngameFocus();
}
} else {
//#if MC<11300
//$$ protected void handleMouseEvent() {
//$$ if (ForgeHooksClient.postMouseEvent()) return;
//$$
//$$ int button = Mouse.getEventButton() - 100;
//$$ boolean pressed = Mouse.getEventButtonState();
//$$
//$$ // Update key binding states
//$$ KeyBinding.setKeyBindState(button, pressed);
//$$ if (pressed) {
//$$ KeyBinding.onTick(button);
//$$ }
//$$
//$$ int wheel = Mouse.getEventDWheel();
//$$ handleScroll(wheel);
//$$
//$$ if (mc.currentScreen == null) {
//$$ if (!mc.inGameHasFocus && Mouse.getEventButtonState()) {
//$$ // Regrab mouse if the user clicks into the window
//$$ mc.setIngameFocus();
//$$ }
//$$ } else {
//#if MC>=10800
try {
mc.currentScreen.handleMouseInput();
} catch (IOException e) { // WHO IS RESPONSIBLE FOR THIS MESS?!?
e.printStackTrace();
}
//$$ try {
//$$ mc.currentScreen.handleMouseInput();
//$$ } catch (IOException e) { // WHO IS RESPONSIBLE FOR THIS MESS?!?
//$$ e.printStackTrace();
//$$ }
//#else
//$$ mc.currentScreen.handleMouseInput();
//#endif
}
FMLCommonHandler.instance().fireMouseInput();
}
protected void handleKeyEvent() {
// TODO 1.7.10: This might be missing some 1.7.10-only key bindings or implement some of them incorrectly
int key = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey();
boolean pressed = Keyboard.getEventKeyState();
KeyBinding.setKeyBindState(key, pressed);
if (pressed) {
KeyBinding.onTick(key);
}
// Still want to be able to create debug crashes ]:D
if (mc.debugCrashKeyPressTime > 0) {
if (Minecraft.getSystemTime() - mc.debugCrashKeyPressTime >= 6000L) {
throw new ReportedException(new CrashReport("Manually triggered debug crash", new Throwable()));
}
if (!Keyboard.isKeyDown(Keyboard.KEY_F3) || !Keyboard.isKeyDown(Keyboard.KEY_C)) {
mc.debugCrashKeyPressTime = -1;
}
} else if (Keyboard.isKeyDown(Keyboard.KEY_F3) && Keyboard.isKeyDown(Keyboard.KEY_C)) {
mc.debugCrashKeyPressTime = Minecraft.getSystemTime();
}
// Twitch, screenshot, fullscreen, etc. (stuff that works everywhere)
if (!MinecraftForge.EVENT_BUS.post(new ReplayDispatchKeypressesEvent.Pre())) {
mc.dispatchKeypresses();
}
if (pressed) {
// This might be subject to change as vanilla shaders are still kinda unused in 1.8
if (key == Keyboard.KEY_F4 && mc.entityRenderer != null) {
//$$ }
//$$
//$$ FMLCommonHandler.instance().fireMouseInput();
//$$ }
//$$
//$$ protected void handleKeyEvent() {
//$$ // TODO 1.7.10: This might be missing some 1.7.10-only key bindings or implement some of them incorrectly
//$$ int key = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey();
//$$ boolean pressed = Keyboard.getEventKeyState();
//$$
//$$ KeyBinding.setKeyBindState(key, pressed);
//$$ if (pressed) {
//$$ KeyBinding.onTick(key);
//$$ }
//$$
//$$ // Still want to be able to create debug crashes ]:D
//$$ if (mc.debugCrashKeyPressTime > 0) {
//$$ if (Minecraft.getSystemTime() - mc.debugCrashKeyPressTime >= 6000L) {
//$$ throw newReportedException(new CrashReport("Manually triggered debug crash", new Throwable()));
//$$ }
//$$
//$$ if (!Keyboard.isKeyDown(Keyboard.KEY_F3) || !Keyboard.isKeyDown(Keyboard.KEY_C)) {
//$$ mc.debugCrashKeyPressTime = -1;
//$$ }
//$$ } else if (Keyboard.isKeyDown(Keyboard.KEY_F3) && Keyboard.isKeyDown(Keyboard.KEY_C)) {
//$$ mc.debugCrashKeyPressTime = Minecraft.getSystemTime();
//$$ }
//$$
//$$ // Twitch, screenshot, fullscreen, etc. (stuff that works everywhere)
//$$ if (!MinecraftForge.EVENT_BUS.post(new ReplayDispatchKeypressesEvent.Pre())) {
//$$ mc.dispatchKeypresses();
//$$ }
//$$
//$$ if (pressed) {
//$$ // This might be subject to change as vanilla shaders are still kinda unused in 1.8
//$$ if (key == Keyboard.KEY_F4 && mc.entityRenderer != null) {
//#if MC>=10800
mc.entityRenderer.switchUseShader();
//$$ mc.entityRenderer.switchUseShader();
//#else
//$$ mc.entityRenderer.activateNextShader();
//#endif
}
if (mc.currentScreen != null) {
//$$ }
//$$
//$$ if (mc.currentScreen != null) {
//#if MC>=10800
try {
mc.currentScreen.handleKeyboardInput();
} catch (IOException e) { // AND WHO THOUGHT THIS WAS A GREAT IDEA?
e.printStackTrace();
}
//$$ try {
//$$ mc.currentScreen.handleKeyboardInput();
//$$ } catch (IOException e) { // AND WHO THOUGHT THIS WAS A GREAT IDEA?
//$$ e.printStackTrace();
//$$ }
//#else
//$$ mc.currentScreen.handleKeyboardInput();
//#endif
} else {
if (key == Keyboard.KEY_ESCAPE) {
mc.displayInGameMenu();
}
// Following are a ton of vanilla keyboard shortcuts, some are removed as they're useless in the
// replay viewer as of now
// TODO Update maybe add new key bindings
// TODO: Translate magic values to Keyboard.KEY_ constants
if (key == 32 && Keyboard.isKeyDown(61) && mc.ingameGUI != null) {
//$$ } else {
//$$ if (key == Keyboard.KEY_ESCAPE) {
//$$ mc.displayInGameMenu();
//$$ }
//$$
//$$ // Following are a ton of vanilla keyboard shortcuts, some are removed as they're useless in the
//$$ // replay viewer as of now
//$$ // TODO Update maybe add new key bindings
//$$ // TODO: Translate magic values to Keyboard.KEY_ constants
//$$
//$$ if (key == 32 && Keyboard.isKeyDown(61) && mc.ingameGUI != null) {
//#if MC>=11100
mc.ingameGUI.getChatGUI().clearChatMessages(false);
//$$ mc.ingameGUI.getChatGUI().clearChatMessages(false);
//#else
//$$ mc.ingameGUI.getChatGUI().clearChatMessages();
//#endif
}
if (key == 31 && Keyboard.isKeyDown(61)) {
mc.refreshResources();
}
if (key == 20 && Keyboard.isKeyDown(61)) {
mc.refreshResources();
}
if (key == 33 && Keyboard.isKeyDown(61)) {
boolean flag1 = Keyboard.isKeyDown(42) | Keyboard.isKeyDown(54);
mc.gameSettings.setOptionValue(GameSettings.Options.RENDER_DISTANCE, flag1 ? -1 : 1);
}
if (key == 30 && Keyboard.isKeyDown(61)) {
mc.renderGlobal.loadRenderers();
}
if (key == 48 && Keyboard.isKeyDown(61)) {
//$$ }
//$$
//$$ if (key == 31 && Keyboard.isKeyDown(61)) {
//$$ mc.refreshResources();
//$$ }
//$$
//$$ if (key == 20 && Keyboard.isKeyDown(61)) {
//$$ mc.refreshResources();
//$$ }
//$$
//$$ if (key == 33 && Keyboard.isKeyDown(61)) {
//$$ boolean flag1 = Keyboard.isKeyDown(42) | Keyboard.isKeyDown(54);
//$$ mc.gameSettings.setOptionValue(GameSettings.Options.RENDER_DISTANCE, flag1 ? -1 : 1);
//$$ }
//$$
//$$ if (key == 30 && Keyboard.isKeyDown(61)) {
//$$ mc.renderGlobal.loadRenderers();
//$$ }
//$$
//$$ if (key == 48 && Keyboard.isKeyDown(61)) {
//#if MC>=10800
mc.getRenderManager().setDebugBoundingBox(!mc.getRenderManager().isDebugBoundingBox());
//$$ mc.getRenderManager().setDebugBoundingBox(!mc.getRenderManager().isDebugBoundingBox());
//#else
//$$ RenderManager.debugBoundingBox = !RenderManager.debugBoundingBox;
//#endif
}
if (key == 25 && Keyboard.isKeyDown(61)) {
mc.gameSettings.pauseOnLostFocus = !mc.gameSettings.pauseOnLostFocus;
mc.gameSettings.saveOptions();
}
if (key == 59) {
mc.gameSettings.hideGUI = !mc.gameSettings.hideGUI;
}
if (key == 61) {
mc.gameSettings.showDebugInfo = !mc.gameSettings.showDebugInfo;
mc.gameSettings.showDebugProfilerChart = GuiScreen.isShiftKeyDown();
}
if (mc.gameSettings.keyBindTogglePerspective.isPressed()) {
mc.gameSettings.thirdPersonView = (mc.gameSettings.thirdPersonView + 1) % 3;
//$$ }
//$$
//$$ if (key == 25 && Keyboard.isKeyDown(61)) {
//$$ mc.gameSettings.pauseOnLostFocus = !mc.gameSettings.pauseOnLostFocus;
//$$ mc.gameSettings.saveOptions();
//$$ }
//$$
//$$ if (key == 59) {
//$$ mc.gameSettings.hideGUI = !mc.gameSettings.hideGUI;
//$$ }
//$$
//$$ if (key == 61) {
//$$ mc.gameSettings.showDebugInfo = !mc.gameSettings.showDebugInfo;
//$$ mc.gameSettings.showDebugProfilerChart = GuiScreen.isShiftKeyDown();
//$$ }
//$$
//$$ if (mc.gameSettings.keyBindTogglePerspective.isPressed()) {
//$$ mc.gameSettings.thirdPersonView = (mc.gameSettings.thirdPersonView + 1) % 3;
//$$
//#if MC>=10800
if (mc.entityRenderer != null) { // Extra check, not in vanilla code
if (mc.gameSettings.thirdPersonView == 0) {
mc.entityRenderer.loadEntityShader(mc.getRenderViewEntity());
} else if (mc.gameSettings.thirdPersonView == 1) {
mc.entityRenderer.loadEntityShader(null);
}
}
//$$ if (mc.entityRenderer != null) { // Extra check, not in vanilla code
//$$ if (mc.gameSettings.thirdPersonView == 0) {
//$$ mc.entityRenderer.loadEntityShader(mc.getRenderViewEntity());
//$$ } else if (mc.gameSettings.thirdPersonView == 1) {
//$$ mc.entityRenderer.loadEntityShader(null);
//$$ }
//$$ }
//#endif
}
}
// Navigation in the debug chart
if (mc.gameSettings.showDebugInfo && mc.gameSettings.showDebugProfilerChart) {
if (key == Keyboard.KEY_0) {
mc.updateDebugProfilerName(0);
}
for (int i = 0; i < 9; ++i) {
if (key == 2 + i) {
mc.updateDebugProfilerName(i + 1);
}
}
}
}
FMLCommonHandler.instance().fireKeyInput();
}
*/
//$$ }
//$$ }
//$$
//$$ // Navigation in the debug chart
//$$ if (mc.gameSettings.showDebugInfo && mc.gameSettings.showDebugProfilerChart) {
//$$ if (key == Keyboard.KEY_0) {
//$$ mc.updateDebugProfilerName(0);
//$$ }
//$$
//$$ for (int i = 0; i < 9; ++i) {
//$$ if (key == 2 + i) {
//$$ mc.updateDebugProfilerName(i + 1);
//$$ }
//$$ }
//$$ }
//$$ }
//$$
//$$ FMLCommonHandler.instance().fireKeyInput();
//$$ }
//#endif
//#if MC<=10710
//$$ public static class RunScheduledTasks extends Event {}