Replace redirect in lifecycle events with wrap operation (#3887)

* Replace redirect in lifecycle events with wrap operation

* Remove old javadoc
This commit is contained in:
AlphaMode 2024-08-04 07:51:48 -05:00 committed by GitHub
parent 8dc279b1d0
commit 6c1df360ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 <K, V> V onLoadWorld(Map<K, V> 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 <K, V> V onLoadWorld(Map<K, V> worlds, K registryKey, V serverWorld, Operation<V> original) {
final V result = original.call(worlds, registryKey, serverWorld);
ServerWorldEvents.LOAD.invoker().onWorldLoad((MinecraftServer) (Object) this, (ServerWorld) serverWorld);
return result;