Skip to content

Commit

Permalink
Add access for the IRecipesGui's parent screen
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Oct 7, 2024
1 parent b8a0253 commit c3bc7ba
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
11 changes: 11 additions & 0 deletions CommonApi/src/main/java/mezz/jei/api/runtime/IRecipesGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import mezz.jei.api.recipe.IFocus;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.client.gui.screens.Screen;

/**
* JEI's gui for displaying recipes. Use this interface to open recipes.
Expand Down Expand Up @@ -58,4 +59,14 @@ default <V> void show(IFocus<V> focus) {
* @return the ingredient that's currently under the mouse in this gui
*/
<T> Optional<T> getIngredientUnderMouse(IIngredientType<T> ingredientType);

/**
* Get the screen that the {@link IRecipesGui} was opened from.
* When the {@link IRecipesGui} is closed, it will re-open the parent screen.
*
* If the {@link IRecipesGui} is not open, this will return {@link Optional#empty()}.
*
* @since 19.20.0
*/
Optional<Screen> getParentScreen();
}
9 changes: 5 additions & 4 deletions Gui/src/main/java/mezz/jei/gui/recipes/RecipesGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.category.IRecipeCategory;
import mezz.jei.api.recipe.transfer.IRecipeTransferManager;
import mezz.jei.api.runtime.IIngredientManager;
import mezz.jei.api.runtime.IRecipesGui;
import mezz.jei.common.Internal;
import mezz.jei.common.config.DebugConfig;
Expand Down Expand Up @@ -67,7 +66,6 @@ public class RecipesGui extends Screen implements IRecipesGui, IRecipeFocusSourc
private final IInternalKeyMappings keyBindings;
private final BookmarkList bookmarks;
private final IFocusFactory focusFactory;
private final IIngredientManager ingredientManager;

private int headerHeight;

Expand Down Expand Up @@ -111,15 +109,13 @@ public class RecipesGui extends Screen implements IRecipesGui, IRecipeFocusSourc
public RecipesGui(
IRecipeManager recipeManager,
IRecipeTransferManager recipeTransferManager,
IIngredientManager ingredientManager,
IInternalKeyMappings keyBindings,
IFocusFactory focusFactory,
BookmarkList bookmarks,
IGuiHelper guiHelper
) {
super(Component.literal("Recipes"));
this.bookmarks = bookmarks;
this.ingredientManager = ingredientManager;
this.keyBindings = keyBindings;
this.logic = new RecipeGuiLogic(
recipeManager,
Expand Down Expand Up @@ -567,6 +563,11 @@ public AbstractContainerMenu getParentContainerMenu() {
return null;
}

@Override
public Optional<Screen> getParentScreen() {
return Optional.ofNullable(parentScreen);
}

@Nullable
public IGuiProperties getProperties() {
if (width <= 0 || height <= 0) {
Expand Down
1 change: 0 additions & 1 deletion Gui/src/main/java/mezz/jei/gui/startup/JeiGuiStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ public static JeiEventHandlers start(IRuntimeRegistration registration) {
RecipesGui recipesGui = new RecipesGui(
recipeManager,
recipeTransferManager,
ingredientManager,
keyMappings,
focusFactory,
bookmarkList,
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ modrinthId=u6dRKJwZ
jUnitVersion=5.8.2

# Version
specificationVersion=19.19.6
specificationVersion=19.20.0

1 comment on commit c3bc7ba

@raoulvdberge
Copy link

@raoulvdberge raoulvdberge commented on c3bc7ba Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, this is used in Refined Storage 2 to return to the parent screen (the grid UI) when autocrafting is started from JEI transfer.

Please sign in to comment.