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 ;
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 .ModernFix ;
@@ -104,6 +107,25 @@ public boolean containsKey(Object o) {
104107 public boolean containsValue (Object o ) {
105108 return permanentOverrides .containsValue (o ) || bakedCache .containsValue (o );
106109 }
110+
111+ private static boolean isVanillaTopLevelModel (ResourceLocation location ) {
112+ if (location instanceof ModelResourceLocation ) {
113+ try {
114+ ModelResourceLocation mrl = (ModelResourceLocation )location ;
115+ ResourceLocation registryKey = new ResourceLocation (mrl .getNamespace (), mrl .getPath ());
116+ // check for standard inventory model
117+ if (mrl .getVariant ().equals ("inventory" ) && Registry .ITEM .containsKey (registryKey ))
118+ return true ;
119+ Optional <Block > blockOpt = Registry .BLOCK .getOptional (registryKey );
120+ if (blockOpt .isPresent ()) {
121+ return ModelBakeryHelpers .getBlockStatesForMRL (blockOpt .get ().getStateDefinition (), mrl ).size () > 0 ;
122+ }
123+ } catch (RuntimeException ignored ) {
124+ // can occur if the MRL is not valid for that blockstate, ignore
125+ }
126+ }
127+ return false ;
128+ }
107129
108130 @ Override
109131 public BakedModel get (Object o ) {
@@ -118,11 +140,11 @@ public BakedModel get(Object o) {
118140 model = missingModel ;
119141 }
120142 if (model == missingModel ) {
121- // to correctly emulate the original map, we return null for missing models
122- permanentOverrides . put ((ResourceLocation ) o , null ) ;
123- return null ;
124- } else
125- return model ;
143+ // to correctly emulate the original map, we return null for missing models, unless they are top-level
144+ model = isVanillaTopLevelModel ((ResourceLocation )o ) ? model : null ;
145+ permanentOverrides . put (( ResourceLocation ) o , model ) ;
146+ }
147+ return model ;
126148 }
127149 }
128150
0 commit comments