From 4be7a3057838ad8175a6796326bac9e618338d5b Mon Sep 17 00:00:00 2001 From: slprime <31038811+slprime@users.noreply.github.com> Date: Sun, 22 Dec 2024 04:01:44 +0200 Subject: [PATCH] Fix Accept Folowing for custom recipe handlers (#570) Co-authored-by: slprime Co-authored-by: Martin Robertz --- .../codechicken/nei/recipe/GuiRecipe.java | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index da8428f97..498229a9d 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -29,6 +29,7 @@ import codechicken.lib.gui.GuiDraw; import codechicken.nei.Button; import codechicken.nei.GuiNEIButton; +import codechicken.nei.ItemStackSet; import codechicken.nei.ItemsTooltipLineHandler; import codechicken.nei.LayoutManager; import codechicken.nei.NEICPH; @@ -135,7 +136,13 @@ public static PermutationTooltipLineHandler getInstance(PositionedStack pStack) items = Arrays.asList(pStack.items); } - return new PermutationTooltipLineHandler(pStack, items); + items = new ItemStackSet().addAll(items).keys(); + + if (items.size() > 1) { + return new PermutationTooltipLineHandler(pStack, items); + } + + return null; } } @@ -869,41 +876,40 @@ && new Rectangle(searchField.x + searchField.w, 15, 44, 16) public List handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey, List currenttip) { - try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) { - List indices = getRecipeIndices(); + List indices = getRecipeIndices(); + try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) { for (int recipeIndex : indices) { currenttip = handler.original.handleItemTooltip(this, itemstack, currenttip, recipeIndex); } + } - if (NEIClientConfig.showCycledIngredientsTooltip()) { - PositionedStack focused = null; + if (NEIClientConfig.showCycledIngredientsTooltip()) { + PositionedStack focused = null; - for (int refIndex = 0; refIndex < indices.size(); refIndex++) { - final int recipeIndex = indices.get(refIndex); + for (int refIndex = 0; refIndex < indices.size(); refIndex++) { + final int recipeIndex = indices.get(refIndex); - if (itemstack != null && focused == null) { - final List stacks = handler.original.getIngredientStacks(recipeIndex); + if (itemstack != null && focused == null) { + final List stacks = handler.original.getIngredientStacks(recipeIndex); - for (PositionedStack pStack : stacks) { - if (isMouseOver(pStack, refIndex)) { - focused = pStack; - break; - } + for (PositionedStack pStack : stacks) { + if (isMouseOver(pStack, refIndex)) { + focused = pStack; + break; } } } - - if (focused == null || focused.items.length <= 1) { - this.permutationTooltipLineHandler = null; - } else if (this.permutationTooltipLineHandler == null - || this.permutationTooltipLineHandler.pStack != focused) { - this.permutationTooltipLineHandler = PermutationTooltipLineHandler.getInstance(focused); - } - } else if (this.permutationTooltipLineHandler != null) { - this.permutationTooltipLineHandler = null; } + if (focused == null || focused.items.length <= 1) { + this.permutationTooltipLineHandler = null; + } else if (this.permutationTooltipLineHandler == null + || this.permutationTooltipLineHandler.pStack != focused) { + this.permutationTooltipLineHandler = PermutationTooltipLineHandler.getInstance(focused); + } + } else if (this.permutationTooltipLineHandler != null) { + this.permutationTooltipLineHandler = null; } if (this.permutationTooltipLineHandler != null) {