From 468b7b468069cb4ed85113020094f877e7bcadbb Mon Sep 17 00:00:00 2001 From: Moulberry Date: Tue, 11 Feb 2025 17:15:43 +0800 Subject: [PATCH] Don't rewind when replay is at start tick --- .../flashback/exporting/ExportJob.java | 67 ++++++++++--------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/moulberry/flashback/exporting/ExportJob.java b/src/main/java/com/moulberry/flashback/exporting/ExportJob.java index 12ab0b7..4a24165 100644 --- a/src/main/java/com/moulberry/flashback/exporting/ExportJob.java +++ b/src/main/java/com/moulberry/flashback/exporting/ExportJob.java @@ -52,7 +52,6 @@ import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.Random; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; @@ -395,43 +394,45 @@ public class ExportJob { private void setup(ReplayServer replayServer) { Minecraft minecraft = Minecraft.getInstance(); - int currentTick = Math.max(0, this.settings.startTick() - 40); + if (replayServer.getReplayTick() != this.settings.startTick()) { + int currentTick = Math.max(0, this.settings.startTick() - 40); - // Ensure replay server is paused at currentTick - this.setServerTickAndWait(replayServer, currentTick, true); - this.runClientTick(false); - - // Clear particles - minecraft.particleEngine.clearParticles(); - - // Reset all walk animations & tick counts - for (Entity entity : minecraft.level.entitiesForRendering()) { - if (entity instanceof LivingEntity livingEntity) { - livingEntity.walkAnimation.stop(); - } - entity.tickCount = 0; - } - - // Advance until tick is at start - while (currentTick < this.settings.startTick()) { - currentTick += 1; + // Ensure replay server is paused at currentTick this.setServerTickAndWait(replayServer, currentTick, true); this.runClientTick(false); - } - // Apply initial position and keyframes at start tick - LocalPlayer player = minecraft.player; - if (player != null) { - Vec3 position = this.settings.initialCameraPosition(); - player.moveTo(position.x, position.y, position.z, this.settings.initialCameraYaw(), this.settings.initialCameraPitch()); - player.setDeltaMovement(Vec3.ZERO); - } - this.settings.editorState().applyKeyframes(new MinecraftKeyframeHandler(Minecraft.getInstance()), this.settings.startTick()); - this.runClientTick(false); + // Clear particles + minecraft.particleEngine.clearParticles(); - // Ensured replay server is paused at startTick - this.setServerTickAndWait(replayServer, this.settings.startTick(), true); - this.runClientTick(false); + // Reset all walk animations & tick counts + for (Entity entity : minecraft.level.entitiesForRendering()) { + if (entity instanceof LivingEntity livingEntity) { + livingEntity.walkAnimation.stop(); + } + entity.tickCount = 0; + } + + // Advance until tick is at start + while (currentTick < this.settings.startTick()) { + currentTick += 1; + this.setServerTickAndWait(replayServer, currentTick, true); + this.runClientTick(false); + } + + // Apply initial position and keyframes at start tick + LocalPlayer player = minecraft.player; + if (player != null) { + Vec3 position = this.settings.initialCameraPosition(); + player.moveTo(position.x, position.y, position.z, this.settings.initialCameraYaw(), this.settings.initialCameraPitch()); + player.setDeltaMovement(Vec3.ZERO); + } + this.settings.editorState().applyKeyframes(new MinecraftKeyframeHandler(Minecraft.getInstance()), this.settings.startTick()); + this.runClientTick(false); + + // Ensured replay server is paused at startTick + this.setServerTickAndWait(replayServer, this.settings.startTick(), true); + this.runClientTick(false); + } // Remove screen minecraft.setScreen(null);