Skip to content

Commit eadb19d

Browse files
committed
Allow Model Loading API to inject and load extra models
1 parent ce7b7cb commit eadb19d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ private void replaceTopLevelBakedModels(ModelBakery bakery, BlockColors val) {
8787
// we can handle recursion in getModel without issues
8888
fabric_enableGetOrLoadModelGuard = false;
8989
this.blockColors = val;
90-
this.ignoreModelLoad = true;
9190
this.loadedBakedModels = CacheBuilder.newBuilder()
9291
.expireAfterAccess(ModelBakeryHelpers.MAX_MODEL_LIFETIME_SECS, TimeUnit.SECONDS)
9392
.maximumSize(ModelBakeryHelpers.MAX_BAKED_MODEL_COUNT)
@@ -119,6 +118,11 @@ public UnbakedModel put(ResourceLocation key, UnbakedModel value) {
119118
this.bakedTopLevelModels = new DynamicBakedModelProvider((ModelBakery)(Object)this, bakedCache);
120119
}
121120

121+
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", ordinal = 0))
122+
private void ignoreFutureModelLoads(CallbackInfo ci) {
123+
this.ignoreModelLoad = true;
124+
}
125+
122126
private <K, V> void onModelRemoved(RemovalNotification<K, V> notification) {
123127
if(!debugDynamicModelLoading)
124128
return;
@@ -193,7 +197,10 @@ private void captureGetter(BiFunction<ResourceLocation, Material, TextureAtlasSp
193197

194198
@Redirect(method = "bakeModels", at = @At(value = "INVOKE", target = "Ljava/util/Map;keySet()Ljava/util/Set;"))
195199
private Set<ResourceLocation> skipBake(Map<ResourceLocation, UnbakedModel> instance) {
196-
return Collections.emptySet();
200+
Set<ResourceLocation> modelSet = new HashSet<>(instance.keySet());
201+
if(modelSet.size() > 0)
202+
ModernFix.LOGGER.info("Early baking {} models", modelSet.size());
203+
return modelSet;
197204
}
198205

199206
/**

0 commit comments

Comments
 (0)