99import net .minecraft .client .resources .model .ModelBakery ;
1010import net .minecraft .client .resources .model .ModelManager ;
1111import net .minecraft .resources .ResourceLocation ;
12+ import net .minecraft .server .packs .resources .Resource ;
1213import net .minecraft .server .packs .resources .ResourceManager ;
1314import net .minecraft .util .GsonHelper ;
1415import net .minecraft .util .profiling .ProfilerFiller ;
2728import org .spongepowered .asm .mixin .injection .At ;
2829import org .spongepowered .asm .mixin .injection .Coerce ;
2930import org .spongepowered .asm .mixin .injection .Inject ;
31+ import org .spongepowered .asm .mixin .injection .ModifyArg ;
3032import org .spongepowered .asm .mixin .injection .Redirect ;
3133import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
3234import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
3840import java .util .Map ;
3941import java .util .Objects ;
4042import java .util .concurrent .CompletableFuture ;
43+ import java .util .concurrent .CompletionStage ;
4144import java .util .concurrent .Executor ;
45+ import java .util .function .Function ;
4246import 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