88import com .mojang .datafixers .util .Pair ;
99import it .unimi .dsi .fastutil .objects .Object2IntOpenHashMap ;
1010import it .unimi .dsi .fastutil .objects .ObjectOpenHashSet ;
11+ import it .unimi .dsi .fastutil .objects .ReferenceOpenHashSet ;
12+ import it .unimi .dsi .fastutil .objects .ReferenceSet ;
1113import net .minecraft .client .renderer .block .model .BlockModel ;
1214import net .minecraft .client .resources .model .*;
1315import net .minecraft .resources .ResourceLocation ;
1416import net .minecraft .server .packs .PackResources ;
1517import net .minecraft .server .packs .PackType ;
1618import net .minecraft .server .packs .resources .FallbackResourceManager ;
19+ import net .minecraft .server .packs .resources .MultiPackResourceManager ;
1720import net .minecraft .server .packs .resources .Resource ;
1821import net .minecraft .server .packs .resources .ResourceManager ;
1922import net .minecraft .world .level .block .Block ;
@@ -82,6 +85,23 @@ private static void logOrSuppressError(Object2IntOpenHashMap<String> suppression
8285 ModernFix .LOGGER .error ("Error reading {} {}: {}" , type , location , e );
8386 }
8487
88+ /**
89+ * Some mods (cough, EBE) inject their custom resource pack into the namespaced resource managers, but not into the
90+ * main list contained inside the parent resource manager, so we need to scan each of the namespaced managers as
91+ * well.
92+ */
93+ private static void checkFallbacks (MultiPackResourceManager manager , List <PackResources > resourcePackList ) {
94+ ReferenceSet <PackResources > knownPacks = new ReferenceOpenHashSet <>(resourcePackList );
95+ Map <String , FallbackResourceManager > namespacedMap = manager .namespacedManagers ;
96+ namespacedMap .values ().stream ().flatMap (FallbackResourceManager ::listPacks ).forEach (pack -> {
97+ if (knownPacks .add (pack )) {
98+ /* the pack was not previously known, add to our list */
99+ ModernFix .LOGGER .debug ("Injecting unlisted pack '{}': {}" , pack .getName (), pack .getClass ().getName ());
100+ resourcePackList .add (pack );
101+ }
102+ });
103+ }
104+
85105 public static void gatherModelMaterials (ResourceManager manager , Predicate <PackResources > isTrustedPack ,
86106 Set <Material > materialSet , Set <ResourceLocation > blockStateFiles ,
87107 Set <ResourceLocation > modelFiles , UnbakedModel missingModel ,
@@ -94,6 +114,9 @@ public static void gatherModelMaterials(ResourceManager manager, Predicate<PackR
94114 * scanning most packs a lot.
95115 */
96116 List <PackResources > allPackResources = new ArrayList <>(manager .listPacks ().collect (Collectors .toList ()));
117+ if (manager instanceof MultiPackResourceManager ) {
118+ checkFallbacks ((MultiPackResourceManager )manager , allPackResources );
119+ }
97120 Collections .reverse (allPackResources );
98121 ObjectOpenHashSet <ResourceLocation > allAvailableModels = new ObjectOpenHashSet <>(), allAvailableStates = new ObjectOpenHashSet <>();
99122 /* try to fix CME in some runtime packs by forcing generation */
0 commit comments