11package me .wurgo .antiresourcereload .mixin ;
22
3+ import com .llamalad7 .mixinextras .injector .ModifyExpressionValue ;
34import com .llamalad7 .mixinextras .injector .WrapWithCondition ;
45import com .llamalad7 .mixinextras .injector .wrapoperation .Operation ;
56import com .llamalad7 .mixinextras .injector .wrapoperation .WrapOperation ;
1213import net .minecraft .tag .EntityTypeTags ;
1314import net .minecraft .tag .FluidTags ;
1415import net .minecraft .tag .ItemTags ;
15- import net .minecraft .util .profiler .Profiler ;
1616import org .spongepowered .asm .mixin .Mixin ;
17- import org .spongepowered .asm .mixin .Shadow ;
1817import org .spongepowered .asm .mixin .injection .At ;
1918
2019import java .util .List ;
2625@ Mixin (MinecraftClient .class )
2726public abstract class MinecraftClientMixin {
2827
29- @ Shadow
30- private Profiler profiler ;
31-
3228 @ WrapOperation (
3329 method = "createIntegratedResourceManager" ,
3430 at = @ At (
3531 value = "INVOKE" ,
3632 target = "Lnet/minecraft/resource/ServerResourceManager;reload(Ljava/util/List;Lnet/minecraft/server/command/CommandManager$RegistrationEnvironment;ILjava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"
3733 )
3834 )
39- private CompletableFuture <ServerResourceManager > cachedReload (List <ResourcePack > dataPacks , CommandManager .RegistrationEnvironment registrationEnvironment , int i , Executor executor , Executor executor2 , Operation <CompletableFuture <ServerResourceManager >> original , @ Local ResourcePackManager <ResourcePackProfile > resourcePackManager ) throws ExecutionException , InterruptedException {
35+ private CompletableFuture <ServerResourceManager > cachedReload (List <ResourcePack > dataPacks , CommandManager .RegistrationEnvironment registrationEnvironment , int i , Executor executor , Executor executor2 , Operation <CompletableFuture <ServerResourceManager >> original , @ Local ResourcePackManager <ResourcePackProfile > resourcePackManager ) {
4036 boolean usingDataPacks = !resourcePackManager .getEnabledProfiles ().stream ().map (ResourcePackProfile ::getName ).collect (Collectors .toList ()).equals (DataPackSettings .SAFE_MODE .getEnabled ());
4137 if (usingDataPacks ) {
4238 AntiResourceReload .log ("Using data-packs, reloading." );
4339 } else if (AntiResourceReload .cache == null ) {
4440 AntiResourceReload .log ("Cached resources unavailable, reloading & caching." );
4541 } else {
4642 AntiResourceReload .log ("Using cached server resources." );
47- // only reload recipes on the main thread
48- // this is for compat with seedqueue creating servers in the background
49- if (MinecraftClient .getInstance ().isOnThread () && AntiResourceReload .hasSeenRecipes ) {
50- ServerResourceManager manager = AntiResourceReload .cache .get ();
51- ((RecipeManagerAccess ) manager .getRecipeManager ()).invokeApply (AntiResourceReload .recipes , manager .getResourceManager (), this .profiler );
52- AntiResourceReload .hasSeenRecipes = false ;
53- }
5443 return AntiResourceReload .cache ;
5544 }
5645
@@ -62,6 +51,24 @@ private CompletableFuture<ServerResourceManager> cachedReload(List<ResourcePack>
6251 return reloaded ;
6352 }
6453
54+ @ ModifyExpressionValue (
55+ method = "startIntegratedServer(Ljava/lang/String;Lnet/minecraft/util/registry/RegistryTracker$Modifiable;Ljava/util/function/Function;Lcom/mojang/datafixers/util/Function4;ZLnet/minecraft/client/MinecraftClient$WorldLoadAction;)V" ,
56+ at = @ At (
57+ value = "INVOKE" ,
58+ target = "Lnet/minecraft/client/MinecraftClient;createIntegratedResourceManager(Lnet/minecraft/util/registry/RegistryTracker$Modifiable;Ljava/util/function/Function;Lcom/mojang/datafixers/util/Function4;ZLnet/minecraft/world/level/storage/LevelStorage$Session;)Lnet/minecraft/client/MinecraftClient$IntegratedResourceManager;"
59+ )
60+ )
61+ private MinecraftClient .IntegratedResourceManager reloadRecipes (MinecraftClient .IntegratedResourceManager integratedResourceManager ) throws ExecutionException , InterruptedException {
62+ ServerResourceManager manager ;
63+ // only reload recipes on the main thread
64+ // this is for compat with seedqueue creating servers in the background
65+ if (MinecraftClient .getInstance ().isOnThread () && AntiResourceReload .hasSeenRecipes && AntiResourceReload .cache != null && (manager = AntiResourceReload .cache .get ()) == integratedResourceManager .getServerResourceManager ()) {
66+ ((RecipeManagerAccess ) manager .getRecipeManager ()).invokeApply (AntiResourceReload .recipes , manager .getResourceManager (), MinecraftClient .getInstance ().getProfiler ());
67+ AntiResourceReload .hasSeenRecipes = false ;
68+ }
69+ return integratedResourceManager ;
70+ }
71+
6572 @ WrapWithCondition (
6673 method = "startIntegratedServer(Ljava/lang/String;Lnet/minecraft/util/registry/RegistryTracker$Modifiable;Ljava/util/function/Function;Lcom/mojang/datafixers/util/Function4;ZLnet/minecraft/client/MinecraftClient$WorldLoadAction;)V" ,
6774 at = @ At (
0 commit comments