Search item id with & prefix

This commit is contained in:
Balthild committed 2020-03-21 22:35:31 +08:00
1 parent e7fcbc1ffa
commit 848d7546f8
1 file changed
+21 -1
@@ -5,6 +5,7 @@ import codechicken.nei.api.ItemInfo;
import cpw.mods.fml.common.registry.GameRegistry;
import me.towdium.pinin.Keyboard;
import me.towdium.pinin.PinIn;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
@@ -18,7 +19,7 @@ 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<>();
@@ -40,6 +41,15 @@ public class NecharSearchFilter implements ItemFilter {
return;
}
case '&':
if (id == null) {
id = piece.substring(1).toLowerCase();
continue;
} else {
invalid = true;
return;
}
case '$':
if (dict == null) {
dict = piece.substring(1).toLowerCase();
@@ -58,6 +68,7 @@ public class NecharSearchFilter implements ItemFilter {
public boolean matches(ItemStack itemStack) {
return !invalid
&& matchesMod(itemStack)
&& matchesId(itemStack)
&& matchesDict(itemStack)
&& matchesKeywords(itemStack);
}
@@ -71,6 +82,15 @@ public class NecharSearchFilter implements ItemFilter {
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;