Add API to skip blockstate/model scanning for specific models

This commit is contained in:
embeddedt 2023-08-10 22:43:45 -04:00
parent 8b698452fd
commit cb6ff1d68b
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,20 @@
package org.embeddedt.modernfix.fabric.api.dynresources;
import net.minecraft.resources.ResourceLocation;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
public class ModelScanController {
public static final List<Predicate<ResourceLocation>> SCAN_PREDICATES = new ArrayList<>();
public static boolean shouldScanAndTestWrapping(ResourceLocation location) {
if(SCAN_PREDICATES.size() > 0) {
for(Predicate<ResourceLocation> predicate : SCAN_PREDICATES) {
if(!predicate.test(location))
return false;
}
}
return true;
}
}

View File

@ -39,6 +39,7 @@ import org.embeddedt.modernfix.api.entrypoint.ModernFixClientIntegration;
import org.embeddedt.modernfix.duck.IExtendedModelBakery;
import org.embeddedt.modernfix.dynamicresources.DynamicBakedModelProvider;
import org.embeddedt.modernfix.dynamicresources.ModelBakeryHelpers;
import org.embeddedt.modernfix.fabric.api.dynresources.ModelScanController;
import org.embeddedt.modernfix.fabric.bridge.ModelV0Bridge;
import org.embeddedt.modernfix.util.LayeredForwardingMap;
import org.jetbrains.annotations.Nullable;
@ -174,6 +175,13 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
private boolean forceLoadModel = false;
@Inject(method = "loadTopLevel", at = @At("HEAD"), cancellable = true)
private void ignoreRejectedModel(ModelResourceLocation location, CallbackInfo ci) {
if(this.inTextureGatheringPass && !this.forceLoadModel && !ModelScanController.shouldScanAndTestWrapping(location)) {
ci.cancel();
}
}
@Inject(method = "loadModel", at = @At(value = "HEAD"), cancellable = true)
private void ignoreNonFabricModel(ResourceLocation modelLocation, CallbackInfo ci) throws Exception {
if(this.inTextureGatheringPass && !this.forceLoadModel && !this.injectedModels.contains(modelLocation)) {