From bef8c5753c007e5b8f3a905afac08b251276e686 Mon Sep 17 00:00:00 2001 From: alpha Date: Tue, 25 Jun 2024 21:00:51 -0500 Subject: [PATCH 1/2] Replace redirect in lifecycle events with wrap operation --- .../mixin/event/lifecycle/MinecraftServerMixin.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/MinecraftServerMixin.java b/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/MinecraftServerMixin.java index 2dcbce66e3..8f78243426 100644 --- a/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/MinecraftServerMixin.java +++ b/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/MinecraftServerMixin.java @@ -22,11 +22,12 @@ import java.util.concurrent.CompletableFuture; import java.util.function.BooleanSupplier; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @@ -75,9 +76,9 @@ private void onEndTick(BooleanSupplier shouldKeepTicking, CallbackInfo info) { // The locals you have to manage for an inject are insane. And do it twice. A redirect is much cleaner. // Here is what it looks like with an inject: https://gist.github.com/i509VCB/f80077cc536eb4dba62b794eba5611c1 - @Redirect(method = "createWorlds", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;")) - private V onLoadWorld(Map worlds, K registryKey, V serverWorld) { - final V result = worlds.put(registryKey, serverWorld); + @WrapOperation(method = "createWorlds", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;")) + private V onLoadWorld(Map worlds, K registryKey, V serverWorld, Operation original) { + final V result = original.call(worlds, registryKey, serverWorld); ServerWorldEvents.LOAD.invoker().onWorldLoad((MinecraftServer) (Object) this, (ServerWorld) serverWorld); return result; From 5487bce10f77d378ce8a8918577f0bb6efc6b5f2 Mon Sep 17 00:00:00 2001 From: alpha Date: Tue, 25 Jun 2024 21:02:40 -0500 Subject: [PATCH 2/2] Remove old javadoc --- .../fabric/mixin/event/lifecycle/MinecraftServerMixin.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/MinecraftServerMixin.java b/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/MinecraftServerMixin.java index 8f78243426..346caeeb70 100644 --- a/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/MinecraftServerMixin.java +++ b/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/MinecraftServerMixin.java @@ -74,8 +74,6 @@ private void onEndTick(BooleanSupplier shouldKeepTicking, CallbackInfo info) { ServerTickEvents.END_SERVER_TICK.invoker().onEndTick((MinecraftServer) (Object) this); } - // The locals you have to manage for an inject are insane. And do it twice. A redirect is much cleaner. - // Here is what it looks like with an inject: https://gist.github.com/i509VCB/f80077cc536eb4dba62b794eba5611c1 @WrapOperation(method = "createWorlds", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;")) private V onLoadWorld(Map worlds, K registryKey, V serverWorld, Operation original) { final V result = original.call(worlds, registryKey, serverWorld);