Skip to content

Commit 431231c

Browse files
committed
Merge remote-tracking branch 'origin/1.16' into 1.18
2 parents 1a25984 + 371e511 commit 431231c

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

common/src/main/java/org/embeddedt/modernfix/dynamicresources/DynamicBakedModelProvider.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
import net.minecraft.client.resources.model.BakedModel;
1010
import net.minecraft.client.resources.model.BlockModelRotation;
1111
import net.minecraft.client.resources.model.ModelBakery;
12+
import net.minecraft.client.resources.model.ModelResourceLocation;
1213
import net.minecraft.core.Direction;
14+
import net.minecraft.core.Registry;
1315
import net.minecraft.resources.ResourceLocation;
16+
import net.minecraft.world.level.block.Block;
1417
import net.minecraft.world.level.block.state.BlockState;
1518
import org.apache.commons.lang3.tuple.Triple;
1619
import 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

Comments
 (0)