From 6c1df360ce1da23730cf63ea76fc118d6dba8980 Mon Sep 17 00:00:00 2001 From: AlphaMode <26313415+AlphaMode@users.noreply.github.com> Date: Sun, 4 Aug 2024 07:51:48 -0500 Subject: [PATCH] Replace redirect in lifecycle events with wrap operation (#3887) * Replace redirect in lifecycle events with wrap operation * Remove old javadoc --- .../mixin/event/lifecycle/MinecraftServerMixin.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 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 2dcbce66e..346caeeb7 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.Map; 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; @@ -73,11 +74,9 @@ public abstract class MinecraftServerMixin { 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 - @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;