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 .Registry ;
1315import net .minecraft .resources .ResourceLocation ;
16+ import net .minecraft .world .level .block .Block ;
1417import net .minecraft .world .level .block .state .BlockState ;
1518import org .apache .commons .lang3 .tuple .Triple ;
1619import org .embeddedt .modernfix .ModernFix ;
@@ -103,6 +106,25 @@ public boolean containsKey(Object o) {
103106 public boolean containsValue (Object o ) {
104107 return permanentOverrides .containsValue (o ) || bakedCache .containsValue (o );
105108 }
109+
110+ private static boolean isVanillaTopLevelModel (ResourceLocation location ) {
111+ if (location instanceof ModelResourceLocation ) {
112+ try {
113+ ModelResourceLocation mrl = (ModelResourceLocation )location ;
114+ ResourceLocation registryKey = new ResourceLocation (mrl .getNamespace (), mrl .getPath ());
115+ // check for standard inventory model
116+ if (mrl .getVariant ().equals ("inventory" ) && Registry .ITEM .containsKey (registryKey ))
117+ return true ;
118+ Optional <Block > blockOpt = Registry .BLOCK .getOptional (registryKey );
119+ if (blockOpt .isPresent ()) {
120+ return ModelBakeryHelpers .getBlockStatesForMRL (blockOpt .get ().getStateDefinition (), mrl ).size () > 0 ;
121+ }
122+ } catch (RuntimeException ignored ) {
123+ // can occur if the MRL is not valid for that blockstate, ignore
124+ }
125+ }
126+ return false ;
127+ }
106128
107129 @ Override
108130 public BakedModel get (Object o ) {
@@ -117,11 +139,11 @@ public BakedModel get(Object o) {
117139 model = missingModel ;
118140 }
119141 if (model == missingModel ) {
120- // to correctly emulate the original map, we return null for missing models
121- permanentOverrides . put ((ResourceLocation ) o , null ) ;
122- return null ;
123- } else
124- return model ;
142+ // to correctly emulate the original map, we return null for missing models, unless they are top-level
143+ model = isVanillaTopLevelModel ((ResourceLocation )o ) ? model : null ;
144+ permanentOverrides . put (( ResourceLocation ) o , model ) ;
145+ }
146+ return model ;
125147 }
126148 }
127149
0 commit comments