Skip to content

Commit

Permalink
Never return a non-null model if it was top level in vanilla
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Aug 5, 2023
1 parent c1277a2 commit 371e511
Showing 1 changed file with 27 additions and 5 deletions.
Expand Up @@ -9,8 +9,11 @@
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.apache.commons.lang3.tuple.Triple;
import org.embeddedt.modernfix.ModernFix;
Expand Down Expand Up @@ -103,6 +106,25 @@ public boolean containsKey(Object o) {
public boolean containsValue(Object o) {
return permanentOverrides.containsValue(o) || bakedCache.containsValue(o);
}

private static boolean isVanillaTopLevelModel(ResourceLocation location) {
if(location instanceof ModelResourceLocation) {
try {
ModelResourceLocation mrl = (ModelResourceLocation)location;
ResourceLocation registryKey = new ResourceLocation(mrl.getNamespace(), mrl.getPath());
// check for standard inventory model
if(mrl.getVariant().equals("inventory") && Registry.ITEM.containsKey(registryKey))
return true;
Optional<Block> blockOpt = Registry.BLOCK.getOptional(registryKey);
if(blockOpt.isPresent()) {
return ModelBakeryHelpers.getBlockStatesForMRL(blockOpt.get().getStateDefinition(), mrl).size() > 0;
}
} catch(RuntimeException ignored) {
// can occur if the MRL is not valid for that blockstate, ignore
}
}
return false;
}

@Override
public BakedModel get(Object o) {
Expand All @@ -117,11 +139,11 @@ public BakedModel get(Object o) {
model = missingModel;
}
if(model == missingModel) {
// to correctly emulate the original map, we return null for missing models
permanentOverrides.put((ResourceLocation) o, null);
return null;
} else
return model;
// to correctly emulate the original map, we return null for missing models, unless they are top-level
model = isVanillaTopLevelModel((ResourceLocation)o) ? model : null;
permanentOverrides.put((ResourceLocation) o, model);
}
return model;
}
}

Expand Down

0 comments on commit 371e511

Please sign in to comment.