mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-13 00:47:35 +00:00
Clear Search Filter Cache after Change Settings (#569)
This commit is contained in:
1 parent
c305649b95
commit
6a787dd5b7
4 files changed
+76
-62
No files matched your search
@@ -432,7 +432,15 @@ public class NEIClientConfig {
|
||||
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));
|
||||
API.addOption(new OptionCycled("inventory.search.patternMode", 3, true) {
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
SearchField.searchParser.clearCache();
|
||||
return super.onClick(button);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
tag.getTag("inventory.search.quoteDropItemName").setComment("Quote Drop Item Name").getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButton("inventory.search.quoteDropItemName", true));
|
||||
@@ -458,6 +466,7 @@ public class NEIClientConfig {
|
||||
SearchField.searchParser.prefixRedefinitions.clear();
|
||||
SearchField.searchParser.prefixRedefinitions.put('%', '@');
|
||||
SearchField.searchParser.prefixRedefinitions.put('@', '%');
|
||||
SearchField.searchParser.clearCache();
|
||||
} else {
|
||||
NEIClientConfig.setIntSetting("inventory.search.modNameSearchMode", 1);
|
||||
NEIClientConfig.setIntSetting("inventory.search.tooltipSearchMode", 0);
|
||||
@@ -466,6 +475,7 @@ public class NEIClientConfig {
|
||||
NEIClientConfig.setIntSetting("inventory.search.subsetsSearchMode", 1);
|
||||
tag.getTag("inventory.search.prefixRedefinitions").setValue("{}");
|
||||
SearchField.searchParser.prefixRedefinitions.clear();
|
||||
SearchField.searchParser.clearCache();
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -477,6 +487,12 @@ public class NEIClientConfig {
|
||||
.getIntValue(1);
|
||||
API.addOption(new OptionCycled("inventory.search.modNameSearchMode", 3, true) {
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
SearchField.searchParser.clearCache();
|
||||
return super.onClick(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return translateN(
|
||||
@@ -496,6 +512,12 @@ public class NEIClientConfig {
|
||||
.getIntValue(0);
|
||||
API.addOption(new OptionCycled("inventory.search.tooltipSearchMode", 3, true) {
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
SearchField.searchParser.clearCache();
|
||||
return super.onClick(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return translateN(
|
||||
@@ -514,6 +536,12 @@ public class NEIClientConfig {
|
||||
.getIntValue(0);
|
||||
API.addOption(new OptionCycled("inventory.search.identifierSearchMode", 3, true) {
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
SearchField.searchParser.clearCache();
|
||||
return super.onClick(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return translateN(
|
||||
@@ -532,6 +560,12 @@ public class NEIClientConfig {
|
||||
.getIntValue(0);
|
||||
API.addOption(new OptionCycled("inventory.search.oreDictSearchMode", 3, true) {
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
SearchField.searchParser.clearCache();
|
||||
return super.onClick(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return translateN(
|
||||
@@ -550,6 +584,12 @@ public class NEIClientConfig {
|
||||
.getIntValue(1);
|
||||
API.addOption(new OptionCycled("inventory.search.subsetsSearchMode", 3, true) {
|
||||
|
||||
@Override
|
||||
public boolean onClick(int button) {
|
||||
SearchField.searchParser.clearCache();
|
||||
return super.onClick(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return translateN(
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -88,38 +87,7 @@ public class SearchTokenParser {
|
||||
}
|
||||
}
|
||||
|
||||
private static class ItemFilterCache implements ItemFilter {
|
||||
|
||||
public ItemFilter filter;
|
||||
private final ItemStackMap<Boolean> states = new ItemStackMap<>();
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
public ItemFilterCache(ItemFilter filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ItemStack item) {
|
||||
lock.lock();
|
||||
|
||||
try {
|
||||
Boolean match = states.get(item);
|
||||
|
||||
if (match == null) {
|
||||
states.put(item, match = this.filter.matches(item));
|
||||
}
|
||||
|
||||
return match;
|
||||
} catch (Throwable th) {
|
||||
th.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final LinkedHashMap<String, ItemFilter> filtersCache = new LinkedHashMap<>() {
|
||||
private final LinkedHashMap<String, ItemFilter> filtersCache = new LinkedHashMap<>() {
|
||||
|
||||
private static final long serialVersionUID = 1042213947848622164L;
|
||||
|
||||
@@ -144,6 +112,11 @@ public class SearchTokenParser {
|
||||
public void addProvider(ISearchParserProvider provider) {
|
||||
this.searchProviders.add(provider);
|
||||
this.providersCache.clear();
|
||||
this.filtersCache.clear();
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
this.filtersCache.clear();
|
||||
}
|
||||
|
||||
protected List<ISearchParserProvider> getProviders() {
|
||||
@@ -176,27 +149,24 @@ public class SearchTokenParser {
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public ItemFilter getFilter(String filterText) {
|
||||
public synchronized ItemFilter getFilter(String filterText) {
|
||||
filterText = EnumChatFormatting.getTextWithoutFormattingCodes(filterText).toLowerCase();
|
||||
|
||||
if (!filtersCache.containsKey(filterText)) {
|
||||
final String[] parts = EnumChatFormatting.getTextWithoutFormattingCodes(filterText).toLowerCase()
|
||||
.split("\\|");
|
||||
return this.filtersCache.computeIfAbsent(filterText, text -> {
|
||||
final String[] parts = text.split("\\|");
|
||||
final List<ItemFilter> searchTokens = Arrays.stream(parts).map(this::parseSearchText).filter(s -> s != null)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
if (searchTokens.isEmpty()) {
|
||||
filtersCache.put(filterText, new EverythingItemFilter());
|
||||
return new EverythingItemFilter();
|
||||
} else if (searchTokens.size() == 1) {
|
||||
filtersCache.put(filterText, new IsRegisteredItemFilter(new ItemFilterCache(searchTokens.get(0))));
|
||||
return new IsRegisteredItemFilter(searchTokens.get(0));
|
||||
} else {
|
||||
filtersCache.put(
|
||||
filterText,
|
||||
new IsRegisteredItemFilter(new ItemFilterCache(new AnyMultiItemFilter(searchTokens))));
|
||||
return new IsRegisteredItemFilter(new AnyMultiItemFilter(searchTokens));
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return filtersCache.get(filterText);
|
||||
}
|
||||
|
||||
public Pattern getSplitPattern() {
|
||||
|
||||
@@ -43,6 +43,7 @@ import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.ItemStackSet;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.SearchField;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
import codechicken.nei.search.TooltipFilter;
|
||||
import codechicken.nei.util.ReadableNumberConverter;
|
||||
@@ -55,6 +56,7 @@ public class GuiContainerManager {
|
||||
public void onResourceManagerReload(IResourceManager p_110549_1_) {
|
||||
renderingErrorItems.clear();
|
||||
TooltipFilter.populateSearchMap();
|
||||
SearchField.searchParser.clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package codechicken.nei.search;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -9,13 +8,12 @@ import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.ItemStackMap;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
|
||||
public class TooltipFilter implements ItemFilter {
|
||||
|
||||
private static final ItemStackMap<String> itemSearchNames = new ItemStackMap<>();
|
||||
private static final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
private final Pattern pattern;
|
||||
|
||||
@@ -36,28 +34,32 @@ public class TooltipFilter implements ItemFilter {
|
||||
}
|
||||
|
||||
protected static String getSearchTooltip(ItemStack stack) {
|
||||
lock.lock();
|
||||
String tooltip = itemSearchNames.get(stack);
|
||||
|
||||
try {
|
||||
String tooltip = itemSearchNames.get(stack);
|
||||
if (tooltip == null) {
|
||||
tooltip = getTooltip(stack.copy());
|
||||
|
||||
if (tooltip == null) {
|
||||
tooltip = getTooltip(stack.copy());
|
||||
synchronized (itemSearchNames) {
|
||||
itemSearchNames.put(stack, tooltip);
|
||||
}
|
||||
|
||||
return tooltip;
|
||||
} catch (Throwable th) {
|
||||
th.printStackTrace();
|
||||
return "";
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
private static String getTooltip(ItemStack itemstack) {
|
||||
final List<String> list = GuiContainerManager.itemDisplayNameMultiline(itemstack, null, true);
|
||||
return EnumChatFormatting.getTextWithoutFormattingCodes(String.join("\n", list.subList(1, list.size())));
|
||||
|
||||
try {
|
||||
List<String> namelist = itemstack.getTooltip(NEIClientUtils.mc().thePlayer, false);
|
||||
|
||||
if (namelist.size() > 1) {
|
||||
return EnumChatFormatting
|
||||
.getTextWithoutFormattingCodes(String.join("\n", namelist.subList(1, namelist.size())));
|
||||
}
|
||||
|
||||
} catch (Throwable ignored) {}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user