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 ;
@@ -83,6 +86,23 @@ private static void logOrSuppressError(Object2IntOpenHashMap<String> suppression
8386 ModernFix .LOGGER .error ("Error reading {} {}: {}" , type , location , e );
8487 }
8588
89+ /**
90+ * Some mods (cough, EBE) inject their custom resource pack into the namespaced resource managers, but not into the
91+ * main list contained inside the parent resource manager, so we need to scan each of the namespaced managers as
92+ * well.
93+ */
94+ private static void checkFallbacks (MultiPackResourceManager manager , List <PackResources > resourcePackList ) {
95+ ReferenceSet <PackResources > knownPacks = new ReferenceOpenHashSet <>(resourcePackList );
96+ Map <String , FallbackResourceManager > namespacedMap = manager .namespacedManagers ;
97+ namespacedMap .values ().stream ().flatMap (FallbackResourceManager ::listPacks ).forEach (pack -> {
98+ if (knownPacks .add (pack )) {
99+ /* the pack was not previously known, add to our list */
100+ ModernFix .LOGGER .debug ("Injecting unlisted pack '{}': {}" , pack .getName (), pack .getClass ().getName ());
101+ resourcePackList .add (pack );
102+ }
103+ });
104+ }
105+
86106 public static void gatherModelMaterials (ResourceManager manager , Predicate <PackResources > isTrustedPack ,
87107 Set <Material > materialSet , Set <ResourceLocation > blockStateFiles ,
88108 Set <ResourceLocation > modelFiles , UnbakedModel missingModel ,
@@ -95,6 +115,9 @@ public static void gatherModelMaterials(ResourceManager manager, Predicate<PackR
95115 * scanning most packs a lot.
96116 */
97117 List <PackResources > allPackResources = new ArrayList <>(manager .listPacks ().collect (Collectors .toList ()));
118+ if (manager instanceof MultiPackResourceManager ) {
119+ checkFallbacks ((MultiPackResourceManager )manager , allPackResources );
120+ }
98121 Collections .reverse (allPackResources );
99122 ObjectOpenHashSet <ResourceLocation > allAvailableModels = new ObjectOpenHashSet <>(), allAvailableStates = new ObjectOpenHashSet <>();
100123 /* try to fix CME in some runtime packs by forcing generation */
0 commit comments