From ff4ecce22b2aeee0e43e4ad969b97a031eb98fcc Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Thu, 2 Jan 2025 14:41:56 +0000 Subject: [PATCH] fix: fix threading issue for JEI loot crate integration --- .../ftbquests/jei/LootCrateRecipeManagerPlugin.java | 9 +++++++-- .../recipemod_common/WrappedLootCrateCache.java | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/dev/ftb/mods/ftbxmodcompat/ftbquests/jei/LootCrateRecipeManagerPlugin.java b/common/src/main/java/dev/ftb/mods/ftbxmodcompat/ftbquests/jei/LootCrateRecipeManagerPlugin.java index 2b60446..a04052c 100644 --- a/common/src/main/java/dev/ftb/mods/ftbxmodcompat/ftbquests/jei/LootCrateRecipeManagerPlugin.java +++ b/common/src/main/java/dev/ftb/mods/ftbxmodcompat/ftbquests/jei/LootCrateRecipeManagerPlugin.java @@ -9,6 +9,7 @@ import mezz.jei.api.recipe.RecipeType; import mezz.jei.api.recipe.advanced.IRecipeManagerPlugin; import mezz.jei.api.recipe.category.IRecipeCategory; +import net.minecraft.client.Minecraft; import net.minecraft.world.item.ItemStack; import java.util.List; @@ -19,12 +20,16 @@ public enum LootCrateRecipeManagerPlugin implements IRecipeManagerPlugin { private final WrappedLootCrateCache cache = new WrappedLootCrateCache( crates -> { if (FTBQuestsJEIIntegration.runtime != null && !crates.isEmpty()) { - FTBQuestsJEIIntegration.runtime.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, crates); + Minecraft.getInstance().tell(() -> + FTBQuestsJEIIntegration.runtime.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, crates) + ); } }, crates -> { if (FTBQuestsJEIIntegration.runtime != null && !crates.isEmpty()) { - FTBQuestsJEIIntegration.runtime.getIngredientManager().addIngredientsAtRuntime(VanillaTypes.ITEM_STACK, crates); + Minecraft.getInstance().tell(() -> + FTBQuestsJEIIntegration.runtime.getIngredientManager().addIngredientsAtRuntime(VanillaTypes.ITEM_STACK, crates) + ); } } ); diff --git a/common/src/main/java/dev/ftb/mods/ftbxmodcompat/ftbquests/recipemod_common/WrappedLootCrateCache.java b/common/src/main/java/dev/ftb/mods/ftbxmodcompat/ftbquests/recipemod_common/WrappedLootCrateCache.java index 2c61959..869c295 100644 --- a/common/src/main/java/dev/ftb/mods/ftbxmodcompat/ftbquests/recipemod_common/WrappedLootCrateCache.java +++ b/common/src/main/java/dev/ftb/mods/ftbxmodcompat/ftbquests/recipemod_common/WrappedLootCrateCache.java @@ -34,7 +34,7 @@ public List getWrappedLootCrates() { } private void rebuildWrappedLootCrateCache() { - preRebuild.accept(crateStacks); + preRebuild.accept(List.copyOf(crateStacks)); wrappedLootCratesCache.clear(); crateStacks.clear(); @@ -49,7 +49,7 @@ private void rebuildWrappedLootCrateCache() { } } - postRebuild.accept(crateStacks); + postRebuild.accept(List.copyOf(crateStacks)); } public void refresh() {