diff --git a/Common/src/main/java/mezz/jei/common/input/IInternalKeyMappings.java b/Common/src/main/java/mezz/jei/common/input/IInternalKeyMappings.java index aa3c55778..303312a0d 100644 --- a/Common/src/main/java/mezz/jei/common/input/IInternalKeyMappings.java +++ b/Common/src/main/java/mezz/jei/common/input/IInternalKeyMappings.java @@ -23,6 +23,7 @@ public interface IInternalKeyMappings extends IJeiKeyMappings { IJeiKeyMapping getCloseRecipeGui(); IJeiKeyMapping getBookmark(); + IJeiKeyMapping getForceBookmark(); IJeiKeyMapping getToggleBookmarkOverlay(); @Override diff --git a/Common/src/main/resources/assets/jei/lang/en_us.json b/Common/src/main/resources/assets/jei/lang/en_us.json index a67ae678f..b603243ff 100644 --- a/Common/src/main/resources/assets/jei/lang/en_us.json +++ b/Common/src/main/resources/assets/jei/lang/en_us.json @@ -84,6 +84,7 @@ "jei.key.category.mouse.hover": "JEI (Hovering With Mouse)", "key.jei.bookmark": "Add/Remove Bookmark", + "key.jei.forceBookmark": "Replace Bookmark", "key.jei.showRecipe": "Show Recipe", "key.jei.showRecipe2": "Show Recipe", "key.jei.showUses": "Show Uses", diff --git a/Gui/src/main/java/mezz/jei/gui/bookmarks/BookmarkList.java b/Gui/src/main/java/mezz/jei/gui/bookmarks/BookmarkList.java index f5a63f945..5a7f02499 100644 --- a/Gui/src/main/java/mezz/jei/gui/bookmarks/BookmarkList.java +++ b/Gui/src/main/java/mezz/jei/gui/bookmarks/BookmarkList.java @@ -54,8 +54,8 @@ public BookmarkList( this.codecHelper = codecHelper; } - public boolean add(IBookmark value) { - if (!addToListWithoutNotifying(value, clientConfig.isAddingBookmarksToFrontEnabled())) { + public boolean add(IBookmark value, boolean shouldForce) { + if (!addToListWithoutNotifying(value, clientConfig.isAddingBookmarksToFrontEnabled(), shouldForce)) { return false; } notifyListenersOfChange(); @@ -90,21 +90,26 @@ public boolean contains(IBookmark value) { return this.bookmarksSet.contains(value); } - public boolean onElementBookmarked(IElement element) { - return element.getBookmark() - .map(this::remove) - .orElseGet(() -> { - ITypedIngredient ingredient = element.getTypedIngredient(); - IBookmark bookmark = IngredientBookmark.create(ingredient, ingredientManager); - return add(bookmark); - }); + public boolean onElementBookmarked(IElement element, boolean shouldForceAdd) { + boolean didExist = element.getBookmark() + .map(this::remove) + .orElse(false); + + if(shouldForceAdd || !didExist) { + ITypedIngredient ingredient = element.getTypedIngredient(); + IBookmark bookmark = IngredientBookmark.create(ingredient, ingredientManager); + return add(bookmark, shouldForceAdd); + } + return true; } - public void toggleBookmark(IBookmark bookmark) { + public void toggleBookmark(IBookmark bookmark, boolean shouldAddBack) { if (remove(bookmark)) { - return; + if(!shouldAddBack) { + return; + } } - add(bookmark); + add(bookmark, false); } public boolean remove(IBookmark ingredient) { @@ -131,9 +136,12 @@ public void setFromConfigFile(List bookmarks) { notifyListenersOfChange(); } - private boolean addToListWithoutNotifying(IBookmark value, boolean addToFront) { + private boolean addToListWithoutNotifying(IBookmark value, boolean addToFront, boolean shouldForce) { if (contains(value)) { - return false; + if(!shouldForce) { + return false; + } + remove(value); } if (addToFront) { bookmarksList.addFirst(value); diff --git a/Gui/src/main/java/mezz/jei/gui/config/InternalKeyMappings.java b/Gui/src/main/java/mezz/jei/gui/config/InternalKeyMappings.java index 712baefd9..3d6e59907 100644 --- a/Gui/src/main/java/mezz/jei/gui/config/InternalKeyMappings.java +++ b/Gui/src/main/java/mezz/jei/gui/config/InternalKeyMappings.java @@ -32,6 +32,7 @@ public final class InternalKeyMappings implements IInternalKeyMappings { private final IJeiKeyMapping nextPage; private final IJeiKeyMapping bookmark; + private final IJeiKeyMapping forceBookmark; private final IJeiKeyMapping toggleBookmarkOverlay; private final IJeiKeyMapping transferRecipeBookmark; private final IJeiKeyMapping maxTransferRecipeBookmark; @@ -128,6 +129,12 @@ public InternalKeyMappings(Consumer registerMethod) { .setContext(JeiKeyConflictContext.JEI_GUI_HOVER) .buildKeyboardKey(GLFW.GLFW_KEY_A) .register(registerMethod); + // Mouse Hover + forceBookmark = mouseHover.createMapping("key.jei.forceBookmark") + .setContext(JeiKeyConflictContext.JEI_GUI_HOVER) + .setModifier(JeiKeyModifier.SHIFT) + .buildKeyboardKey(GLFW.GLFW_KEY_A) + .register(registerMethod); showRecipe1 = mouseHover.createMapping("key.jei.showRecipe") .setContext(JeiKeyConflictContext.JEI_GUI_HOVER) @@ -369,6 +376,11 @@ public IJeiKeyMapping getBookmark() { return bookmark; } + @Override + public IJeiKeyMapping getForceBookmark() { + return forceBookmark; + } + @Override public IJeiKeyMapping getToggleBookmarkOverlay() { return toggleBookmarkOverlay; diff --git a/Gui/src/main/java/mezz/jei/gui/input/handlers/BookmarkInputHandler.java b/Gui/src/main/java/mezz/jei/gui/input/handlers/BookmarkInputHandler.java index 4ece53bdb..d70dcfc1d 100644 --- a/Gui/src/main/java/mezz/jei/gui/input/handlers/BookmarkInputHandler.java +++ b/Gui/src/main/java/mezz/jei/gui/input/handlers/BookmarkInputHandler.java @@ -20,18 +20,21 @@ public BookmarkInputHandler(CombinedRecipeFocusSource focusSource, BookmarkList @Override public Optional handleUserInput(Screen screen, UserInput input, IInternalKeyMappings keyBindings) { - if (input.is(keyBindings.getBookmark())) { - return handleBookmark(input, keyBindings); + if (input.is(keyBindings.getForceBookmark())) { + return handleBookmark(input, keyBindings, true); + } + else if (input.is(keyBindings.getBookmark())) { + return handleBookmark(input, keyBindings, false); } return Optional.empty(); } - private Optional handleBookmark(UserInput input, IInternalKeyMappings keyBindings) { + private Optional handleBookmark(UserInput input, IInternalKeyMappings keyBindings, boolean shouldForce) { return focusSource.getIngredientUnderMouse(input, keyBindings) .findFirst() .flatMap(clicked -> { if (input.isSimulate() || - bookmarkList.onElementBookmarked(clicked.getElement()) + bookmarkList.onElementBookmarked(clicked.getElement(), shouldForce) ) { IUserInputHandler handler = new SameElementInputHandler(this, clicked::isMouseOver); return Optional.of(handler); diff --git a/Gui/src/main/java/mezz/jei/gui/recipes/RecipeBookmarkButton.java b/Gui/src/main/java/mezz/jei/gui/recipes/RecipeBookmarkButton.java index a66da24c4..23bdd0967 100644 --- a/Gui/src/main/java/mezz/jei/gui/recipes/RecipeBookmarkButton.java +++ b/Gui/src/main/java/mezz/jei/gui/recipes/RecipeBookmarkButton.java @@ -87,7 +87,7 @@ protected boolean isIconToggledOn() { protected boolean onMouseClicked(UserInput input) { if (recipeBookmark != null) { if (!input.isSimulate()) { - bookmarks.toggleBookmark(recipeBookmark); + bookmarks.toggleBookmark(recipeBookmark, false); } return true; }