From d9da2e135cb21c391f456e8829b2ea8f089fcb77 Mon Sep 17 00:00:00 2001 From: Jochem <29899660+JochCool@users.noreply.github.com> Date: Tue, 16 Nov 2021 00:10:21 +0100 Subject: [PATCH] Sync world border animation & movement to Replay speed Fixes an issue where the world border would move at normal speed when speeding up or slowing down the replay, and also at an incorrect speed when rendering the replay, causing it to get out of sync with the rest of the world. Co-authored-by: Jonas Herzig --- .../Mixin_UseReplayTime_ForMovement.java | 38 +++++++++++++++++++ .../Mixin_UseReplayTime_ForTexture.java | 29 ++++++++++++++ .../resources/mixins.replay.replaymod.json | 2 + 3 files changed, 69 insertions(+) create mode 100644 src/main/java/com/replaymod/replay/mixin/world_border/Mixin_UseReplayTime_ForMovement.java create mode 100644 src/main/java/com/replaymod/replay/mixin/world_border/Mixin_UseReplayTime_ForTexture.java diff --git a/src/main/java/com/replaymod/replay/mixin/world_border/Mixin_UseReplayTime_ForMovement.java b/src/main/java/com/replaymod/replay/mixin/world_border/Mixin_UseReplayTime_ForMovement.java new file mode 100644 index 00000000..1e8f9e2b --- /dev/null +++ b/src/main/java/com/replaymod/replay/mixin/world_border/Mixin_UseReplayTime_ForMovement.java @@ -0,0 +1,38 @@ +package com.replaymod.replay.mixin.world_border; + +import com.replaymod.core.versions.MCVer; +import com.replaymod.replay.ReplayHandler; +import com.replaymod.replay.ReplayModReplay; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +/** + * Normally Minecraft's world border movement is based off real time; + * this redirect ensures that it is synced with the time in the Replay instead. + */ +//#if MC>=11400 +// FIXME: preprocessor should be able to remap between fabric and forge +//#if FABRIC +@Mixin(targets = "net.minecraft.world.border.WorldBorder.MovingArea") +//#else +//$$ @Mixin(targets = "net.minecraft.world.border.WorldBorder.MovingBorderInfo") +//#endif +//#else +//$$ @Mixin(net.minecraft.world.border.WorldBorder.class) +//#endif +public class Mixin_UseReplayTime_ForMovement { + + //#if MC>=11400 + @Redirect(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Util;getMeasuringTimeMs()J")) + //#else + //$$ @Redirect(method = "*", at = @At(value = "INVOKE", target = "Ljava/lang/System;currentTimeMillis()J")) + //#endif + private long getWorldBorderTime() { + ReplayHandler replayHandler = ReplayModReplay.instance.getReplayHandler(); + if (replayHandler != null) { + return replayHandler.getReplaySender().currentTimeStamp(); + } + return MCVer.milliTime(); + } +} diff --git a/src/main/java/com/replaymod/replay/mixin/world_border/Mixin_UseReplayTime_ForTexture.java b/src/main/java/com/replaymod/replay/mixin/world_border/Mixin_UseReplayTime_ForTexture.java new file mode 100644 index 00000000..9abf28c4 --- /dev/null +++ b/src/main/java/com/replaymod/replay/mixin/world_border/Mixin_UseReplayTime_ForTexture.java @@ -0,0 +1,29 @@ +package com.replaymod.replay.mixin.world_border; + +import com.replaymod.core.versions.MCVer; +import com.replaymod.replay.ReplayHandler; +import com.replaymod.replay.ReplayModReplay; +import net.minecraft.client.render.WorldRenderer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +/** + * Normally Minecraft's world border texture animation is based off real time; + * this redirect ensures that it is synced with the time in the Replay instead. + */ +@Mixin(WorldRenderer.class) +public class Mixin_UseReplayTime_ForTexture { + //#if MC>=11400 + @Redirect(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Util;getMeasuringTimeMs()J")) + //#else + //$$ @Redirect(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;getSystemTime()J")) + //#endif + private long getWorldBorderTime() { + ReplayHandler replayHandler = ReplayModReplay.instance.getReplayHandler(); + if (replayHandler != null) { + return replayHandler.getReplaySender().currentTimeStamp(); + } + return MCVer.milliTime(); + } +} diff --git a/src/main/resources/mixins.replay.replaymod.json b/src/main/resources/mixins.replay.replaymod.json index f4205619..02e6fe65 100644 --- a/src/main/resources/mixins.replay.replaymod.json +++ b/src/main/resources/mixins.replay.replaymod.json @@ -7,6 +7,8 @@ "client": [ "entity_tracking.Mixin_EntityExt", "entity_tracking.Mixin_FixPartialUpdates", + "world_border.Mixin_UseReplayTime_ForMovement", + "world_border.Mixin_UseReplayTime_ForTexture", "Mixin_FixNPCSkinCaching", //#if MC>=11800 //$$ "Mixin_FixEntityNotTracking",