From a4a9473111b30d01359b5491b7519093fcf10ef1 Mon Sep 17 00:00:00 2001
From: CrushedPixel <crushedpixelmaps@gmail.com>
Date: Wed, 1 Nov 2017 15:36:15 +0100
Subject: [PATCH] Hide GUI when exporting screenshot Workaround not all chunks
 being loaded in screenshot Fix wrong RenderSettings being exposed in
 ScreenshotRenderer Update Language submodule

---
 .../advancedscreenshots/GuiCreateScreenshot.java     |  9 ++++++++-
 .../advancedscreenshots/ScreenshotRenderer.java      | 12 ++++++------
 .../extras/advancedscreenshots/ScreenshotWriter.java |  3 +++
 src/main/resources/assets/replaymod/lang             |  2 +-
 4 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/replaymod/extras/advancedscreenshots/GuiCreateScreenshot.java b/src/main/java/com/replaymod/extras/advancedscreenshots/GuiCreateScreenshot.java
index d4512d98..3ef09234 100644
--- a/src/main/java/com/replaymod/extras/advancedscreenshots/GuiCreateScreenshot.java
+++ b/src/main/java/com/replaymod/extras/advancedscreenshots/GuiCreateScreenshot.java
@@ -7,6 +7,7 @@ import com.replaymod.replay.ReplayModReplay;
 import de.johni0702.minecraft.gui.container.GuiContainer;
 import de.johni0702.minecraft.gui.container.GuiPanel;
 import de.johni0702.minecraft.gui.element.GuiLabel;
+import de.johni0702.minecraft.gui.function.Loadable;
 import de.johni0702.minecraft.gui.layout.GridLayout;
 import de.johni0702.minecraft.gui.layout.VerticalLayout;
 import net.minecraft.crash.CrashReport;
@@ -20,7 +21,7 @@ import java.util.ArrayList;
 import static com.replaymod.core.utils.Utils.error;
 import static com.replaymod.render.ReplayModRender.LOGGER;
 
-public class GuiCreateScreenshot extends GuiRenderSettings {
+public class GuiCreateScreenshot extends GuiRenderSettings implements Loadable {
 
     private final ReplayMod mod;
 
@@ -73,6 +74,12 @@ public class GuiCreateScreenshot extends GuiRenderSettings {
         return container;
     }
 
+    @Override
+    public void load() {
+        // pause replay when opening this gui
+        ReplayModReplay.instance.getReplayHandler().getReplaySender().setReplaySpeed(0);
+    }
+
     @Override
     protected File generateOutputFile(RenderSettings.EncodingPreset encodingPreset) {
         File screenshotFolder = new File(getMinecraft().mcDataDir, "screenshots");
diff --git a/src/main/java/com/replaymod/extras/advancedscreenshots/ScreenshotRenderer.java b/src/main/java/com/replaymod/extras/advancedscreenshots/ScreenshotRenderer.java
index 72aad0ac..2133432d 100644
--- a/src/main/java/com/replaymod/extras/advancedscreenshots/ScreenshotRenderer.java
+++ b/src/main/java/com/replaymod/extras/advancedscreenshots/ScreenshotRenderer.java
@@ -22,6 +22,8 @@ public class ScreenshotRenderer implements RenderInfo {
             int displayWidthBefore = mc.displayWidth;
             int displayHeightBefore = mc.displayHeight;
 
+            boolean hideGUIBefore = mc.gameSettings.hideGUI;
+
             ChunkLoadingRenderGlobal clrg = new ChunkLoadingRenderGlobal(mc.renderGlobal);
 
             Pipelines.newPipeline(settings.getRenderMethod(),this,
@@ -29,6 +31,7 @@ public class ScreenshotRenderer implements RenderInfo {
 
             clrg.uninstall();
 
+            mc.gameSettings.hideGUI = hideGUIBefore;
             mc.resize(displayWidthBefore, displayHeightBefore);
             return true;
         } catch (OutOfMemoryError e) {
@@ -46,7 +49,8 @@ public class ScreenshotRenderer implements RenderInfo {
 
     @Override
     public int getTotalFrames() {
-        return 1;
+        // render 2 frames, because only the second contains all frames fully loaded
+        return 2;
     }
 
     @Override
@@ -56,10 +60,6 @@ public class ScreenshotRenderer implements RenderInfo {
 
     @Override
     public RenderSettings getRenderSettings() {
-        return new RenderSettings(
-                null, null, settings.getVideoWidth(), settings.getVideoHeight(), 0, 0, null,
-                true, true, true, true, null,
-                false, RenderSettings.AntiAliasing.NONE, null, null, false
-        );
+        return settings;
     }
 }
diff --git a/src/main/java/com/replaymod/extras/advancedscreenshots/ScreenshotWriter.java b/src/main/java/com/replaymod/extras/advancedscreenshots/ScreenshotWriter.java
index e04d1b59..c601f28f 100644
--- a/src/main/java/com/replaymod/extras/advancedscreenshots/ScreenshotWriter.java
+++ b/src/main/java/com/replaymod/extras/advancedscreenshots/ScreenshotWriter.java
@@ -25,6 +25,9 @@ public class ScreenshotWriter implements FrameConsumer<RGBFrame> {
 
     @Override
     public void consume(RGBFrame frame) {
+        // skip the first frame, in which not all chunks are properly loaded
+        if (frame.getFrameId() == 0) return;
+
         try {
             final ReadableDimension frameSize = frame.getSize();
 
diff --git a/src/main/resources/assets/replaymod/lang b/src/main/resources/assets/replaymod/lang
index 94282826..75edb999 160000
--- a/src/main/resources/assets/replaymod/lang
+++ b/src/main/resources/assets/replaymod/lang
@@ -1 +1 @@
-Subproject commit 942828260079edb1e35b2e500d6763c5234f6bbb
+Subproject commit 75edb99901404c1364de54352b5ad8b5a21d9536
