From 64ee2d29142bc5b08bb2d9ed1820680b10dd3b78 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sat, 26 Apr 2025 12:32:11 -0400 Subject: [PATCH] Add back datapack reload time tracking during world creation --- .../measure_time/WorldLoaderMixin.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 common/src/main/java/org/embeddedt/modernfix/common/mixin/feature/measure_time/WorldLoaderMixin.java diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/feature/measure_time/WorldLoaderMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/feature/measure_time/WorldLoaderMixin.java new file mode 100644 index 00000000..f96448a7 --- /dev/null +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/feature/measure_time/WorldLoaderMixin.java @@ -0,0 +1,35 @@ +package org.embeddedt.modernfix.common.mixin.feature.measure_time; + +import com.google.common.base.Stopwatch; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; +import net.minecraft.server.WorldLoader; +import org.embeddedt.modernfix.ModernFix; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.concurrent.CompletableFuture; + +@Mixin(WorldLoader.class) +public class WorldLoaderMixin { + @Inject(method = "load", at = @At("HEAD")) + private static void startStopwatch(CallbackInfoReturnable> cir, @Share("stopwatch") LocalRef stopwatch) { + stopwatch.set(Stopwatch.createStarted()); + } + + @ModifyReturnValue(method = "load", at = @At("RETURN")) + private static CompletableFuture finishStopwatch(CompletableFuture original, @Share("stopwatch") LocalRef stopwatch) { + Stopwatch watch = stopwatch.get(); + if (watch != null) { + return original.whenComplete((o, throwable) -> { + watch.stop(); + ModernFix.LOGGER.warn("Initial datapack load took {}", watch); + }); + } else { + return original; + } + } +}