From 13a7ee144b799c69a592f3e0ebfb9af2f733fb54 Mon Sep 17 00:00:00 2001 From: Mirality Date: Tue, 12 Nov 2024 20:32:17 +1300 Subject: [PATCH 1/3] Add JEI request search to crafting teach window --- .../api/util/constant/WindowConstants.java | 12 +++ .../client/gui/containers/WindowCrafting.java | 74 ++++++++++++++---- .../gui/containers/WindowFurnaceCrafting.java | 55 ++++++++++++- .../core/compatibility/jei/JEIPlugin.java | 33 ++++++++ .../textures/gui/craftingswitch.png | Bin 1210 -> 3190 bytes 5 files changed, 158 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/minecolonies/api/util/constant/WindowConstants.java b/src/main/java/com/minecolonies/api/util/constant/WindowConstants.java index 5c1bafafe4f..a0d71599cd9 100755 --- a/src/main/java/com/minecolonies/api/util/constant/WindowConstants.java +++ b/src/main/java/com/minecolonies/api/util/constant/WindowConstants.java @@ -1,7 +1,9 @@ package com.minecolonies.api.util.constant; import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.common.util.Size2i; +import static com.minecolonies.api.util.constant.Constants.MOD_ID; import static com.minecolonies.api.util.constant.TranslationConstants.*; /** @@ -1278,6 +1280,16 @@ public final class WindowConstants */ public static final String TITLE_LABEL = "title"; + /** + * Crafting switch buttons texture. + */ + public static final ResourceLocation CRAFTING_SWITCH_TEXTURE = new ResourceLocation(MOD_ID, "textures/gui/craftingswitch.png"); + + /** + * Switch button size. + */ + public static final Size2i CRAFTING_SWITCH_SIZE = new Size2i(20, 18); + /** * Private constructor to hide implicit public one. */ diff --git a/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java b/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java index 1fd7a0a1755..22c25ebe406 100755 --- a/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java +++ b/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java @@ -1,15 +1,19 @@ package com.minecolonies.core.client.gui.containers; import com.minecolonies.api.colony.IColonyManager; +import com.minecolonies.api.colony.requestsystem.request.IRequest; +import com.minecolonies.api.colony.requestsystem.requestable.IConcreteDeliverable; import com.minecolonies.api.crafting.ItemStorage; import com.minecolonies.api.crafting.ModCraftingTypes; import com.minecolonies.api.inventory.container.ContainerCrafting; import com.minecolonies.api.util.ItemStackUtils; import com.minecolonies.core.Network; +import com.minecolonies.core.client.gui.modules.WindowSelectRequest; import com.minecolonies.core.colony.buildings.moduleviews.CraftingModuleView; import com.minecolonies.core.colony.buildings.views.AbstractBuildingView; import com.minecolonies.core.network.messages.server.SwitchRecipeCraftingTeachingMessage; import com.minecolonies.core.network.messages.server.colony.building.worker.AddRemoveRecipeMessage; +import com.minecolonies.core.util.DomumOrnamentumUtils; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.ImageButton; @@ -19,12 +23,17 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.function.Consumer; import static com.minecolonies.api.util.constant.Constants.MOD_ID; import static com.minecolonies.api.util.constant.TranslationConstants.WARNING_MAXIMUM_NUMBER_RECIPES; +import static com.minecolonies.api.util.constant.WindowConstants.*; import static com.minecolonies.api.util.constant.translation.BaseGameTranslationConstants.BASE_GUI_DONE; /** @@ -36,8 +45,6 @@ public class WindowCrafting extends AbstractContainerScreen private static final ResourceLocation CRAFTING_TABLE_GUI_TEXTURES3X3 = new ResourceLocation(MOD_ID, "textures/gui/crafting3x3.png"); - private static final ResourceLocation SWITCH_TEXTURE = new ResourceLocation(MOD_ID, "textures/gui/craftingswitch.png"); - /** * X offset of the button. */ @@ -58,16 +65,6 @@ public class WindowCrafting extends AbstractContainerScreen */ private static final int BUTTON_HEIGHT = 20; - /** - * Switch button width. - */ - private static final int SWITCH_WIDTH = 20; - - /** - * Switch button height. - */ - private static final int SWITCH_HEIGHT = 18; - /** * Switch button horizontal location. */ @@ -76,7 +73,13 @@ public class WindowCrafting extends AbstractContainerScreen /** * Switch button vertical location. */ - private static final int SWITCH_Y_OFFSET = 43 - (SWITCH_HEIGHT / 2); + private static final int SWITCH_Y_OFFSET = 43 - (CRAFTING_SWITCH_SIZE.height / 2); + + /** + * Request list button location. + */ + private static final int REQUEST_X_OFFSET = 100 - (CRAFTING_SWITCH_SIZE.width / 2); + private static final int REQUEST_Y_OFFSET = 70 - CRAFTING_SWITCH_SIZE.height; /** * Color of the gui description. @@ -123,6 +126,9 @@ public class WindowCrafting extends AbstractContainerScreen */ private ImageButton switchButton; + @Nullable public static Consumer JEI_REQUEST_HOOK; + private final Map, ItemStack> requestables = new HashMap<>(); + /** * Create a crafting gui window. * @@ -167,13 +173,24 @@ protected void init() doneButton.active = false; } - this.switchButton = new ImageButton(leftPos + SWITCH_X_OFFSET, topPos + SWITCH_Y_OFFSET, SWITCH_WIDTH, SWITCH_HEIGHT, - 0, 0, SWITCH_HEIGHT + 1, SWITCH_TEXTURE, btn -> + this.switchButton = new ImageButton(leftPos + SWITCH_X_OFFSET, topPos + SWITCH_Y_OFFSET, CRAFTING_SWITCH_SIZE.width, CRAFTING_SWITCH_SIZE.height, + 0, 0, CRAFTING_SWITCH_SIZE.height + 1, CRAFTING_SWITCH_TEXTURE, btn -> { Network.getNetwork().sendToServer(new SwitchRecipeCraftingTeachingMessage()); }); this.switchButton.visible = false; this.addRenderableWidget(this.switchButton); + + if (completeCrafting) + { + final ImageButton requestsButton = new ImageButton(leftPos + REQUEST_X_OFFSET, topPos + REQUEST_Y_OFFSET, CRAFTING_SWITCH_SIZE.width, CRAFTING_SWITCH_SIZE.height, + CRAFTING_SWITCH_SIZE.width + 1, 0, CRAFTING_SWITCH_SIZE.height + 1, CRAFTING_SWITCH_TEXTURE, btn -> + { + requestables.clear(); + new WindowSelectRequest(this.building, this::matchingRequest, this::reopenWithRequest).open(); + }); + this.addRenderableWidget(requestsButton); + } } @Override @@ -184,6 +201,33 @@ protected void containerTick() this.switchButton.visible = this.menu.canSwitchRecipes(); } + private boolean matchingRequest(@NotNull final IRequest request) + { + if (!DomumOrnamentumUtils.getRequestedStack(request).isEmpty()) return false; + + if (request.getRequest() instanceof IConcreteDeliverable deliverable) + { + for (final ItemStack stack : deliverable.getRequestedItems()) + { + // todo filter? + requestables.put(request, stack); + return true; + } + } + return false; + } + + private void reopenWithRequest(@Nullable final IRequest request) + { + minecraft.setScreen(this); + + final ItemStack stack = requestables.getOrDefault(request, ItemStack.EMPTY); + if (!stack.isEmpty() && JEI_REQUEST_HOOK != null) + { + JEI_REQUEST_HOOK.accept(stack); + } + } + private void onDoneClicked(final Button button) { if (module.canLearn(ModCraftingTypes.SMALL_CRAFTING.get())) diff --git a/src/main/java/com/minecolonies/core/client/gui/containers/WindowFurnaceCrafting.java b/src/main/java/com/minecolonies/core/client/gui/containers/WindowFurnaceCrafting.java index 0aed618d76c..49f4cb5a0a4 100755 --- a/src/main/java/com/minecolonies/core/client/gui/containers/WindowFurnaceCrafting.java +++ b/src/main/java/com/minecolonies/core/client/gui/containers/WindowFurnaceCrafting.java @@ -1,17 +1,22 @@ package com.minecolonies.core.client.gui.containers; import com.minecolonies.api.colony.IColonyManager; +import com.minecolonies.api.colony.requestsystem.request.IRequest; +import com.minecolonies.api.colony.requestsystem.requestable.IConcreteDeliverable; import com.minecolonies.api.crafting.ItemStorage; import com.minecolonies.api.crafting.ModCraftingTypes; import com.minecolonies.api.inventory.container.ContainerCraftingFurnace; import com.minecolonies.api.util.ItemStackUtils; import com.minecolonies.api.util.constant.Constants; import com.minecolonies.core.Network; +import com.minecolonies.core.client.gui.modules.WindowSelectRequest; import com.minecolonies.core.colony.buildings.moduleviews.CraftingModuleView; import com.minecolonies.core.colony.buildings.views.AbstractBuildingView; import com.minecolonies.core.network.messages.server.colony.building.worker.AddRemoveRecipeMessage; +import com.minecolonies.core.util.DomumOrnamentumUtils; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.ImageButton; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -19,12 +24,17 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Blocks; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; -import static com.minecolonies.api.util.constant.translation.BaseGameTranslationConstants.BASE_GUI_DONE; import static com.minecolonies.api.util.constant.TranslationConstants.WARNING_MAXIMUM_NUMBER_RECIPES; +import static com.minecolonies.api.util.constant.WindowConstants.CRAFTING_SWITCH_SIZE; +import static com.minecolonies.api.util.constant.WindowConstants.CRAFTING_SWITCH_TEXTURE; +import static com.minecolonies.api.util.constant.translation.BaseGameTranslationConstants.BASE_GUI_DONE; /** * Furnace crafting gui. @@ -53,6 +63,12 @@ public class WindowFurnaceCrafting extends AbstractContainerScreen, ItemStack> requestables = new HashMap<>(); + /** * Create a crafting gui window. * @@ -103,6 +121,14 @@ protected void init() { doneButton.active = false; } + + final ImageButton requestsButton = new ImageButton(leftPos + REQUEST_X_OFFSET, topPos + REQUEST_Y_OFFSET, CRAFTING_SWITCH_SIZE.width, CRAFTING_SWITCH_SIZE.height, + CRAFTING_SWITCH_SIZE.width + 1, 0, CRAFTING_SWITCH_SIZE.height + 1, CRAFTING_SWITCH_TEXTURE, btn -> + { + requestables.clear(); + new WindowSelectRequest(this.building, this::matchingRequest, this::reopenWithRequest).open(); + }); + this.addRenderableWidget(requestsButton); } public class OnButtonPress implements Button.OnPress @@ -124,6 +150,33 @@ public void onPress(@NotNull final Button button) } } + private boolean matchingRequest(@NotNull final IRequest request) + { + if (!DomumOrnamentumUtils.getRequestedStack(request).isEmpty()) return false; + + if (request.getRequest() instanceof IConcreteDeliverable deliverable) + { + for (final ItemStack stack : deliverable.getRequestedItems()) + { + // todo filter? + requestables.put(request, stack); + return true; + } + } + return false; + } + + private void reopenWithRequest(@Nullable final IRequest request) + { + minecraft.setScreen(this); + + final ItemStack stack = requestables.getOrDefault(request, ItemStack.EMPTY); + if (!stack.isEmpty() && WindowCrafting.JEI_REQUEST_HOOK != null) + { + WindowCrafting.JEI_REQUEST_HOOK.accept(stack); + } + } + /** * Draws the background layer of this container (behind the items). */ diff --git a/src/main/java/com/minecolonies/core/compatibility/jei/JEIPlugin.java b/src/main/java/com/minecolonies/core/compatibility/jei/JEIPlugin.java index d22acbd8ce5..20ea35d5c68 100644 --- a/src/main/java/com/minecolonies/core/compatibility/jei/JEIPlugin.java +++ b/src/main/java/com/minecolonies/core/compatibility/jei/JEIPlugin.java @@ -12,6 +12,7 @@ import com.minecolonies.api.util.Log; import com.minecolonies.api.util.constant.Constants; import com.minecolonies.api.util.constant.TranslationConstants; +import com.minecolonies.core.client.gui.containers.WindowCrafting; import com.minecolonies.core.colony.buildings.modules.AnimalHerdingModule; import com.minecolonies.core.colony.crafting.RecipeAnalyzer; import com.minecolonies.core.compatibility.jei.transfer.*; @@ -21,8 +22,11 @@ import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.helpers.IJeiHelpers; import mezz.jei.api.helpers.IModIdHelper; +import mezz.jei.api.recipe.IFocus; +import mezz.jei.api.recipe.RecipeIngredientRole; import mezz.jei.api.recipe.RecipeType; import mezz.jei.api.registration.*; +import mezz.jei.api.runtime.IJeiRuntime; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.network.chat.Component; @@ -31,6 +35,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.function.BiConsumer; @@ -38,6 +43,11 @@ @mezz.jei.api.JeiPlugin public class JEIPlugin implements IModPlugin { + public JEIPlugin() + { + WindowCrafting.JEI_REQUEST_HOOK = this::showOutputStack; + } + @NotNull @Override public ResourceLocation getPluginUid() @@ -46,6 +56,8 @@ public ResourceLocation getPluginUid() } private final List> categories = new ArrayList<>(); + @Nullable + private IJeiRuntime jei; @Override public void registerCategories(@NotNull final IRecipeCategoryRegistration registration) @@ -187,4 +199,25 @@ public void registerGuiHandlers(@NotNull final IGuiHandlerRegistration registrat new FurnaceCraftingGuiHandler(this.categories).register(registration); new BrewingCraftingGuiHandler(this.categories).register(registration); } + + @Override + public void onRuntimeAvailable(@NotNull final IJeiRuntime jeiRuntime) + { + this.jei = jeiRuntime; + } + + @Override + public void onRuntimeUnavailable() + { + this.jei = null; + } + + private void showOutputStack(@NotNull final ItemStack stack) + { + if (this.jei != null) + { + final IFocus focus = this.jei.getJeiHelpers().getFocusFactory().createFocus(RecipeIngredientRole.OUTPUT, VanillaTypes.ITEM_STACK, stack); + this.jei.getRecipesGui().show(focus); + } + } } diff --git a/src/main/resources/assets/minecolonies/textures/gui/craftingswitch.png b/src/main/resources/assets/minecolonies/textures/gui/craftingswitch.png index abdaa9e47172832942e0b058ba3a874c5984ef46..2085e38f42358f561e363f0b76cb3133c9c3261d 100644 GIT binary patch delta 2955 zcmV;63v~3l3HBI}BYy_^dQ@0+Qek%>aB^>EX>4U6ba`-PAZ2)IW&i+q+U=KJlHIrs zh2Ob~EP)^i0$dJ%tFnVEKOgT^cWjSmVkfD}OH19NL{T7s103Ln{g1z&@HdX+(L+)5 z+G>p)rInUCHy+jhY^iD$ zD_l#8X0>teDHg+TOJ5(RcE8i{A?W+(@Ub+ZQ`%W_d|%&M=KEiAXGY%FyY9I+t|h0p zwgJdcf&2FOHh;yxJpN4k@U8j}?7sx}k7$Pv6l!{2#f&UmD6Gk1fg?t&&KJb#Uz$i zoN;hYX_5f(NRcI7j_lVsWujt9I~ik2Gl1otbiin70)MvvDW{xdx#g7|xF;czFVvs9 z$ZOm7+HQ)+72*<>CPA3+$$xx?UtM@!IUy4L(^u$~Zq%Vg6yU!D%RofV<5Yb)_~ZQX zxVUBz)R&tb1A83dEn=wrE4cCt=*&W8d?&HkdIaDiwpNrOVT!~m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Actually meh, allow 2x2 request teaching too --- .../client/gui/containers/WindowCrafting.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java b/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java index 22c25ebe406..b31c381b2f3 100755 --- a/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java +++ b/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java @@ -181,16 +181,13 @@ protected void init() this.switchButton.visible = false; this.addRenderableWidget(this.switchButton); - if (completeCrafting) + final ImageButton requestsButton = new ImageButton(leftPos + REQUEST_X_OFFSET, topPos + REQUEST_Y_OFFSET, CRAFTING_SWITCH_SIZE.width, CRAFTING_SWITCH_SIZE.height, + CRAFTING_SWITCH_SIZE.width + 1, 0, CRAFTING_SWITCH_SIZE.height + 1, CRAFTING_SWITCH_TEXTURE, btn -> { - final ImageButton requestsButton = new ImageButton(leftPos + REQUEST_X_OFFSET, topPos + REQUEST_Y_OFFSET, CRAFTING_SWITCH_SIZE.width, CRAFTING_SWITCH_SIZE.height, - CRAFTING_SWITCH_SIZE.width + 1, 0, CRAFTING_SWITCH_SIZE.height + 1, CRAFTING_SWITCH_TEXTURE, btn -> - { - requestables.clear(); - new WindowSelectRequest(this.building, this::matchingRequest, this::reopenWithRequest).open(); - }); - this.addRenderableWidget(requestsButton); - } + requestables.clear(); + new WindowSelectRequest(this.building, this::matchingRequest, this::reopenWithRequest).open(); + }); + this.addRenderableWidget(requestsButton); } @Override From 55e8e7cebfde12dd3a1de747efd316f437b5d756 Mon Sep 17 00:00:00 2001 From: Mirality Date: Mon, 13 Jan 2025 21:54:03 +1300 Subject: [PATCH 3/3] Show all items from a StackList request --- .../client/gui/containers/WindowCrafting.java | 27 ++++++++----------- .../gui/containers/WindowFurnaceCrafting.java | 17 +++++------- .../core/compatibility/jei/JEIPlugin.java | 14 ++++++---- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java b/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java index b31c381b2f3..dab8dbe6fce 100755 --- a/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java +++ b/src/main/java/com/minecolonies/core/client/gui/containers/WindowCrafting.java @@ -25,15 +25,13 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.Consumer; import static com.minecolonies.api.util.constant.Constants.MOD_ID; import static com.minecolonies.api.util.constant.TranslationConstants.WARNING_MAXIMUM_NUMBER_RECIPES; -import static com.minecolonies.api.util.constant.WindowConstants.*; +import static com.minecolonies.api.util.constant.WindowConstants.CRAFTING_SWITCH_SIZE; +import static com.minecolonies.api.util.constant.WindowConstants.CRAFTING_SWITCH_TEXTURE; import static com.minecolonies.api.util.constant.translation.BaseGameTranslationConstants.BASE_GUI_DONE; /** @@ -126,8 +124,8 @@ public class WindowCrafting extends AbstractContainerScreen */ private ImageButton switchButton; - @Nullable public static Consumer JEI_REQUEST_HOOK; - private final Map, ItemStack> requestables = new HashMap<>(); + @Nullable public static Consumer> JEI_REQUEST_HOOK; + private final Map, List> requestables = new HashMap<>(); /** * Create a crafting gui window. @@ -204,12 +202,9 @@ private boolean matchingRequest(@NotNull final IRequest request) if (request.getRequest() instanceof IConcreteDeliverable deliverable) { - for (final ItemStack stack : deliverable.getRequestedItems()) - { - // todo filter? - requestables.put(request, stack); - return true; - } + // todo filter? + requestables.put(request, deliverable.getRequestedItems()); + return true; } return false; } @@ -218,10 +213,10 @@ private void reopenWithRequest(@Nullable final IRequest request) { minecraft.setScreen(this); - final ItemStack stack = requestables.getOrDefault(request, ItemStack.EMPTY); - if (!stack.isEmpty() && JEI_REQUEST_HOOK != null) + final List stacks = requestables.getOrDefault(request, new ArrayList<>()); + if (!stacks.isEmpty() && JEI_REQUEST_HOOK != null) { - JEI_REQUEST_HOOK.accept(stack); + JEI_REQUEST_HOOK.accept(stacks); } } diff --git a/src/main/java/com/minecolonies/core/client/gui/containers/WindowFurnaceCrafting.java b/src/main/java/com/minecolonies/core/client/gui/containers/WindowFurnaceCrafting.java index 49f4cb5a0a4..cfea104ae5d 100755 --- a/src/main/java/com/minecolonies/core/client/gui/containers/WindowFurnaceCrafting.java +++ b/src/main/java/com/minecolonies/core/client/gui/containers/WindowFurnaceCrafting.java @@ -84,7 +84,7 @@ public class WindowFurnaceCrafting extends AbstractContainerScreen, ItemStack> requestables = new HashMap<>(); + private final Map, List> requestables = new HashMap<>(); /** * Create a crafting gui window. @@ -156,12 +156,9 @@ private boolean matchingRequest(@NotNull final IRequest request) if (request.getRequest() instanceof IConcreteDeliverable deliverable) { - for (final ItemStack stack : deliverable.getRequestedItems()) - { - // todo filter? - requestables.put(request, stack); - return true; - } + // todo filter? + requestables.put(request, deliverable.getRequestedItems()); + return true; } return false; } @@ -170,10 +167,10 @@ private void reopenWithRequest(@Nullable final IRequest request) { minecraft.setScreen(this); - final ItemStack stack = requestables.getOrDefault(request, ItemStack.EMPTY); - if (!stack.isEmpty() && WindowCrafting.JEI_REQUEST_HOOK != null) + final List stacks = requestables.getOrDefault(request, new ArrayList<>()); + if (!stacks.isEmpty() && WindowCrafting.JEI_REQUEST_HOOK != null) { - WindowCrafting.JEI_REQUEST_HOOK.accept(stack); + WindowCrafting.JEI_REQUEST_HOOK.accept(stacks); } } diff --git a/src/main/java/com/minecolonies/core/compatibility/jei/JEIPlugin.java b/src/main/java/com/minecolonies/core/compatibility/jei/JEIPlugin.java index 20ea35d5c68..20a4ed01ed6 100644 --- a/src/main/java/com/minecolonies/core/compatibility/jei/JEIPlugin.java +++ b/src/main/java/com/minecolonies/core/compatibility/jei/JEIPlugin.java @@ -23,6 +23,7 @@ import mezz.jei.api.helpers.IJeiHelpers; import mezz.jei.api.helpers.IModIdHelper; import mezz.jei.api.recipe.IFocus; +import mezz.jei.api.recipe.IFocusFactory; import mezz.jei.api.recipe.RecipeIngredientRole; import mezz.jei.api.recipe.RecipeType; import mezz.jei.api.registration.*; @@ -45,7 +46,7 @@ public class JEIPlugin implements IModPlugin { public JEIPlugin() { - WindowCrafting.JEI_REQUEST_HOOK = this::showOutputStack; + WindowCrafting.JEI_REQUEST_HOOK = this::showOutputStacks; } @NotNull @@ -212,12 +213,15 @@ public void onRuntimeUnavailable() this.jei = null; } - private void showOutputStack(@NotNull final ItemStack stack) + private void showOutputStacks(@NotNull final List stacks) { - if (this.jei != null) + if (this.jei != null && !stacks.isEmpty()) { - final IFocus focus = this.jei.getJeiHelpers().getFocusFactory().createFocus(RecipeIngredientRole.OUTPUT, VanillaTypes.ITEM_STACK, stack); - this.jei.getRecipesGui().show(focus); + final IFocusFactory focusFactory = this.jei.getJeiHelpers().getFocusFactory(); + final List> focuses = stacks.stream() + .>map(stack -> focusFactory.createFocus(RecipeIngredientRole.OUTPUT, VanillaTypes.ITEM_STACK, stack)) + .toList(); + this.jei.getRecipesGui().show(focuses); } } }