From b8a025330fbd796dd120c9ce9e662b5169d24d5d Mon Sep 17 00:00:00 2001 From: mezz Date: Fri, 4 Oct 2024 16:49:57 +0900 Subject: [PATCH] Fix #3795 Prevent retaining the player client when crossing dimensions --- .../java/mezz/jei/common/util/TagUtil.java | 3 +-- .../mezz/jei/gui/recipes/IRecipeGuiLogic.java | 2 +- .../mezz/jei/gui/recipes/RecipeGuiLogic.java | 11 ++++++++--- .../java/mezz/jei/gui/recipes/RecipesGui.java | 4 ++-- .../recipes/layouts/IRecipeLayoutList.java | 2 +- .../recipes/layouts/LazyRecipeLayoutList.java | 19 +++++++++++-------- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/Common/src/main/java/mezz/jei/common/util/TagUtil.java b/Common/src/main/java/mezz/jei/common/util/TagUtil.java index f0170998a..a6a058352 100644 --- a/Common/src/main/java/mezz/jei/common/util/TagUtil.java +++ b/Common/src/main/java/mezz/jei/common/util/TagUtil.java @@ -15,8 +15,7 @@ public class TagUtil { public static Optional> getTagEquivalent( Collection stacks, Function stackToValue, - Supplier, - HolderSet.Named>>> tagSupplier + Supplier, HolderSet.Named>>> tagSupplier ) { List values = stacks.stream() .map(stackToValue) diff --git a/Gui/src/main/java/mezz/jei/gui/recipes/IRecipeGuiLogic.java b/Gui/src/main/java/mezz/jei/gui/recipes/IRecipeGuiLogic.java index 4dcf86f7a..680122a4c 100644 --- a/Gui/src/main/java/mezz/jei/gui/recipes/IRecipeGuiLogic.java +++ b/Gui/src/main/java/mezz/jei/gui/recipes/IRecipeGuiLogic.java @@ -37,7 +37,7 @@ public interface IRecipeGuiLogic { void nextPage(); - void tick(); + void tick(@Nullable AbstractContainerMenu container); boolean showFocus(IFocusGroup focuses); diff --git a/Gui/src/main/java/mezz/jei/gui/recipes/RecipeGuiLogic.java b/Gui/src/main/java/mezz/jei/gui/recipes/RecipeGuiLogic.java index dc0f6480d..2f0702540 100644 --- a/Gui/src/main/java/mezz/jei/gui/recipes/RecipeGuiLogic.java +++ b/Gui/src/main/java/mezz/jei/gui/recipes/RecipeGuiLogic.java @@ -40,6 +40,7 @@ public class RecipeGuiLogic implements IRecipeGuiLogic { private final IFocusFactory focusFactory; private @Nullable IRecipeCategory cachedRecipeCategory; private @Nullable IRecipeLayoutList cachedRecipeLayoutsWithButtons; + private int cachedContainerId = -1; private Set cachedSorterStages = Set.of(); public RecipeGuiLogic( @@ -64,9 +65,9 @@ public RecipeGuiLogic( } @Override - public void tick() { + public void tick(@Nullable AbstractContainerMenu container) { if (cachedRecipeLayoutsWithButtons != null) { - cachedRecipeLayoutsWithButtons.tick(); + cachedRecipeLayoutsWithButtons.tick(container); } } @@ -121,6 +122,7 @@ private boolean setState(ILookupState state, boolean saveHistory) { this.initialState = false; this.cachedRecipeCategory = null; this.cachedRecipeLayoutsWithButtons = null; + this.cachedContainerId = -1; stateListener.onStateChange(); return true; } @@ -204,9 +206,11 @@ public List> getVisibleRecipeLayoutsWithButtons( IClientConfig clientConfig = jeiClientConfigs.getClientConfig(); Set recipeSorterStages = clientConfig.getRecipeSorterStages(); + int containerId = container == null ? -1 : container.containerId; if (!recipeSorterStages.equals(cachedSorterStages) || this.cachedRecipeLayoutsWithButtons == null || - this.cachedRecipeCategory != recipeCategory + this.cachedRecipeCategory != recipeCategory || + this.cachedContainerId != containerId ) { IFocusedRecipes focusedRecipes = this.state.getFocusedRecipes(); @@ -221,6 +225,7 @@ public List> getVisibleRecipeLayoutsWithButtons( ); this.cachedRecipeCategory = recipeCategory; this.cachedSorterStages = Set.copyOf(recipeSorterStages); + this.cachedContainerId = containerId; } final int recipeHeight = diff --git a/Gui/src/main/java/mezz/jei/gui/recipes/RecipesGui.java b/Gui/src/main/java/mezz/jei/gui/recipes/RecipesGui.java index 1d4c72e11..c4c6b19c8 100644 --- a/Gui/src/main/java/mezz/jei/gui/recipes/RecipesGui.java +++ b/Gui/src/main/java/mezz/jei/gui/recipes/RecipesGui.java @@ -351,7 +351,7 @@ public void tick() { this.optionButtons.tick(); - this.logic.tick(); + this.logic.tick(container); } @Override @@ -554,7 +554,7 @@ private ImmutableRect2i getRecipeLayoutsArea() { } @Nullable - private AbstractContainerMenu getParentContainerMenu() { + public AbstractContainerMenu getParentContainerMenu() { Screen screen; if (parentScreen == null) { screen = Minecraft.getInstance().screen; diff --git a/Gui/src/main/java/mezz/jei/gui/recipes/layouts/IRecipeLayoutList.java b/Gui/src/main/java/mezz/jei/gui/recipes/layouts/IRecipeLayoutList.java index d1891a97c..f5d9dec27 100644 --- a/Gui/src/main/java/mezz/jei/gui/recipes/layouts/IRecipeLayoutList.java +++ b/Gui/src/main/java/mezz/jei/gui/recipes/layouts/IRecipeLayoutList.java @@ -41,5 +41,5 @@ static IRecipeLayoutList create( Optional> findFirst(); - void tick(); + void tick(@Nullable AbstractContainerMenu container); } diff --git a/Gui/src/main/java/mezz/jei/gui/recipes/layouts/LazyRecipeLayoutList.java b/Gui/src/main/java/mezz/jei/gui/recipes/layouts/LazyRecipeLayoutList.java index b81324884..643318517 100644 --- a/Gui/src/main/java/mezz/jei/gui/recipes/layouts/LazyRecipeLayoutList.java +++ b/Gui/src/main/java/mezz/jei/gui/recipes/layouts/LazyRecipeLayoutList.java @@ -30,7 +30,6 @@ import java.util.Set; public class LazyRecipeLayoutList implements IRecipeLayoutList { - private final @Nullable AbstractContainerMenu container; private final IRecipeManager recipeManager; private final IRecipeCategory recipeCategory; private final RecipesGui recipesGui; @@ -55,7 +54,6 @@ public LazyRecipeLayoutList( this.bookmarkList = bookmarkList; boolean matchingBookmarks = recipeSorterStages.contains(RecipeSorterStage.BOOKMARKED); boolean matchingCraftable = recipeSorterStages.contains(RecipeSorterStage.CRAFTABLE); - this.container = container; this.recipeManager = recipeManager; this.recipesGui = recipesGui; this.focusGroup = focusGroup; @@ -112,7 +110,11 @@ private IRecipeLayoutDrawable createRecipeLayout(T recipe) { return recipeManager.createRecipeLayoutDrawableOrShowError(recipeCategory, recipe, focusGroup); } - private RecipeLayoutWithButtons createRecipeLayoutWithButtons(IRecipeLayoutDrawable recipeLayoutDrawable, IIngredientManager ingredientManager) { + private RecipeLayoutWithButtons createRecipeLayoutWithButtons( + IRecipeLayoutDrawable recipeLayoutDrawable, + IIngredientManager ingredientManager, + @Nullable AbstractContainerMenu container + ) { RecipeBookmark recipeBookmark = RecipeBookmark.create(recipeLayoutDrawable, ingredientManager); return createRecipeLayoutWithButtons(recipeLayoutDrawable, recipeBookmark, bookmarkList, recipesGui, container); } @@ -129,8 +131,9 @@ public List> subList(int from, int to) { } private void ensureResults(int index) { + AbstractContainerMenu container = recipesGui.getParentContainerMenu(); while (index >= results.size()) { - if (!calculateNextResult()) { + if (!calculateNextResult(container)) { return; } } @@ -146,18 +149,18 @@ public Optional> findFirst() { } @Override - public void tick() { - calculateNextResult(); + public void tick(@Nullable AbstractContainerMenu container) { + calculateNextResult(container); } - private boolean calculateNextResult() { + private boolean calculateNextResult(@Nullable AbstractContainerMenu container) { IJeiRuntime jeiRuntime = Internal.getJeiRuntime(); IIngredientManager ingredientManager = jeiRuntime.getIngredientManager(); while (unsortedIterator.hasNext()) { T recipe = unsortedIterator.next(); IRecipeLayoutDrawable recipeLayout = createRecipeLayout(recipe); - RecipeLayoutWithButtons recipeLayoutWithButtons = createRecipeLayoutWithButtons(recipeLayout, ingredientManager); + RecipeLayoutWithButtons recipeLayoutWithButtons = createRecipeLayoutWithButtons(recipeLayout, ingredientManager, container); RecipeTransferButton transferButton = recipeLayoutWithButtons.transferButton(); if (matchingCraftable) {