Skip to content

Commit

Permalink
Add a 1.19 config for the position of new bookmarks (#3113)
Browse files Browse the repository at this point in the history
  • Loading branch information
WaitingIdly committed Feb 12, 2023
1 parent 15bbaa4 commit fffffc6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Common/src/main/resources/assets/jei/lang/en_us.json
Expand Up @@ -136,6 +136,8 @@
"config.jei.advanced.maxRecipeGuiHeight.comment": "The maximum height of the recipe GUI.",
"config.jei.advanced.giveMode": "Give Mode",
"config.jei.advanced.giveMode.comment": "Choose if JEI should give ingredients direct to the inventory (inventory) or pick them up with the mouse (mouse_pickup).",
"config.jei.advanced.addBookmarksToFront": "Prepend New Bookmarks",
"config.jei.advanced.addBookmarksToFront.comment": "When true, adds new bookmarks to the front of the bookmark list. When false, adds new bookmarks to the end of the bookmark list",

"_comment": "Hide Ingredients Mode",
"gui.jei.editMode.description": "JEI Hide Ingredients Mode:",
Expand Down
5 changes: 5 additions & 0 deletions Forge/src/test/java/mezz/jei/test/lib/TestClientConfig.java
Expand Up @@ -28,6 +28,11 @@ public boolean isCheatToHotbarUsingHotkeysEnabled() {
return false;
}

@Override
public boolean isAddingBookmarksToFront() {
return false;
}

@Override
public GiveMode getGiveMode() {
return GiveMode.INVENTORY;
Expand Down
7 changes: 5 additions & 2 deletions Gui/src/main/java/mezz/jei/gui/bookmarks/BookmarkList.java
Expand Up @@ -5,6 +5,7 @@
import mezz.jei.api.ingredients.subtypes.UidContext;
import mezz.jei.api.runtime.IIngredientManager;
import mezz.jei.gui.config.IBookmarkConfig;
import mezz.jei.gui.config.IClientConfig;
import mezz.jei.gui.overlay.IIngredientGridSource;
import net.minecraft.world.item.ItemStack;

Expand All @@ -17,18 +18,20 @@ public class BookmarkList implements IIngredientGridSource {
private final List<ITypedIngredient<?>> list = new LinkedList<>();
private final IIngredientManager ingredientManager;
private final IBookmarkConfig bookmarkConfig;
private final IClientConfig clientConfig;
private final List<SourceListChangedListener> listeners = new ArrayList<>();

public BookmarkList(IIngredientManager ingredientManager, IBookmarkConfig bookmarkConfig) {
public BookmarkList(IIngredientManager ingredientManager, IBookmarkConfig bookmarkConfig, IClientConfig clientConfig) {
this.ingredientManager = ingredientManager;
this.bookmarkConfig = bookmarkConfig;
this.clientConfig = clientConfig;
}

public <T> boolean add(ITypedIngredient<T> value) {
if (contains(value)) {
return false;
}
addToList(value, true);
addToList(value, clientConfig.isAddingBookmarksToFront());
notifyListenersOfChange();
bookmarkConfig.saveBookmarks(ingredientManager, list);
return true;
Expand Down
11 changes: 11 additions & 0 deletions Gui/src/main/java/mezz/jei/gui/config/ClientConfig.java
Expand Up @@ -19,6 +19,7 @@ public final class ClientConfig implements IClientConfig {
private final Supplier<Boolean> centerSearchBarEnabled;
private final Supplier<Boolean> lowMemorySlowSearchEnabled;
private final Supplier<Boolean> cheatToHotbarUsingHotkeysEnabled;
private final Supplier<Boolean> addBookmarksToFront;
private final Supplier<GiveMode> giveMode;
private final Supplier<Integer> maxRecipeGuiHeight;
private final Supplier<List<IngredientSortStage>> ingredientSorterStages;
Expand All @@ -42,6 +43,11 @@ public ClientConfig(IConfigSchemaBuilder schema) {
false,
"Enable cheating items into the hotbar by using the shift+number keys."
);
addBookmarksToFront = advanced.addBoolean(
"AddBookmarksToFrontEnabled",
true,
"Enable adding new bookmarks to the front of the bookmark list."
);
giveMode = advanced.addEnum(
"GiveMode",
GiveMode.defaultGiveMode,
Expand Down Expand Up @@ -88,6 +94,11 @@ public boolean isCheatToHotbarUsingHotkeysEnabled() {
return cheatToHotbarUsingHotkeysEnabled.get();
}

@Override
public boolean isAddingBookmarksToFront() {
return addBookmarksToFront.get();
}

@Override
public GiveMode getGiveMode() {
return giveMode.get();
Expand Down
2 changes: 2 additions & 0 deletions Gui/src/main/java/mezz/jei/gui/config/IClientConfig.java
Expand Up @@ -16,6 +16,8 @@ public interface IClientConfig {

boolean isCheatToHotbarUsingHotkeysEnabled();

boolean isAddingBookmarksToFront();

GiveMode getGiveMode();

int getMaxRecipeGuiHeight();
Expand Down
2 changes: 1 addition & 1 deletion Gui/src/main/java/mezz/jei/gui/startup/JeiGuiStarter.java
Expand Up @@ -142,7 +142,7 @@ public static JeiEventHandlers start(IRuntimeRegistration registration) {
);
registration.setIngredientListOverlay(ingredientListOverlay);

BookmarkList bookmarkList = new BookmarkList(ingredientManager, bookmarkConfig);
BookmarkList bookmarkList = new BookmarkList(ingredientManager, bookmarkConfig, clientConfig);
bookmarkConfig.loadBookmarks(ingredientManager, bookmarkList);

BookmarkOverlay bookmarkOverlay = OverlayHelper.createBookmarkOverlay(
Expand Down

0 comments on commit fffffc6

Please sign in to comment.