mirror of
https://github.com/GTNewHorizons/NotEnoughCharacters.git
synced 2026-11-28 23:58:52 +00:00
Update NEI Search Rules
This commit is contained in:
1 parent
ef3f2f7380
commit
fdf6b68b49
8 files changed
+183
-148
No files matched your search
+1
-1
@@ -35,5 +35,5 @@
|
||||
*/
|
||||
dependencies {
|
||||
shadowImplementation("com.github.Towdium:PinIn:1.6.0")
|
||||
devOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.5.24-GTNH:dev")
|
||||
devOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.6.38-GTNH:dev")
|
||||
}
|
||||
@@ -1,5 +1,15 @@
|
||||
package net.moecraft.nechar;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.client.resources.Language;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.vfyjxf.nechar.NechConfig;
|
||||
|
||||
import codechicken.nei.SearchTokenParser.ISearchParserProvider;
|
||||
import codechicken.nei.SearchTokenParser.SearchMode;
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.IConfigureNEI;
|
||||
|
||||
@@ -7,10 +17,42 @@ public class NEINecharConfig implements IConfigureNEI {
|
||||
|
||||
@Override
|
||||
public void loadConfig() {
|
||||
API.addSearchProvider(new NecharSearchProvider());
|
||||
final List<Language> matchingLanguages = getMatchingLanguages();
|
||||
|
||||
API.addSearchProvider(
|
||||
new NecharSearchParserProvider(
|
||||
'\0',
|
||||
"default",
|
||||
EnumChatFormatting.RESET,
|
||||
NecharDisplayFilter::new,
|
||||
matchingLanguages) {
|
||||
|
||||
@Override
|
||||
public SearchMode getSearchMode() {
|
||||
return SearchMode.ALWAYS;
|
||||
}
|
||||
|
||||
});
|
||||
API.addSearchProvider(
|
||||
new NecharSearchParserProvider(
|
||||
'#',
|
||||
"tooltip",
|
||||
EnumChatFormatting.YELLOW,
|
||||
NecharTooltipFilter::new,
|
||||
matchingLanguages));
|
||||
|
||||
NotEnoughCharacters.logger.info("search provider added!");
|
||||
}
|
||||
|
||||
protected List<Language> getMatchingLanguages() {
|
||||
return ISearchParserProvider.getAllLanguages()
|
||||
.stream()
|
||||
.filter(
|
||||
lang -> Arrays.stream(NechConfig.neiAllowedLanguages)
|
||||
.anyMatch(lang.getLanguageCode()::equals))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NotEnoughCharacters.ID;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package net.moecraft.nechar;
|
||||
|
||||
import static net.moecraft.nechar.NotEnoughCharacters.CONTEXT;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import codechicken.nei.ItemList.PatternItemFilter;
|
||||
|
||||
public class NecharDisplayFilter extends PatternItemFilter {
|
||||
|
||||
private final String searchText;
|
||||
|
||||
public NecharDisplayFilter(String searchText, Pattern pattern) {
|
||||
super(pattern);
|
||||
this.searchText = searchText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ItemStack itemStack) {
|
||||
String displayName = EnumChatFormatting.getTextWithoutFormattingCodes(itemStack.getDisplayName());
|
||||
|
||||
if (!displayName.isEmpty() && CONTEXT.contains(displayName, this.searchText)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (itemStack.hasDisplayName()) {
|
||||
displayName = EnumChatFormatting.getTextWithoutFormattingCodes(
|
||||
itemStack.getItem()
|
||||
.getItemStackDisplayName(itemStack));
|
||||
|
||||
if (displayName.isEmpty() && CONTEXT.contains(displayName, this.searchText)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return super.matches(itemStack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
package net.moecraft.nechar;
|
||||
|
||||
import static net.moecraft.nechar.NotEnoughCharacters.CONTEXT;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public class NecharSearchFilter implements ItemFilter {
|
||||
|
||||
protected boolean invalid = false;
|
||||
|
||||
protected String mod = null;
|
||||
protected String id = null;
|
||||
protected String dict = null;
|
||||
|
||||
protected List<String> keywords = new LinkedList<>();
|
||||
|
||||
public NecharSearchFilter(String searchText) {
|
||||
String[] pieces = searchText.split("\\s+");
|
||||
|
||||
for (String piece : pieces) {
|
||||
if (piece.isEmpty()) continue;
|
||||
|
||||
switch (piece.charAt(0)) {
|
||||
case '@':
|
||||
if (mod == null) {
|
||||
mod = piece.substring(1)
|
||||
.toLowerCase();
|
||||
continue;
|
||||
} else {
|
||||
invalid = true;
|
||||
return;
|
||||
}
|
||||
|
||||
case '&':
|
||||
if (id == null) {
|
||||
id = piece.substring(1)
|
||||
.toLowerCase();
|
||||
continue;
|
||||
} else {
|
||||
invalid = true;
|
||||
return;
|
||||
}
|
||||
|
||||
case '$':
|
||||
if (dict == null) {
|
||||
dict = piece.substring(1)
|
||||
.toLowerCase();
|
||||
continue;
|
||||
} else {
|
||||
invalid = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
keywords.add(piece);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ItemStack itemStack) {
|
||||
return !invalid && matchesMod(itemStack)
|
||||
&& matchesId(itemStack)
|
||||
&& matchesDict(itemStack)
|
||||
&& matchesKeywords(itemStack);
|
||||
}
|
||||
|
||||
protected boolean matchesMod(ItemStack itemStack) {
|
||||
if (mod == null || mod.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
GameRegistry.UniqueIdentifier itemId = GameRegistry.findUniqueIdentifierFor(itemStack.getItem());
|
||||
|
||||
return itemId != null && itemId.modId.toLowerCase()
|
||||
.contains(mod);
|
||||
}
|
||||
|
||||
protected boolean matchesId(ItemStack itemStack) {
|
||||
if (id == null || id.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String itemId = Item.itemRegistry.getNameForObject(itemStack.getItem());
|
||||
|
||||
return itemId.toLowerCase()
|
||||
.contains(id);
|
||||
}
|
||||
|
||||
protected boolean matchesDict(ItemStack itemStack) {
|
||||
if (dict == null || dict.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int[] oreIds = OreDictionary.getOreIDs(itemStack);
|
||||
|
||||
for (int id : oreIds) {
|
||||
if (OreDictionary.getOreName(id)
|
||||
.toLowerCase()
|
||||
.contains(dict)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean matchesKeywords(ItemStack itemStack) {
|
||||
if (keywords == null || keywords.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String name = ItemInfo.getSearchName(itemStack);
|
||||
for (String keyword : keywords) {
|
||||
if (!CONTEXT.contains(name, keyword)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package net.moecraft.nechar;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.client.resources.Language;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import codechicken.nei.ItemList.NothingItemFilter;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.SearchField;
|
||||
import codechicken.nei.SearchTokenParser.ISearchParserProvider;
|
||||
import codechicken.nei.SearchTokenParser.SearchMode;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
|
||||
public class NecharSearchParserProvider implements ISearchParserProvider {
|
||||
|
||||
protected final List<Language> matchingLanguages;
|
||||
protected final BiFunction<String, Pattern, ItemFilter> createFilter;
|
||||
protected final String name;
|
||||
protected final char prefix;
|
||||
protected final EnumChatFormatting highlightedColor;
|
||||
|
||||
public NecharSearchParserProvider(char prefix, String name, EnumChatFormatting highlightedColor,
|
||||
BiFunction<String, Pattern, ItemFilter> createFilter, List<Language> matchingLanguages) {
|
||||
this.prefix = prefix;
|
||||
this.name = name;
|
||||
this.highlightedColor = highlightedColor;
|
||||
this.createFilter = createFilter;
|
||||
this.matchingLanguages = matchingLanguages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemFilter getFilter(String searchText) {
|
||||
Pattern pattern = SearchField.getPattern(searchText);
|
||||
|
||||
if (pattern != null) {
|
||||
final ItemFilter filter = this.createFilter.apply(searchText, pattern);
|
||||
return filter == null ? new NothingItemFilter() : filter;
|
||||
}
|
||||
|
||||
return new NothingItemFilter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Language> getMatchingLanguages() {
|
||||
return this.matchingLanguages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumChatFormatting getHighlightedColor() {
|
||||
return this.highlightedColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchMode getSearchMode() {
|
||||
return SearchMode.fromInt(NEIClientConfig.getIntSetting("inventory.search." + this.name + "SearchMode"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package net.moecraft.nechar;
|
||||
|
||||
import codechicken.nei.SearchField;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
|
||||
public class NecharSearchProvider implements SearchField.ISearchProvider {
|
||||
|
||||
@Override
|
||||
public boolean isPrimary() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemFilter getFilter(String searchText) {
|
||||
return new NecharSearchFilter(searchText);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.moecraft.nechar;
|
||||
|
||||
import static net.moecraft.nechar.NotEnoughCharacters.CONTEXT;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import codechicken.nei.search.TooltipFilter;
|
||||
|
||||
public class NecharTooltipFilter extends TooltipFilter {
|
||||
|
||||
private final String searchText;
|
||||
|
||||
public NecharTooltipFilter(String searchText, Pattern pattern) {
|
||||
super(pattern);
|
||||
this.searchText = searchText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ItemStack itemStack) {
|
||||
return CONTEXT.contains(getSearchTooltip(itemStack), this.searchText) || super.matches(itemStack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ public class NechConfig {
|
||||
public static boolean EnableFEng2En = false;
|
||||
public static boolean EnableFU2V = false;
|
||||
public static Spell KeyboardType = Spell.QUANPIN;
|
||||
public static String[] neiAllowedLanguages = new String[0];
|
||||
public static String[] transformerRegExpAdditionalList = new String[0];
|
||||
public static String[] transformerStringAdditionalList = new String[0];
|
||||
public static String[] transformerMethodBlackList = new String[0];
|
||||
@@ -142,6 +143,11 @@ public class NechConfig {
|
||||
KeyboardType = Spell.QUANPIN;
|
||||
}
|
||||
|
||||
// nei
|
||||
neiAllowedLanguages = config
|
||||
.get("nei", "allowedLanguages", new String[] { "zh_CN", "zh_TW" }, "List of languages PinIn is used for")
|
||||
.getStringList();
|
||||
|
||||
if (config.hasChanged()) config.save();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user