Open GuiRecipe: normalizeItemStack

This commit is contained in:
slprime committed 2024-02-03 18:10:44 +02:00
1 parent d64c270e3a
commit 1b60f0b3af
3 files changed
+48 -25

No files matched your search

@@ -20,8 +20,6 @@ import codechicken.nei.recipe.BookmarkRecipeId;
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 {
@@ -67,11 +65,11 @@ public abstract class ShortcutInputHandler {
}
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")) {
@@ -101,7 +99,6 @@ public abstract class ShortcutInputHandler {
if (stackover != null) {
final int button = Mouse.getEventButton();
stackover = stackover.copy();
if (button == 0) {
return GuiCraftingRecipe.openRecipeGui("item", stackover);
@@ -167,10 +164,4 @@ public abstract class ShortcutInputHandler {
return false;
}
private static ItemStack normalizeItemStack(ItemStack stack) {
GTFluidStackStringifyHandler.replaceAE2FCFluidDrop = true;
stack = StackInfo.loadFromNBT(StackInfo.itemStackToNBT(stack));
GTFluidStackStringifyHandler.replaceAE2FCFluidDrop = false;
return stack;
}
}
@@ -18,6 +18,7 @@ import codechicken.nei.ItemPanels;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;
public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
@@ -33,6 +34,7 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
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];
@@ -114,6 +116,13 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
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) {
@@ -4,9 +4,11 @@ import java.util.ArrayList;
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> {
@@ -14,29 +16,50 @@ public class GuiUsageRecipe extends GuiRecipe<IUsageHandler> {
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) {