Skip to content

Commit

Permalink
Merge remote-tracking branch 'slprime/bookmarks_groups_and_filter' in…
Browse files Browse the repository at this point in the history
…to dev
  • Loading branch information
Dream-Master committed Feb 3, 2024
2 parents 5576f1b + 1b60f0b commit 1bcb711
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
13 changes: 2 additions & 11 deletions src/main/java/codechicken/nei/api/ShortcutInputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.GuiUsageRecipe;
import codechicken.nei.recipe.StackInfo;
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;

public abstract class ShortcutInputHandler {

Expand Down Expand Up @@ -67,11 +65,11 @@ public static boolean handleKeyEvent(ItemStack stackover) {
}

if (NEIClientConfig.isKeyHashDown("gui.recipe")) {
return GuiCraftingRecipe.openRecipeGui("item", normalizeItemStack(stackover));
return GuiCraftingRecipe.openRecipeGui("item", stackover);
}

if (NEIClientConfig.isKeyHashDown("gui.usage")) {
return GuiUsageRecipe.openRecipeGui("item", normalizeItemStack(stackover));
return GuiUsageRecipe.openRecipeGui("item", stackover);
}

if (NEIClientConfig.isKeyHashDown("gui.bookmark")) {
Expand Down Expand Up @@ -101,7 +99,6 @@ public static boolean handleMouseClick(ItemStack stackover) {

if (stackover != null) {
final int button = Mouse.getEventButton();
stackover = stackover.copy();

if (button == 0) {
return GuiCraftingRecipe.openRecipeGui("item", stackover);
Expand Down Expand Up @@ -167,10 +164,4 @@ private static boolean saveRecipeInBookmark(ItemStack stack, boolean saveIngredi
return false;
}

private static ItemStack normalizeItemStack(ItemStack stack) {
GTFluidStackStringifyHandler.replaceAE2FCFluidDrop = true;
stack = StackInfo.loadFromNBT(StackInfo.itemStackToNBT(stack));
GTFluidStackStringifyHandler.replaceAE2FCFluidDrop = false;
return stack;
}
}
9 changes: 9 additions & 0 deletions src/main/java/codechicken/nei/recipe/GuiCraftingRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;

public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {

Expand All @@ -33,6 +34,7 @@ public static GuiRecipe<?> createRecipeGui(String outputId, boolean open, Object
final BookmarkRecipeId recipeId;

if ("item".equals(outputId)) {
results = Arrays.asList(results).stream().map(rslt -> normalizeItemStack((ItemStack) rslt)).toArray();
recipeId = getRecipeId(mc.currentScreen, (ItemStack) results[0]);
} else if ("recipeId".equals(outputId)) {
recipeId = (BookmarkRecipeId) results[1];
Expand Down Expand Up @@ -114,6 +116,13 @@ private static String getHandlerName(ICraftingHandler handler) {
return GuiRecipeTab.getHandlerInfo(handler).getHandlerName();
}

private static ItemStack normalizeItemStack(ItemStack stack) {
GTFluidStackStringifyHandler.replaceAE2FCFluidDrop = true;
stack = StackInfo.loadFromNBT(StackInfo.itemStackToNBT(stack));
GTFluidStackStringifyHandler.replaceAE2FCFluidDrop = false;
return stack;
}

protected static BookmarkRecipeId getRecipeId(GuiScreen gui, ItemStack stackover) {

if (gui instanceof GuiRecipe) {
Expand Down
51 changes: 37 additions & 14 deletions src/main/java/codechicken/nei/recipe/GuiUsageRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,62 @@
import java.util.Arrays;

import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;

import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;

public class GuiUsageRecipe extends GuiRecipe<IUsageHandler> {

public static ArrayList<IUsageHandler> usagehandlers = new ArrayList<>();
public static ArrayList<IUsageHandler> serialUsageHandlers = new ArrayList<>();

public static boolean openRecipeGui(String inputId, Object... ingredients) {
RecipeHandlerQuery<IUsageHandler> recipeQuery = new RecipeHandlerQuery<>(

if ("item".equals(inputId)) {
ingredients = Arrays.asList(ingredients).stream().map(ingr -> normalizeItemStack((ItemStack) ingr))
.toArray();
}

final ArrayList<IUsageHandler> handlers = getUsageHandlers(inputId, ingredients);

if (!handlers.isEmpty()) {
final Minecraft mc = NEIClientUtils.mc();
final BookmarkRecipeId recipeId = getCurrentRecipe(mc.currentScreen);
final GuiUsageRecipe gui = new GuiUsageRecipe(handlers);

mc.displayGuiScreen(gui);
gui.openTargetRecipe(recipeId);
return true;
}

return false;
}

private GuiUsageRecipe(ArrayList<IUsageHandler> handlers) {
super(NEIClientUtils.mc().currentScreen);
this.currenthandlers = handlers;
}

public static ArrayList<IUsageHandler> getUsageHandlers(String inputId, Object... ingredients) {

final RecipeHandlerQuery<IUsageHandler> recipeQuery = new RecipeHandlerQuery<>(
h -> getUsageOrCatalystHandler(h, inputId, ingredients),
usagehandlers,
serialUsageHandlers,
"Error while looking up usage recipe",
"inputId: " + inputId,
"ingredients: " + Arrays.toString(ingredients));
ArrayList<IUsageHandler> handlers = recipeQuery.runWithProfiling("recipe.concurrent.usage");
if (handlers.isEmpty()) return false;

Minecraft mc = NEIClientUtils.mc();
BookmarkRecipeId recipeId = getCurrentRecipe(mc.currentScreen);
GuiUsageRecipe gui = new GuiUsageRecipe(handlers);

mc.displayGuiScreen(gui);
gui.openTargetRecipe(recipeId);

return true;
return recipeQuery.runWithProfiling("recipe.concurrent.usage");
}

private GuiUsageRecipe(ArrayList<IUsageHandler> handlers) {
super(NEIClientUtils.mc().currentScreen);
this.currenthandlers = handlers;
private static ItemStack normalizeItemStack(ItemStack stack) {
GTFluidStackStringifyHandler.replaceAE2FCFluidDrop = true;
stack = StackInfo.loadFromNBT(StackInfo.itemStackToNBT(stack));
GTFluidStackStringifyHandler.replaceAE2FCFluidDrop = false;
return stack;
}

public static void registerUsageHandler(IUsageHandler handler) {
Expand Down

0 comments on commit 1bcb711

Please sign in to comment.