99import net .minecraft .client .resources .model .BakedModel ;
1010import net .minecraft .client .resources .model .BlockModelRotation ;
1111import net .minecraft .client .resources .model .ModelBakery ;
12+ import net .minecraft .client .resources .model .ModelResourceLocation ;
1213import net .minecraft .core .Direction ;
14+ import net .minecraft .core .registries .BuiltInRegistries ;
1315import net .minecraft .resources .ResourceLocation ;
1416import net .minecraft .util .RandomSource ;
17+ import net .minecraft .world .level .block .Block ;
1518import net .minecraft .world .level .block .state .BlockState ;
1619import org .apache .commons .lang3 .tuple .Triple ;
1720import org .embeddedt .modernfix .duck .IExtendedModelBakery ;
@@ -106,6 +109,25 @@ public boolean containsKey(Object o) {
106109 public boolean containsValue (Object o ) {
107110 return permanentOverrides .containsValue (o ) || bakedCache .containsValue (o );
108111 }
112+
113+ private static boolean isVanillaTopLevelModel (ResourceLocation location ) {
114+ if (location instanceof ModelResourceLocation ) {
115+ try {
116+ ModelResourceLocation mrl = (ModelResourceLocation )location ;
117+ ResourceLocation registryKey = new ResourceLocation (mrl .getNamespace (), mrl .getPath ());
118+ // check for standard inventory model
119+ if (mrl .getVariant ().equals ("inventory" ) && BuiltInRegistries .ITEM .containsKey (registryKey ))
120+ return true ;
121+ Optional <Block > blockOpt = BuiltInRegistries .BLOCK .getOptional (registryKey );
122+ if (blockOpt .isPresent ()) {
123+ return ModelBakeryHelpers .getBlockStatesForMRL (blockOpt .get ().getStateDefinition (), mrl ).size () > 0 ;
124+ }
125+ } catch (RuntimeException ignored ) {
126+ // can occur if the MRL is not valid for that blockstate, ignore
127+ }
128+ }
129+ return false ;
130+ }
109131
110132 @ Override
111133 public BakedModel get (Object o ) {
@@ -120,11 +142,11 @@ public BakedModel get(Object o) {
120142 model = missingModel ;
121143 }
122144 if (model == missingModel ) {
123- // to correctly emulate the original map, we return null for missing models
124- permanentOverrides . put ((ResourceLocation ) o , null ) ;
125- return null ;
126- } else
127- return model ;
145+ // to correctly emulate the original map, we return null for missing models, unless they are top-level
146+ model = isVanillaTopLevelModel ((ResourceLocation )o ) ? model : null ;
147+ permanentOverrides . put (( ResourceLocation ) o , model ) ;
148+ }
149+ return model ;
128150 }
129151 }
130152
0 commit comments