From 2ea9ae1eb9f7d3ffff80f6dc15796ab4e725fab6 Mon Sep 17 00:00:00 2001 From: slprime <31038811+slprime@users.noreply.github.com> Date: Thu, 9 Oct 2025 22:22:37 +0300 Subject: [PATCH] Show Handler Icon in Bookmarks (#747) --- .../java/codechicken/nei/BookmarkPanel.java | 12 ++-- .../java/codechicken/nei/NEIClientConfig.java | 4 ++ .../nei/bookmark/BookmarksGridSlot.java | 67 +++++++++++++++++-- src/main/resources/assets/nei/lang/en_US.lang | 6 +- src/main/resources/assets/nei/lang/ru_RU.lang | 2 +- 5 files changed, 77 insertions(+), 14 deletions(-) diff --git a/src/main/java/codechicken/nei/BookmarkPanel.java b/src/main/java/codechicken/nei/BookmarkPanel.java index aea50851..c89473ef 100644 --- a/src/main/java/codechicken/nei/BookmarkPanel.java +++ b/src/main/java/codechicken/nei/BookmarkPanel.java @@ -185,22 +185,24 @@ public class BookmarkPanel extends PanelWidget { && this.grid.existsRecipe(recipeId, BookmarkGrid.DEFAULT_GROUP_ID); final NBTTagCompound nbTag = StackInfo.itemStackToNBT(itemStack); long factor = nbTag.getInteger("Count"); + long count = factor; if (existsRecipe) { - for (int i = 0; i < this.grid.size(); i++) { if (this.grid.getBookmarkItem(i).equalsRecipe(recipeId, groupId)) { - final long multiplier = this.grid.getBookmarkItem(i).getMultiplier(); - factor *= multiplier; + count *= this.grid.getBookmarkItem(i).getMultiplier(); break; } } + } - } else { + if (factor == 0) { factor = nbTag.hasKey("gtFluidName") ? Math.min(144, nbTag.getInteger("Count")) : 1; } - this.grid.addItem(BookmarkItem.of(groupId, itemStack, factor, recipeId, false), true); + this.grid.addItem( + BookmarkItem.of(groupId, StackInfo.withAmount(itemStack, count), factor, recipeId, false), + true); return true; } diff --git a/src/main/java/codechicken/nei/NEIClientConfig.java b/src/main/java/codechicken/nei/NEIClientConfig.java index 57e1016a..cd6c3dc0 100644 --- a/src/main/java/codechicken/nei/NEIClientConfig.java +++ b/src/main/java/codechicken/nei/NEIClientConfig.java @@ -209,6 +209,10 @@ public class NEIClientConfig { 0, OptionIntegerField.UNSIGNED_INT_MAX)); + tag.getTag("inventory.bookmarks.showRecipeHandlerIcon").setComment("Show Recipe Handler Icon") + .getBooleanValue(false); + API.addOption(new OptionToggleButton("inventory.bookmarks.showRecipeHandlerIcon", true)); + tag.getTag("inventory.bookmarks.recipeChainDir").getIntValue(1); API.addOption(new OptionCycled("inventory.bookmarks.recipeChainDir", 2, true)); diff --git a/src/main/java/codechicken/nei/bookmark/BookmarksGridSlot.java b/src/main/java/codechicken/nei/bookmark/BookmarksGridSlot.java index 4203a663..1b6f61ed 100644 --- a/src/main/java/codechicken/nei/bookmark/BookmarksGridSlot.java +++ b/src/main/java/codechicken/nei/bookmark/BookmarksGridSlot.java @@ -4,6 +4,8 @@ import java.awt.Color; import net.minecraft.item.ItemStack; +import org.lwjgl.opengl.GL11; + import codechicken.lib.vec.Rectangle4i; import codechicken.nei.BookmarkPanel.BookmarkViewMode; import codechicken.nei.ItemPanels; @@ -14,6 +16,9 @@ import codechicken.nei.NEIClientUtils; import codechicken.nei.NEIClientUtils.Alignment; import codechicken.nei.bookmark.BookmarkGrid.BookmarkMouseContext; import codechicken.nei.bookmark.RecipeChainDetails.CalculatedType; +import codechicken.nei.guihook.GuiContainerManager; +import codechicken.nei.recipe.GuiRecipeTab; +import codechicken.nei.recipe.HandlerInfo; import codechicken.nei.recipe.Recipe.RecipeId; import codechicken.nei.recipe.StackInfo; import codechicken.nei.util.ReadableNumberConverter; @@ -51,6 +56,7 @@ public class BookmarksGridSlot extends ItemsGridSlot { protected final CalculatedType calculatedType; protected final CalculatedType realType; protected final BookmarkItem bookmarkItem; + protected HandlerInfo handlerInfo = null; protected final boolean isOutputRecipe; protected final boolean isFirstOutput; @@ -175,6 +181,13 @@ public class BookmarksGridSlot extends ItemsGridSlot { && mouseContext.recipeId.equals(this.group.crafting.itemToRecipe.get(this.itemIndex)); } + protected HandlerInfo getHandlerInfo() { + if (this.bookmarkItem.recipeId != null && this.handlerInfo == null) { + this.handlerInfo = GuiRecipeTab.getHandlerInfo(this.bookmarkItem.recipeId.getHandleName(), null); + } + return this.handlerInfo; + } + @Override public void drawItem(Rectangle4i rect) { super.drawItem(this.emptyItemStack, rect); @@ -255,27 +268,67 @@ public class BookmarksGridSlot extends ItemsGridSlot { drawMarker( rect, "x" + ReadableNumberConverter.INSTANCE.toWideReadableForm(this.realMultiplier), - 0xFFFFFF); + 0xFFFFFF, + Alignment.TopLeft); } else if (shownItemType == ShownItemType.SHIFT) { - drawMarker(rect, "x" + ReadableNumberConverter.INSTANCE.toWideReadableForm(getMultiplier()), 0xFFFFFF); + drawMarker( + rect, + "x" + ReadableNumberConverter.INSTANCE.toWideReadableForm(getMultiplier()), + 0xFFFFFF, + Alignment.TopLeft); } else if (this.isOutputRecipe || this.realMultiplier > 1) { drawMarker( rect, "x" + ReadableNumberConverter.INSTANCE.toWideReadableForm(this.realMultiplier), - NEIClientConfig.getSetting("inventory.bookmarks.recipeMarkerColor").getHexValue()); + NEIClientConfig.getSetting("inventory.bookmarks.recipeMarkerColor").getHexValue(), + Alignment.TopLeft); + } + + if (NEIClientConfig.getBooleanSetting("inventory.bookmarks.showRecipeHandlerIcon") + && getHandlerInfo() != null) { + drawHandlerIcon(rect); } else if (NEIClientConfig.showRecipeMarkerMode() == 1) { drawMarker( rect, "R", - NEIClientConfig.getSetting("inventory.bookmarks.recipeMarkerColor").getHexValue()); + NEIClientConfig.getSetting("inventory.bookmarks.recipeMarkerColor").getHexValue(), + Alignment.TopRight); } + } else if (NEIClientConfig.showRecipeMarkerMode() == 1) { - drawMarker(rect, "R", NEIClientConfig.getSetting("inventory.bookmarks.recipeMarkerColor").getHexValue()); + drawMarker( + rect, + "R", + NEIClientConfig.getSetting("inventory.bookmarks.recipeMarkerColor").getHexValue(), + Alignment.TopRight); } } - protected void drawMarker(Rectangle4i rect, String text, int color) { + protected void drawHandlerIcon(Rectangle4i rect) { + float panelFactor = 1; + + if (rect.w != DEFAULT_SLOT_SIZE) { + panelFactor = (rect.w - 2) / (DEFAULT_SLOT_SIZE - 2); + } + + panelFactor *= 0.4f; + float x = rect.x + 2 + 16 - 16 * panelFactor; + + GL11.glTranslatef(x, rect.y, 0); + GL11.glScaled(panelFactor, panelFactor, 1.5f); + + if (this.handlerInfo.getImage() != null) { + this.handlerInfo.getImage().draw(0, 0); + } else { + GuiContainerManager.drawItem(0, 0, this.handlerInfo.getItemStack(), true, ""); + } + + GL11.glScaled(1f / panelFactor, 1f / panelFactor, 1f / 1.5f); + GL11.glTranslatef(-1 * x, -1 * rect.y, 0); + } + + protected void drawMarker(Rectangle4i rect, String text, int color, Alignment alignment) { final float panelFactor = (rect.w - 2) / (DEFAULT_SLOT_SIZE - 2); NEIClientUtils.drawNEIOverlayText( text, @@ -283,7 +336,7 @@ public class BookmarksGridSlot extends ItemsGridSlot { panelFactor, color, true, - Alignment.TopLeft); + alignment); } protected void drawStackSize(Rectangle4i rect, ShownItemType shownItemType) { diff --git a/src/main/resources/assets/nei/lang/en_US.lang b/src/main/resources/assets/nei/lang/en_US.lang index a02ea3cf..84af0002 100644 --- a/src/main/resources/assets/nei/lang/en_US.lang +++ b/src/main/resources/assets/nei/lang/en_US.lang @@ -229,8 +229,12 @@ nei.options.inventory.bookmarks.recipeTooltipsMode.2=In Vertical View nei.options.inventory.bookmarks.recipeTooltipsMode.3=Always nei.options.inventory.bookmarks.showRecipeMarkerMode=Show Recipe Marker nei.options.inventory.bookmarks.showRecipeMarkerMode.0=None -nei.options.inventory.bookmarks.showRecipeMarkerMode.1=Icon +nei.options.inventory.bookmarks.showRecipeMarkerMode.1=Text nei.options.inventory.bookmarks.showRecipeMarkerMode.2=Background +nei.options.inventory.bookmarks.showRecipeHandlerIcon=Show Handler Icon +nei.options.inventory.bookmarks.showRecipeHandlerIcon.true=Yes +nei.options.inventory.bookmarks.showRecipeHandlerIcon.false=No + nei.options.inventory.bookmarks.recipeMarkerColor=Recipe Marker Color nei.options.inventory.bookmarks.ignorePotionOverlap=Ignore overlap with potion effect HUD nei.options.inventory.bookmarks.ignorePotionOverlap.true=Yes diff --git a/src/main/resources/assets/nei/lang/ru_RU.lang b/src/main/resources/assets/nei/lang/ru_RU.lang index dd01cc7b..e900a25c 100644 --- a/src/main/resources/assets/nei/lang/ru_RU.lang +++ b/src/main/resources/assets/nei/lang/ru_RU.lang @@ -179,7 +179,7 @@ nei.options.inventory.bookmarks.recipeTooltipsMode.2=В вертикальном nei.options.inventory.bookmarks.recipeTooltipsMode.3=Всегда nei.options.inventory.bookmarks.showRecipeMarkerMode=Показывать маркер рецепта nei.options.inventory.bookmarks.showRecipeMarkerMode.0=Нет -nei.options.inventory.bookmarks.showRecipeMarkerMode.1=Иконка +nei.options.inventory.bookmarks.showRecipeMarkerMode.1=Текст nei.options.inventory.bookmarks.showRecipeMarkerMode.2=Фон nei.options.inventory.bookmarks.ignorePotionOverlap=Игнорировать перекрытие с HUD эффектов зелий nei.options.inventory.bookmarks.ignorePotionOverlap.true=Да