Skip to content

Commit 63aeef1

Browse files
committed
Add back datapack reload time tracking during world creation
1 parent 51c4f3e commit 63aeef1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.embeddedt.modernfix.common.mixin.feature.measure_time;
2+
3+
import com.google.common.base.Stopwatch;
4+
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
5+
import com.llamalad7.mixinextras.sugar.Share;
6+
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
7+
import net.minecraft.server.WorldLoader;
8+
import org.embeddedt.modernfix.ModernFix;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Inject;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
13+
14+
import java.util.concurrent.CompletableFuture;
15+
16+
@Mixin(WorldLoader.class)
17+
public class WorldLoaderMixin {
18+
@Inject(method = "load", at = @At("HEAD"))
19+
private static void startStopwatch(CallbackInfoReturnable<CompletableFuture<?>> cir, @Share("stopwatch") LocalRef<Stopwatch> stopwatch) {
20+
stopwatch.set(Stopwatch.createStarted());
21+
}
22+
23+
@ModifyReturnValue(method = "load", at = @At("RETURN"))
24+
private static CompletableFuture<?> finishStopwatch(CompletableFuture<?> original, @Share("stopwatch") LocalRef<Stopwatch> stopwatch) {
25+
Stopwatch watch = stopwatch.get();
26+
if (watch != null) {
27+
return original.whenComplete((o, throwable) -> {
28+
watch.stop();
29+
ModernFix.LOGGER.warn("Initial datapack load took {}", watch);
30+
});
31+
} else {
32+
return original;
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)