/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.datafixers.util.Pair * com.mojang.logging.LogUtils * org.slf4j.Logger */ package net.minecraft.server; import com.mojang.datafixers.util.Pair; import com.mojang.logging.LogUtils; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.stream.Stream; import net.minecraft.commands.Commands; import net.minecraft.core.HolderLookup; import net.minecraft.core.LayeredRegistryAccess; import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; import net.minecraft.resources.RegistryDataLoader; import net.minecraft.server.MinecraftServer; import net.minecraft.server.RegistryLayer; import net.minecraft.server.ReloadableServerResources; import net.minecraft.server.packs.PackResources; import net.minecraft.server.packs.PackType; import net.minecraft.server.packs.repository.PackRepository; import net.minecraft.server.packs.resources.CloseableResourceManager; import net.minecraft.server.packs.resources.MultiPackResourceManager; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.permissions.PermissionSet; import net.minecraft.tags.TagLoader; import net.minecraft.world.level.WorldDataConfiguration; import org.slf4j.Logger; public class WorldLoader { private static final Logger LOGGER = LogUtils.getLogger(); public static CompletableFuture load(InitConfig config, WorldDataSupplier worldDataSupplier, ResultFactory resultFactory, Executor backgroundExecutor, Executor mainThreadExecutor) { try { Pair packsAndResourceManager = config.packConfig.createResourceManager(); CloseableResourceManager resources = (CloseableResourceManager)packsAndResourceManager.getSecond(); LayeredRegistryAccess initialLayers = RegistryLayer.createRegistryAccess(); List> staticLayerTags = TagLoader.loadTagsForExistingRegistries(resources, initialLayers.getLayer(RegistryLayer.STATIC)); RegistryAccess.Frozen worldgenLoadContext = initialLayers.getAccessForLoading(RegistryLayer.WORLDGEN); List> worldgenContextRegistries = TagLoader.buildUpdatedLookups(worldgenLoadContext, staticLayerTags); RegistryAccess.Frozen loadedWorldgenRegistries = RegistryDataLoader.load(resources, worldgenContextRegistries, RegistryDataLoader.WORLDGEN_REGISTRIES); List> dimensionContextRegistries = Stream.concat(worldgenContextRegistries.stream(), loadedWorldgenRegistries.listRegistries()).toList(); RegistryAccess.Frozen initialWorldgenDimensions = RegistryDataLoader.load(resources, dimensionContextRegistries, RegistryDataLoader.DIMENSION_REGISTRIES); WorldDataConfiguration worldDataConfiguration = (WorldDataConfiguration)packsAndResourceManager.getFirst(); HolderLookup.Provider dimensionContextProvider = HolderLookup.Provider.create(dimensionContextRegistries.stream()); DataLoadOutput worldDataAndRegistries = worldDataSupplier.get(new DataLoadContext(resources, worldDataConfiguration, dimensionContextProvider, initialWorldgenDimensions)); LayeredRegistryAccess resourcesLoadContext = initialLayers.replaceFrom(RegistryLayer.WORLDGEN, loadedWorldgenRegistries, worldDataAndRegistries.finalDimensions); return ((CompletableFuture)ReloadableServerResources.loadResources(resources, resourcesLoadContext, staticLayerTags, worldDataConfiguration.enabledFeatures(), config.commandSelection(), config.functionCompilationPermissions(), backgroundExecutor, mainThreadExecutor).whenComplete((managers, throwable) -> { if (throwable != null) { resources.close(); } })).thenApplyAsync(managers -> { managers.updateStaticRegistryTags(); return resultFactory.create(resources, (ReloadableServerResources)managers, resourcesLoadContext, worldDataAndRegistries.cookie); }, mainThreadExecutor); } catch (Exception e) { return CompletableFuture.failedFuture(e); } } public record InitConfig(PackConfig packConfig, Commands.CommandSelection commandSelection, PermissionSet functionCompilationPermissions) { } public record PackConfig(PackRepository packRepository, WorldDataConfiguration initialDataConfig, boolean safeMode, boolean initMode) { public Pair createResourceManager() { WorldDataConfiguration newPackConfig = MinecraftServer.configurePackRepository(this.packRepository, this.initialDataConfig, this.initMode, this.safeMode); List openedPacks = this.packRepository.openAllSelected(); MultiPackResourceManager resources = new MultiPackResourceManager(PackType.SERVER_DATA, openedPacks); return Pair.of((Object)newPackConfig, (Object)resources); } } public record DataLoadContext(ResourceManager resources, WorldDataConfiguration dataConfiguration, HolderLookup.Provider datapackWorldgen, RegistryAccess.Frozen datapackDimensions) { } @FunctionalInterface public static interface WorldDataSupplier { public DataLoadOutput get(DataLoadContext var1); } public record DataLoadOutput(D cookie, RegistryAccess.Frozen finalDimensions) { } @FunctionalInterface public static interface ResultFactory { public R create(CloseableResourceManager var1, ReloadableServerResources var2, LayeredRegistryAccess var3, D var4); } }