Skip to content

Commit a913953

Browse files
committed
fix: move recipe reloading into seperate injector
this ensures the check to reload recipes is run when loading an existing seedqueue entry (cherry picked from commit f7135c71906de45c37f6ae8751de928ac5bb7752)
1 parent 8522834 commit a913953

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

src/main/java/me/wurgo/antiresourcereload/mixin/MinecraftClientMixin.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.wurgo.antiresourcereload.mixin;
22

3+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
34
import com.llamalad7.mixinextras.injector.WrapWithCondition;
45
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
56
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
@@ -12,9 +13,7 @@
1213
import net.minecraft.tag.EntityTypeTags;
1314
import net.minecraft.tag.FluidTags;
1415
import net.minecraft.tag.ItemTags;
15-
import net.minecraft.util.profiler.Profiler;
1616
import org.spongepowered.asm.mixin.Mixin;
17-
import org.spongepowered.asm.mixin.Shadow;
1817
import org.spongepowered.asm.mixin.injection.At;
1918

2019
import java.util.List;
@@ -26,31 +25,21 @@
2625
@Mixin(MinecraftClient.class)
2726
public 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

Comments
 (0)