Skip to content

Commit 74eb8a0

Browse files
committed
Split unbaked model load event into load and pre-bake stages
Allows mods like Continuity to wrap the model being baked separately from the model in the cache
1 parent be4c860 commit 74eb8a0

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

common/src/main/java/org/embeddedt/modernfix/api/entrypoint/ModernFixClientIntegration.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ default UnbakedModel onUnbakedModelLoad(ResourceLocation location, UnbakedModel
3434
return originalModel;
3535
}
3636

37+
/**
38+
* Called to allow mods to observe the use of an unbaked model at bake time and either make changes to it or wrap it with their
39+
* own instance.
40+
* @param location the ResourceLocation of the model (this may be a ModelResourceLocation)
41+
* @param originalModel the original model
42+
* @param bakery the model bakery - do not touch internal fields as they probably don't behave the way you expect
43+
* with dynamic resources on
44+
* @return the model which should actually be loaded for this resource location
45+
*/
46+
default UnbakedModel onUnbakedModelPreBake(ResourceLocation location, UnbakedModel originalModel, ModelBakery bakery) {
47+
return originalModel;
48+
}
49+
3750
/**
3851
* Called to allow mods to observe the loading of a baked model and either make changes to it or wrap it with their
3952
* own instance.

fabric/src/main/java/org/embeddedt/modernfix/fabric/mixin/perf/dynamic_resources/ModelBakeryMixin.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,17 @@ public void getOrLoadBakedModelDynamic(ResourceLocation arg, ModelState arg2, Ca
448448

449449
if(iunbakedmodel == missingModel && debugDynamicModelLoading)
450450
LOGGER.warn("Model {} not present", arg);
451+
452+
if(iunbakedmodel != missingModel) {
453+
for(ModernFixClientIntegration integration : ModernFixClient.CLIENT_INTEGRATIONS) {
454+
try {
455+
iunbakedmodel = integration.onUnbakedModelPreBake(arg, iunbakedmodel, (ModelBakery)(Object)this);
456+
} catch(RuntimeException e) {
457+
ModernFix.LOGGER.error("Exception firing model pre-bake event for {}", arg, e);
458+
}
459+
}
460+
}
461+
451462
BakedModel ibakedmodel = null;
452463
if (iunbakedmodel instanceof BlockModel) {
453464
BlockModel blockmodel = (BlockModel)iunbakedmodel;

forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ModelBakeryMixin.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,17 @@ public void getOrLoadBakedModelDynamic(ResourceLocation arg, ModelState arg2, Fu
322322
iunbakedmodel.getMaterials(this::getModel, new HashSet<>());
323323
if(iunbakedmodel == missingModel && debugDynamicModelLoading)
324324
LOGGER.warn("Model {} not present", arg);
325+
326+
if(iunbakedmodel != missingModel) {
327+
for(ModernFixClientIntegration integration : ModernFixClient.CLIENT_INTEGRATIONS) {
328+
try {
329+
iunbakedmodel = integration.onUnbakedModelPreBake(arg, iunbakedmodel, (ModelBakery)(Object)this);
330+
} catch(RuntimeException e) {
331+
ModernFix.LOGGER.error("Exception encountered firing bake event for {}", arg, e);
332+
}
333+
}
334+
}
335+
325336
BakedModel ibakedmodel = null;
326337
if (iunbakedmodel instanceof BlockModel) {
327338
BlockModel blockmodel = (BlockModel)iunbakedmodel;

0 commit comments

Comments
 (0)