diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ModelDiscoveryMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ModelDiscoveryMixin.java new file mode 100644 index 00000000..e3ae9523 --- /dev/null +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ModelDiscoveryMixin.java @@ -0,0 +1,22 @@ +package org.embeddedt.modernfix.common.mixin.perf.dynamic_resources; + +import net.minecraft.client.resources.model.ModelDiscovery; +import org.embeddedt.modernfix.annotation.ClientOnlyMixin; +import org.slf4j.Logger; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ModelDiscovery.class) +@ClientOnlyMixin +public class ModelDiscoveryMixin { + /** + * @author embeddedt + * @reason We will show the warning ourselves later when loading the model dynamically, this is just spam since + * the models don't exist during early loading + */ + @Redirect(method = "loadBlockModel", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;warn(Ljava/lang/String;Ljava/lang/Object;)V")) + private void disableMissingModelWarning(Logger instance, String s, Object o) { + + } +} diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ModelManagerMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ModelManagerMixin.java index 7a2bcaea..4e8dbf9f 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ModelManagerMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ModelManagerMixin.java @@ -10,6 +10,7 @@ import net.minecraft.client.renderer.item.ItemModel; import net.minecraft.client.resources.model.AtlasSet; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.BlockStateModelLoader; +import net.minecraft.client.resources.model.ClientItemInfoLoader; import net.minecraft.client.resources.model.ModelManager; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.client.resources.model.UnbakedModel; @@ -58,6 +59,11 @@ public class ModelManagerMixin implements DynamicModelProvider.ModelManagerExten return Map.of(); } + @Redirect(method = "reload", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/ClientItemInfoLoader;scheduleLoad(Lnet/minecraft/server/packs/resources/ResourceManager;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;")) + private CompletableFuture disableClientItemEarlyLoad(ResourceManager resourceManager, Executor executor) { + return CompletableFuture.completedFuture(new ClientItemInfoLoader.LoadedClientInfos(Map.of())); + } + @ModifyArg(method = "reload", at = @At(value = "INVOKE", target = "Ljava/util/concurrent/CompletableFuture;allOf([Ljava/util/concurrent/CompletableFuture;)Ljava/util/concurrent/CompletableFuture;", ordinal = 1)) private CompletableFuture[] createModelProvider(CompletableFuture[] cfs, @Local(ordinal = 0) CompletableFuture entityModelFuture, @Local(ordinal = 0, argsOnly = true) Executor executor, @Local(ordinal = 0) Map> atlasPreparations) { CompletableFuture makeModelProviderFuture = CompletableFuture.supplyAsync(() -> { diff --git a/common/src/main/java/org/embeddedt/modernfix/dynamicresources/DynamicModelProvider.java b/common/src/main/java/org/embeddedt/modernfix/dynamicresources/DynamicModelProvider.java index 57f4639c..3c5eb68f 100644 --- a/common/src/main/java/org/embeddedt/modernfix/dynamicresources/DynamicModelProvider.java +++ b/common/src/main/java/org/embeddedt/modernfix/dynamicresources/DynamicModelProvider.java @@ -98,6 +98,8 @@ public class DynamicModelProvider { private final Map itemStackModelOverrides = new ConcurrentHashMap<>(); private final Map standaloneModelOverrides = new ConcurrentHashMap<>(); + private static final boolean DEBUG_DYNAMIC_MODEL_LOADING = Boolean.getBoolean("modernfix.debugDynamicModelLoading"); + public DynamicModelProvider(ResourceManager resourceManager, EntityModelSet entityModelSet, Map atlasMap) { this.unbakedMissingModel = MissingBlockModel.missingModel(); @@ -313,6 +315,9 @@ public class DynamicModelProvider { if(stateDefinition == null) { return Optional.empty(); } + if (DEBUG_DYNAMIC_MODEL_LOADING) { + ModernFix.LOGGER.info("Loading blockstate definition '{}'", location); + } List resources = resourceManager.getResourceStack(ResourceLocation.fromNamespaceAndPath(location.getNamespace(), "blockstates/" + location.getPath() + ".json")); List loadedDefinitions = new ArrayList<>(resources.size()); for(Resource resource : resources) { @@ -328,6 +333,9 @@ public class DynamicModelProvider { } private BakedModel bakeModel(UnbakedModel model, ModelDebugName name) { + if (DEBUG_DYNAMIC_MODEL_LOADING) { + ModernFix.LOGGER.info("Baking model '{}'", name.get()); + } synchronized (this) { this.resolver.clearResolver(); model.resolveDependencies(this.resolver); @@ -337,6 +345,9 @@ public class DynamicModelProvider { } private BakedModel bakeModel(UnbakedBlockStateModel model, ModelDebugName name) { + if (DEBUG_DYNAMIC_MODEL_LOADING) { + ModernFix.LOGGER.info("Baking model '{}'", name.get()); + } synchronized (this) { this.resolver.clearResolver(); model.resolveDependencies(this.resolver); @@ -379,6 +390,9 @@ public class DynamicModelProvider { } private Optional loadBlockModel(ResourceLocation location) { + if (DEBUG_DYNAMIC_MODEL_LOADING) { + ModernFix.LOGGER.info("Loading block model '{}'", location); + } if (location.equals(ItemModelGenerator.GENERATED_ITEM_MODEL_ID)) { return Optional.of(this.itemModelGenerator); } @@ -398,6 +412,9 @@ public class DynamicModelProvider { } private Optional loadClientItemProperties(ResourceLocation location) { + if (DEBUG_DYNAMIC_MODEL_LOADING) { + ModernFix.LOGGER.info("Loading client item '{}'", location); + } var resource = this.resourceManager.getResource(ResourceLocation.fromNamespaceAndPath(location.getNamespace(), "items/" + location.getPath() + ".json")); if(resource.isPresent()) { try(Reader reader = resource.get().openAsReader()) { @@ -414,6 +431,9 @@ public class DynamicModelProvider { } private Optional loadItemModel(ResourceLocation location) { + if (DEBUG_DYNAMIC_MODEL_LOADING) { + ModernFix.LOGGER.info("Loading item model '{}'", location); + } var override = this.itemStackModelOverrides.get(location); if (override != null) { return Optional.of(override);