Fix merged mod resource pack not returning all resources with the same name when asked. Closes #9194

This commit is contained in:
LexManos committed 2022-12-09 12:44:40 -08:00
1 parent c1f26d544a
commit 69eb940764
3 files changed
+46

No files matched your search

@@ -5,7 +5,12 @@
package net.minecraftforge.common.extensions;
import java.util.Collection;
import org.jetbrains.annotations.Nullable;
import net.minecraft.server.packs.PackResources;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraftforge.resource.DelegatingPackResources;
public interface IForgePackResources
{
@@ -20,4 +25,14 @@ public interface IForgePackResources
default void initForNamespace(final String nameSpace) {}
default void init(final PackType packType) {}
/**
* Gets a collection of {@code PackResource} instances nested inside this pack.
* Used to merge several packs into one entry in the resource pack selection UI without
* losing the ability for each pack to return a resource in
* {@link ResourceManager#getResourceStack(ResourceLocation)}
* @return Collection of nested {@code PackResource}, or null if this pack has no children
* @see DelegatingPackResources
*/
@Nullable default Collection<PackResources> getChildren() { return null; }
}
@@ -10,6 +10,7 @@ import com.google.common.collect.ImmutableMap;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -123,6 +124,12 @@ public class DelegatingPackResources extends AbstractPackResources
return null;
}
@Nullable
public Collection<PackResources> getChildren()
{
return delegates;
}
private List<PackResources> getCandidatePacks(PackType type, ResourceLocation location)
{
Map<String, List<PackResources>> map = type == PackType.CLIENT_RESOURCES ? namespacesAssets : namespacesData;