/* * Decompiled with CFR 0.152. * * Could not load the following classes: * org.jspecify.annotations.Nullable */ package net.minecraft.client.resources; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; import java.util.Map; import java.util.Optional; import java.util.function.BiConsumer; import java.util.function.Function; import net.minecraft.SharedConstants; import net.minecraft.network.chat.Component; import net.minecraft.resources.Identifier; import net.minecraft.server.packs.BuiltInMetadata; import net.minecraft.server.packs.PackLocationInfo; import net.minecraft.server.packs.PackResources; import net.minecraft.server.packs.PackSelectionConfig; import net.minecraft.server.packs.PackType; import net.minecraft.server.packs.VanillaPackResources; import net.minecraft.server.packs.VanillaPackResourcesBuilder; import net.minecraft.server.packs.metadata.pack.PackMetadataSection; import net.minecraft.server.packs.repository.BuiltInPackSource; import net.minecraft.server.packs.repository.KnownPack; import net.minecraft.server.packs.repository.Pack; import net.minecraft.server.packs.repository.PackSource; import net.minecraft.world.level.validation.DirectoryValidator; import org.jspecify.annotations.Nullable; public class ClientPackSource extends BuiltInPackSource { private static final PackMetadataSection VERSION_METADATA_SECTION = new PackMetadataSection(Component.translatable("resourcePack.vanilla.description"), SharedConstants.getCurrentVersion().packVersion(PackType.CLIENT_RESOURCES).minorRange()); private static final BuiltInMetadata BUILT_IN_METADATA = BuiltInMetadata.of(PackMetadataSection.CLIENT_TYPE, VERSION_METADATA_SECTION); public static final String HIGH_CONTRAST_PACK = "high_contrast"; private static final Map SPECIAL_PACK_NAMES = Map.of("programmer_art", Component.translatable("resourcePack.programmer_art.name"), "high_contrast", Component.translatable("resourcePack.high_contrast.name")); private static final PackLocationInfo VANILLA_PACK_INFO = new PackLocationInfo("vanilla", Component.translatable("resourcePack.vanilla.name"), PackSource.BUILT_IN, Optional.of(CORE_PACK_INFO)); private static final PackSelectionConfig VANILLA_SELECTION_CONFIG = new PackSelectionConfig(true, Pack.Position.BOTTOM, false); private static final PackSelectionConfig BUILT_IN_SELECTION_CONFIG = new PackSelectionConfig(false, Pack.Position.TOP, false); private static final Identifier PACKS_DIR = Identifier.withDefaultNamespace("resourcepacks"); private final @Nullable Path externalAssetDir; public ClientPackSource(Path externalAssetSource, DirectoryValidator validator) { super(PackType.CLIENT_RESOURCES, ClientPackSource.createVanillaPackSource(externalAssetSource), PACKS_DIR, validator); this.externalAssetDir = this.findExplodedAssetPacks(externalAssetSource); } private static PackLocationInfo createBuiltInPackLocation(String id, Component title) { return new PackLocationInfo(id, title, PackSource.BUILT_IN, Optional.of(KnownPack.vanilla(id))); } private @Nullable Path findExplodedAssetPacks(Path externalAssetSource) { Path devAssetDir; if (SharedConstants.IS_RUNNING_IN_IDE && externalAssetSource.getFileSystem() == FileSystems.getDefault() && Files.isDirectory(devAssetDir = externalAssetSource.getParent().resolve("resourcepacks"), new LinkOption[0])) { return devAssetDir; } return null; } private static VanillaPackResources createVanillaPackSource(Path externalAssetRoot) { VanillaPackResourcesBuilder builder = new VanillaPackResourcesBuilder().setMetadata(BUILT_IN_METADATA).exposeNamespace("minecraft", "realms"); return builder.applyDevelopmentConfig().pushJarResources().pushAssetPath(PackType.CLIENT_RESOURCES, externalAssetRoot).build(VANILLA_PACK_INFO); } @Override protected Component getPackTitle(String id) { Component title = SPECIAL_PACK_NAMES.get(id); return title != null ? title : Component.literal(id); } @Override protected @Nullable Pack createVanillaPack(PackResources resources) { return Pack.readMetaAndCreate(VANILLA_PACK_INFO, ClientPackSource.fixedResources(resources), PackType.CLIENT_RESOURCES, VANILLA_SELECTION_CONFIG); } @Override protected @Nullable Pack createBuiltinPack(String id, Pack.ResourcesSupplier resources, Component name) { return Pack.readMetaAndCreate(ClientPackSource.createBuiltInPackLocation(id, name), resources, PackType.CLIENT_RESOURCES, BUILT_IN_SELECTION_CONFIG); } @Override protected void populatePackList(BiConsumer> discoveredPacks) { super.populatePackList(discoveredPacks); if (this.externalAssetDir != null) { this.discoverPacksInPath(this.externalAssetDir, discoveredPacks); } } }