From 36a2cafdacf896b7a9e6c06a2c237bdb916ef677 Mon Sep 17 00:00:00 2001 From: slprime <31038811+slprime@users.noreply.github.com> Date: Sun, 13 Oct 2024 23:00:06 +0300 Subject: [PATCH] Small Fixes (#543) Co-authored-by: slprime Co-authored-by: Martin Robertz --- .../java/codechicken/nei/NEIClientConfig.java | 246 ++++++++++++------ .../codechicken/nei/SearchTokenParser.java | 2 +- .../java/codechicken/nei/SubsetWidget.java | 3 +- .../java/codechicken/nei/api/ItemInfo.java | 2 +- .../nei/config/OptionUtilities.java | 3 + .../assets/nei/cfg/enableautofocus.cfg | 2 +- src/main/resources/assets/nei/lang/en_US.lang | 3 + 7 files changed, 173 insertions(+), 88 deletions(-) diff --git a/src/main/java/codechicken/nei/NEIClientConfig.java b/src/main/java/codechicken/nei/NEIClientConfig.java index 734141ab6..4b9ffd999 100644 --- a/src/main/java/codechicken/nei/NEIClientConfig.java +++ b/src/main/java/codechicken/nei/NEIClientConfig.java @@ -166,90 +166,7 @@ public boolean optionValid(int index) { API.addOption(new OptionGamemodes("inventory.gamemodes")); ItemSorter.initConfig(tag); - - tag.getTag("inventory.search.widgetPosition").setComment("Widget Position").getBooleanValue(true); - API.addOption(new OptionToggleButton("inventory.search.widgetPosition", true)); - - tag.getTag("inventory.search.widgetAutofocus") - .setComment( - "Focus Search Widget on Open, blurs/unfocuses on mouse move unless typing has started first") - .getIntValue(0); - API.addOption(new OptionCycled("inventory.search.widgetAutofocus", 3, true)); - - tag.getTag("inventory.search.patternMode").setComment("Search Mode").getIntValue(1); - API.addOption(new OptionCycled("inventory.search.patternMode", 3, true)); - - tag.getTag("inventory.search.quoteDropItemName").setComment("Quote Drop Item Name").getBooleanValue(true); - API.addOption(new OptionToggleButton("inventory.search.quoteDropItemName", true)); - - tag.getTag("inventory.search.modNameSearchMode").setComment("Search mode for Mod Names (prefix: @)") - .getIntValue(1); - API.addOption(new OptionCycled("inventory.search.modNameSearchMode", 3, true) { - - @Override - public String getButtonText() { - return translateN(name + "." + value(), EnumChatFormatting.LIGHT_PURPLE + "@"); - } - - }); - - tag.getTag("inventory.search.tooltipSearchMode").setComment("Search mode for Tooltips (prefix: #)") - .getIntValue(0); - API.addOption(new OptionCycled("inventory.search.tooltipSearchMode", 3, true) { - - @Override - public String getButtonText() { - return translateN(name + "." + value(), EnumChatFormatting.YELLOW + "#"); - } - - }); - - tag.getTag("inventory.search.identifierSearchMode").setComment("Search mode for identifier (prefix: &)") - .getIntValue(0); - API.addOption(new OptionCycled("inventory.search.identifierSearchMode", 3, true) { - - @Override - public String getButtonText() { - return translateN(name + "." + value(), EnumChatFormatting.GOLD + "&"); - } - - }); - - tag.getTag("inventory.search.oreDictSearchMode").setComment("Search mode for Tag Names (prefix: $)") - .getIntValue(0); - API.addOption(new OptionCycled("inventory.search.oreDictSearchMode", 3, true) { - - @Override - public String getButtonText() { - return translateN(name + "." + value(), EnumChatFormatting.AQUA + "$"); - } - - }); - - tag.getTag("inventory.search.subsetsSearchMode").setComment("Search mode for Item Subsets (prefix: %)") - .getIntValue(1); - API.addOption(new OptionCycled("inventory.search.subsetsSearchMode", 3, true) { - - @Override - public String getButtonText() { - return translateN(name + "." + value(), EnumChatFormatting.DARK_PURPLE + "%"); - } - - }); - - String prefixRedefinitions = tag.getTag("inventory.search.prefixRedefinitions").setComment( - "Redefine search prefixes by providing a char-to-char map (JSON). The keys are the original prefixes, the values the new ones. Example: { \"$\": \"€\", \"#\": \"+\", \"@\": \"°\", \"%\": \"!\" }") - .getValue("{}"); - try { - TypeToken> typeToken = new TypeToken>() { - - private static final long serialVersionUID = 1L; - }; - Map charMap = new Gson().fromJson(prefixRedefinitions, typeToken.getType()); - SearchField.searchParser.prefixRedefinitions.putAll(charMap); - } catch (JsonParseException e) { - logger.warn("Failed to convert prefix redefinitions from JSON to CharToCharMap:", e); - } + setInventorySearchDefaults(tag); tag.getTag("inventory.bookmarks.enabled").setComment("Enable/Disable Bookmark Panel").getBooleanValue(true); API.addOption(new OptionToggleButton("inventory.bookmarks.enabled", true)); @@ -502,6 +419,167 @@ public GuiOptionList getGui(GuiScreen parent, OptionList list, boolean world) { }); } + private static void setInventorySearchDefaults(ConfigTagParent tag) { + + tag.getTag("inventory.search.widgetPosition").setComment("Widget Position").getBooleanValue(true); + API.addOption(new OptionToggleButton("inventory.search.widgetPosition", true)); + + tag.getTag("inventory.search.widgetAutofocus") + .setComment( + "Focus Search Widget on Open, blurs/unfocuses on mouse move unless typing has started first") + .getIntValue(0); + API.addOption(new OptionCycled("inventory.search.widgetAutofocus", 3, true)); + + tag.getTag("inventory.search.patternMode").setComment("Search Mode").getIntValue(1); + API.addOption(new OptionCycled("inventory.search.patternMode", 3, true)); + + tag.getTag("inventory.search.quoteDropItemName").setComment("Quote Drop Item Name").getBooleanValue(true); + API.addOption(new OptionToggleButton("inventory.search.quoteDropItemName", true)); + + tag.getTag("inventory.search.format").setComment("Search Format (true: old format, false: custom format)") + .getBooleanValue(false); + API.addOption(new OptionToggleButton("inventory.search.format", true) { + + @Override + public boolean onClick(int button) { + + if (!super.onClick(button)) { + return false; + } + + if (state()) { + NEIClientConfig.setIntSetting("inventory.search.modNameSearchMode", 0); + NEIClientConfig.setIntSetting("inventory.search.tooltipSearchMode", 0); + NEIClientConfig.setIntSetting("inventory.search.identifierSearchMode", 0); + NEIClientConfig.setIntSetting("inventory.search.oreDictSearchMode", 0); + NEIClientConfig.setIntSetting("inventory.search.subsetsSearchMode", 1); + tag.getTag("inventory.search.prefixRedefinitions").setValue("{\"%\": \"@\", \"@\": \"%\"}"); + SearchField.searchParser.prefixRedefinitions.clear(); + SearchField.searchParser.prefixRedefinitions.put('%', '@'); + SearchField.searchParser.prefixRedefinitions.put('@', '%'); + } else { + NEIClientConfig.setIntSetting("inventory.search.modNameSearchMode", 1); + NEIClientConfig.setIntSetting("inventory.search.tooltipSearchMode", 0); + NEIClientConfig.setIntSetting("inventory.search.identifierSearchMode", 0); + NEIClientConfig.setIntSetting("inventory.search.oreDictSearchMode", 0); + NEIClientConfig.setIntSetting("inventory.search.subsetsSearchMode", 1); + tag.getTag("inventory.search.prefixRedefinitions").setValue("{}"); + SearchField.searchParser.prefixRedefinitions.clear(); + } + + return true; + } + + }); + + tag.getTag("inventory.search.modNameSearchMode").setComment("Search mode for Mod Names (prefix: @)") + .getIntValue(1); + API.addOption(new OptionCycled("inventory.search.modNameSearchMode", 3, true) { + + @Override + public String getButtonText() { + return translateN( + name + "." + value(), + EnumChatFormatting.LIGHT_PURPLE + + String.valueOf(SearchField.searchParser.getRedefinedPrefix('@'))); + } + + @Override + public boolean isEnabled() { + return !tag.getTag("inventory.search.format").getBooleanValue(); + } + + }); + + tag.getTag("inventory.search.tooltipSearchMode").setComment("Search mode for Tooltips (prefix: #)") + .getIntValue(0); + API.addOption(new OptionCycled("inventory.search.tooltipSearchMode", 3, true) { + + @Override + public String getButtonText() { + return translateN( + name + "." + value(), + EnumChatFormatting.YELLOW + String.valueOf(SearchField.searchParser.getRedefinedPrefix('#'))); + } + + @Override + public boolean isEnabled() { + return !tag.getTag("inventory.search.format").getBooleanValue(); + } + + }); + + tag.getTag("inventory.search.identifierSearchMode").setComment("Search mode for identifier (prefix: &)") + .getIntValue(0); + API.addOption(new OptionCycled("inventory.search.identifierSearchMode", 3, true) { + + @Override + public String getButtonText() { + return translateN( + name + "." + value(), + EnumChatFormatting.GOLD + String.valueOf(SearchField.searchParser.getRedefinedPrefix('&'))); + } + + @Override + public boolean isEnabled() { + return !tag.getTag("inventory.search.format").getBooleanValue(); + } + + }); + + tag.getTag("inventory.search.oreDictSearchMode").setComment("Search mode for Tag Names (prefix: $)") + .getIntValue(0); + API.addOption(new OptionCycled("inventory.search.oreDictSearchMode", 3, true) { + + @Override + public String getButtonText() { + return translateN( + name + "." + value(), + EnumChatFormatting.AQUA + String.valueOf(SearchField.searchParser.getRedefinedPrefix('$'))); + } + + @Override + public boolean isEnabled() { + return !tag.getTag("inventory.search.format").getBooleanValue(); + } + + }); + + tag.getTag("inventory.search.subsetsSearchMode").setComment("Search mode for Item Subsets (prefix: %)") + .getIntValue(1); + API.addOption(new OptionCycled("inventory.search.subsetsSearchMode", 3, true) { + + @Override + public String getButtonText() { + return translateN( + name + "." + value(), + EnumChatFormatting.DARK_PURPLE + + String.valueOf(SearchField.searchParser.getRedefinedPrefix('%'))); + } + + @Override + public boolean isEnabled() { + return !tag.getTag("inventory.search.format").getBooleanValue(); + } + + }); + + String prefixRedefinitions = tag.getTag("inventory.search.prefixRedefinitions").setComment( + "Redefine search prefixes by providing a char-to-char map (JSON). The keys are the original prefixes, the values the new ones. Example: { \"$\": \"€\", \"#\": \"+\", \"@\": \"°\", \"%\": \"!\" }") + .getValue("{}"); + try { + TypeToken> typeToken = new TypeToken>() { + + private static final long serialVersionUID = 1L; + }; + Map charMap = new Gson().fromJson(prefixRedefinitions, typeToken.getType()); + SearchField.searchParser.prefixRedefinitions.putAll(charMap); + } catch (JsonParseException e) { + logger.warn("Failed to convert prefix redefinitions from JSON to CharToCharMap:", e); + } + + } + private static void setDefaultKeyBindings() { API.addHashBind("gui.recipe", Keyboard.KEY_R); API.addHashBind("gui.usage", Keyboard.KEY_U); diff --git a/src/main/java/codechicken/nei/SearchTokenParser.java b/src/main/java/codechicken/nei/SearchTokenParser.java index c2c5f2273..c9722a5e8 100644 --- a/src/main/java/codechicken/nei/SearchTokenParser.java +++ b/src/main/java/codechicken/nei/SearchTokenParser.java @@ -159,7 +159,7 @@ public Pattern getSplitPattern() { return Pattern.compile("((-*)([" + Pattern.quote(prefixes.toString()) + "]*)(\\\".*?(?:\\\"|$)|\\S+))"); } - private char getRedefinedPrefix(char prefix) { + public char getRedefinedPrefix(char prefix) { if (this.prefixRedefinitions.containsKey(prefix)) { return this.prefixRedefinitions.get(prefix); } diff --git a/src/main/java/codechicken/nei/SubsetWidget.java b/src/main/java/codechicken/nei/SubsetWidget.java index 2e030751c..79b0f5941 100644 --- a/src/main/java/codechicken/nei/SubsetWidget.java +++ b/src/main/java/codechicken/nei/SubsetWidget.java @@ -73,7 +73,8 @@ protected void slotClicked(int slot, int button, int mx, int my, int count) { if (slot < sorted.size()) { SubsetTag tag = sorted.get(slot); if (NEIClientUtils.shiftKey()) { - LayoutManager.searchField.setText("%" + tag.fullname.replaceAll("\\s+", "")); + LayoutManager.searchField.setText( + SearchField.searchParser.getRedefinedPrefix('%') + tag.fullname.replaceAll("\\s+", "")); } else if (button == 0 && count >= 2) { SubsetWidget.showOnly(tag); } else { diff --git a/src/main/java/codechicken/nei/api/ItemInfo.java b/src/main/java/codechicken/nei/api/ItemInfo.java index e47234edc..256a2625d 100644 --- a/src/main/java/codechicken/nei/api/ItemInfo.java +++ b/src/main/java/codechicken/nei/api/ItemInfo.java @@ -499,6 +499,6 @@ public static List getText(ItemStack itemStack, World world, EntityPlaye @Deprecated public static String getSearchName(ItemStack stack) { - return GuiContainerManager.concatenatedDisplayName(stack, true); + return GuiContainerManager.concatenatedDisplayName(stack, true).toLowerCase(); } } diff --git a/src/main/java/codechicken/nei/config/OptionUtilities.java b/src/main/java/codechicken/nei/config/OptionUtilities.java index 236b20a85..c95294877 100644 --- a/src/main/java/codechicken/nei/config/OptionUtilities.java +++ b/src/main/java/codechicken/nei/config/OptionUtilities.java @@ -46,6 +46,8 @@ public void drawIcons() { x += 24; LayoutManager.drawIcon(x + 4, 4, new Image(132, 12, 12, 12)); x += 24; + + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); RenderHelper.enableGUIStandardItemLighting(); GL11.glEnable(GL12.GL_RESCALE_NORMAL); ItemStack sword = new ItemStack(Items.diamond_sword); @@ -55,5 +57,6 @@ public void drawIcons() { GuiContainerManager.drawItem(x + 2, 2, new ItemStack(Items.potionitem)); x += 24; GuiContainerManager.drawItem(x + 2, 2, new ItemStack(Blocks.stone)); + GL11.glPopAttrib(); } } diff --git a/src/main/resources/assets/nei/cfg/enableautofocus.cfg b/src/main/resources/assets/nei/cfg/enableautofocus.cfg index b52694157..568aeb5d3 100644 --- a/src/main/resources/assets/nei/cfg/enableautofocus.cfg +++ b/src/main/resources/assets/nei/cfg/enableautofocus.cfg @@ -1,5 +1,5 @@ # Each line in this file should either be a comment (line starts with '#'), or a prefix of a fully-qualified class name # (that includes the package name) for a Minecraft GUI Container screen. # If you delete this file, it will be regenerated with the default enable autofocus list. -net.minecraft.client.gui.inventory.GuiInventory +net.minecraft.client.gui. makamys.satchels.gui.GuiSatchelsInventory diff --git a/src/main/resources/assets/nei/lang/en_US.lang b/src/main/resources/assets/nei/lang/en_US.lang index ed685a677..6e79b0ce9 100644 --- a/src/main/resources/assets/nei/lang/en_US.lang +++ b/src/main/resources/assets/nei/lang/en_US.lang @@ -227,6 +227,9 @@ nei.options.inventory.search.patternMode.2=Regex nei.options.inventory.search.quoteDropItemName=Quote Drop Item Name nei.options.inventory.search.quoteDropItemName.true=Yes nei.options.inventory.search.quoteDropItemName.false=No +nei.options.inventory.search.format=Search Format +nei.options.inventory.search.format.true=Old Format +nei.options.inventory.search.format.false=Extended nei.options.inventory.search.modNameSearchMode=Mod Name Search nei.options.inventory.search.modNameSearchMode.0=Always nei.options.inventory.search.modNameSearchMode.1=Prefix: %s