/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.collect.Lists * com.mojang.logging.LogUtils * org.slf4j.Logger */ package net.minecraft.server.packs.resources; import com.google.common.collect.Lists; import com.mojang.logging.LogUtils; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.function.Predicate; import java.util.stream.Collectors; 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.MultiPackResourceManager; import net.minecraft.server.packs.resources.PreparableReloadListener; import net.minecraft.server.packs.resources.ReloadInstance; import net.minecraft.server.packs.resources.Resource; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.packs.resources.SimpleReloadInstance; import net.minecraft.util.Unit; import org.slf4j.Logger; public class ReloadableResourceManager implements AutoCloseable, ResourceManager { private static final Logger LOGGER = LogUtils.getLogger(); private CloseableResourceManager resources; private final List listeners = Lists.newArrayList(); private final PackType type; public ReloadableResourceManager(PackType type) { this.type = type; this.resources = new MultiPackResourceManager(type, List.of()); } @Override public void close() { this.resources.close(); } public void registerReloadListener(PreparableReloadListener listener) { this.listeners.add(listener); } public ReloadInstance createReload(Executor backgroundExecutor, Executor mainThreadExecutor, CompletableFuture initialTask, List resourcePacks) { LOGGER.info("Reloading ResourceManager: {}", LogUtils.defer(() -> resourcePacks.stream().map(PackResources::packId).collect(Collectors.joining(", ")))); this.resources.close(); this.resources = new MultiPackResourceManager(this.type, resourcePacks); return SimpleReloadInstance.create(this.resources, this.listeners, backgroundExecutor, mainThreadExecutor, initialTask, LOGGER.isDebugEnabled()); } @Override public Optional getResource(Identifier location) { return this.resources.getResource(location); } @Override public Set getNamespaces() { return this.resources.getNamespaces(); } @Override public List getResourceStack(Identifier location) { return this.resources.getResourceStack(location); } @Override public Map listResources(String directory, Predicate filenameFilter) { return this.resources.listResources(directory, filenameFilter); } @Override public Map> listResourceStacks(String directory, Predicate filter) { return this.resources.listResourceStacks(directory, filter); } @Override public Stream listPacks() { return this.resources.listPacks(); } }