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
This commit is contained in:
embeddedt 2023-05-23 18:50:49 -04:00
parent be4c8607d4
commit 74eb8a0619
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 35 additions and 0 deletions

View File

@ -34,6 +34,19 @@ public interface ModernFixClientIntegration {
return originalModel;
}
/**
* 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
* own instance.
* @param location the ResourceLocation of the model (this may be a ModelResourceLocation)
* @param originalModel the original model
* @param bakery the model bakery - do not touch internal fields as they probably don't behave the way you expect
* with dynamic resources on
* @return the model which should actually be loaded for this resource location
*/
default UnbakedModel onUnbakedModelPreBake(ResourceLocation location, UnbakedModel originalModel, ModelBakery bakery) {
return originalModel;
}
/**
* Called to allow mods to observe the loading of a baked model and either make changes to it or wrap it with their
* own instance.

View File

@ -448,6 +448,17 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
if(iunbakedmodel == missingModel && debugDynamicModelLoading)
LOGGER.warn("Model {} not present", arg);
if(iunbakedmodel != missingModel) {
for(ModernFixClientIntegration integration : ModernFixClient.CLIENT_INTEGRATIONS) {
try {
iunbakedmodel = integration.onUnbakedModelPreBake(arg, iunbakedmodel, (ModelBakery)(Object)this);
} catch(RuntimeException e) {
ModernFix.LOGGER.error("Exception firing model pre-bake event for {}", arg, e);
}
}
}
BakedModel ibakedmodel = null;
if (iunbakedmodel instanceof BlockModel) {
BlockModel blockmodel = (BlockModel)iunbakedmodel;

View File

@ -322,6 +322,17 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
iunbakedmodel.getMaterials(this::getModel, new HashSet<>());
if(iunbakedmodel == missingModel && debugDynamicModelLoading)
LOGGER.warn("Model {} not present", arg);
if(iunbakedmodel != missingModel) {
for(ModernFixClientIntegration integration : ModernFixClient.CLIENT_INTEGRATIONS) {
try {
iunbakedmodel = integration.onUnbakedModelPreBake(arg, iunbakedmodel, (ModelBakery)(Object)this);
} catch(RuntimeException e) {
ModernFix.LOGGER.error("Exception encountered firing bake event for {}", arg, e);
}
}
}
BakedModel ibakedmodel = null;
if (iunbakedmodel instanceof BlockModel) {
BlockModel blockmodel = (BlockModel)iunbakedmodel;