diff --git a/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/api/event/lifecycle/v1/ServerLifecycleEvents.java b/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/api/event/lifecycle/v1/ServerLifecycleEvents.java index 50bf8a507..dc717497c 100644 --- a/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/api/event/lifecycle/v1/ServerLifecycleEvents.java +++ b/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/api/event/lifecycle/v1/ServerLifecycleEvents.java @@ -16,7 +16,7 @@ package net.fabricmc.fabric.api.event.lifecycle.v1; -import net.minecraft.resource.ServerResourceManager; +import net.minecraft.resource.ReloadableResourceManager; import net.minecraft.server.MinecraftServer; import net.minecraft.server.PlayerManager; @@ -113,7 +113,7 @@ public final class ServerLifecycleEvents { } public interface StartDataPackReload { - void startDataPackReload(MinecraftServer server, ServerResourceManager serverResourceManager); + void startDataPackReload(MinecraftServer server, ReloadableResourceManager serverResourceManager); } public interface EndDataPackReload { @@ -126,6 +126,6 @@ public final class ServerLifecycleEvents { * @param serverResourceManager the server resource manager * @param success if the reload was successful */ - void endDataPackReload(MinecraftServer server, ServerResourceManager serverResourceManager, boolean success); + void endDataPackReload(MinecraftServer server, ReloadableResourceManager serverResourceManager, boolean success); } } 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 503a6a901..b465a9e00 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 @@ -16,11 +16,11 @@ package net.fabricmc.fabric.mixin.event.lifecycle; -import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; import java.util.function.BooleanSupplier; import org.spongepowered.asm.mixin.Mixin; @@ -29,14 +29,15 @@ 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; import net.minecraft.block.entity.BlockEntity; -import net.minecraft.entity.Entity; -import net.minecraft.resource.ServerResourceManager; import net.minecraft.server.MinecraftServer; import net.minecraft.server.world.ServerWorld; +import net.minecraft.resource.ReloadableResourceManager; +import net.minecraft.resource.ResourcePack; +import net.minecraft.util.Unit; +import net.minecraft.world.level.LevelProperties; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerBlockEntityEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; @@ -46,7 +47,7 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents; @Mixin(MinecraftServer.class) public abstract class MinecraftServerMixin { @Shadow - private ServerResourceManager serverResourceManager; + private ReloadableResourceManager dataManager; @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;setupServer()Z"), method = "run") private void beforeSetupServer(CallbackInfo info) { @@ -83,8 +84,6 @@ public abstract class MinecraftServerMixin { */ @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;close()V"), method = "shutdown", locals = LocalCapture.CAPTURE_FAILEXCEPTION) private void closeWorld(CallbackInfo ci, Iterator worlds, ServerWorld serverWorld) { - final List entities = serverWorld.getEntities(null, entity -> true); // Get every single entity in the world - for (BlockEntity blockEntity : serverWorld.blockEntities) { ServerBlockEntityEvents.BLOCK_ENTITY_UNLOAD.invoker().onUnload(blockEntity, serverWorld); } @@ -100,17 +99,18 @@ public abstract class MinecraftServerMixin { return result; } - @Inject(method = "reloadResources", at = @At("HEAD")) - private void startResourceReload(Collection collection, CallbackInfoReturnable> cir) { - ServerLifecycleEvents.START_DATA_PACK_RELOAD.invoker().startDataPackReload((MinecraftServer) (Object) this, this.serverResourceManager); + @Inject(method = "reloadDataPacks", at = @At("HEAD")) + private void startResourceReload(LevelProperties levelProperties, CallbackInfo cir) { + ServerLifecycleEvents.START_DATA_PACK_RELOAD.invoker().startDataPackReload((MinecraftServer) (Object) this, this.dataManager); } - @Inject(method = "reloadResources", at = @At("TAIL")) - private void endResourceReload(Collection collection, CallbackInfoReturnable> cir) { - cir.getReturnValue().handleAsync((value, throwable) -> { - // Hook into fail - ServerLifecycleEvents.END_DATA_PACK_RELOAD.invoker().endDataPackReload((MinecraftServer) (Object) this, this.serverResourceManager, throwable == null); - return value; - }, (MinecraftServer) (Object) this); + @Redirect(method = "reloadDataPacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/ReloadableResourceManager;beginReload(Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/List;Ljava/util/concurrent/CompletableFuture;)Ljava/util/concurrent/CompletableFuture;")) + private CompletableFuture endResourceReload(ReloadableResourceManager reloadableResourceManager, Executor prepareExecutor, Executor applyExecutor, List packs, CompletableFuture initialStage) throws Exception { + return reloadableResourceManager.beginReload(prepareExecutor, applyExecutor, packs, initialStage) + .handleAsync((value, throwable) -> { + // Hook into fail + ServerLifecycleEvents.END_DATA_PACK_RELOAD.invoker().endDataPackReload((MinecraftServer) (Object) this, this.dataManager, throwable == null); + return value; + }, (MinecraftServer) (Object) this); } } diff --git a/fabric-lifecycle-events-v1/src/testmod/java/net/fabricmc/fabric/test/event/lifecycle/ServerLifecycleTests.java b/fabric-lifecycle-events-v1/src/testmod/java/net/fabricmc/fabric/test/event/lifecycle/ServerLifecycleTests.java index 59f5dfb3a..4bce68a65 100644 --- a/fabric-lifecycle-events-v1/src/testmod/java/net/fabricmc/fabric/test/event/lifecycle/ServerLifecycleTests.java +++ b/fabric-lifecycle-events-v1/src/testmod/java/net/fabricmc/fabric/test/event/lifecycle/ServerLifecycleTests.java @@ -44,7 +44,7 @@ public class ServerLifecycleTests implements ModInitializer { }); ServerWorldEvents.LOAD.register((server, world) -> { - LOGGER.info("Loaded world " + world.getRegistryKey().getValue().toString()); + LOGGER.info("Loaded world " + world.dimension.getType().toString()); }); } }