Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small Fixes #543

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
246 changes: 162 additions & 84 deletions src/main/java/codechicken/nei/NEIClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<Character, Character>> typeToken = new TypeToken<Map<Character, Character>>() {

private static final long serialVersionUID = 1L;
};
Map<Character, Character> 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));
Expand Down Expand Up @@ -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<Map<Character, Character>> typeToken = new TypeToken<Map<Character, Character>>() {

private static final long serialVersionUID = 1L;
};
Map<Character, Character> 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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/codechicken/nei/SearchTokenParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/codechicken/nei/SubsetWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/codechicken/nei/api/ItemInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,6 @@ public static List<String> getText(ItemStack itemStack, World world, EntityPlaye

@Deprecated
public static String getSearchName(ItemStack stack) {
return GuiContainerManager.concatenatedDisplayName(stack, true);
return GuiContainerManager.concatenatedDisplayName(stack, true).toLowerCase();
}
}
3 changes: 3 additions & 0 deletions src/main/java/codechicken/nei/config/OptionUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
}
2 changes: 1 addition & 1 deletion src/main/resources/assets/nei/cfg/enableautofocus.cfg
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions src/main/resources/assets/nei/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down