Skip to content

Commit

Permalink
Retrieve missing model when first required
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Feb 7, 2024
1 parent e0516eb commit e91220c
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ public DynamicBakedModelProvider(ModelBakery bakery, Map<ModelBakery.BakedCacheK
currentInstance = this;
}

public void setMissingModel(BakedModel model) {
this.missingModel = model;
this.put(ModelBakery.MISSING_MODEL_LOCATION, this.missingModel);
}

private static ModelBakery.BakedCacheKey vanillaKey(Object o) {
return new ModelBakery.BakedCacheKey((ResourceLocation)o, BlockModelRotation.X0_Y0.getRotation(), false);
}
Expand Down Expand Up @@ -140,6 +135,14 @@ private static boolean isVanillaTopLevelModel(ResourceLocation location) {
return false;
}

private BakedModel getMissingModel() {
BakedModel m = missingModel;
if(m == null) {
m = missingModel = ((IExtendedModelBakery)bakery).bakeDefault(ModelBakery.MISSING_MODEL_LOCATION, BlockModelRotation.X0_Y0);
}
return m;
}

@Override
public BakedModel get(Object o) {
BakedModel model = permanentOverrides.getOrDefault(o, SENTINEL);
Expand All @@ -148,14 +151,14 @@ public BakedModel get(Object o) {
else {
try {
if(BAKE_SKIPPED_TOPLEVEL.contains((ResourceLocation)o))
model = missingModel;
model = getMissingModel();
else
model = ((IExtendedModelBakery)bakery).bakeDefault((ResourceLocation)o, BlockModelRotation.X0_Y0);
} catch(RuntimeException e) {
ModernFix.LOGGER.error("Exception baking {}: {}", o, e);
model = missingModel;
model = getMissingModel();
}
if(model == missingModel) {
if(model == getMissingModel()) {
// 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);
Expand Down

0 comments on commit e91220c

Please sign in to comment.