From 9b081ed2a7f90ca138baf97599e7071c7431737b Mon Sep 17 00:00:00 2001 From: slprime <31038811+slprime@users.noreply.github.com> Date: Sun, 3 Dec 2023 18:07:54 +0200 Subject: [PATCH] fix bookmarks Infinite loop in todo list (#442) Co-authored-by: slprime --- .../java/codechicken/nei/BookmarkPanel.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/codechicken/nei/BookmarkPanel.java b/src/main/java/codechicken/nei/BookmarkPanel.java index d633e90f..db12cfb8 100644 --- a/src/main/java/codechicken/nei/BookmarkPanel.java +++ b/src/main/java/codechicken/nei/BookmarkPanel.java @@ -177,29 +177,43 @@ public class BookmarkPanel extends PanelWidget { } BookmarkStackMeta meta; + boolean isFirstColumn = false; + boolean isIngredient = false; int size = size(); int idx = 0; while (idx < size) { ArrayList pmask = new ArrayList<>(); + int lastIdx = idx; for (int i = 0, perPage = rows * columns; i < perPage && idx < size; i++) { + if (isInvalidSlot(i)) { pmask.add(null); } else { meta = getMetadata(idx); + isFirstColumn = (i % columns) == 0; + isIngredient = meta.recipeId != null && meta.ingredient; - if (idx > 0 && ((i % columns) == 0) == (meta.recipeId != null && meta.ingredient - && meta.recipeId.equals(getRecipeId(idx - 1)))) { - pmask.add(null); - } else { + if (isFirstColumn && !isIngredient) { pmask.add(idx++); - if ((i % columns) == 0) { - todoItemsCount++; - } + todoItemsCount++; + } else if (isIngredient && (!isFirstColumn || i + 1 < perPage && isInvalidSlot(i + 1))) { + // The ingredients that do not fit on the first line are moved to the second starting with + // the second column. This condition checks whether the second column is available. If not + // available, the ingredient takes the first column + pmask.add(idx++); + } else { + pmask.add(null); } + } + + } + + if (lastIdx == idx) { + break; } gridMask.add(pmask);