Skip to content

Commit

Permalink
Fix #2898 Expose "show uses/recipes" key bindings in the API
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Jul 19, 2022
1 parent 96f6117 commit c7f4c07
Show file tree
Hide file tree
Showing 48 changed files with 265 additions and 139 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package mezz.jei.common.config;

import java.util.function.Consumer;
import mezz.jei.common.input.IKeyBindings;
import mezz.jei.common.input.keys.IJeiKeyMapping;

import mezz.jei.api.runtime.IJeiKeyMapping;
import mezz.jei.common.input.IInternalKeyMappings;
import mezz.jei.common.input.keys.IJeiKeyMappingCategoryBuilder;
import mezz.jei.common.input.keys.JeiKeyConflictContext;
import mezz.jei.common.input.keys.JeiKeyModifier;
import mezz.jei.common.input.keys.JeiMultiKeyMapping;
import mezz.jei.common.platform.IPlatformInputHelper;
import mezz.jei.common.platform.Services;
import mezz.jei.common.util.Translator;
import net.minecraft.client.KeyMapping;
import org.lwjgl.glfw.GLFW;

import java.util.List;

public final class KeyBindings implements IKeyBindings {
public final class InternalKeyMappings implements IInternalKeyMappings {
private final IJeiKeyMapping toggleOverlay;
private final IJeiKeyMapping focusSearch;
private final IJeiKeyMapping toggleCheatMode;
Expand All @@ -34,11 +34,11 @@ public final class KeyBindings implements IKeyBindings {
private final IJeiKeyMapping bookmark;
private final IJeiKeyMapping toggleBookmarkOverlay;

private final List<IJeiKeyMapping> showRecipe;
private final List<IJeiKeyMapping> showUses;
private final IJeiKeyMapping showRecipe;
private final IJeiKeyMapping showUses;

private final List<IJeiKeyMapping> cheatOneItem;
private final List<IJeiKeyMapping> cheatItemStack;
private final IJeiKeyMapping cheatOneItem;
private final IJeiKeyMapping cheatItemStack;

private final IJeiKeyMapping toggleHideIngredient;
private final IJeiKeyMapping toggleWildcardHideIngredient;
Expand All @@ -55,9 +55,9 @@ public final class KeyBindings implements IKeyBindings {
private final IJeiKeyMapping escapeKey;
private final IJeiKeyMapping leftClick;
private final IJeiKeyMapping rightClick;
private final List<IJeiKeyMapping> enterKey;
private final IJeiKeyMapping enterKey;

public KeyBindings(Consumer<KeyMapping> registerMethod) {
public InternalKeyMappings(Consumer<KeyMapping> registerMethod) {
IPlatformInputHelper inputHelper = Services.PLATFORM.getInputHelper();

IJeiKeyMapping showRecipe1;
Expand Down Expand Up @@ -254,10 +254,10 @@ public KeyBindings(Consumer<KeyMapping> registerMethod) {
.buildUnbound()
.register(registerMethod);

showRecipe = List.of(showRecipe1, showRecipe2);
showUses = List.of(showUses1, showUses2);
cheatOneItem = List.of(cheatOneItem1, cheatOneItem2);
cheatItemStack = List.of(cheatItemStack1, cheatItemStack2);
showRecipe = new JeiMultiKeyMapping(showRecipe1, showRecipe2);
showUses = new JeiMultiKeyMapping(showUses1, showUses2);
cheatOneItem = new JeiMultiKeyMapping(cheatOneItem1, cheatOneItem2);
cheatItemStack = new JeiMultiKeyMapping(cheatItemStack1, cheatItemStack2);

String jeiHiddenInternalCategoryName = "jei.key.category.hidden.internal";
IJeiKeyMappingCategoryBuilder jeiHidden = inputHelper.createKeyMappingCategoryBuilder(jeiHiddenInternalCategoryName);
Expand All @@ -274,7 +274,7 @@ public KeyBindings(Consumer<KeyMapping> registerMethod) {
.setContext(JeiKeyConflictContext.GUI)
.buildMouseRight();

enterKey = List.of(
enterKey = new JeiMultiKeyMapping(
jeiHidden.createMapping("key.jei.internal.enter.key")
.setContext(JeiKeyConflictContext.GUI)
.buildKeyboardKey(GLFW.GLFW_KEY_ENTER),
Expand Down Expand Up @@ -361,22 +361,22 @@ public IJeiKeyMapping getToggleBookmarkOverlay() {
}

@Override
public List<IJeiKeyMapping> getShowRecipe() {
public IJeiKeyMapping getShowRecipe() {
return showRecipe;
}

@Override
public List<IJeiKeyMapping> getShowUses() {
public IJeiKeyMapping getShowUses() {
return showUses;
}

@Override
public List<IJeiKeyMapping> getCheatOneItem() {
public IJeiKeyMapping getCheatOneItem() {
return cheatOneItem;
}

@Override
public List<IJeiKeyMapping> getCheatItemStack() {
public IJeiKeyMapping getCheatItemStack() {
return cheatItemStack;
}

Expand Down Expand Up @@ -426,7 +426,7 @@ public IJeiKeyMapping getRightClick() {
}

@Override
public List<IJeiKeyMapping> getEnterKey() {
public IJeiKeyMapping getEnterKey() {
return enterKey;
}
}
6 changes: 3 additions & 3 deletions Common/src/main/java/mezz/jei/common/config/WorldConfig.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package mezz.jei.common.config;

import mezz.jei.common.input.IKeyBindings;
import mezz.jei.common.input.IInternalKeyMappings;
import mezz.jei.common.network.IConnectionToServer;
import mezz.jei.core.config.IWorldConfig;
import mezz.jei.common.network.packets.PacketRequestCheatPermission;

public class WorldConfig implements IWorldConfig {
private final IConnectionToServer serverConnection;
private final IKeyBindings keyBindings;
private final IInternalKeyMappings keyBindings;
private boolean overlayEnabled = true;
private boolean cheatItemsEnabled = false;
private boolean editModeEnabled = false;
private boolean bookmarkOverlayEnabled = true;

public WorldConfig(IConnectionToServer serverConnection, IKeyBindings keyBindings) {
public WorldConfig(IConnectionToServer serverConnection, IInternalKeyMappings keyBindings) {
this.serverConnection = serverConnection;
this.keyBindings = keyBindings;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.mojang.blaze3d.vertex.PoseStack;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.common.gui.textures.Textures;
import mezz.jei.common.input.IKeyBindings;
import mezz.jei.common.input.IInternalKeyMappings;
import mezz.jei.common.input.IUserInputHandler;
import mezz.jei.common.input.UserInput;
import mezz.jei.common.util.ImmutableRect2i;
Expand Down Expand Up @@ -89,7 +89,7 @@ public UserInputHandler(GuiIconButton button) {
}

@Override
public Optional<IUserInputHandler> handleUserInput(Screen screen, UserInput input, IKeyBindings keyBindings) {
public Optional<IUserInputHandler> handleUserInput(Screen screen, UserInput input, IInternalKeyMappings keyBindings) {
if (!input.isMouse()) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import mezz.jei.common.gui.HoverChecker;
import mezz.jei.common.gui.TooltipRenderer;
import mezz.jei.common.gui.textures.Textures;
import mezz.jei.common.input.IKeyBindings;
import mezz.jei.common.input.IInternalKeyMappings;
import mezz.jei.common.input.IUserInputHandler;
import mezz.jei.common.input.UserInput;
import mezz.jei.common.util.ImmutableRect2i;
Expand Down Expand Up @@ -68,7 +68,7 @@ public final void drawTooltips(PoseStack poseStack, int mouseX, int mouseY) {

private class UserInputHandler implements IUserInputHandler {
@Override
public final Optional<IUserInputHandler> handleUserInput(Screen screen, UserInput input, IKeyBindings keyBindings) {
public final Optional<IUserInputHandler> handleUserInput(Screen screen, UserInput input, IInternalKeyMappings keyBindings) {
if (isMouseOver(input.getMouseX(), input.getMouseY())) {
IUserInputHandler handler = button.createInputHandler();
return handler.handleUserInput(screen, input, keyBindings)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mezz.jei.common.gui.overlay;

import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.common.input.IKeyBindings;
import mezz.jei.common.input.IInternalKeyMappings;
import mezz.jei.common.platform.IPlatformConfigHelper;
import mezz.jei.common.platform.Services;
import mezz.jei.core.config.IWorldConfig;
Expand All @@ -19,16 +19,16 @@
import java.util.function.BooleanSupplier;

public class ConfigButton extends GuiIconToggleButton {
private final IKeyBindings keyBindings;
private final IInternalKeyMappings keyBindings;

public static ConfigButton create(BooleanSupplier isListDisplayed, IWorldConfig worldConfig, Textures textures, IKeyBindings keyBindings) {
public static ConfigButton create(BooleanSupplier isListDisplayed, IWorldConfig worldConfig, Textures textures, IInternalKeyMappings keyBindings) {
return new ConfigButton(textures.getConfigButtonIcon(), textures.getConfigButtonCheatIcon(), isListDisplayed, worldConfig, textures, keyBindings);
}

private final BooleanSupplier isListDisplayed;
private final IWorldConfig worldConfig;

private ConfigButton(IDrawable disabledIcon, IDrawable enabledIcon, BooleanSupplier isListDisplayed, IWorldConfig worldConfig, Textures textures, IKeyBindings keyBindings) {
private ConfigButton(IDrawable disabledIcon, IDrawable enabledIcon, BooleanSupplier isListDisplayed, IWorldConfig worldConfig, Textures textures, IInternalKeyMappings keyBindings) {
super(disabledIcon, enabledIcon, textures);
this.isListDisplayed = isListDisplayed;
this.worldConfig = worldConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import mezz.jei.api.helpers.IModIdHelper;
import mezz.jei.api.ingredients.IIngredientType;
import mezz.jei.api.ingredients.ITypedIngredient;
import mezz.jei.common.input.IKeyBindings;
import mezz.jei.common.input.IInternalKeyMappings;
import mezz.jei.common.network.IConnectionToServer;
import mezz.jei.core.config.IClientConfig;
import mezz.jei.common.config.IEditModeConfig;
Expand Down Expand Up @@ -59,7 +59,7 @@ public IngredientGrid(
GuiScreenHelper guiScreenHelper,
IModIdHelper modIdHelper,
IConnectionToServer serverConnection,
IKeyBindings keyBindings
IInternalKeyMappings keyBindings
) {
this.gridConfig = gridConfig;
this.guiScreenHelper = guiScreenHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import mezz.jei.api.ingredients.ITypedIngredient;
import mezz.jei.common.color.ColorNamer;
import mezz.jei.common.config.IIngredientFilterConfig;
import mezz.jei.common.input.IKeyBindings;
import mezz.jei.common.input.IInternalKeyMappings;
import mezz.jei.core.config.IWorldConfig;
import mezz.jei.core.search.SearchMode;
import mezz.jei.common.gui.TooltipRenderer;
Expand All @@ -28,14 +28,14 @@ public final class IngredientGridTooltipHelper {
private final IIngredientFilterConfig ingredientFilterConfig;
private final IWorldConfig worldConfig;
private final IModIdHelper modIdHelper;
private final IKeyBindings keyBindings;
private final IInternalKeyMappings keyBindings;

public IngredientGridTooltipHelper(
RegisteredIngredients registeredIngredients,
IIngredientFilterConfig ingredientFilterConfig,
IWorldConfig worldConfig,
IModIdHelper modIdHelper,
IKeyBindings keyBindings
IInternalKeyMappings keyBindings
) {
this.registeredIngredients = registeredIngredients;
this.ingredientFilterConfig = ingredientFilterConfig;
Expand Down Expand Up @@ -85,7 +85,7 @@ private static <T> void addColorSearchInfoToTooltip(List<Component> tooltip, T i
}
}

private static void addEditModeInfoToTooltip(List<Component> tooltip, IKeyBindings keyBindings) {
private static void addEditModeInfoToTooltip(List<Component> tooltip, IInternalKeyMappings keyBindings) {
List<Component> lines = List.of(
CommonComponents.EMPTY,
Component.translatable("gui.jei.editMode.description")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import mezz.jei.api.ingredients.IIngredientType;
import mezz.jei.api.ingredients.ITypedIngredient;
import mezz.jei.common.gui.textures.Textures;
import mezz.jei.common.input.IKeyBindings;
import mezz.jei.common.input.IInternalKeyMappings;
import mezz.jei.common.network.IConnectionToServer;
import mezz.jei.core.config.IClientConfig;
import mezz.jei.common.config.IIngredientGridConfig;
Expand Down Expand Up @@ -335,7 +335,7 @@ public boolean handleMouseScrolled(double mouseX, double mouseY, double scrollDe
}

@Override
public Optional<IUserInputHandler> handleUserInput(Screen screen, UserInput input, IKeyBindings keyBindings) {
public Optional<IUserInputHandler> handleUserInput(Screen screen, UserInput input, IInternalKeyMappings keyBindings) {
if (input.is(keyBindings.getNextPage())) {
this.paged.nextPage();
return Optional.of(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import mezz.jei.common.ingredients.RegisteredIngredients;
import mezz.jei.common.input.ICharTypedHandler;
import mezz.jei.common.input.IClickedIngredient;
import mezz.jei.common.input.IKeyBindings;
import mezz.jei.common.input.IInternalKeyMappings;
import mezz.jei.common.input.IRecipeFocusSource;
import mezz.jei.common.input.IUserInputHandler;
import mezz.jei.common.input.MouseUtil;
Expand Down Expand Up @@ -71,7 +71,7 @@ public IngredientListOverlay(
IWorldConfig worldConfig,
IConnectionToServer serverConnection,
Textures textures,
IKeyBindings keyBindings
IInternalKeyMappings keyBindings
) {
this.guiScreenHelper = guiScreenHelper;
this.contents = contents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.drawable.IDrawableStatic;
import mezz.jei.api.runtime.IJeiKeyMapping;
import mezz.jei.common.bookmarks.BookmarkList;
import mezz.jei.common.gui.elements.GuiIconToggleButton;
import mezz.jei.common.gui.textures.Textures;
import mezz.jei.common.input.IKeyBindings;
import mezz.jei.common.input.IInternalKeyMappings;
import mezz.jei.common.input.UserInput;
import mezz.jei.common.input.keys.IJeiKeyMapping;
import mezz.jei.core.config.IWorldConfig;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
Expand All @@ -16,7 +16,7 @@
import java.util.List;

public class BookmarkButton extends GuiIconToggleButton {
public static BookmarkButton create(BookmarkOverlay bookmarkOverlay, BookmarkList bookmarkList, Textures textures, IWorldConfig worldConfig, IKeyBindings keyBindings) {
public static BookmarkButton create(BookmarkOverlay bookmarkOverlay, BookmarkList bookmarkList, Textures textures, IWorldConfig worldConfig, IInternalKeyMappings keyBindings) {
IDrawableStatic offIcon = textures.getBookmarkButtonDisabledIcon();
IDrawableStatic onIcon = textures.getBookmarkButtonEnabledIcon();
return new BookmarkButton(offIcon, onIcon, textures, bookmarkOverlay, bookmarkList, worldConfig, keyBindings);
Expand All @@ -25,9 +25,9 @@ public static BookmarkButton create(BookmarkOverlay bookmarkOverlay, BookmarkLis
private final BookmarkOverlay bookmarkOverlay;
private final BookmarkList bookmarkList;
private final IWorldConfig worldConfig;
private final IKeyBindings keyBindings;
private final IInternalKeyMappings keyBindings;

private BookmarkButton(IDrawable offIcon, IDrawable onIcon, Textures textures, BookmarkOverlay bookmarkOverlay, BookmarkList bookmarkList, IWorldConfig worldConfig, IKeyBindings keyBindings) {
private BookmarkButton(IDrawable offIcon, IDrawable onIcon, Textures textures, BookmarkOverlay bookmarkOverlay, BookmarkList bookmarkList, IWorldConfig worldConfig, IInternalKeyMappings keyBindings) {
super(offIcon, onIcon, textures);
this.bookmarkOverlay = bookmarkOverlay;
this.bookmarkList = bookmarkList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import mezz.jei.api.ingredients.ITypedIngredient;
import mezz.jei.api.runtime.IBookmarkOverlay;
import mezz.jei.common.bookmarks.BookmarkList;
import mezz.jei.common.input.IKeyBindings;
import mezz.jei.common.input.IInternalKeyMappings;
import mezz.jei.common.network.IConnectionToServer;
import mezz.jei.core.config.IClientConfig;
import mezz.jei.core.config.IWorldConfig;
Expand Down Expand Up @@ -57,7 +57,7 @@ public BookmarkOverlay(
IWorldConfig worldConfig,
GuiScreenHelper guiScreenHelper,
IConnectionToServer serverConnection,
IKeyBindings keyBindings
IInternalKeyMappings keyBindings
) {
this.bookmarkList = bookmarkList;
this.worldConfig = worldConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import mezz.jei.api.ingredients.IIngredientRenderer;
import mezz.jei.api.ingredients.ITypedIngredient;
import mezz.jei.api.recipe.category.IRecipeCategory;
import mezz.jei.common.config.KeyBindings;
import mezz.jei.common.gui.textures.Textures;
import mezz.jei.common.ingredients.RegisteredIngredients;
import mezz.jei.common.input.IKeyBindings;
import mezz.jei.common.input.IInternalKeyMappings;
import mezz.jei.common.input.UserInput;
import mezz.jei.common.input.IUserInputHandler;
import net.minecraft.client.Minecraft;
Expand All @@ -38,7 +37,7 @@ public RecipeCategoryTab(IRecipeGuiLogic logic, IRecipeCategory<?> category, Tex
}

@Override
public Optional<IUserInputHandler> handleUserInput(Screen screen, UserInput input, IKeyBindings keyBindings) {
public Optional<IUserInputHandler> handleUserInput(Screen screen, UserInput input, IInternalKeyMappings keyBindings) {
if (!isMouseOver(input.getMouseX(), input.getMouseY())) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import mezz.jei.common.ingredients.RegisteredIngredients;
import mezz.jei.common.input.ClickedIngredient;
import mezz.jei.common.input.IClickedIngredient;
import mezz.jei.common.input.IKeyBindings;
import mezz.jei.common.input.IInternalKeyMappings;
import mezz.jei.common.input.IRecipeFocusSource;
import mezz.jei.common.input.IUserInputHandler;
import mezz.jei.common.input.InputType;
Expand Down Expand Up @@ -68,7 +68,7 @@ public class RecipesGui extends Screen implements IRecipesGui, IRecipeFocusSourc
private final RegisteredIngredients registeredIngredients;
private final IModIdHelper modIdHelper;
private final IClientConfig clientConfig;
private final IKeyBindings keyBindings;
private final IInternalKeyMappings keyBindings;

private int headerHeight;

Expand Down Expand Up @@ -107,7 +107,7 @@ public RecipesGui(
IClientConfig clientConfig,
Textures textures,
IIngredientVisibility ingredientVisibility,
IKeyBindings keyBindings
IInternalKeyMappings keyBindings
) {
super(Component.literal("Recipes"));
this.recipeTransferManager = recipeTransferManager;
Expand Down
Loading

0 comments on commit c7f4c07

Please sign in to comment.