mirror of
https://github.com/GTNewHorizons/Applied-Energistics-2-Unofficial.git
synced 2026-10-26 14:25:20 +00:00
Add Search Cache to Terminal (#621)
Co-authored-by: slprime <history-21@yandex.ru> Co-authored-by: Maya <10861407+serenibyss@users.noreply.github.com>
This commit is contained in:
3 files changed
+42
-34
No files matched your search
@@ -909,11 +909,13 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
|
||||
final NBTTagList tags = encodedValue.getTagList(in ? "in" : "out", NBT.TAG_COMPOUND);
|
||||
final boolean containsInvalidDisplayName = GuiText.UnknownItem.getLocal().toLowerCase().contains(searchTerm);
|
||||
Predicate<ItemStack> itemFilter = (is) -> Platform
|
||||
.getItemDisplayName(AEApi.instance().storage().createItemStack(is)).toLowerCase().contains(searchTerm);
|
||||
Predicate<ItemStack> itemFilter;
|
||||
|
||||
if (NEI.searchField.existsSearchField()) {
|
||||
itemFilter = NEI.searchField.getFilter(searchTerm);
|
||||
} else {
|
||||
itemFilter = is -> Platform.getItemDisplayName(AEApi.instance().storage().createItemStack(is)).toLowerCase()
|
||||
.contains(searchTerm);
|
||||
}
|
||||
|
||||
for (int i = 0; i < tags.tagCount(); i++) {
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
package appeng.client.me;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -52,6 +54,7 @@ public class ItemRepo implements IDisplayRepo {
|
||||
private int rowSize = 9;
|
||||
|
||||
private String searchString = "";
|
||||
private Map<IAEItemStack, Boolean> searchCache = new WeakHashMap<>();
|
||||
private IPartitionList<IAEItemStack> myPartitionList;
|
||||
private boolean hasPower;
|
||||
|
||||
@@ -108,22 +111,32 @@ public class ItemRepo implements IDisplayRepo {
|
||||
|
||||
final Enum viewMode = this.sortSrc.getSortDisplay();
|
||||
final Enum typeFilter = this.sortSrc.getTypeFilter();
|
||||
Predicate<IAEItemStack> itemFilter;
|
||||
Predicate<IAEItemStack> itemFilter = null;
|
||||
|
||||
if (NEI.searchField.existsSearchField()) {
|
||||
final Predicate<ItemStack> neiFilter = NEI.searchField.getFilter(this.searchString);
|
||||
itemFilter = is -> neiFilter.test(is.getItemStack());
|
||||
} else {
|
||||
itemFilter = getFilter(this.searchString);
|
||||
}
|
||||
|
||||
if (itemFilter == null) {
|
||||
return;
|
||||
if (!this.searchString.trim().isEmpty()) {
|
||||
if (NEI.searchField.existsSearchField()) {
|
||||
final Predicate<ItemStack> neiFilter = NEI.searchField.getFilter(this.searchString);
|
||||
itemFilter = is -> neiFilter.test(is.getItemStack());
|
||||
} else {
|
||||
itemFilter = getFilter(this.searchString);
|
||||
}
|
||||
}
|
||||
|
||||
IItemDisplayRegistry registry = AEApi.instance().registries().itemDisplay();
|
||||
|
||||
out: for (IAEItemStack is : this.list) {
|
||||
if (viewMode == ViewItems.CRAFTABLE && !is.isCraftable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (viewMode == ViewItems.STORED && is.getStackSize() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this.myPartitionList != null && !this.myPartitionList.isListed(is)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (registry.isBlacklisted(is.getItem()) || registry.isBlacklisted(is.getItem().getClass())) {
|
||||
continue;
|
||||
}
|
||||
@@ -132,24 +145,13 @@ public class ItemRepo implements IDisplayRepo {
|
||||
if (!filter.test((TypeFilter) typeFilter, is)) continue out;
|
||||
}
|
||||
|
||||
if (this.myPartitionList != null && !this.myPartitionList.isListed(is)) {
|
||||
continue;
|
||||
}
|
||||
if (itemFilter == null || Boolean.TRUE.equals(this.searchCache.computeIfAbsent(is, itemFilter::test))) {
|
||||
|
||||
if (viewMode == ViewItems.CRAFTABLE && !is.isCraftable()) {
|
||||
continue;
|
||||
}
|
||||
if (viewMode == ViewItems.CRAFTABLE) {
|
||||
is = is.copy();
|
||||
is.setStackSize(0);
|
||||
}
|
||||
|
||||
if (viewMode == ViewItems.CRAFTABLE) {
|
||||
is = is.copy();
|
||||
is.setStackSize(0);
|
||||
}
|
||||
|
||||
if (viewMode == ViewItems.STORED && is.getStackSize() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (itemFilter.test(is)) {
|
||||
this.view.add(is);
|
||||
}
|
||||
}
|
||||
@@ -262,13 +264,17 @@ public class ItemRepo implements IDisplayRepo {
|
||||
|
||||
@Override
|
||||
public void setSearchString(@Nonnull final String searchString) {
|
||||
this.searchString = searchString;
|
||||
if (!searchString.equals(this.searchString)) {
|
||||
this.searchString = searchString;
|
||||
this.searchCache.clear();
|
||||
|
||||
if (NEI.searchField.existsSearchField()) {
|
||||
final Enum searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
|
||||
if (searchMode == SearchBoxMode.NEI_AUTOSEARCH || searchMode == SearchBoxMode.NEI_MANUAL_SEARCH) {
|
||||
NEI.searchField.setText(this.searchString);
|
||||
if (NEI.searchField.existsSearchField()) {
|
||||
final Enum searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
|
||||
if (searchMode == SearchBoxMode.NEI_AUTOSEARCH || searchMode == SearchBoxMode.NEI_MANUAL_SEARCH) {
|
||||
NEI.searchField.setText(this.searchString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public class NEISearchField {
|
||||
|
||||
if (searchField != null) {
|
||||
final ItemFilter filter = searchField.getFilter(filterText);
|
||||
return stack -> filter.matches(stack);
|
||||
return filter::matches;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user