mirror of
https://github.com/GTNewHorizons/NotEnoughCharacters.git
synced 2026-11-27 23:45:54 +00:00
Merge pull request #2 from slprime/new_nei_search
This commit is contained in:
14 files changed
+204
-153
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")
|
||||
}
|
||||
+12
-1
@@ -76,6 +76,11 @@ accessTransformersFile =
|
||||
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
|
||||
usesMixins = false
|
||||
|
||||
# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main.
|
||||
# This can speed up compile times thanks to not running the mixin annotation processor on all input sources.
|
||||
# Mixin classes will have access to "main" classes, but not the other way around.
|
||||
separateMixinSourceSet =
|
||||
|
||||
# Adds some debug arguments like verbose output and class export.
|
||||
usesMixinDebug = false
|
||||
|
||||
@@ -108,9 +113,15 @@ minimizeShadowedDependencies = true
|
||||
# If disabled, won't rename the shadowed classes.
|
||||
relocateShadowedDependencies = true
|
||||
|
||||
# Adds the GTNH maven, CurseMaven, IC2/Player maven, and some more well-known 1.7.10 repositories.
|
||||
# Adds CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
|
||||
includeWellKnownRepositories = true
|
||||
|
||||
# A list of repositories to exclude from the includeWellKnownRepositories setting. Should be a space separated
|
||||
# list of strings, with the acceptable keys being(case does not matter):
|
||||
# cursemaven
|
||||
# modrinth
|
||||
excludeWellKnownRepositories =
|
||||
|
||||
# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven.
|
||||
# Authenticate with the MAVEN_USER and MAVEN_PASSWORD environment variables.
|
||||
# If you need a more complex setup disable maven publishing here and add a publishing repository to addon.gradle.
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
@@ -55,7 +57,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@@ -84,7 +86,8 @@ done
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
||||
' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
Vendored
+2
@@ -13,6 +13,8 @@
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
|
||||
+1
-1
@@ -17,5 +17,5 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.16'
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.27'
|
||||
}
|
||||
@@ -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