mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-12 16:37:45 +00:00
Added show all handlers and recipes function (#852)
Co-authored-by: Martin Robertz <dream-master@gmx.net>
This commit is contained in:
1 parent
06d4a96c3a
commit
900b9f90e7
4 files changed
+83
-6
No files matched your search
@@ -21,6 +21,7 @@ import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.bookmark.BookmarkItem.BookmarkItemType;
|
||||
import codechicken.nei.bookmark.BookmarksGridSlot;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler.RecipeTransferRect;
|
||||
|
||||
public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
|
||||
|
||||
@@ -77,7 +78,9 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
|
||||
ArrayList<ICraftingHandler> serialCraftingHandlers = GuiCraftingRecipe.serialCraftingHandlers;
|
||||
UnaryOperator<ICraftingHandler> recipeHandlerFunction;
|
||||
|
||||
if ("recipeId".equals(outputId)) {
|
||||
if ("all".equals(outputId)) {
|
||||
recipeHandlerFunction = GuiCraftingRecipe::buildAllRecipesHandler;
|
||||
} else if ("recipeId".equals(outputId)) {
|
||||
ItemStack stack = (ItemStack) results[0];
|
||||
RecipeId recipeId = (RecipeId) results[1];
|
||||
craftinghandlers = filterByHandlerName(craftinghandlers, recipeId.getHandleName());
|
||||
@@ -98,6 +101,24 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
|
||||
return recipeQuery.runWithProfiling(NEIClientUtils.translate("recipe.concurrent.crafting"));
|
||||
}
|
||||
|
||||
private static ICraftingHandler buildAllRecipesHandler(ICraftingHandler handler) {
|
||||
if (handler instanceof TemplateRecipeHandler templateHandler) {
|
||||
TemplateRecipeHandler allHandler = templateHandler.newInstance();
|
||||
if (allHandler.transferRects.isEmpty()) {
|
||||
allHandler.loadCraftingRecipes("all");
|
||||
return allHandler;
|
||||
}
|
||||
for (RecipeTransferRect rect : allHandler.transferRects) {
|
||||
if (allHandler.specifyTransferRect() == null
|
||||
|| allHandler.specifyTransferRect().equals(rect.outputId)) {
|
||||
allHandler.loadCraftingRecipes(rect.outputId, rect.results);
|
||||
return allHandler;
|
||||
}
|
||||
}
|
||||
}
|
||||
return handler.getRecipeHandler("all");
|
||||
}
|
||||
|
||||
private static ArrayList<ICraftingHandler> filterByHandlerName(ArrayList<ICraftingHandler> craftinghandlers,
|
||||
String handlerName) {
|
||||
return craftinghandlers.stream().filter(h -> getHandlerName(h).equals(handlerName))
|
||||
|
||||
@@ -17,6 +17,7 @@ import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -603,6 +604,15 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
return;
|
||||
}
|
||||
|
||||
if (button == 0 && isHandlerTitleHovered(mousex, mousey)) {
|
||||
if (this instanceof GuiCraftingRecipe) {
|
||||
GuiCraftingRecipe.openRecipeGui("all");
|
||||
} else if (this instanceof GuiUsageRecipe) {
|
||||
GuiUsageRecipe.openRecipeGui("all");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
super.mouseClicked(mousex, mousey, button);
|
||||
}
|
||||
|
||||
@@ -708,6 +718,10 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
this.recipeTabs.handleTooltip(mousex, mousey, currenttip);
|
||||
|
||||
if (currenttip.isEmpty() && isHandlerTitleHovered(mousex, mousey)) {
|
||||
currenttip.add(NEIClientUtils.translate("recipe.tab.view_all.tooltip"));
|
||||
}
|
||||
|
||||
if (currenttip.isEmpty() && GuiRecipe.searchField.isVisible()
|
||||
&& new Rectangle(GuiRecipe.searchField.x + GuiRecipe.searchField.w, 15, 44, 16)
|
||||
.contains(mousex - this.guiLeft, mousey - this.guiTop)) {
|
||||
@@ -822,9 +836,11 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
this.prevpage.yPosition + BUTTON_HEIGHT,
|
||||
0x30000000);
|
||||
|
||||
final String handlerTitle = this.handler.original.getRecipeName().trim();
|
||||
final String titleColorCode = getHandlerTitleColorCode(isHandlerTitleHovered(mouseX, mouseY));
|
||||
drawCenteredString(
|
||||
this.fontRendererObj,
|
||||
this.handler.original.getRecipeName().trim(),
|
||||
titleColorCode + handlerTitle + EnumChatFormatting.RESET,
|
||||
this.guiLeft + this.xSize / 2,
|
||||
this.prevtype.yPosition + textMiddle,
|
||||
0xffffff);
|
||||
@@ -872,6 +888,24 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isHandlerTitleHovered(int mousex, int mousey) {
|
||||
final String handlerTitle = this.handler.original.getRecipeName().trim();
|
||||
final int titleWidth = this.fontRendererObj.getStringWidth(handlerTitle);
|
||||
final int textMiddle = (BUTTON_WIDTH - this.fontRendererObj.FONT_HEIGHT) / 2;
|
||||
final int titleX = this.guiLeft + (this.xSize - titleWidth) / 2;
|
||||
final int titleY = this.prevtype.yPosition + textMiddle;
|
||||
return new Rectangle(titleX, titleY, titleWidth, this.fontRendererObj.FONT_HEIGHT).contains(mousex, mousey);
|
||||
}
|
||||
|
||||
private String getHandlerTitleColorCode(boolean hovered) {
|
||||
final String key = hovered ? "recipe.title.color.hover" : "recipe.title.color.normal";
|
||||
final String translated = NEIClientUtils.translate(key);
|
||||
if (!translated.startsWith("nei.")) { // Optional localization string for resource packs
|
||||
return translated;
|
||||
}
|
||||
return hovered ? EnumChatFormatting.YELLOW.toString() : EnumChatFormatting.WHITE.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiContainer getFirstScreen() {
|
||||
return this.firstGui;
|
||||
|
||||
@@ -12,6 +12,7 @@ import codechicken.nei.ItemPanels;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler.RecipeTransferRect;
|
||||
|
||||
public class GuiUsageRecipe extends GuiRecipe<IUsageHandler> {
|
||||
|
||||
@@ -38,12 +39,10 @@ public class GuiUsageRecipe extends GuiRecipe<IUsageHandler> {
|
||||
&& ingredients[0] instanceof ItemStack stack) {
|
||||
ItemPanels.itemPanel.historyPanel.addItem(stack);
|
||||
}
|
||||
|
||||
mc.displayGuiScreen(gui);
|
||||
gui.openTargetRecipe(recipeId);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -55,14 +54,36 @@ public class GuiUsageRecipe extends GuiRecipe<IUsageHandler> {
|
||||
public static ArrayList<IUsageHandler> getUsageHandlers(String inputId, Object... ingredients) {
|
||||
|
||||
final RecipeHandlerQuery<IUsageHandler> recipeQuery = new RecipeHandlerQuery<>(
|
||||
h -> getUsageOrCatalystHandler(h, inputId, ingredients),
|
||||
"all".equals(inputId) ? GuiUsageRecipe::buildAllRecipesHandler
|
||||
: h -> getUsageOrCatalystHandler(h, inputId, ingredients),
|
||||
GuiUsageRecipe.usagehandlers,
|
||||
GuiUsageRecipe.serialUsageHandlers,
|
||||
"Error while looking up usage recipe",
|
||||
"inputId: " + inputId,
|
||||
"ingredients: " + Arrays.toString(ingredients));
|
||||
|
||||
return recipeQuery.runWithProfiling(NEIClientUtils.translate("recipe.concurrent.usage"));
|
||||
ArrayList<IUsageHandler> handlers = recipeQuery
|
||||
.runWithProfiling(NEIClientUtils.translate("recipe.concurrent.usage"));
|
||||
return handlers;
|
||||
}
|
||||
|
||||
private static IUsageHandler buildAllRecipesHandler(IUsageHandler handler) {
|
||||
if (handler instanceof TemplateRecipeHandler templateHandler) {
|
||||
TemplateRecipeHandler allHandler = templateHandler.newInstance();
|
||||
if (allHandler.transferRects.isEmpty()) {
|
||||
allHandler.loadCraftingRecipes("all");
|
||||
return allHandler;
|
||||
}
|
||||
for (RecipeTransferRect rect : allHandler.transferRects) {
|
||||
if (allHandler.specifyTransferRect() == null
|
||||
|| allHandler.specifyTransferRect().equals(rect.outputId)) {
|
||||
allHandler.loadCraftingRecipes(rect.outputId, rect.results);
|
||||
return allHandler;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return handler.getUsageHandler("all");
|
||||
}
|
||||
|
||||
public static void registerUsageHandler(IUsageHandler handler) {
|
||||
|
||||
Reference in new issue
Block a user