Skip to content

Commit

Permalink
Show all items from a StackList request
Browse files Browse the repository at this point in the history
  • Loading branch information
uecasm committed Jan 13, 2025
1 parent 8ee3f3a commit 55e8e7c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -126,8 +124,8 @@ public class WindowCrafting extends AbstractContainerScreen<ContainerCrafting>
*/
private ImageButton switchButton;

@Nullable public static Consumer<ItemStack> JEI_REQUEST_HOOK;
private final Map<IRequest<?>, ItemStack> requestables = new HashMap<>();
@Nullable public static Consumer<List<ItemStack>> JEI_REQUEST_HOOK;
private final Map<IRequest<?>, List<ItemStack>> requestables = new HashMap<>();

/**
* Create a crafting gui window.
Expand Down Expand Up @@ -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;
}
Expand All @@ -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<ItemStack> stacks = requestables.getOrDefault(request, new ArrayList<>());
if (!stacks.isEmpty() && JEI_REQUEST_HOOK != null)
{
JEI_REQUEST_HOOK.accept(stack);
JEI_REQUEST_HOOK.accept(stacks);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class WindowFurnaceCrafting extends AbstractContainerScreen<ContainerCraf
*/
private final CraftingModuleView module;

private final Map<IRequest<?>, ItemStack> requestables = new HashMap<>();
private final Map<IRequest<?>, List<ItemStack>> requestables = new HashMap<>();

/**
* Create a crafting gui window.
Expand Down Expand Up @@ -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;
}
Expand All @@ -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<ItemStack> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -45,7 +46,7 @@ public class JEIPlugin implements IModPlugin
{
public JEIPlugin()
{
WindowCrafting.JEI_REQUEST_HOOK = this::showOutputStack;
WindowCrafting.JEI_REQUEST_HOOK = this::showOutputStacks;
}

@NotNull
Expand Down Expand Up @@ -212,12 +213,15 @@ public void onRuntimeUnavailable()
this.jei = null;
}

private void showOutputStack(@NotNull final ItemStack stack)
private void showOutputStacks(@NotNull final List<ItemStack> 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<IFocus<?>> focuses = stacks.stream()
.<IFocus<?>>map(stack -> focusFactory.createFocus(RecipeIngredientRole.OUTPUT, VanillaTypes.ITEM_STACK, stack))
.toList();
this.jei.getRecipesGui().show(focuses);
}
}
}

0 comments on commit 55e8e7c

Please sign in to comment.