Skip to content

Commit 6050585

Browse files
committed
Merge remote-tracking branch 'origin/1.18' into 1.19.2
2 parents 41ca9fc + 431231c commit 6050585

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,9 +9,12 @@
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;
1416
import net.minecraft.util.RandomSource;
17+
import net.minecraft.world.level.block.Block;
1518
import net.minecraft.world.level.block.state.BlockState;
1619
import org.apache.commons.lang3.tuple.Triple;
1720
import 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

Comments
 (0)