Skip to content

Commit ff6b687

Browse files
committed
Tweak ModelManager mixin to improve compat with some mods
Supplementaries injects into the lambda near the start of loadBlockModels. By adjusting this mixin to still run that lambda, we allow the Supplementaries hook to run while still avoiding the load of all block models
1 parent aaaa8ad commit ff6b687

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_resources/ModelManagerMixin.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.minecraft.client.resources.model.ModelBakery;
1010
import net.minecraft.client.resources.model.ModelManager;
1111
import net.minecraft.resources.ResourceLocation;
12+
import net.minecraft.server.packs.resources.Resource;
1213
import net.minecraft.server.packs.resources.ResourceManager;
1314
import net.minecraft.util.GsonHelper;
1415
import net.minecraft.util.profiling.ProfilerFiller;
@@ -27,6 +28,7 @@
2728
import org.spongepowered.asm.mixin.injection.At;
2829
import org.spongepowered.asm.mixin.injection.Coerce;
2930
import org.spongepowered.asm.mixin.injection.Inject;
31+
import org.spongepowered.asm.mixin.injection.ModifyArg;
3032
import org.spongepowered.asm.mixin.injection.Redirect;
3133
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3234
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@@ -38,7 +40,9 @@
3840
import java.util.Map;
3941
import java.util.Objects;
4042
import java.util.concurrent.CompletableFuture;
43+
import java.util.concurrent.CompletionStage;
4144
import java.util.concurrent.Executor;
45+
import java.util.function.Function;
4246
import java.util.stream.Collectors;
4347

4448
@Mixin(ModelManager.class)
@@ -56,10 +60,12 @@ private void injectDummyBakedRegistry(CallbackInfo ci) {
5660
}
5761
}
5862

59-
@Redirect(method = "reload", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/ModelManager;loadBlockModels(Lnet/minecraft/server/packs/resources/ResourceManager;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"))
60-
private CompletableFuture<Map<ResourceLocation, BlockModel>> deferBlockModelLoad(ResourceManager manager, Executor executor) {
61-
var cache = CacheUtil.<ResourceLocation, BlockModel>simpleCacheForLambda(location -> loadSingleBlockModel(manager, location), 100L);
62-
return CompletableFuture.completedFuture(new LambdaMap<>(location -> cache.getUnchecked(location)));
63+
@ModifyArg(method = "loadBlockModels", at = @At(value = "INVOKE", target = "Ljava/util/concurrent/CompletableFuture;thenCompose(Ljava/util/function/Function;)Ljava/util/concurrent/CompletableFuture;", ordinal = 0), index = 0)
64+
private static Function<Map<ResourceLocation, Resource>, ? extends CompletionStage<Map<ResourceLocation, BlockModel>>> deferBlockModelLoad(Function<Map<ResourceLocation, Resource>, ? extends CompletionStage<Map<ResourceLocation, BlockModel>>> fn, @Local(ordinal = 0, argsOnly = true) ResourceManager manager) {
65+
return resourceMap -> {
66+
var cache = CacheUtil.<ResourceLocation, BlockModel>simpleCacheForLambda(location -> loadSingleBlockModel(manager, location), 100L);
67+
return CompletableFuture.completedFuture(new LambdaMap<>(location -> cache.getUnchecked(location)));
68+
};
6369
}
6470

6571
@Redirect(method = "reload", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/ModelManager;loadBlockStates(Lnet/minecraft/server/packs/resources/ResourceManager;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"))
@@ -73,7 +79,7 @@ private ImmutableList<BlockState> skipCollection(StateDefinition<Block, BlockSta
7379
return ImmutableList.of();
7480
}
7581

76-
private BlockModel loadSingleBlockModel(ResourceManager manager, ResourceLocation location) {
82+
private static BlockModel loadSingleBlockModel(ResourceManager manager, ResourceLocation location) {
7783
return manager.getResource(location).map(resource -> {
7884
try (BufferedReader reader = resource.openAsReader()) {
7985
return BlockModel.fromStream(reader);

0 commit comments

Comments
 (0)