/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.logging.LogUtils * org.jspecify.annotations.Nullable * org.slf4j.Logger */ package net.minecraft.server.packs.resources; import com.mojang.logging.LogUtils; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.TreeMap; import java.util.function.Predicate; import java.util.stream.Stream; import net.minecraft.resources.Identifier; import net.minecraft.server.packs.PackResources; import net.minecraft.server.packs.PackType; import net.minecraft.server.packs.resources.CloseableResourceManager; import net.minecraft.server.packs.resources.FallbackResourceManager; import net.minecraft.server.packs.resources.Resource; import net.minecraft.server.packs.resources.ResourceFilterSection; import net.minecraft.server.packs.resources.ResourceManager; import org.jspecify.annotations.Nullable; import org.slf4j.Logger; public class MultiPackResourceManager implements CloseableResourceManager { private static final Logger LOGGER = LogUtils.getLogger(); private final Map namespacedManagers; private final List packs; public MultiPackResourceManager(PackType type, List packs) { this.packs = List.copyOf(packs); HashMap namespacedManagers = new HashMap(); List namespaces = packs.stream().flatMap(p -> p.getNamespaces(type).stream()).distinct().toList(); for (PackResources pack : packs) { ResourceFilterSection filterSection = this.getPackFilterSection(pack); Set providedNamespaces = pack.getNamespaces(type); Predicate pathFilter = filterSection != null ? location -> filterSection.isPathFiltered(location.getPath()) : null; for (String namespace : namespaces) { boolean filterMatchesNamespace; boolean packContainsNamespace = providedNamespaces.contains(namespace); boolean bl = filterMatchesNamespace = filterSection != null && filterSection.isNamespaceFiltered(namespace); if (!packContainsNamespace && !filterMatchesNamespace) continue; FallbackResourceManager fallbackResourceManager = (FallbackResourceManager)namespacedManagers.get(namespace); if (fallbackResourceManager == null) { fallbackResourceManager = new FallbackResourceManager(type, namespace); namespacedManagers.put(namespace, fallbackResourceManager); } if (packContainsNamespace && filterMatchesNamespace) { fallbackResourceManager.push(pack, pathFilter); continue; } if (packContainsNamespace) { fallbackResourceManager.push(pack); continue; } fallbackResourceManager.pushFilterOnly(pack.packId(), pathFilter); } } this.namespacedManagers = namespacedManagers; } private @Nullable ResourceFilterSection getPackFilterSection(PackResources pack) { try { return pack.getMetadataSection(ResourceFilterSection.TYPE); } catch (IOException e) { LOGGER.error("Failed to get filter section from pack {}", (Object)pack.packId()); return null; } } @Override public Set getNamespaces() { return this.namespacedManagers.keySet(); } @Override public Optional getResource(Identifier location) { ResourceManager pack = this.namespacedManagers.get(location.getNamespace()); if (pack != null) { return pack.getResource(location); } return Optional.empty(); } @Override public List getResourceStack(Identifier location) { ResourceManager pack = this.namespacedManagers.get(location.getNamespace()); if (pack != null) { return pack.getResourceStack(location); } return List.of(); } @Override public Map listResources(String directory, Predicate filter) { MultiPackResourceManager.checkTrailingDirectoryPath(directory); TreeMap result = new TreeMap(); for (FallbackResourceManager manager : this.namespacedManagers.values()) { result.putAll(manager.listResources(directory, filter)); } return result; } @Override public Map> listResourceStacks(String directory, Predicate filter) { MultiPackResourceManager.checkTrailingDirectoryPath(directory); TreeMap> result = new TreeMap>(); for (FallbackResourceManager manager : this.namespacedManagers.values()) { result.putAll(manager.listResourceStacks(directory, filter)); } return result; } private static void checkTrailingDirectoryPath(String directory) { if (directory.endsWith("/")) { throw new IllegalArgumentException("Trailing slash in path " + directory); } } @Override public Stream listPacks() { return this.packs.stream(); } @Override public void close() { this.packs.forEach(PackResources::close); } }