Allow replay to be started in sync mode (required for #349)

This commit is contained in:
Jonas Herzig
2020-09-05 14:51:55 +02:00
parent 76a8623531
commit fcd1224fa0
3 changed files with 17 additions and 17 deletions

View File

@@ -225,7 +225,7 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
/** /**
* Whether we're currently reading packets from the login phase. * Whether we're currently reading packets from the login phase.
*/ */
private boolean loginPhase; private boolean loginPhase = true;
/** /**
* Whether we need to restart the current replay. E.g. when jumping backwards in time * Whether we need to restart the current replay. E.g. when jumping backwards in time

View File

@@ -167,24 +167,34 @@ public class ReplayModReplay implements Module {
} }
public void startReplay(ReplayFile replayFile) throws IOException { public void startReplay(ReplayFile replayFile) throws IOException {
startReplay(replayFile, true); startReplay(replayFile, true, true);
} }
public void startReplay(ReplayFile replayFile, boolean checkModCompat) throws IOException { public ReplayHandler startReplay(ReplayFile replayFile, boolean checkModCompat, boolean asyncMode) throws IOException {
if (replayHandler != null) { if (replayHandler != null) {
replayHandler.endReplay(); replayHandler.endReplay();
} }
if (checkModCompat) { if (checkModCompat) {
ModCompat.ModInfoDifference modDifference = new ModCompat.ModInfoDifference(replayFile.getModInfo()); ModCompat.ModInfoDifference modDifference = new ModCompat.ModInfoDifference(replayFile.getModInfo());
if (!modDifference.getMissing().isEmpty() || !modDifference.getDiffering().isEmpty()) { if (!modDifference.getMissing().isEmpty() || !modDifference.getDiffering().isEmpty()) {
new GuiModCompatWarning(this, replayFile, modDifference).display(); GuiModCompatWarning screen = new GuiModCompatWarning(modDifference);
return; screen.loadButton.onClick(() -> {
try {
startReplay(replayFile, false, asyncMode);
} catch (IOException e) {
e.printStackTrace();
}
});
screen.display();
return null;
} }
} }
replayHandler = new ReplayHandler(replayFile, true); replayHandler = new ReplayHandler(replayFile, asyncMode);
//#if MC>=11400 //#if MC>=11400
KeyBinding.updateKeysByCode(); // see Mixin_ContextualKeyBindings KeyBinding.updateKeysByCode(); // see Mixin_ContextualKeyBindings
//#endif //#endif
return replayHandler;
} }
public void forcefullyStopReplay() { public void forcefullyStopReplay() {

View File

@@ -1,9 +1,7 @@
package com.replaymod.replay.gui.screen; package com.replaymod.replay.gui.screen;
import com.replaymod.core.utils.ModCompat; import com.replaymod.core.utils.ModCompat;
import com.replaymod.replay.ReplayModReplay;
import com.replaymod.replaystudio.data.ModInfo; import com.replaymod.replaystudio.data.ModInfo;
import com.replaymod.replaystudio.replay.ReplayFile;
import com.replaymod.replaystudio.util.I18n; import com.replaymod.replaystudio.util.I18n;
import de.johni0702.minecraft.gui.container.AbstractGuiScreen; import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
import de.johni0702.minecraft.gui.container.GuiPanel; import de.johni0702.minecraft.gui.container.GuiPanel;
@@ -14,7 +12,6 @@ import de.johni0702.minecraft.gui.layout.CustomLayout;
import de.johni0702.minecraft.gui.layout.HorizontalLayout; import de.johni0702.minecraft.gui.layout.HorizontalLayout;
import de.johni0702.minecraft.gui.layout.VerticalLayout; import de.johni0702.minecraft.gui.layout.VerticalLayout;
import java.io.IOException;
import java.util.Map; import java.util.Map;
public class GuiModCompatWarning extends AbstractGuiScreen<GuiModCompatWarning> { public class GuiModCompatWarning extends AbstractGuiScreen<GuiModCompatWarning> {
@@ -38,7 +35,7 @@ public class GuiModCompatWarning extends AbstractGuiScreen<GuiModCompatWarning>
content.getListLayout().setSpacing(8); content.getListLayout().setSpacing(8);
} }
public GuiModCompatWarning(ReplayModReplay mod, ReplayFile replayFile, ModCompat.ModInfoDifference difference) { public GuiModCompatWarning(ModCompat.ModInfoDifference difference) {
VerticalLayout.Data data = new VerticalLayout.Data(0.5); VerticalLayout.Data data = new VerticalLayout.Data(0.5);
GuiPanel content = this.content.getListPanel(); GuiPanel content = this.content.getListPanel();
content.addElements(data, new GuiLabel().setI18nText("replaymod.gui.modwarning.message1")); content.addElements(data, new GuiLabel().setI18nText("replaymod.gui.modwarning.message1"));
@@ -82,13 +79,6 @@ public class GuiModCompatWarning extends AbstractGuiScreen<GuiModCompatWarning>
} }
cancelButton.onClick(() -> getMinecraft().openScreen(null)); cancelButton.onClick(() -> getMinecraft().openScreen(null));
loadButton.onClick(() -> {
try {
mod.startReplay(replayFile, false);
} catch (IOException e) {
e.printStackTrace();
}
});
} }
@Override @Override