From ea03cfa17d930332bb8dcf74ec3fb2aeca0d4b64 Mon Sep 17 00:00:00 2001 From: slprime <31038811+slprime@users.noreply.github.com> Date: Fri, 1 Mar 2024 20:36:15 +0200 Subject: [PATCH] Correctly find the recipeId under mouse when using the search (#465) * Correctly find the recipeId under mouse when using the search * optimize --------- Co-authored-by: slprime --- .../java/codechicken/nei/BookmarkPanel.java | 2 +- .../codechicken/nei/ItemHistoryPanel.java | 3 +-- .../codechicken/nei/recipe/GuiRecipe.java | 19 ++++++++++++------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/codechicken/nei/BookmarkPanel.java b/src/main/java/codechicken/nei/BookmarkPanel.java index 0ab98d07..4dd81efe 100644 --- a/src/main/java/codechicken/nei/BookmarkPanel.java +++ b/src/main/java/codechicken/nei/BookmarkPanel.java @@ -1631,7 +1631,7 @@ public class BookmarkPanel extends PanelWidget { itemStr); } - } catch (IllegalArgumentException | JsonSyntaxException e) { + } catch (IllegalArgumentException | JsonSyntaxException | IllegalStateException e) { NEIClientConfig.logger.error("Failed to load bookmarked ItemStack from json string:\n{}", itemStr); } } diff --git a/src/main/java/codechicken/nei/ItemHistoryPanel.java b/src/main/java/codechicken/nei/ItemHistoryPanel.java index 969e0517..993d653b 100644 --- a/src/main/java/codechicken/nei/ItemHistoryPanel.java +++ b/src/main/java/codechicken/nei/ItemHistoryPanel.java @@ -39,8 +39,7 @@ public class ItemHistoryPanel extends Widget { public void addItem(ItemStack stack) { if (stack != null) { - ItemStack is = stack.copy(); - is.stackSize = 1; + ItemStack is = StackInfo.loadFromNBT(StackInfo.itemStackToNBT(stack), 0); grid.realItems.removeIf(historyStack -> StackInfo.equalItemAndNBT(historyStack, stack, true)); grid.realItems.add(0, is); diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index 71a0839f..b5d0d2c7 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -543,9 +543,11 @@ public abstract class GuiRecipe extends GuiContainer i } public List getFocusedRecipeIngredients() { + List indices = getRecipeIndices(); - for (int recipeIndex : getRecipeIndices()) { - if (recipeInFocus(recipeIndex)) { + for (int refIndex = 0; refIndex < indices.size(); refIndex++) { + final int recipeIndex = indices.get(refIndex); + if (recipeInFocus(refIndex, recipeIndex)) { return handler.original.getIngredientStacks(recipeIndex); } } @@ -554,9 +556,11 @@ public abstract class GuiRecipe extends GuiContainer i } public int prepareFocusedRecipeResultStackSize(ItemStack stackover) { + List indices = getRecipeIndices(); - for (int recipeIndex : getRecipeIndices()) { - if (recipeInFocus(recipeIndex)) { + for (int refIndex = 0; refIndex < indices.size(); refIndex++) { + final int recipeIndex = indices.get(refIndex); + if (recipeInFocus(refIndex, recipeIndex)) { final PositionedStack result = handler.original.getResultStack(recipeIndex); int stackSize = 0; @@ -578,15 +582,16 @@ public abstract class GuiRecipe extends GuiContainer i return stackover.stackSize; } - protected boolean recipeInFocus(int recipeIndex) { + protected boolean recipeInFocus(int refIndex, int recipeIndex) { final PositionedStack result = handler.original.getResultStack(recipeIndex); - if (result != null && isMouseOver(result, recipeIndex)) { + + if (result != null && isMouseOver(result, refIndex)) { return true; } final List stacks = handler.original.getOtherStacks(recipeIndex); for (PositionedStack stack : stacks) { - if (isMouseOver(stack, recipeIndex)) { + if (isMouseOver(stack, refIndex)) { return true; } }