Make thread requirements of ReplayHandler#setup explicit and fix illegal usage

This commit is contained in:
Jonas Herzig
2019-07-08 09:53:47 +02:00
parent 8261767657
commit c4d2be9e89
2 changed files with 16 additions and 17 deletions

View File

@@ -845,11 +845,11 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
startFromBeginning = false; startFromBeginning = false;
nextPacket = null; nextPacket = null;
lastPacketSent = System.currentTimeMillis(); lastPacketSent = System.currentTimeMillis();
replayHandler.restartedReplay();
if (replayIn != null) { if (replayIn != null) {
replayIn.close(); replayIn.close();
replayIn = null; replayIn = null;
} }
ReplayMod.instance.runSync(replayHandler::restartedReplay);
} }
} }
} catch (Exception e) { } catch (Exception e) {

View File

@@ -161,25 +161,22 @@ public class ReplayHandler {
} }
void restartedReplay() { void restartedReplay() {
Preconditions.checkState(isOnMainThread(), "Must be called from Minecraft thread.");
channel.close(); channel.close();
// Force re-creation of camera entity by unloading the previous world
try {
ReplayMod.instance.runSync(() -> {
//#if MC>=11300 //#if MC>=11300
mc.mouse.unlockCursor(); mc.mouse.unlockCursor();
//#else //#else
//$$ mc.setIngameNotInFocus(); //$$ mc.setIngameNotInFocus();
//#endif //#endif
// Force re-creation of camera entity by unloading the previous world
//#if MC>=11400 //#if MC>=11400
mc.disconnect(); mc.disconnect();
//#else //#else
//$$ mc.loadWorld(null); //$$ mc.loadWorld(null);
//#endif //#endif
});
} catch (InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.error("Failed to properly restart (shutdown) replay:", e);
}
restrictions = new Restrictions(); restrictions = new Restrictions();
@@ -236,6 +233,8 @@ public class ReplayHandler {
} }
private void setup() { private void setup() {
Preconditions.checkState(isOnMainThread(), "Must be called from Minecraft thread.");
//#if MC>=11100 //#if MC>=11100
mc.inGameHud.getChatHud().clear(false); mc.inGameHud.getChatHud().clear(false);
//#else //#else