5959import java .nio .file .Path ;
6060import java .util .List ;
6161import java .util .concurrent .ExecutionException ;
62+ import java .util .concurrent .ExecutorService ;
63+ import java .util .concurrent .Executors ;
6264import java .util .stream .Collectors ;
6365import java .util .stream .Stream ;
6466
@@ -129,6 +131,8 @@ private static Pair<RegistryAccess.Frozen, ReloadableServerResources> loadVanill
129131 // Load resource packs, see WorldStem.load
130132 // and call to WorldStem.load in net.minecraft.server.Main
131133 // We don't currently try to load any datapacks here
134+ final ExecutorService executor = Executors .newCachedThreadPool ();
135+
132136 final var packRepository = ServerPacksSource .createVanillaTrustedRepository ();
133137 MinecraftServer .configurePackRepository (packRepository , WorldDataConfiguration .DEFAULT , /* safeMode = */ false , true );
134138 final CloseableResourceManager rm = new MultiPackResourceManager (PackType .SERVER_DATA , packRepository .openAllSelected ());
@@ -138,10 +142,10 @@ private static Pair<RegistryAccess.Frozen, ReloadableServerResources> loadVanill
138142 List <Registry .PendingTags <?>> pendingTags = TagLoader .loadTagsForExistingRegistries (rm , staticRegistries .getLayer (RegistryLayer .STATIC ));
139143 final var wga = staticRegistries .getAccessForLoading (RegistryLayer .WORLDGEN );
140144 List <HolderLookup .RegistryLookup <?>> tl = TagLoader .buildUpdatedLookups (wga , pendingTags );
141- RegistryAccess .Frozen wgr = RegistryDataLoader .load (rm , tl , RegistryDataLoader .WORLDGEN_REGISTRIES );
145+ RegistryAccess .Frozen wgr = RegistryDataLoader .load (rm , tl , RegistryDataLoader .WORLDGEN_REGISTRIES , executor ). join ( );
142146 List <HolderLookup .RegistryLookup <?>> cl = Stream .concat (tl .stream (), wgr .listRegistries ()).toList ();
143147 final LayeredRegistryAccess <RegistryLayer > withWorldGen = staticRegistries .replaceFrom (RegistryLayer .WORLDGEN , wgr );
144- RegistryAccess .Frozen da = RegistryDataLoader .load (rm , cl , RegistryDataLoader .DIMENSION_REGISTRIES );
148+ RegistryAccess .Frozen da = RegistryDataLoader .load (rm , cl , RegistryDataLoader .DIMENSION_REGISTRIES , executor ). join ( );
145149 final LayeredRegistryAccess <RegistryLayer > withDimensions = withWorldGen .replaceFrom (RegistryLayer .DIMENSIONS , da );
146150 TagLoader .loadTagsForExistingRegistries (rm , withDimensions .getLayer (RegistryLayer .WORLDGEN ));
147151
@@ -153,12 +157,13 @@ private static Pair<RegistryAccess.Frozen, ReloadableServerResources> loadVanill
153157 packRepository .getRequestedFeatureFlags (),
154158 CommandSelection .ALL ,
155159 LevelBasedPermissionSet .ALL_PERMISSIONS , // functionPermissionLevel
156- Util . backgroundExecutor () , // prepareExecutor
160+ executor , // prepareExecutor
157161 Runnable ::run // applyExecutor
158162 ).whenComplete ((result , ex ) -> {
159163 if (ex != null ) {
160164 rm .close ();
161165 }
166+ executor .shutdown ();
162167 }).thenApply (resources -> {
163168 resources .updateStaticRegistryTags ();
164169 return resources ;
@@ -170,6 +175,7 @@ private static Pair<RegistryAccess.Frozen, ReloadableServerResources> loadVanill
170175 try {
171176 resources = resourcesFuture .get ();
172177 } catch (final InterruptedException | ExecutionException ex ) {
178+ executor .shutdown ();
173179 Logger .error (ex , "Failed to load registries/datapacks" );
174180 System .exit (1 );
175181 throw new RuntimeException ();
0 commit comments